<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[zenly blog - Medium]]></title>
        <description><![CDATA[zenly.com - Medium]]></description>
        <link>https://medium.com/zenlyapp?source=rss----af548b3cb007---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>zenly blog - Medium</title>
            <link>https://medium.com/zenlyapp?source=rss----af548b3cb007---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 09:30:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/zenlyapp" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Xcode 12.5 on macOS Monterey]]></title>
            <link>https://medium.com/zenlyapp/xcode-12-5-on-macos-monterey-23c257260316?source=rss----af548b3cb007---4</link>
            <guid isPermaLink="false">https://medium.com/p/23c257260316</guid>
            <category><![CDATA[bazel]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Steeve Morin]]></dc:creator>
            <pubDate>Mon, 15 Nov 2021 21:33:05 GMT</pubDate>
            <atom:updated>2021-12-01T14:39:34.855Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T9_d21jR1qlF-DaUVrg-WQ.jpeg" /></figure><p>So macOS Monterey shipped with a rather annoying peculiarity: <a href="https://twitter.com/ethanhuang13/status/1442123371416731651">it can only run Xcode ≥13.0</a>. This is a rather sobering realisation if for some reason you’re still stuck with Xcode 12.5 (for instance you can’t or don’t want to update your app’s SDK).</p><p>Now, it’s possible to launch the binary directly via Xcode-12.5.1.app/Contents/MacOS/Xcode, but this stopgap solution unfortunately doesn’t work with tools that rely on macOS’ Launch Services to figure out Xcode installations on the system, such as <a href="https://github.com/bazelbuild/bazel/blob/master/tools/osx/xcode_locator.m">bazel’s xcode_locator</a>, which relies on <a href="https://developer.apple.com/documentation/coreservices/1449290-lscopyapplicationurlsforbundleid?language=objc">LSCopyApplicationURLsForBundleIdentifier</a>. This tool exists because bazel can work with multiple Xcode versions on a given system without relying on xcode-select. See issues <a href="https://github.com/bazelbuild/bazel/issues/14037">#14037</a> and <a href="https://github.com/bazelbuild/bazel/issues/14174">#14174</a> for the dirty details.</p><p>Thankfully, it’s possible to fool the Launch Services daemon into accepting the bundle. Apparently Launch Services work with the CFBundleIdentifier + CFBundleVersion pair. This means we could fool Launch Services into thinking Xcode 12.5 is fine, piggybacking the fact that Xcode 13 was validated.</p><p>Here is the trick:</p><ul><li>Launch Xcode 13</li><li>Copy Xcode 13’s Info.plist CFBundleVersion to Xcode 12.5’s Info.plist</li><li>Launch the modified Xcode 12.5</li><li>Kill it, restore the original Xcode 12.5’s Info.plist</li><li>Launch Xcode 12.5 again (just in case)</li></ul><p>After this, Xcode 12.5 is properly detected by bazel’s xcode_locatorand can also be launched from the Finder or via open.</p><p>We have made a small script to automate this. Of course, use it at your own risk: <a href="https://gist.github.com/steeve/4e5d37ca9a07d4a796b909a6c9ae6156">https://gist.github.com/steeve/4e5d37ca9a07d4a796b909a6c9ae6156</a></p><p>Enjoy Monterey + Xcode 12.5!</p><h3>We are always hiring</h3><p>You knew this was coming. If you want to work on cool problems, reach out <a href="https://twitter.com/steeve">to me</a>/us, <a href="https://zen.ly/jobs">we have jobs open</a> and it’s always great to meet new people.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23c257260316" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenlyapp/xcode-12-5-on-macos-monterey-23c257260316">Xcode 12.5 on macOS Monterey</a> was originally published in <a href="https://medium.com/zenlyapp">zenly blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fast, cheap and globally accessible Bazel remote cache on Google Cloud Run & Storage]]></title>
            <link>https://medium.com/zenlyapp/fast-cheap-and-globally-accessible-bazel-remote-cache-on-google-cloud-run-storage-282e908df514?source=rss----af548b3cb007---4</link>
            <guid isPermaLink="false">https://medium.com/p/282e908df514</guid>
            <category><![CDATA[build]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-cloud-run]]></category>
            <category><![CDATA[bazel]]></category>
            <dc:creator><![CDATA[Steeve Morin]]></dc:creator>
            <pubDate>Thu, 04 Mar 2021 17:24:05 GMT</pubDate>
            <atom:updated>2021-03-11T19:45:47.474Z</atom:updated>
            <content:encoded><![CDATA[<p>Remote caching is one of Bazel’s strongest features. In this post, we’re introducing <a href="https://github.com/znly/bazel-cache">znly/bazel-cache</a> and describing how we deployed a fast (gRPC), cheap (scale to zero, automatic garbage collection) and globally accessible (TLS, authentication) Bazel remote cache.</p><h3>znly/bazel-cache</h3><p><a href="https://github.com/znly/bazel-cache">znly/bazel-cache</a> is a minimal, cloud oriented Bazel remote cache. It only supports Bazel’s <a href="https://github.com/bazelbuild/remote-apis/blob/master/build/bazel/remote/execution/v2/remote_execution.proto">v2 remote execution protocol over gRPC</a>. It was inspired by <a href="https://github.com/buchgr/bazel-remote">buchgr/bazel-remote</a>’s simplicity and accessibility.</p><p>It is meant to be deployed serverless-ly (currently on Cloud Run) and backed by an object storage (currently Google Cloud Storage). Of course we welcome PRs for other platforms. Thanks to Google Cloud Storage <a href="https://cloud.google.com/storage/docs/lifecycle">Object Lifecycle Management</a>, it features automatic TTL-based garbage collection.</p><h3>Bazel gRPC remote caching protocol</h3><p>Bazel implements remote caching over several protocols: HTTP/WebDAV, gRPC and Google Cloud Storage (which is HTTP really). We went with the <a href="https://github.com/bazelbuild/remote-apis/blob/master/build/bazel/remote/execution/v2/remote_execution.proto">v2 remote execution over gRPC</a>. It is a lot faster than the legacy ones, especially when combined with <a href="https://docs.bazel.build/versions/master/command-line-reference.html#flag--remote_download_toplevel">--remote_download_toplevel</a> a.k.a <a href="https://github.com/bazelbuild/bazel/issues/6862">Remote Builds without the Bytes</a>. Additionally, because gRPC is really HTTP/2, it is a lot less constrained by geographic imperatives for throughput based applications.</p><p>As an example, here is a fully cached build of @com_github_apple_swift_protobuf//:SwiftProtobuf with gRPC and HTTPS backed by the same GCS bucket on Bazel 4.0.0:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca83ba251d95591043d944f6e8a8fff4/href">https://medium.com/media/ca83ba251d95591043d944f6e8a8fff4/href</a></iframe><p>The reason it’s faster is mostly due to how the gRPC remote protocol works vs HTTP: it batches hashes lookups into one gRPC call, vs many HTTP calls. Not only that, but <a href="https://github.com/znly/bazel-cache">znly/bazel-cache</a> spawns multiple calls to GCS in parallel on a per-file basis. Finally, Cloud Run is much closer to GCS that our CI or developer machines are.</p><h3>Automatic Garbage Collection</h3><p>Garbage collection is automatic via Google Cloud Storage Object Lifecycle Management by setting a DaysSinceCustomTime + DeleteAction on the bucket when it is started.</p><p>When a hash is looked up by Bazel, <a href="https://github.com/znly/bazel-cache">znly/bazel-cache</a> will determine if the hash exists by updating its CustomTime. This means that testing if an object exists (and fetching its metadata such as size) and bumping its CustomTime happens in a single pass.</p><p>Because the CustomTime is bumped when testing if an object exists, only objects that haven’t been looked up in a while won’t get their CustomTime updated, and thus will be deleted by GCS. Effectively enabling garbage collection for free.</p><h3>Deploying on Google Cloud Run</h3><p>When deployed on Google Cloud Run, it will handle TLS, load balancing, scaling (down to zero) and authentication. This is standard Cloud Run really, but here goes.</p><h4>Creating the GCS Bucket</h4><p>First, create the GCS bucket in the same region your plan to deploy the container to (for optimised latency). We found the STANDARD class in a single region to be the best performing (YMMV):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8a871d8fa5757f14decf4ebfbbfb27b/href">https://medium.com/media/b8a871d8fa5757f14decf4ebfbbfb27b/href</a></iframe><h4>Creating a dedicated Service Account</h4><p>Create a service account that has the proper permissions to write to the bucket and administer it by adding the necessary roles to it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d807d581d14a46b7c17dc170227a8462/href">https://medium.com/media/d807d581d14a46b7c17dc170227a8462/href</a></iframe><h4>Pushing the Image</h4><p>Pull the <a href="https://github.com/znly/bazel-cache">znly/bazel-cache</a> image and push it to your project’s gcr.io registry:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/729ea5da0ea59d4b99f43c2e9141a23e/href">https://medium.com/media/729ea5da0ea59d4b99f43c2e9141a23e/href</a></iframe><h4>Deploying the service</h4><p>Once everything is done, deploy the bazel-cache service with the proper service account:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7c328f90df4f8923eea7d87959dc415/href">https://medium.com/media/e7c328f90df4f8923eea7d87959dc415/href</a></iframe><p>You’ll need to use the current beta track to enable the --use-http2, since gRPC streaming requires it (it works without, but can run into problems).</p><p>The service should appear in your Cloud Run console. It’s done!</p><figure><img alt="bazel-cache service running in Cloud Run" src="https://cdn-images-1.medium.com/max/1024/1*45n00X7IdvDx867v-6_51A.png" /><figcaption>bazel-cache is running in Cloud Run</figcaption></figure><h3>Authentication</h3><p>This one is tricky at the moment. <a href="https://cloud.google.com/run/docs/authenticating/developers">Cloud Run has builtin authentication</a>, and it’s perfect for that use case.</p><p>However, while Bazel supports Google Cloud’s Access Tokens via the<a href="https://docs.bazel.build/versions/master/command-line-reference.html#flag--google_credentials">--google_credentials</a> and <a href="https://docs.bazel.build/versions/master/command-line-reference.html#flag--google_default_credentials">--google_default_credentials</a> flags, <a href="https://cloud.google.com/run/docs/securing/service-identity">Cloud Run only supports Identity Tokens</a> as of the writing of this post. Bazel could support Identity Tokens natively, but it is not possible until <a href="https://github.com/googleapis/google-auth-library-java/pull/469">googleapis/google-auth-library-java#469</a> and <a href="https://github.com/bazelbuild/bazel/issues/12135">bazelbuild/bazel#12135</a> are fixed.</p><p>Thankfully, Bazel’s <a href="https://github.com/bazelbuild/bazel/blob/3.7.0/scripts/packages/bazel.sh">builtin wrapper support</a> makes it possible to invoke gcloud auth print-identity-token and pass the token via the <a href="https://docs.bazel.build/versions/master/command-line-reference.html#flag--remote_header">--remote_header</a> flag: when invoked, Bazel will look for an executable at tools/bazel in the workspace and, if it exists, will invoke it with a BAZEL_REAL environment pointing the actual Bazel binary.</p><p>By using the supplied <a href="https://github.com/znly/bazel-cache/blob/master/tools/bazel">tools/bazel</a> wrapper (made in Python), it will look for a --config=cache flag and invoke gcloud as needed. This is a tiny bit hackish, but it works well enough for us. Until native support in Bazel or Cloud Run, we are all ears for a cleaner solution.</p><h3>Enjoy!</h3><p>We have been running <a href="https://github.com/znly/bazel-cache">znly/bazel-cache</a> in production for our CI for a few months now and it has been working well, and most importantly, with zero maintenance.<br>Being able to use the CI cache over the public internet is also a great win since any developer can use it at will, no matter where they are.</p><h3>We are always hiring</h3><p>You knew this was coming. If you want to work on cool problems, reach out to me/us, <a href="https://zen.ly/jobs">we have jobs open</a> and it’s always great to meet new people. You could also check out our <a href="https://zen.ly/">maximalistic website</a>, that’d make a few folks over here happy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=282e908df514" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenlyapp/fast-cheap-and-globally-accessible-bazel-remote-cache-on-google-cloud-run-storage-282e908df514">Fast, cheap and globally accessible Bazel remote cache on Google Cloud Run &amp; Storage</a> was originally published in <a href="https://medium.com/zenlyapp">zenly blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scaling the Internationalization Process]]></title>
            <link>https://medium.com/zenlyapp/scaling-the-internationalization-process-53e6d2ebf361?source=rss----af548b3cb007---4</link>
            <guid isPermaLink="false">https://medium.com/p/53e6d2ebf361</guid>
            <category><![CDATA[i18n]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[localization]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Martin Moizard]]></dc:creator>
            <pubDate>Thu, 19 Nov 2020 12:27:48 GMT</pubDate>
            <atom:updated>2020-11-19T12:29:02.204Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Lessons from localizing Zenly for users around the world</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XlKCTpcTJghhNjxDLlZw9g.png" /></figure><p>Internationalization (i18n), the process of adapting your app to support multiple languages and regions, can be a really time-consuming process involving many different people (engineers, copywriters, translators, etc.). At Zenly, we’ve developed a number of workflows to enable us to support 30+ languages for our users all over the world. This blog post sets out the issues we faced as Zenly grew, and the tools and processes we developed along the way to help us scale our internationalization process.</p><p>If the project you’re working on grows and attracts users across many different languages, chances are you will face some of the following issues:</p><ul><li>Adding a new language/region becomes tedious: Zenly is supporting 30+ locales. As such adding/editing a translation implies editing 30+ files. 😅</li><li>Hard to know if everything in the app is translated in all of the supported languages.</li><li>Impossible to know if some translations are unused and still packaged.</li><li>Need to maintain enormous .xml (Android) or .strings (iOS) files.</li></ul><p>This post will go into detail on how we addressed each issue and built processes around it.</p><h3>Filling the gaps of the iOS platform</h3><p>Android provides a built-in way to statically reference translations keys using R.string.someKey. Out of the box, it provides a bunch of advantages:</p><ul><li>It’s impossible to point to a translation that does not exist, the compiler will output an error if you did a typo.</li><li>The IDE offers code completion even for translation keys.</li><li>And most of all, since the IDE warns you about unused symbols, you can know if one of your translation key is not used.</li></ul><p>On iOS, this is exactly the opposite. Natively, a key is referenced using a string: NSLocalizedString(&quot;someKey&quot;). As such, you can’t distinguish between a string used as a log from one used as a translation key. To fill in the gap between the Android and iOS platform, we decided to use <a href="https://github.com/mac-cain13/R.swift">R.swift</a> in our iOS project to get strong typed and autocompleted translations.</p><p>This plays perfectly well with our home made tool, let’s see how!</p><h3>Introducing Babbler</h3><p>Babbler is our internal tool that we use when dealing with Localization. It downloads all translations from PhraseApp (the external tool used to deal with translations), to create strings.xml files on Android and Localizable.strings files on iOS.</p><h3>Translated vs Untranslated</h3><p>Our project is organised in different modules, each of them containing these two files:</p><ul><li>strings_untranslated.xml (Android) or Untranslated.strings (iOS): list of keys that are not yet translated, but already used in the project.</li><li>.babbler: list of keys used in this module.</li></ul><p>Bundling those 2 files in each module allows each of our feature team to make all modules atomic and encapsulated. For instance, the “chat” module eventually contains only chat-related translations. Same for the “profile” module. In other words, it lets teams have full control and complete ownership of the translation a module contains.</p><h4>Untranslated</h4><p>Relying on an Untranslated file to define untranslated strings has many benefits:</p><ul><li>The i18n team just have to look at this file to know what’s left to be translated.</li><li>Software engineers are never blocked by the i18n team in case a translation is not ready. They can add entries to the Untranslated file whenever they want without the approval of the i18 team. This is crucial to avoid any friction and preserve developers’ velocity.</li><li>Translation strings are always referenced statically in the code source (even when not translated): with the compiler’s help, it makes it impossible to use a string that does not exist.</li></ul><p>Here is how the Untranslated file looks like in the iOS project 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfa1688f1005c71dfc33f62d9f61b586/href">https://medium.com/media/cfa1688f1005c71dfc33f62d9f61b586/href</a></iframe><h4>Translated</h4><p>Later in the process, when the i18n team is done with translating the necessary strings, only two simple things are required:</p><ul><li>Moving the key from the Untranslated file to .babbler</li><li>Running ./babbler</li></ul><p>And voilà! New translations are downloaded, linted, and dispatched to the appropriate module in the Android/iOS project.</p><h3><strong>What we love about Babbler ️♥</strong></h3><p>Babbler is a fairly lightweight tool and comes with a lot of benefits.<strong>️</strong></p><h4><strong>🔗 Ease up the translation process</strong></h4><p>Software engineers and the localization team have different processes, challenges and goals, which can make it hard for them to work together frictionlessly. To fix that, Babbler introduces a single point of contact between those two entities: the Untranslated files.</p><p>Software engineers simply add an entry in this file and, just like that, they’re done for the i18n part and can focus on other important aspects (architecture, UI design, performance, etc.). They don’t even have to agree on the new key name since the key name can easily be changed when the i18 team moves it to the .babbler file.</p><h4><strong>🦺 Safety net before the release</strong></h4><p>Checking the Untranslated files before a release is ✨golden✨. In a matter of seconds, Babbler is able to extract what is yet to be translated. The way to go is to have this step automated in the release pipeline of the CI and make the build fail if Babbler finds untranslated elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1eadd5982772d9fc1667aa9540da7f59/href">https://medium.com/media/1eadd5982772d9fc1667aa9540da7f59/href</a></iframe><h4><strong>📱Use the platform</strong></h4><p>We’re not reinventing the wheel: Babbler creates files that are natively supported by Android and iOS. The heavy work (resource switching based on the locale — language, region, variant — or pluralization) is consequently done by the platform.</p><h4><strong>☀️ Maintenance does not have to be painful</strong></h4><p>An application always evolves over time, so do the translations. Babbler really helps a lot to keep things simple, clean and tidy.</p><p><strong>Edition</strong>: when adding/removing a translation, only one line has to be changed in the .babbler file, then Babbler automatically updates 30+ files with the intended change.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0a35d884b525501e544923380a3124d/href">https://medium.com/media/c0a35d884b525501e544923380a3124d/href</a></iframe><p><strong>Clean up</strong>: Since we’re not doing Over The Air translations, we don’t have to worry about breaking things in old app versions. This makes it possible to clean things up on PhraseApp side. Babbler includes a helper for the i18 team to easily know what is exported by PhraseApp but not used in the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8dbea5a033df44bae7fbb8d605f524b/href">https://medium.com/media/b8dbea5a033df44bae7fbb8d605f524b/href</a></iframe><p><strong>Catch recurring mistakes</strong>: Babbler analyzes the downloaded translations and runs a series of checks to catch common mistakes. This really helps us to improve the overall quality of the translations we ship. As an example, we always make sure to replace ... with the ellipsis character …. Or in French, we replace &#39; with curly apostrophe character ’.</p><p>Thanks for reading ♥️! This is some insight into our process, but it can always be improved. If you have tips on how to scale the i18n of a mobile project, we’d love to hear from you!</p><p>🍦 PS — if you love building and improving technical processes that will impact millions of users around the world, please consider checking out our current <a href="https://zen.ly/jobs">job openings</a>.</p><blockquote>Martin is an iOS Developer at Zenly. He is part of the Conversation Team, bringing joy and lots of ice cream into the chat experience for Zenly users around the world every day.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53e6d2ebf361" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenlyapp/scaling-the-internationalization-process-53e6d2ebf361">Scaling the Internationalization Process</a> was originally published in <a href="https://medium.com/zenlyapp">zenly blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go & iOS: remember to enable Cocoa multithreading]]></title>
            <link>https://medium.com/zenlyapp/go-ios-remember-to-enable-cocoa-multithreading-95394491ad5e?source=rss----af548b3cb007---4</link>
            <guid isPermaLink="false">https://medium.com/p/95394491ad5e</guid>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[bazel]]></category>
            <dc:creator><![CDATA[Steeve Morin]]></dc:creator>
            <pubDate>Tue, 17 Nov 2020 16:13:08 GMT</pubDate>
            <atom:updated>2021-12-01T14:40:44.781Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QhgnMTz4g7bLKLNClo-LtA.png" /></figure><p>We do a lot of Go on iOS (and Android) at Zenly. We got bitten hard by this one.</p><p>When working with Go code and interfacing with Cocoa via CGo, any thread may call into the runtime. However, Cocoa isn’t multithreaded by default, and that mode needs to be <a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/20000738-125024">enabled explicitly</a>:</p><blockquote>For multithreaded applications, Cocoa frameworks use locks and other forms of internal synchronization to ensure they behave correctly. To prevent these locks from degrading performance in the single-threaded case, however, Cocoa does not create them until the application spawns its first new thread using the <a href="https://developer.apple.com/library/archive/documentation/LegacyTechnologies/WebObjects/WebObjects_3.5/Reference/Frameworks/ObjC/Foundation/Classes/NSThread/Description.html#//apple_ref/occ/cl/NSThread">NSThread</a> class. If you spawn threads using only POSIX thread routines, Cocoa does not receive the notifications it needs to know that your application is now multithreaded. When that happens, operations involving the Cocoa frameworks may destabilize or crash your application.</blockquote><blockquote>To let Cocoa know that you intend to use multiple threads, all you have to do is spawn a single thread using the NSThread class and let that thread immediately exit. Your thread entry point need not do anything. Just the act of spawning a thread using NSThread is enough to ensure that the locks needed by the Cocoa frameworks are put in place.</blockquote><blockquote>If you are not sure if Cocoa thinks your application is multithreaded or not, you can use the <a href="https://developer.apple.com/library/archive/documentation/LegacyTechnologies/WebObjects/WebObjects_3.5/Reference/Frameworks/ObjC/Foundation/Classes/NSThread/Description.html#//apple_ref/occ/clm/NSThread/isMultiThreaded">isMultiThreaded</a> method of NSThread to check.</blockquote><p>So Cocoa switches to this mode when a thread is started, and the minimum code to do that is:</p><pre>[[NSThread new] start];</pre><h3>Leveraging Go’s init chain</h3><p>To ensure that this is done before issuing calls to Cocoa, it is possible to leverage Go’s init chain by having a special iosinit package that is imported by all Go packages interfacing with Cocoa, and enable multithreading mode in its init method:</p><pre>package iosinit</pre><pre>/*<br>#cgo CFLAGS: -xobjective-c -fmodules -fobjc-arc</pre><pre>#import &lt;Foundation/Foundation.h&gt;</pre><pre>static inline void activate_cocoa_multithreading() {<br>    [[NSThread new] start];<br>}</pre><pre>#pragma GCC visibility push(hidden)<br>*/<br>import &quot;C&quot;</pre><pre>func init() {<br>    C.activate_cocoa_multithreading()<br>}</pre><p>Then, in packages interfacing with Cocoa, we can just add:</p><pre>package uiapplication</pre><pre>import (<br>    ...</pre><pre>    _ &quot;github.com/my/project/iosinit&quot;<br>)</pre><h3>Doing this automatically on Bazel</h3><p>When using Bazel, it is possible to define a macro that will code generate and inject a .go file at build-time doing the import, this will ensure that the iosinit package is imported by all packages using Cocoa. When using ios_go_library macro, the import will then be done automatically:</p><pre>load(&quot;<a href="http://twitter.com/io_bazel_rules_go">@io_bazel_rules_go</a>//go:def.bzl&quot;, &quot;go_library&quot;)</pre><pre>_IOSINIT_CMD = &quot;&quot;&quot;cat &lt;&lt;EOF &gt; $(@)<br>package {package}<br>import _ &quot;github.com/my/project/iosinit&quot;<br>EOF<br>&quot;&quot;&quot;</pre><pre>def ios_go_library(name, importpath, srcs = [], copts = [], deps = [], **kwargs):<br>    pkg = importpath.split(&quot;/&quot;)[-1]<br>    iosinit = name + &quot;.iosinit&quot;<br>    native.genrule(<br>        name = iosinit,<br>        outs = [iosinit + &quot;.go&quot;],<br>        cmd = _IOSINIT_CMD.format(package = pkg),<br>        tags = [&quot;manual&quot;],<br>        visibility = [&quot;//visibility:private&quot;],<br>    )<br>    go_library(<br>        name = name,<br>        srcs = srcs + [iosinit],<br>        copts = copts + [<br>            &quot;-xobjective-c&quot;,<br>            &quot;-fmodules&quot;,<br>            &quot;-fobjc-arc&quot;,<br>        ],<br>        importpath = importpath,<br>        deps = deps + [<br>            &quot;//iosinit:go_default_library&quot;,<br>        ],<br>        **kwargs<br>    )</pre><h3>Conclusion</h3><p>Failing to initialise Cocoa for multithreading can cause some unexpected issues to your app, such as randomly failing to properly fetch the application state when starting. And when it happens on code running on millions of devices, the situation turns dire.</p><p>If this is the sort of engineering you’d like to work on, shoot me an email at steeve at zen dot ly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95394491ad5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenlyapp/go-ios-remember-to-enable-cocoa-multithreading-95394491ad5e">Go &amp; iOS: remember to enable Cocoa multithreading</a> was originally published in <a href="https://medium.com/zenlyapp">zenly blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Putting Ice Cream on the Map]]></title>
            <link>https://medium.com/zenlyapp/putting-ice-cream-on-the-map-8f7eb048c1ab?source=rss----af548b3cb007---4</link>
            <guid isPermaLink="false">https://medium.com/p/8f7eb048c1ab</guid>
            <category><![CDATA[branding]]></category>
            <category><![CDATA[user-engagement]]></category>
            <category><![CDATA[zenly]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[marketing]]></category>
            <dc:creator><![CDATA[Sarah McBride]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 15:26:39 GMT</pubDate>
            <atom:updated>2021-10-25T18:21:15.322Z</atom:updated>
            <content:encoded><![CDATA[<p>Lessons from a viral ice cream truck in Japan. 🍦</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SBNR-JTewFQw5CVT" /></figure><p>On November 1st, a select group of users in Japan opened Zenly to find an ice cream truck driving around Tokyo. 3 days and a few laps around the country later, the truck unlocked to unveil Zenly World — an online merch store that we built for our most loving and engaged Japanese users.</p><p>The mysterious truck spilled over to social media as people screen shotted and screen recorded the new pin on their map. When the store unlocked, everyone wanted to know who was going to buy <a href="https://zenly.world/products/the-giant-popsicle?variant=36819571114145">the $14,000 5ft giant popsicle art piece</a> (someone did actually buy it). On TikTok, the Zenly hashtag in Japanese surpassed 22 million views in just a few days. The truck also caused a spike in active users and friend requests, and grew the following of our Japan Twitter account by 4x.</p><p>We brought this project from conception to merch-selling ice cream truck execution in the space of 4 months. What follows is an overview of the challenges we navigated and the lessons we learned from building a viral brand experience directly in Zenly. 🍦</p><p>Zenly has a history of building joy-inducing user experiences. Someone once described Zenly as “unwrapping a cool lemon pop on a hot summer day”. Every tap, transition, share card, line of copy has been crafted to create joy. So we knew that building a merch store, and putting it on the map, should feel no different.</p><p>There were 3 distinct experiences we had to build for:</p><ol><li>Putting an ice cream truck on the map — The truck would first appear in Zenly with a countdown timer above while driving around Japan. 3 days later, the timer would disappear and tapping the truck would open a native web view in the app.</li><li>Building an online merch store — Once the truck unlocked, the native web view would load a custom Shopify store selling Zenly clothing and accessories.</li><li>Coordinating fulfilment — Once an item was purchased, we had to coordinate with our fulfilment center in Japan to send the package out to zenly.world customers, and create a physical unboxing experience linked to the digital experience.</li></ol><h3>The anti-ecom experience 🌐</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0pwwMx8CdAaImDyp" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g4QNX943P-iyxBNg" /><figcaption>How it started vs how it’s going. 💖</figcaption></figure><p>This project required building an entire web experience from scratch, so we started with the online store. The core of the brief was to build an immersive and fun experience for users who already know and love Zenly — <em>not</em> about building a dialled e-commerce experience. To bring this anti-ecommerce experience to life, we were fortunate to work with one of our longtime partners, <a href="https://www.makata.tv/">Makata</a>.</p><p>The core of the design was inspired by the popsicle on a warm summer’s day analogy. Ice cream is our middle name and our app icon. We had toyed with an ice cream truck design in the past, but never found a place for it. This was the perfect opportunity to finally bring the truck to life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wPlqKUUtpVK8DtfqNJnKA.png" /><figcaption>The ice cream truck’s time to shine. ✨</figcaption></figure><p>The store was built as a custom Shopify site, with the world view built in three.js. Although the majority of the traffic to the site would come through the native web view initially, we wanted to build a site that could live independently when accessed directly via the <a href="http://zenly.world/">zenly.world</a> URL. That meant building a website that felt as native as possible to the app experience when loaded through the web view, worked great on desktop, and was responsive on mobile.</p><h3>Putting ice cream on the map 🍦</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oihgknh9M4iHUTZZBgfQKQ.png" /><figcaption>The truck in the locked and unlocked state on the map. ⏳</figcaption></figure><p>As clothing production and website development whirled in the background, we turned our attention to building the in-app experience. At the same time, we welcomed our new iOS intern: Seb.</p><p>Seb’s first technical challenge was to make the truck drive as smoothly as possible between the 6,000 GPS data points that we had painstakingly plotted for the truck to follow around Japan (side note: this is a great way to brush up on Japanese geography). To solve this, Seb had to interpolate GPS points between the ones we had already plotted so that the truck drove at a constant speed and to smooth out the transitions between each data point.</p><p>His second technical challenge was to ensure that the truck path would be synchronized between all devices, i.e every user would see the truck in the exact same position in Japan at the same time. To solve this, he created 2 timestamps: the current timestamp and another one as a reference. With that, we could calculate an index to know at which point in the path the truck should start from or be located on a user’s map.</p><pre>var indexDouble: Double = Double(currentTime — firstTime) / 10</pre><pre>let index: Int = Int(floor(indexDouble)) % coordinates.count</pre><pre>let nextIndex = (index + 1) % coordinates.count</pre><pre>// modulus of a Double</pre><pre>indexDouble -= Double(Int(indexDouble / Double(coordinates.count)) * coordinates.count)</pre><pre>let safeIndex = index.clamped(betweenMinValue: 0, maxValue: coordinates.count — 1)</pre><pre>let safeNextIndex = nextIndex.clamped(betweenMinValue: 0, maxValue: coordinates.count — 1)</pre><pre>let dLat = deltaLatitude(a: coordinates[safeIndex], b: coordinates[safeNextIndex])</pre><pre>let dLon = deltaLongitude(a: coordinates[safeIndex], b: coordinates[safeNextIndex])</pre><pre>let decimalPart = indexDouble.truncatingRemainder(dividingBy: 1)</pre><pre>let newLatitude = coordinates[index].latitude + dLat * decimalPart</pre><pre>let newLongitude = coordinates[index].longitude + dLon * decimalPart</pre><pre>let newCoordinate = CLLocationCoordinate2DMake(newLatitude, newLongitude)</pre><p>As I come from a non-technical background, and much of the work was carried out remotely, building visual- and then coded-prototypes became more important than ever. We tried to ship something to our internal beta app every evening for a week so that we could all play around with it until it felt right, running through several iterations of the transition from truck on the map to opening up the native web view.</p><h3>Make it fun, make it Zenly 🤪</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tYCfoQIPN476XIdf" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IcLDDC3AuSD8jpXi" /><figcaption>We went through a considerable volume of ice cream during this photoshoot on the streets of Tokyo. 🤠</figcaption></figure><p>At its core, this project was about building a brand experience, and so putting in place the brand and marketing foundations to support it. What that meant in practice was making sure every line of copy on the website, from the product descriptions, to the FAQ, to the checkout, to the confirmation emails, carried the Zenly tone of voice. It also meant building an influencer campaign with 50 of Japan’s top influencers, to launch in tandem with the store unlocking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ARa_clhu9x5i6mlwB-Pw5w.gif" /></figure><p>For the influencer activation, we created an influencer gift box, which required taking elements of the digital brand experience (the app, the truck pin, the website) and mapping them across to a physical brand experience (an influencer box stuffed full of Zenly merch). The additional challenge came with the lead times required to produce physical things (2 months given COVID delays) vs the speed at which we were building and iterating the digital experience (mere weeks). We also carried many of the physical design elements from the influencer boxes over to the unboxing experience for the end customer of the merch store. If opening Zenly is like unwrapping a popsicle on a warm summer’s day, we wanted to emulate that with our physical unboxing experience.</p><h3>What the truck?! 🚚</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gTgKMS0a1rq1wEC1" /></figure><p>The truck went live on people’s maps just after 10AM, Japan local time, on Sunday November 1st.</p><p>Throughout the day, the truck was all over social media. We had the expected conversation: what was coming once the countdown timer concluded. But also lots of unexpected responses. We had users trying to reverse engineer the criteria for seeing the truck (you had to have unlocked the golden app icon). We had users wondering if it was linked to Halloween. We had users who banded together to see if they could see the truck on the highway after someone on Tik Tok <a href="https://vt.tiktok.com/ZSVAyayT/">claimed to have spotted it</a> — and it went viral. We also had users who were scared of the truck, no thanks to our choice of a melody that played every time you tapped the truck in the locked state…that happened to be the same melody in a popular horror movie in Japan (🤦‍♀️).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kz6xLMt5ZMgvfrrdZIeb4Q.png" /><figcaption>Users took to social media to share their truck spotting attempts. 🤔</figcaption></figure><p>Even when you think you’ve planned for every comms eventuality, people will always surprise you. We closely monitored the conversation on social and adapted our comms and support plan on the fly to respond to any questions people had.</p><h3>Learnings with sprinkles on top ✍️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h1g9qR9DWDDJpQ4v" /><figcaption>The giant popsicle found a new home. 🥰</figcaption></figure><p>After 4 months of intense work, it was over in a flash. The countdown timer concluded and the store went live. The conversation peaked for a second time on social, and people bought Zenly-branded clothes and accessories, including the one-of-its-kind 5ft giant Zenly popsicle art piece. 5 days later, it was all over.</p><p>Plans changed along the way, things broke, and some users thought they were in a horror movie sequel. But the learnings along the way were invaluable. Through this project, we took our brand and made it live in an experience outside of the app (and finally gave the Zenly ice cream truck the spotlight). From a technical standpoint, we learned not only how to put a moving truck pin onto the map, but also how to build a native web app experience with a website that behaves just like an app. From a brand perspective, we learned that some of our users are very enthusiastic about buying socks covered in poop emojis, while some prefer the basic Zenly logo look.</p><p>This project was one of many firsts at Zenly: the first time we built something specially for our users in Japan. The first time we put a pin on the map that isn’t linked to a user or significant place. The first time we built a brand experience that lives outside the map, but was integrated directly into it. The first piece of code that our iOS intern Seb shipped (2 weeks into the job). The first time I have PM’d something — not just at Zenly, but in my entire career. And the first time we have sold a $14,000 5ft giant Zenly popsicle art piece.</p><p>In the end, I believe that our success in driving a viral conversation around the brand (and selling that $14,000 popsicle) was thanks to the culture of <em>build, ship, and learn</em> at Zenly — and the opportunity to do it no matter what your job title is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YWtOe28YCVCKEy-o2ihSLg.gif" /><figcaption>Or as we say here in Paris, merci. 😘</figcaption></figure><p><em>Zenly is a mobile app that shows you a live map of your friends and family. Founded in Paris in 2014, Zenly joined Snap in 2017, and continues to run as an independent entity with millions of loving active users around the world.</em></p><p><em>PS — we’re hiring: </em><a href="https://zen.ly/jobs"><em>https://zen.ly/jobs</em></a><em> 🍦</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f7eb048c1ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenlyapp/putting-ice-cream-on-the-map-8f7eb048c1ab">Putting Ice Cream on the Map</a> was originally published in <a href="https://medium.com/zenlyapp">zenly blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-time machine learning in Go at Zenly]]></title>
            <link>https://medium.com/zenlyapp/real-time-machine-learning-in-go-at-zenly-5fece526b2ac?source=rss----af548b3cb007---4</link>
            <guid isPermaLink="false">https://medium.com/p/5fece526b2ac</guid>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[David Bouba]]></dc:creator>
            <pubDate>Thu, 29 Nov 2018 19:57:51 GMT</pubDate>
            <atom:updated>2018-11-30T14:21:55.903Z</atom:updated>
            <content:encoded><![CDATA[<p>Zenly is a social map app that allows you to share where you are and what you’re up to with your best friends without ever taking your phone out of your pocket. We use real time location as an enabler to get friends together more often in real life and we’re trying to make sure that no one ever sends a “where are you?” text again 🤗</p><p>Whether it’s about knowing which venue your mates are hanging out in, suggest relevant new friends or identify your means of transportation, such tasks often translate to complex underlying patterns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61R6Dzz6z2-0E4bvfEfazg.png" /></figure><h4>Machine learning + live = 😍</h4><p>Rule-based models can be a good start for most applications when dealing with low-dimensionality problems. They are fast to implement and only require a good comprehension of what is going on under the hood regarding the input-output relationship we are trying to abstract.</p><p>Yet, as our app gets richer and richer, so do our users’ behavior and it rapidly gets impossible to make these kind of systems evolve, or even to maintain them.</p><p>Furthermore, for some application the decision-making is not performed offline, but rather triggered by some users’s action and it needs to be served live with low-latency. In such scenarios, the provided solution should at least answer to the two following questions:</p><ul><li>how to port an <strong>R&amp;D</strong> model to <strong>production</strong> ?</li><li>how to satisfy <strong>real-time </strong>constraints ?</li></ul><p>In this post, we will give an overview on how Zenly uses machine learning in production for real-time applications.</p><h4><a href="https://github.com/znly/go-ml-transpiler">go-ml-transpiler</a>: compile model in Go</h4><p>For offering a good trade-off between performance and productivity, <em>Go</em> has been widely used at Zenly. In addition, <em>Go</em> has the benefit of coming with powerful built-in concurrency features, which is more than welcomed for the backend of a mobile app like ours.</p><p>On the other side, the data-science team mostly runs experiments in Python for its simplicity and the importance of its ML ecosystem and community, or Spark<em> </em>to<em> </em>leverage its distributed architecture when dealing with large amounts of data.</p><blockquote>Being able to iterate quickly on modeling is a hard-constraint for us as it is the core of what’s driving innovation here.</blockquote><p>Also, for a wide range of problems, classic machine learning algorithms such as <a href="https://en.wikipedia.org/wiki/Gradient_boosting"><strong>gradient tree boosting</strong></a> or <a href="https://en.wikipedia.org/wiki/Random_forest"><strong>random forest</strong></a> give state-of-the-art results. They have the advantage of being interpretable as well, which can sometimes be of a great help when debugging. Last but not least, once trained they are fully describable as if / else operations which make them easily portable.</p><p>As a result, we came out with the idea of exporting such Python/Scala-Spark trained models as a self-contained <em>Go</em> library, and developed a small Python package: <a href="https://github.com/znly/go-ml-transpiler"><strong><em>go-ml-transpiler</em></strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XVOcfKuJEIFwRT7oHPJUqg.png" /></figure><p>Basically — with <em>go-ml-transpiler — </em>you can train your model in Python<em> </em>or<em> </em>in<em> </em>Spark<em> </em>as usual, then simply export it as <em>Go</em> code. For now it only supports <a href="https://xgboost.readthedocs.io/en/latest/"><strong>XGBoost</strong></a> (Python/Scala-Spark) and <a href="http://scikit-learn.org/"><strong>Scikit-Learn</strong></a> random forest (Python), both for classification and regression objectives.</p><p>Here’s an example of a <em>Scala-Spark </em>to<em> Go </em>pipeline:</p><ol><li>Train your XGBoost model in Spark</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2812d8c95f620fee5c866a143a7da54/href">https://medium.com/media/e2812d8c95f620fee5c866a143a7da54/href</a></iframe><p>At this point your model is trained and can be loaded in Python.<br>Or you could also have trained your model directly in Python.</p><p>2. … and then just load it in Python and transpile it to <em>Go</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29dded2334356cba6bb022a8726924f5/href">https://medium.com/media/29dded2334356cba6bb022a8726924f5/href</a></iframe><p>It outputs a production-ready machine learning prediction API which can be compiled in any <em>Go</em> project.</p><h4>Go + gRPC + Docker for a simple real-time serving</h4><p>As an illustration, we provide a very basic serving service using gRPC and Docker.</p><p>We use gRPC<em> </em>as a communication framework for three main reasons: it is easy, fast and strongly-typed. gRPC provides a simple API definition through Protobuf, which can be compiled in all major languages (see <a href="https://grpc.io/docs/">grpc.io/docs</a>).</p><p>A basic gRPC service would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f307abc9dfcbb5764cbf47e4f8dddd9e/href">https://medium.com/media/f307abc9dfcbb5764cbf47e4f8dddd9e/href</a></iframe><p>Defining a client is also straightforward. Sending a request to the server in <em>Go </em>would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3117d1f3c9b07d7d45c0f299c583d536/href">https://medium.com/media/3117d1f3c9b07d7d45c0f299c583d536/href</a></iframe><p>This server can also be requested through any of the supported languages in few lines of code. Here’s an example of a Python client:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e4c669952c70f282a144b6f87c0206e/href">https://medium.com/media/9e4c669952c70f282a144b6f87c0206e/href</a></iframe><p>where service_pb2.py and service_pb2_grpc.py are generated by the protocol buffer compiler and provide all the necessary classes and methods to set up a gRPC server/client and handle requests in Python.</p><p>Finally, the server application is containerized with Docker and is now ready to serve!</p><p>You can find the code right <a href="https://github.com/znly/go-ml-transpiler/tree/master/serving">here</a> 🤖</p><h4><strong><em>Benchmark</em></strong></h4><p>To assess the performance of this approach, we trained on the <a href="https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+(Diagnostic)">Breast Cancer Wisconsin</a> dataset an ensemble model composed of a Random Forest model and an XGBoost model (100 trees for both models), and evaluated:</p><ol><li>the transpiled model latency (binary classification)</li><li>the serving latency (ensemble model + Docker + gRPC)</li></ol><p>Our configuration was the following:</p><pre>Model: MacBook Pro (15-inch, 2017)<br>Processor: Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz<br>Memory: 16 GB 2133 MHz LPDDR3</pre><p>Here are the results:</p><ul><li>~5us/op for the transpiled model (<strong>vs</strong> <em>~4ms/op in Python):</em> <br>→ this is a <strong>~800x </strong>boost in<strong> </strong>performance</li><li>~220us/op for the serving latency</li></ul><h4>Discussion</h4><p>By adopting a very simple pipeline we achieved a very competitive end-to-end latency for a machine learning serving service. This pipeline relies on a strongly-typed communication protocol, has auto-scaling capabilities using Docker, and can handle intensive training with Spark.</p><p>We are only in the beginning of empowering our real-time features with machine learning, yet it has unlocked a vast range of opportunities and will continue to boost creativity at Zenly.</p><p><em>To try Zenly out → </em><a href="https://zen.ly/app"><em>https://zen.ly/app</em></a><em> </em>✌️</p><p><em>Special thanks to </em><a href="https://medium.com/u/81b8053240af"><em>Nicolas FALLOURD</em></a><em>, </em><a href="https://medium.com/u/f97528b99b4f"><em>Julien Martin</em></a><em> for the cool illustrations, and to </em><a href="https://medium.com/u/280d29b36a3"><em>Xabier Jaureguiberry</em></a><em>, </em><a href="https://medium.com/u/fc940015fec5"><em>Pierre Leveau</em></a><em>, </em><a href="https://medium.com/u/c8c1a851b538"><em>Antoine Sinton</em></a><em> and </em><a href="https://medium.com/u/772a096f404a"><em>Alexis Bonillo</em></a><em> who helped in reviewing this post.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fece526b2ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenlyapp/real-time-machine-learning-in-go-at-zenly-5fece526b2ac">Real-time machine learning in Go at Zenly</a> was originally published in <a href="https://medium.com/zenlyapp">zenly blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Custom Drawables — part 1]]></title>
            <link>https://medium.com/zenlyapp/implementing-custom-drawables-part-1-5530a98cefc9?source=rss----af548b3cb007---4</link>
            <guid isPermaLink="false">https://medium.com/p/5530a98cefc9</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Cyril Mottier]]></dc:creator>
            <pubDate>Tue, 26 Jun 2018 13:18:44 GMT</pubDate>
            <atom:updated>2018-06-27T10:43:24.513Z</atom:updated>
            <content:encoded><![CDATA[<p>Android has always offered several ways and layers to draw things on screen, one of which is Drawable. As its name suggests, Drawable is a general abstraction of “something that can be drawn”. In particular, it can be considered as an entity that can be drawn onto a Canvas— the vessel for drawing commands on Android. As such, some might say it makes it similar to View. Indeed, both provide ways to render on a Canvas. However, Drawable doesn’t deal with things like touch event dispatching, save state, measure and layout, etc. As it only draws things it makes it a much more suitable and light-weight option when it only comes to draw on Android.</p><p>Being a very demanding app in term of rendering content, the Zenly app makes an extensive use of Drawables. It obviously relies a lot on PNG/JPG images (i.e. BitmapDrawable and NinePatchDrawable). However, in some cases, framework-provided Drawables are not enough or don’t exactly match our needs. In these cases, we generally have to create our own rendering code. Implementing custom Drawables is one of our prefered way to do so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c0hsn9FSak7sncCtaHXPLQ.jpeg" /><figcaption>A corridor in the Zenly office.</figcaption></figure><p>At Zenly, we love colors and 🌈. As a consequence, it’s completely logical for us to use bold colors and include rainbow stripes in the app design! This is exemplified in a feature called “Best Friends” which is unlocked once you have enough friends on Zenly. “Best Friends” let’s you access some nice information about your friends: your favorite workmate or lunchmate, time spent together in the last 7 days, pals you haven’t seen for a long time, etc. In order to make this informative screen look cool, the header features a striped rainbow background. I encourage you to test this app section for real (yep… there is more 😉) but here is what it looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*VPZaNX6hw6UcHamIgxWCmQ.png" /><figcaption>Who are your best friends!?!</figcaption></figure><p>As shown in the image above, the header background is made of several colorful stripes. In practice, vertical stripes are tilted 30° clockwise and are repeated to fully fill the header bounds.</p><h3>The original implementation</h3><p>The very first naive implementation of this “rainbow stripes” effect consisted of replicating a pattern image to fill the entire area. In practice, we had an image name rainbow_stripes_pattern exported in the three densities supported by the app: hdpi, xhdpi and xxhdpi. The asset was intelligently sliced so that it could act as a repeatable pattern. Indeed, as shown below, you can put the same image (represented in translucent opacity) in any direction of a fixed image (shown completely opaque), it will always give the impression you are expanding the stripes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*laeoNOG57RWXwVtHwC7MLg.png" /><figcaption>Let’s repeat tiles over and over again…</figcaption></figure><p>In app, this “repeat” effect was implemented creating a new rainbow_stripes BitmapDrawable in XML with tileMode set to repeat. This special tile mode simply informs the rendering pipeline that the image should be repeated on both the X and Y axis rather than stretched to fill the Drawable bounds:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19f58b8dea056d11f05329da7ed81735/href">https://medium.com/media/19f58b8dea056d11f05329da7ed81735/href</a></iframe><p>In order to display the rainbow stripes, you simply need to set the Drawable defined above as the background of a View.</p><h3>A better implementation</h3><p>From a strict product point of view, the UI appearance was satisfying. The app was displaying infinite colorful rainbows after all! Unfortunately, although it was visually correct, the technique described above was suffering from several drawbacks and limitations:</p><ol><li>Exporting and updating the pattern image was a nightmare. Stripes beeing tilted by 30° made it impossible to have pixel-perfect pattern size. Designers had to either tweak the angle or trick users by ensuring misalignment was only visible at a sub-pixel level.</li><li>In order to have smooth and sharp-edged stripes, the APK contained the same image in several densities making it larger in size. Fortunately, image compression and the recent introduction of dynamic delevery reduces the impact on the end users.</li><li>Loading the image at runtime was quite heavy in term of memory resources. Indeed, the image being 360x624dp, loading it into memory was taking about 3.5MB in xhdpi (and up to 8MB in xxhdpi). Being that Zenly is quite intensive in term of memory usage, it didn’t feel right to take up so much memory for an easter-egg.</li></ol><p>Pretty logically, the alternative is to render the rainbow stripes dynamically (i.e. at runtime). A possible implementation would be to draw several rectangles on a 30° rotated Canvas. While this solution would probably work, it looks pretty complex. A better and simpler solution is to consider the stripes as a gradient whose colors and stops are determined in a way in which the switch between two colors is instant.</p><p>The Android framework offers several ways to render a gradient. The most obvious way is GradientDrawable. However, its API is pretty high level and only allows special types of gradient. For instance, it doesn’t let you choose an angle which is not multiple of 45° nor the color stops. As a consequence, GradientDrawable is not a suitable option in our case.</p><p>The correct way to draw such a gradient, is to use the low-level API that powers GradientDrawable: LinearGradient. LinearGradient is a Shader you can set on a Paint. In general, Paint describes a single color, a single font, etc. Attaching Shaders to a Paint allow passing information about how to draw multiple colors at once.</p><p>The API of LinearGradient is pretty simple as the class only exposes 2 constructors. The first constructor is a convenience initializer as it only accepts 2 colors. The second one is the most generic one and accepts an array of colors as well as an array of stops/positions. You may have guessed it, we will use the most generic one in this case.</p><p>The LinearGradient generic constructor requires several arguments as input. Indeed, a gradient is generally defined by 4 main values: two 2D coordinates defining the gradient line and two arrays defining, as described previously, the colors to be distributed along the gradient line and the relative position (in the [0, 1] range) of each corresponding color in the colors array. A final parameter defines the “tile mode” (cf <a href="https://developer.android.com/reference/android/graphics/Shader.TileMode">Shader.TileMode</a>) and describes how the rendering pipeline should deal with shaders not filling the entire bounds (e.g. clamp, mirror or repeat).</p><p>In order to build our LinearGradient, we need to look at the original asset. Thanks to some basic math and a little trigonometry, we can easily compute the start and end coordinates of our gradient line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vc13WR42faoNv6b-2F7ttA.png" /><figcaption>Having fun with trigonometry!</figcaption></figure><p>First of all, let’s start initializing some constants:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71c248e0ceacf3d85aaf638f44741221/href">https://medium.com/media/71c248e0ceacf3d85aaf638f44741221/href</a></iframe><p>The first step consists on computing the colors and stops:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b819167fc331f4021978c5d9a784d88/href">https://medium.com/media/1b819167fc331f4021978c5d9a784d88/href</a></iframe><p>Once both the colors and stops arrays are initialized, you can easy build a LinearGradient and expose it thanks to a Drawable. This makes it easy to integrate in your app (as the background of a View for instance). Please keep in mind, the following Drawable doesn’t respect all of the Drawable APIs. For instance, there is no support for alpha, color filters, constant state, etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01502cdaf0cc40e4931b9dabd24ae54a/href">https://medium.com/media/01502cdaf0cc40e4931b9dabd24ae54a/href</a></iframe><p>Using this newly created custom Drawable as the background of a fullscreen View works as expected: rainbow stripes are correctly rendered and are repeated infinitely to fully fill the bounds of the View. There’s a small glitch though. Indeed, if you look closely at the junction between two colors, you’ll notice a “darker” line as shown magnified on the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ysYfhDRQ2MAtr6jcr5qv4w.png" /></figure><p>To be totally honest, I couldn’t find the exact reason behind this glitch when looking at AOSP source code. Vector rendering software such as Affinity Designer or Sketch don’t have the issue. My only assumption here is the Android rendering pipeline overlaps two colors at stop points forming a darker thin line.</p><p>In order to workaround it, you can add/subtract a small value to stop points. Let’s call the small value <em>epsilon</em>. If we consider the frontier between color <em>N</em> and color <em>N+1</em>, we end up having color <em>N</em> ending stop reduced by <em>epsilon</em> and color <em>N+1</em> starting stop augmented by <em>epsilon</em>. The code below shows the modified code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4617169f4dc07631eea1d2e07c0ee5d/href">https://medium.com/media/e4617169f4dc07631eea1d2e07c0ee5d/href</a></iframe><p>The final rendering looks exactly as expected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wQJfXnsowcwErldfqLJ_zw.png" /></figure><h3>Conclusion</h3><p>And we’re done! Building custom Drawables on Android can be a huge win in some cases. For instance, it can help reduce the memory footprint (disk and RAM). In most cases, the Android UI toolkit APIs provide all of the necessary concepts to render things created by your designers on tools like Affinity Designer or Sketch. The only tricky (but fun 🤓) part is generally to find a way to render these nice UIs in code.<br> <br>If you like this kind of UI tricks and optimizations, my team at Zenly is hiring. We’re looking for talented iOS and Android engineers. Come say 👋 on <a href="https://twitter.com/cyrilmottier">Twitter</a>, my DMs are open.</p><p><strong>Edit</strong> (<em>Jun 27, 2018)</em>: <a href="https://medium.com/u/22c02a30ae04">Nick Butcher</a> created a similar effect using only XML code. The implementation relies on VectorDrawable. You can have a look at his tweet for more details on the implementation:</p><h3>Nick Butcher on Twitter</h3><p>You can also create a similar effect using a VectorDrawable. https://t.co/gXF5CCpxm0</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5530a98cefc9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenlyapp/implementing-custom-drawables-part-1-5530a98cefc9">Implementing Custom Drawables — part 1</a> was originally published in <a href="https://medium.com/zenlyapp">zenly blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>