<?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[Stories by Yarden Eitan on Medium]]></title>
        <description><![CDATA[Stories by Yarden Eitan on Medium]]></description>
        <link>https://medium.com/@yardeneitan?source=rss-974f9fd6d0d8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tZcpcJMWtRiiaixxnPJnyg.jpeg</url>
            <title>Stories by Yarden Eitan on Medium</title>
            <link>https://medium.com/@yardeneitan?source=rss-974f9fd6d0d8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:07:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yardeneitan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Google Built the Shape System for Material Design]]></title>
            <link>https://medium.com/hackernoon/building-the-shape-system-for-material-design-eef36725b28b?source=rss-974f9fd6d0d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/eef36725b28b</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[shape-system]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[google-shape-system]]></category>
            <dc:creator><![CDATA[Yarden Eitan]]></dc:creator>
            <pubDate>Tue, 18 Dec 2018 00:00:00 GMT</pubDate>
            <atom:updated>2019-01-09T10:07:45.026Z</atom:updated>
            <content:encoded><![CDATA[<h4>I am Yarden, an iOS engineer for Material Design — Google’s open-source system for designing and building excellent user interfaces. I help build and maintain our <a href="https://goo.gl/ExQEYR">iOS components</a>, but I’m also the engineering lead for Material’s shape system.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*PPVO6HMf-XRVFURn.gif" /></figure><h3>Shape: It’s kind of a big deal</h3><p>You can’t have a UI without shape. Cards, buttons, sheets, text fields — and just about everything else you see on a screen — are often displayed within some kind of “surface” or “container.” For most of computing’s history, that’s meant rectangles. Lots of rectangles.</p><p>But the Material team knew there was potential in giving designers and developers the ability to systematically apply unique shapes across all of our Material Design UI components. Rounded corners! Angular cuts! For designers, this means being able to create beautiful interfaces that are even better at d<a href="https://medium.com/google-design/you-need-a-shape-system-8d2aa9016817">irecting attention, expressing brand, and supporting interactions</a>. For developers, having consistent shape support across all major platforms means we can easily apply and customize shape across apps.</p><p>My role as engineering lead was truly exciting — I got to collaborate with our design leads to scope the project and find the best way to create this complex new system. Compared to systems for typography and color (which have clear structures and precedents like the web’s H1-H6 type hierarchy, or the idea of primary/secondary colors) shape is the Wild West. It’s a relatively unexplored terrain with rules and best practices still waiting to be defined. To meet this challenge, I got to work with all the different Material Design engineering platforms to identify possible blockers, scope the effort, and build it!</p><p>When building out the system, we had two high level goals:</p><ul><li>Adding shape support for our components — giving developers the ability to customize the shape of buttons, cards, chips, sheets, etc.</li><li>Defining and developing a good way to theme our components using shape — so developers could set their product’s shape story once and have it cascade through their app, instead of needing to customize each component individually.</li></ul><p>From an engineering perspective, adding shape support held the bulk of the work and complexities, whereas theming had more design-driven challenges. In this post, I’ll mostly focus on the engineering work and how we added shape support to our components.</p><p>Here’s a rundown of what I’ll cover here:</p><ul><li>Scoping out the shape support functionality</li><li>Building shape support consistently across platforms is hard</li><li>Implementing shape support on iOS:</li><li><em>— Shape core implementation</em></li><li><em>— Adding shape support for components</em></li><li>Applying a custom shape on your component</li><li>Final words</li></ul><h3>Scoping out the shape support functionality</h3><p>We soon found that having no restrictions would make it extremely hard to define such a system. More flexibility doesn’t necessarily mean a better result. For example, it’d be quite a feat to define a flexible and easy API that lets you make a snake-shaped FAB and train-shaped cards. But those elements would almost certainly contradict the clear and straightforward approach championed by Material Design guidance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*63bCFOnEjQN0qG7Q.png" /><figcaption>This truck-shaped FAB is a definite “don’t” in Material Design guidance.</figcaption></figure><p>We had to weigh the expense of time and resources against the added value for each functionality we could provide.</p><p>To solve these open questions we decided to conduct a full weeklong workshop including team members from design, engineering, and tooling. It proved to be extremely effective. Even though there were a lot of inputs, we were able to hone down what features were feasible and most impactful for our users. Our final proposal was to make the initial system support three types of shapes: square, rounded, and cut. These shapes can be achieved through an API customizing a component’s corners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/0*3Hf2gf8zVVhvZBeN.png" /></figure><h3>Building shape support consistently across platforms (it’s hard)</h3><p>Anyone who’s built for multiple platforms knows that <strong>consistency is key</strong>. But during our workshop, we realized how difficult it would be to provide the exact same functionality for all our platforms: Android, Flutter, iOS, and the web. Our biggest blocker? Getting cut corners to work on the web.</p><p>Unlike sharp or rounded corners, cut corners do not have a built-in native solution on the web.</p><p>Our web team looked at a range of solutions — we even considered the idea of adding background-colored squares over each corner to mask it and make it appear cut. Of course, the drawbacks there are obvious: Shadows are masked and the squares themselves need to act as chameleons when the background isn’t static or has more than one color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zMYyFNzp7ielLGii.png" /></figure><p>We then investigated the <a href="https://goo.gl/hQDbAB">Houdini (paint worklet) API</a> along with <a href="https://goo.gl/FiDfpJ">polyfill</a> which initially seemed like a viable solution that would actually work. However, adding this support would require additional effort:</p><ul><li>Our UI components use shadows to display elevation and the new canvas shadows look different than the native CSS box-shadow, which would require us to reimplement shadows throughout our system.</li><li>Our UI components also display a visual ripple effect when being tapped — to show intractability. For us to continue using ripple in the paint worklet, we would need to reimplement it, as there is no cross-browser masking solution that doesn’t provide significant performance hits.</li></ul><p>Even if we’d decided to add more engineering effort and go down the Houdini path, the question of value vs cost still remained, especially with Houdini still being “<a href="https://goo.gl/ZP9kzN">not ready</a>” across the web ecosystem.</p><p>Based on our research and weighing the cost of the effort, we ultimately decided to move forward <em>without</em> supporting cut corners for web UIs (at least for now). But the good news was that we have spec-ed out the requirements and could start building!</p><h3>Implementing shape support on iOS</h3><p>After honing down the feature set, it was up to the engineers of each platform to go and start building. I helped build out shape support for iOS. Here’s how we did it:</p><h4>Core implementation</h4><p>In iOS, the basic building block of user interfaces is based on instances of the UIView class. Each UIView is backed by a CALayer instance to manage and display its visual content. By modifying the CALayer&#39;s properties, you can modify various properties of its visual appearance, like color, border, shadow, and also the geometry.</p><p>When we refer to a CALayer&#39;s geometry, we always talk about it in the form of a rectangle.</p><p>Its frame is built from an (x, y) pair for position and a (width, height) pair for size. The main API for manipulating the layer’s rectangular shape is by setting its cornerRadius, which receives a radius value, and in turn sets its four corners to be rounded by that value. The notion of a rectangular backing and an easy API for rounded corners exists pretty much across the board for Android, Flutter, and the web. But things like cut corners and custom edges are usually not as straightforward. To be able to offer these features we built a shape library that provides a generator for creating CALayers with specific, well-defined shape attributes.</p><p>Thankfully, Apple provides us with the class CAShapeLayer, which subclasses CALayer and has a customPath property. Assigning this property to a custom CGPath allows us to create any shape we want.</p><p>With the path capabilities in mind, we then built a class that leverages the CGPath APIs and provides properties that our users will care about when shaping their components. Here is the API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e31fc17d00f6fd2d04cbc8c2e5dab3b3/href">https://medium.com/media/e31fc17d00f6fd2d04cbc8c2e5dab3b3/href</a></iframe><p>By providing such an API, a user can generate a path for only a corner or an edge, and the MDCRectangleShapeGenerator class above will create a shape with those properties in mind. For this initial implementation of our initial shape system, we used only the corner properties.</p><p>As you can see, the corners themselves are made of the class MDCCornerTreatment, which encapsulates three pieces of important information:</p><ul><li>The value of the corner (each specific corner type receives a value).</li><li>Whether the value provided is a percentage of the height of the surface or an absolute value.</li><li>A method that returns a path generator based on the given value and corner type. This will provide MDCRectangleShapeGenerator a way to receive the right path for the corner, which it can then append to the overall path of the shape.</li></ul><p>To make things even simpler, we didn’t want our users to have to build the custom corner by calculating the corner path, so we provided 3 convenient subclasses for our MDCCornerTreatment that generate a rounded, curved, and cut corner.</p><p>As an example, our cut corner treatment receives a value called a “cut” — which defines the angle and size of the cut based on the number of UI points starting from the edge of the corner, and going an equal distance on the X axis and the Y axis. If the shape is a square with a size of 100x100, and we have all its corners set with MDCCutCornerTreatment and a cut value of 50, then the final result will be a diamond with a size of 50x50.</p><p>Here’s how the cut corner treatment implements the path generator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84a58f9dbc600295b352189bb8099f32/href">https://medium.com/media/84a58f9dbc600295b352189bb8099f32/href</a></iframe><p>The cut corner’s path only cares about the 2 points (one on each edge of the corner) that dictate the cut. The points are (0, cut) and (sin(angle) * cut, cos(angle) * cut). In our case — because we are talking only about rectangles where their corner is 90 degrees — the latter point is equivalent to (cut, 0) where sin(90) = 1 and cos(90) = 0.</p><p>Here’s how the rounded corner treatment implements the path generator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f175887f8be1529915ea2faf7ae75d09/href">https://medium.com/media/f175887f8be1529915ea2faf7ae75d09/href</a></iframe><p>From the starting point of (0, radius) we draw an arc of a circle to the point (sin(angle) * radius, cos(angle) * radius) which — similarly to the cut example — translates to (radius, 0). Lastly, the radius value is the radius of the arc.</p><h4>Adding shape support for components</h4><p>After providing an MDCRectangleShapeGenerator with the convenient APIs for setting the corners and edges, we then needed to add a property for each of our components to receive the shape generator and apply the shape to the component.</p><p>Each supported component now has a shapeGenerator property in its API that can receive an MDCShapeGenerator or any different shape generator that implements the pathForSize method: Given the width and height of the component, it returns a CGPath of the shape. We also needed to make sure that the path generated is then applied to the underlying CALayer of the component&#39;s UIView for it to be displayed.</p><p>By applying the shape generator’s path on the component, we had to keep a couple things in mind:</p><p><strong>Adding proper shadow, border, and background color support</strong></p><p>Because the shadows, borders, and background colors are part of the default UIView API and don&#39;t necessarily take into account custom CALayer paths (they follow the default rectangular bounds), we needed to provide additional support. So we implemented MDCShapedShadowLayer to be the view&#39;s main CALayer. What this class does is take the shape generator path, and then passes that path to be the layer&#39;s shadow path—so the shadow will follow the custom shape. It also provides different APIs for setting the background color and border color/width by explicitly setting the values on the CALayer that holds the custom path, rather than invoking the top level UIView APIs. As an example, when setting the background color to black (instead of invoking UIView&#39;s backgroundColor) we invoke CALayer&#39;s fillColor.</p><p><strong>Being conscious of setting layer’s properties such as shadowPath and cornerRadius</strong></p><p>Because the shape’s layer is set up differently than the view’s default layer, we need to be conscious of places where we set our layer’s properties in our existing component code. As an example, setting the cornerRadius of a component—which is the default way to set rounded corners using Apple&#39;s API—will actually not be applicable if you also set a custom shape.</p><p><strong>Supporting touch events</strong></p><p>Receiving touch also applies only on the original rectangular bounds of the view. With a custom shape, we’ll have cases where there are places in the rectangular bounds where the layer <em>isn’t</em> drawn, or places outside the bounds where the layer <em>is</em> drawn. So we needed a way to support proper touch that corresponds to where the shape is and isn’t, and act accordingly.</p><p>To achieve this, we override the hitTest method of our UIView. The hitTest method is responsible for returning the view supposed to receive the touch. In our case, we implemented it so it returns the custom shape&#39;s view if the touch event is contained inside the generated shape path:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f526aca6604b1a32af0c6f2db7774e07/href">https://medium.com/media/f526aca6604b1a32af0c6f2db7774e07/href</a></iframe><p><strong>Ink Ripple Support</strong></p><p>As with the other properties, our ink ripple (which provides a ripple effect to the user as touch feedback) is also built on top of the default rectangular bounds. For ink, there are two things we update: 1) the maxRippleRadius and 2) the masking to bounds. The maxRippleRadius must be updated in cases where the shape is either smaller or bigger than the bounds. In these cases we can&#39;t rely on the bounds because for smaller shapes the ink will ripple too fast, and for bigger shapes the ripple won&#39;t cover the entire shape. The ink layer&#39;s maskToBounds needs to also be set to NO so we can allow the ink to spread outside of the bounds when the custom shape is bigger than the default bounds.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee87a54833f3f997ff29368d8b2f816f/href">https://medium.com/media/ee87a54833f3f997ff29368d8b2f816f/href</a></iframe><h3>Applying a custom shape to your components</h3><p>With all the implementation complete, here are per-platform examples of how to provide cut corners to a Material Button component:</p><p><strong>Android:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5880e4a39843103e12ce14f3f8cb5c3/href">https://medium.com/media/d5880e4a39843103e12ce14f3f8cb5c3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98a9b3fdbd4468a56f13920e8666939d/href">https://medium.com/media/98a9b3fdbd4468a56f13920e8666939d/href</a></iframe><p><strong>Flutter:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d351c4adcce4522921f7988312283d34/href">https://medium.com/media/d351c4adcce4522921f7988312283d34/href</a></iframe><p><strong>iOS:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17fc23dab0251800d5778eb5c7f3a86b/href">https://medium.com/media/17fc23dab0251800d5778eb5c7f3a86b/href</a></iframe><p><strong>Web (rounded corners):</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48ff44520f8a774ab190d00cff7a8e08/href">https://medium.com/media/48ff44520f8a774ab190d00cff7a8e08/href</a></iframe><h3>Final words</h3><p>I’m really excited to have tackled this problem and have it be part of the Material Design system. I’m particularly happy to have worked so collaboratively with design. As an engineer, I tend to tackle problems more or less from similar angles, and also think about problems very similarly to other engineers. But when solving problems together with designers, it feels like the challenge is actually looked at from all the right angles (pun intended), and the solution often turns out to be better and more thoughtful.</p><p>We’re in good shape to continue growing the Material shape system and offering even more support for things like edge treatments and more complicated shapes. One day (when Houdini is ready) we’ll even be able to support cut corners on the web.</p><p>Please check our code out on GitHub across the different platforms: <a href="https://goo.gl/fpwhmZ">Android</a>, <a href="https://goo.gl/AVRsSs">Flutter</a>, <a href="https://goo.gl/iXkmAa">iOS</a>, <a href="https://goo.gl/deomkm">Web</a>. And check out our newly updated <a href="https://goo.gl/9StPZB">Material Design guidance on shape</a>.</p><p><em>Originally published at </em><a href="https://developers.googleblog.com/2018/12/building-shape-system-for-material.html"><em>developers.googleblog.com</em></a><em> on December 18, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eef36725b28b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/building-the-shape-system-for-material-design-eef36725b28b">How Google Built the Shape System for Material Design</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving our Flask backend from Heroku to AWS — The Guide]]></title>
            <link>https://medium.com/hackernoon/moving-our-flask-backend-from-heroku-to-aws-the-guide-31b2b372291c?source=rss-974f9fd6d0d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/31b2b372291c</guid>
            <category><![CDATA[founders]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Yarden Eitan]]></dc:creator>
            <pubDate>Tue, 05 Apr 2016 21:04:07 GMT</pubDate>
            <atom:updated>2017-07-13T20:32:09.265Z</atom:updated>
            <content:encoded><![CDATA[<p>The original reasoning for the move was purely cost related, however the performance improvement was huge. Our company decided to officialy move into the “Cockroach Age”, and by that it sadly meant moving a lot of our server-side implementation out of Heroku. Heroku made things simple, that’s for sure, but we had a ton of Amazon credits and were feeling a bit taken advantage of by paying more and getting less all for pure laziness.</p><p>I can’t say it was easy. I literally looked at dozens of articles, all providing partial information or outdated/wrong information. I was thinking to myself “this is weird, why is there no simple and clear guide to tell us small and poor startups how to move away from Heroku”. So after a lot of guides, stack overflow error solving, AWS architect 1 on 1, and some sheer frustration on the brink of giving up, I am here providing you a full guide on how to do this scary move.</p><h4>1. Elastic Beanstalk (EB)</h4><p>Most of us have already used or are aware of EC2 instances, but when using a dedicated EC2 instance for an entire backend, it becomes harder to scale when workloads change. Therefore I chose to use Elastic Beanstalk, which is an easy to use service for deploying and scaling web applications, and moreover it is free. Here is how to set it up for Flask (<em>I use the EB CLI interface, so you will need to download it prior: </em><a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html"><em>http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html</em></a><em>)</em>:</p><ul><li>Go to the folder where your project lies</li><li>In the command line type: <strong><em>eb init</em></strong></li><li>Choose your region, create a new application, enter its name, and select its platform (Python in our case). Choose the version (most likely 2.7), say yes to setting up SSH, and either select an existing key pair you already had set up in AWS or create a new one.</li></ul><p>Now we have finished setting up the directory for EB, and we can create our running environment.</p><ul><li>Type in the command line: <strong><em>eb create</em></strong></li></ul><p>Congrats! you have just created your first EB environment. EB has now created an EC2 instance and attached a storage volume to it. You can now go into your AWS EB dashboard and see your newly made environment. EB is pretty smart, and as you see it was simple to set up. It zips and uploads your folder to AWS, and constructs the server based on its knowledge of Python environments. It will look at your requirements.txt file to know what libraries to download, and will try to find your WSGI configuration to start up the server. You can go into the configuration tab and change its scaling and networking. You can also see the enviroment’s health in the dashboard or fetch logs if you need to have more intel of what’s going on.</p><p>Of course my execution brought with it a handful of errors, and the key thing to focus on is a creature they call “.ebextensions”. This is a folder you need to add to your project which consists of .config files. These files basically allow you to configure your environment while it is being set up.</p><pre>#my example.config<br>packages:<br>  yum:<br>    git: []<br>    libffi-devel: []<br>    libjpeg-turbo-devel: []<br><br>container_commands:<br>  01_wsgipass:<br>    command: &#39;echo &quot;WSGIPassAuthorization On&quot; &gt;&gt; ../wsgi.conf&#39;<br>  AddGlobalWSGIGroupAccess:<br>    command: &quot;if ! grep -q &#39;WSGIApplicationGroup %{GLOBAL}&#39; ../wsgi.conf ; then echo &#39;WSGIApplicationGroup %{GLOBAL}&#39; &gt;&gt; ../wsgi.conf; fi;&quot;<br><br>option_settings:<br>  &quot;aws:elasticbeanstalk:container:python&quot;:<br>    WSGIPath: application.py<br>    NumProcesses: 3<br>    NumThreads: 20<br>  &quot;aws:elasticbeanstalk:application:environment&quot;:<br>    EXAMPLE_ENV_VAR: env_var_value</pre><p>In my case I was using the <strong><em>yum</em></strong> command to install some cryptography libraries and git on the machine. I used <strong><em>aws:elasticbeanstalk:application:environment</em></strong> to add all my environment variables. Most importantly I had a few WSGI issues I needed to fix. WSGIPath to tell EB what file to launch my app from. <strong><em>01_wsgipass</em></strong> to allow basic HTTP authentication headers to not be truncated when passed to the server, and <strong><em>AddGlobalWSGIGroupAccess</em></strong> due to issues I had related to this article: <a href="http://djm.io/deploying-scipy-into-aws-elastic-beanstalk/">http://djm.io/deploying-scipy-into-aws-elastic-beanstalk/</a></p><p>Alright! now after you have added your .ebextensions folder, just go back to the CLI and issue the command <strong><em>eb deploy</em></strong>, and that basically re-deploys your server with the new changes.</p><h4>2. Workers</h4><p>We had a few more things to figure out, as we also had a worker process running our longer tasks, or tasks we didn’t want to have block our server. We used a Redis Queue and a separate dyno on Heroku to produce our current worker configuration. Luckily, Elastic Beanstalk also comes with a Worker environment that is pretty simple to set up. What you need to do is follow the same steps as setting up the web environment, only this time choose the existing application you have created and when prompted choose to create a worker environment. The worker environment will prompt you about an SQS creation, which we will talk about now.</p><p>The way worker environments work in EB is by communicating with the web env using SQS. SQS is basically a simple queue service that you can send information to. In this case, our web env can send a message to the SQS queue and the worker thread has a daemon installed that listens to that queue and fetches the message when it arrives, does what is needed and returns a 200 (ok) status back. If it doesn’t return a 200, the message gets sent to a dead queue which can then be used if these failed requests need to be re-issued.</p><p>What needs to be set up to make this work:</p><ul><li>Install <a href="https://aws.amazon.com/sdk-for-python/">boto</a> (AWS SDK for Python) on your flask backend and create a method that sends an SQS message to the desired queue that was set up for the worker env <em>(you will probably need to set up the proper AWS permissions for your server to allow you to send SQS messages)</em>. In my case, I sent an SQS message consisting of two parameters, a function name, and an argument list.</li></ul><pre>def send_message_to_sqs(<em>data</em>):<br>    # Put the message in the queue<br>    m = boto.sqs.message.RawMessage()<br>    m.set_body(json.dumps(<em>data</em>))<br>    status = q.write(m)<br>    print status</pre><pre>send_message_to_sqs({&#39;func&#39;:&#39;save_to_s3_and_update_user&#39;, &#39;args&#39;:{&#39;user_id&#39;:str(usr.id)}})</pre><p>b. Have an endpoint in your worker env for it to have the SQS messages be sent to. You configure the endpoint name in the Worker env configuration.</p><p>c. The method of that endpoint in my worker env basically looked at the incoming message, based on the function name understood what function to call, and gave it the argument list. At the end if everything was successful, it just returned a 200 (ok) status.</p><p>Here is an example <a href="https://github.com/awslabs/eb-py-flask-signup">web environment</a> and <a href="https://github.com/awslabs/eb-py-flask-signup-worker">worker environment</a> Amazon provides as an example.</p><p>If you were able to reach this point, you most likely now have configured a basic Elastic Beanstalk web app with a worker thread that interacts with it. Hurray!</p><h4>3. MongoDB</h4><p>We used one of the Heroku add-ons (mLab) for our MongoDB database. It makes things super simple, and they offer you full support, do the setting up, and maintain the database for you. However, we decided to give AWS a fair chance with this as well. This is a pretty long and elaborate guide, so I am just going to link you to the best guide I found on this:</p><p><a href="https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/">Amazon EC2</a></p><p>Just a few pointers if you are having trouble or receiving errors (like we did):</p><ol><li>Make sure you have a security group that opens ports 22 and 27017. You will need to SSH to your machine so you need port 22, and 27017 is for your MongoDB connection.</li><li>Edit /etc/mongod.conf and look for <strong><em>bind_ip</em></strong>. If it is pointing to the localhost, you won’t be able to access it from an outside ip. Either give it the ip of the machine that needs to access it, or comment out that command entirely.</li><li>Make sure you add a <strong><em>dbOwner</em></strong> user (or the right role that fits your needs) to your MongoDB users for the database you are interacting with. You do this by connecting to your mongo shell (SSHing then typing <strong><em>mongo</em></strong> or doing a remote <strong><em>mongo </em></strong>command<strong><em> </em></strong>from your local machine), and then issuing a <strong><em>db.createUser()</em></strong> command. The role I gave my new user is:</li></ol><pre>“roles” : [ {“role” : “dbOwner”, “db” : “my_database_name”} ]</pre><p>If you connect to your database without any user, you might be in read-only mode. Make sure you are connecting to the database with the right username and password on your flask backend.</p><h4>4. Add-ons</h4><p>Heroku had a lot of neat add ons, specifically in my case I found a lot of use for the UI logging, and periodic database backups. No one said you can’t do that on EB too!</p><p><strong>Papertrail for logging</strong></p><p><a href="http://help.papertrailapp.com/kb/hosting-services/aws-elastic-beanstalk/">AWS Elastic Beanstalk</a></p><p>Basically as simple as adding another config file to your .ebextensions and configuring it properly :)</p><p><strong>Periodic backups for your MongoDB</strong></p><p><a href="https://github.com/theycallmeswift/node-mongodb-s3-backup">theycallmeswift/node-mongodb-s3-backup</a></p><p>Simple and easy to use Node package that backups your database to S3 every day.</p><h4>Final Words</h4><p>I hope this guide was able to help you on <strong><em>your</em></strong> journey of moving from Heroku to AWS, or at least showed you my personal tackling of it. Since our move, we are definitely more cost effective, have better response times for our app, and are pretty satisfied :)</p><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a>family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp;sponsorship</a> opportunities.</blockquote><blockquote>To learn more, <a href="https://goo.gl/4ofytp">read our about page</a>, <a href="http://bit.ly/HackernoonFB">like/message us on Facebook</a>, or simply, <a href="https://goo.gl/k7XYbx">tweet/DM @HackerNoon.</a></blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31b2b372291c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/moving-our-flask-backend-from-heroku-to-aws-the-guide-31b2b372291c">Moving our Flask backend from Heroku to AWS — The Guide</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I love Swift more than Objective-C]]></title>
            <link>https://medium.com/@yardeneitan/why-i-love-swift-more-than-objective-c-58e6e9e66e0e?source=rss-974f9fd6d0d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/58e6e9e66e0e</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[objective-c]]></category>
            <dc:creator><![CDATA[Yarden Eitan]]></dc:creator>
            <pubDate>Mon, 25 Jan 2016 01:12:23 GMT</pubDate>
            <atom:updated>2016-02-06T19:54:40.759Z</atom:updated>
            <content:encoded><![CDATA[<p>Swift is the new programming language developed by Apple.</p><p>It was built to offer an easier and more efficient way to build software for Apple products. Apple billed it as a language that’s “Like Objective-C without the bulk of C.” when it was introduced at the developer’s conference in June 2014.</p><p>Swift <a href="http://nondot.org/sabre/">drew its ideas</a> from other modern languages such as: Haskell, Ruby, Python, C#, and many more. That makes Swift a multi-paradigm language consisting of object-oriented, imperative, and functional programming aspects. Moreover, version 2.2 of Swift was recently announced as <a href="https://github.com/apple/swift">open source</a>, which makes it even more nimble to advances in languages and new concepts.</p><p>I decided to give Swift a go, and I haven’t looked back at Objective-C — or its square brackets (<em>[foo bar]</em>), semicolon line endings, and pointers of pointers (<em>NSError **error</em>) — since. There are many reasons why I prefer Swift. I’ll break down some of the reasons why we should all be using it:</p><h4>Optionals</h4><p>Prior to Swift, to make sure we weren’t using any object pointers mistakenly pointing to null, we had to enforce a check, otherwise we might crash at runtime or get a no-operation. This could lead to unexpected results and makes it harder to understand where the problem originates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b922dcd83ef6d06aa65cd909dac4541/href">https://medium.com/media/7b922dcd83ef6d06aa65cd909dac4541/href</a></iframe><p>Swift introduced the art of optionals. Optionals help us better define the absence of a value, <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID309">and say</a> either “there <em>is</em> a value, and it equals <em>x</em>” or “there <em>isn’t</em> a value at all”. Optionals can be used not only on objects, but also on primitives such as Int or Bool, yay! They are safer than null pointers, and help us enforce type safety during compilation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d5HAYdE21mLJhAwO_0Pepw.png" /></figure><p>By initializing a parameter with a question mark: <em>var x : Int?</em>. We are hereby declaring it an optional. To get the value from an optional, you do an action called ‘unwrapping’. You can unwrap an optional in many different and cool ways, here are a few:</p><ul><li><em>if let xUnwrapped = x { /*x is not null*/ }</em> — This allows you to enter the conditional only if x is not null and already have it unwrapped in a new parameter. You can also use “optional chaining” if you need to make sure every parameter along the way is not null as well: <em>if let z_unwrapped = x?.y?.z { /*x, x.y, and x.y.z are not null*/ }</em></li><li><em>x!</em> — This forcefully unwraps the optional, but is unsafe if you don’t know prior that x actually has a value. You can also initialize a parameter in such a way: <em>var x : String!</em></li><li><em>x ?? y</em> — the nil coalescing operator allows us to use x if it has a value, or otherwise use y.</li><li><em>guard let xUnwrapped = x else { /* x</em><strong><em> is</em></strong><em> null */ }</em> — guard is similar to Ruby’s Unless, and bypasses the brackets if x has a value. xUnwrapped remains in the scope and can be used even after the statement!</li></ul><h4>No more header files!</h4><p>While Objective-C used header files to define interfaces, Swift takes the stance of more modern languages, and by getting rid of header files, it removes code redundancy, potential circular imports and allows us to focus more on correct separation of objects and methods, rather than files. In fact, Swift entirely removes the need for imports within the same module.</p><h4>Generics</h4><p>Objective-C allowed us to store just about anything in a collection, but it lacked type safety and could potentially be dangerous if not looked after well. Swift forces typed collections, but with their safety comes the need for flexibility — and then came Generics.</p><p>Generics allows us to give functions and types a generic classification:</p><pre><em>func</em> <em>foo&lt;T&gt;([T])</em></pre><p>This allows us to pass the method an array with just about anything that is of the same type; Strings, Ints, or custom objects. Where in Objective-C you could be sending an array of NSStrings and NSNumbers to a Sum function and ending up executing <em>“hey” + 6</em>, in Swift you can make sure only the type you are interested in is sent (yes, in Swift you can use the + operator to append Strings).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50e52ea889b8f100cecad67d3e8cd98d/href">https://medium.com/media/50e52ea889b8f100cecad67d3e8cd98d/href</a></iframe><p>As you can see, this is a much safer approach, and it lessens code duplication by allowing multiple types to use the same function.</p><h4>Tuples</h4><p>I have been reminiscing of tuples ever since I was introduced to ML in one of my undergrad classes. Tuples allow us to initialize a comma separated list with 0 or more types, that looks like so: <em>(3, “John”, 2.1)</em>. What I like most about tuples is not only the pattern matching, or the variables with multiple types, but the capability of a function to finally return multiple types.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa6afa71b300d26adb51f644fcbd0da0/href">https://medium.com/media/fa6afa71b300d26adb51f644fcbd0da0/href</a></iframe><h4>Improved Structs and Enums</h4><p>While enums were created to define a list of possible values, the old school C and Objective-C enums only allowed Ints. Thankfully Swift gave enums some muscles, and now enums can consist of different types, and also initializers and custom functions (at the core, Optionals are enums as well).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9916ffe80dd6b9e4582edd037a3cff51/href">https://medium.com/media/9916ffe80dd6b9e4582edd037a3cff51/href</a></iframe><p>Structs also got a brand new look in Swift. Unlike their older counterpart, they can now have methods, properties, initializers, and also conform to protocols. The beauty of structs is that they are passed by value, whereas classes are passed by reference. Therefore we can easily copy them to a new instance and change data without it propagating to the other instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14a7ded0ae5f8f65f16b3e5c51512a1e/href">https://medium.com/media/14a7ded0ae5f8f65f16b3e5c51512a1e/href</a></iframe><h4>Type Inference and Pattern Matching</h4><p>Type inference in Swift allows us to omit the types of variables and expressions in our code. The compiler is able to deduce at compilation the type of the expression based on the value it is given. This makes our code extra neat and easier to read.</p><pre>var str = “hello” //String<br>var dbl = 3.4 //Double</pre><p>Pattern matching is most useful when it comes to switch cases, but can also partially be used in declarations and for…in statements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe6dc0722c4fab4c43e10603bce0da7c/href">https://medium.com/media/fe6dc0722c4fab4c43e10603bce0da7c/href</a></iframe><p>See how much fun we can have with it?</p><h4>Playgrounds</h4><p>Testing out a new algorithm to see that it is working as expected could become a hassle if you have a complex project, or even the friction of opening a new one. With Playgrounds, you can just blurt out the code on a new playground project, check for errors, and get immediate inline executions of it. With the ease of writing and testing code, and the interactive feedback loop of the execution, we improve development speed and efficiency.</p><h4>Conclusion</h4><p>Swift is a powerful tool that is blessed with new features that top it’s older comrade Objective-C. Not only is it easier to read, it is also faster (no more legacy C conventions), requires less code (yay string interpolation and syntactic sugar), and is safer (need I remind optionals?). If all this still didn’t convince you, maybe the real Swift can.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fw1oM3kQpXRo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dw1oM3kQpXRo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fw1oM3kQpXRo%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ac4d95f0121eb3448523e2ca1bb7e55/href">https://medium.com/media/2ac4d95f0121eb3448523e2ca1bb7e55/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58e6e9e66e0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>