<?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 Arpith Siromoney on Medium]]></title>
        <description><![CDATA[Stories by Arpith Siromoney on Medium]]></description>
        <link>https://medium.com/@arpith?source=rss-8fcab1c95a89------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*d0W5rScLXmIUkxum.jpeg</url>
            <title>Stories by Arpith Siromoney on Medium</title>
            <link>https://medium.com/@arpith?source=rss-8fcab1c95a89------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:35:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arpith/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[Fun with SSH Timeouts]]></title>
            <link>https://medium.com/@arpith/fun-with-ssh-timeouts-49a294661ffa?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/49a294661ffa</guid>
            <category><![CDATA[iptables]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Sun, 10 Mar 2019 20:51:20 GMT</pubDate>
            <atom:updated>2019-03-10T20:51:20.680Z</atom:updated>
            <content:encoded><![CDATA[<p>This week at work I was looking at an issue where a tool we had written to run a command on multiple servers would get stuck on a server that was under some load. The way we had written it was to run the command using ssh, like ssh host command, on different threads (one per server).</p><p>This was originally published at <a href="https://arpith.co/ssh-timeouts">https://arpith.co/ssh-timeouts</a></p><p>My first thought was that ssh should have a way to set a timeout on idle connections, and indeed it does — ssh -o serveraliveinterval=15 sends a message every 15 seconds to the server requesting a response. Interestingly, this option was already being set by the tool. So I explored ServerAliveMaxCount which sets how long the client will wait before disconnecting if the server is unresponsive. Setting it to 0 would disconnect the ssh connection after 15 seconds, but setting it to anything else (for example, the default which is 3) would keep the connection open.</p><p>In order to to make sure the options were working as described in the man page, I ran ssh -o serveraliveinterval=15 $SERVER &quot;iptables -A OUTPUT -d $SSH_CLIENT -j DROP &amp;&amp; sleep 180 &amp;&amp; iptables -A OUTPUT -d $SSH_CLIENT -j ACCEPT&quot; on a functioning server to prevent it from sending packets back to my laptop for some time. This made the connection drop after 45 seconds, which was great!</p><p>So I discussed the issue with a coworker and the specific case was that the server was swapping, so the command couldn’t actually run. However, we believe that in this case the ssh server was still able to respond to the keep alive messages from the client, which was why the connection wasn’t timing out.</p><p>We finally decided that a combination of an optional hard timeout and a fix to the tool to allow killing the processes that were stuck would be a reasonable fix to this problem. I ended up implementing the timeout with a thread that would sleep for the provided time and then just kill the ssh process, and he implemented the fix that passed on Ctrl-C’s.</p><p>I liked this issue because it helped me understand what our tool was doing, learn about SSH timeouts and fix something that impacted engineers outside our team.</p><p>03 March 2019</p><p><em>Originally published at </em><a href="https://arpith.co/ssh-timeouts"><em>arpith.co</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49a294661ffa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using GitHub Pages to Blog with Jekyll]]></title>
            <link>https://medium.com/@arpith/using-github-pages-to-blog-with-jekyll-405059645c2a?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/405059645c2a</guid>
            <category><![CDATA[jekyll]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[blogging]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Sun, 10 Mar 2019 20:47:11 GMT</pubDate>
            <atom:updated>2019-03-10T20:47:11.806Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been writing on Medium and Tumblr in the past but I’ve always wanted to switch to a static website where I could have more control / ownership. That day has come! This post is an explanation of the new setup. This was originally published at <a href="https://arpith.co/new-blog-setup">arpith.co/new-blog-setup</a></p><h3>Exporting my posts</h3><p>I used <a href="https://github.com/xdamman/mediumexporter">mediumexporter</a> to export my recent posts from Medium and <a href="https://github.com/jaanus/tumblr2markdown">tumblr2markdown</a> to export the rest of the posts from Tumblr. I now had a directory of markdown files.</p><h3>GitHub pages</h3><p>GitHub pages is a neat way to set up a static website. It uses Jekyll and renders markdown files without needing any extra configuration.</p><h3>Routes</h3><p>I wanted urls to look like arpith.co/new-blog-setup but also wanted my posts to sit in a separate directory in the repository. To do this I used <a href="https://github.com/jekyll/jekyll/issues/5628#issuecomment-275459907">this _config.yml</a>, changing the “mypages” path to “posts”. This let me drop “posts” from the urls.</p><pre>defaults: - scope: path: &quot;posts&quot; type: &quot;pages&quot; values: permalink: &quot;/:basename&quot;</pre><h3>Index page</h3><p>My homepage is just a list of posts. This is a throwback to my undergrad days (before I switched to Tumblr). The post list is generated with the following Liquid code. I’m using pages instead of posts because I don’t want to keep timestamps in my filenames. This means I need to sort site.pages by date and reverse it.</p><pre>{% assign posts = site.pages | sort: &#39;date&#39; | reverse %} {% for post in posts %} - [{{post.title}}]({{post.url}}){% endfor %}</pre><h3>Misc</h3><p>I’m using index.md for the index page and README.md for the repository readme.</p><p>assets/css/style.css is where the style sheet lives and _layouts contains the templates.</p><p>Finally, I set up my domain name to point to GitHub pages’ addresses, and added the domain name in the repository’s settings page. This created a file in the repository called CNAME which contains the domain name.</p><p>And that’s it! I’m pretty happy with the result!</p><p>Thanks to <a href="https://trueskawka.github.io/">Alicja Raszkowska</a> and <a href="http://composition.al/">Lindsey Kuper</a>!</p><p>23 September 2018</p><p><em>Originally published at </em><a href="https://arpith.co/new-blog-setup"><em>arpith.co</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=405059645c2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Confidant v1 REST API Routes]]></title>
            <link>https://medium.com/@arpith/confidant-v1-rest-api-routes-5a83bfb3bd56?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a83bfb3bd56</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Wed, 01 Aug 2018 05:20:30 GMT</pubDate>
            <atom:updated>2018-08-01T05:20:30.251Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://lyft.github.io/confidant/">Confidant</a> is an open source credential storage project from Lyft. I’ve written about <a href="https://medium.com/@arpith/how-confidant-uses-kms-for-authentication-4aa14d5f6b91">how clients authenticate with AWS KMS</a> and what a request looks like. This post contains the <a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py">list of routes</a> supported by the Confidant v1 REST API.</p><h3>Services</h3><h4>/v1/services</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L73">Get list of services</a></p><h4>/v1/services/&lt;id&gt;</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L99">Get service metadata and list of credentials and blind credentials for a service</a><br><strong>PUT: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L251">Update a service’s credentials, blind_credentials, account and enabled flag</a></p><h3>Credentials</h3><h4>/v1/credentials</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L347">Get list of credentials sorted by name</a><br><strong>POST: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L712">Creates a credential</a></p><h4>/v1/credentials/&lt;id&gt;</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L366">Get a credential (includes the secrets)</a><br><strong>PUT: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L722">Updates a credentials</a></p><h4>/v1/credentials/&lt;id&gt;/services</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L712">Get list of service ids and enabled flag for credential</a></p><h3>Blind Credentials</h3><h4>/v1/blind_credentials</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L842">get list of blind credentials</a><br><strong>POST: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L978">creates a blind credential</a></p><h4>/v1/blind_credentials/&lt;id&gt;</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L859">gets a blind credential</a><br><strong>PUT: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L1074">updates a blind credential</a></p><h4>/v1/blind_credentials/&lt;id&gt;/services</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L1064">returns a list of services associated with this blind credential</a></p><h3>Archive</h3><h4>/v1/archive/services</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L181">Get a list of archived services</a></p><h4>/v1/archive/services/&lt;id&gt;</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L143">Get a list of revisions for an archived service</a></p><h4>/v1/archive/credentials</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L445">Gets a list of archived credentials</a></p><h4>/v1/archive/credentials/&lt;id&gt;</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L408">get a list of revisions for an archived credential</a></p><h4>/v1/archive/blind_credentials</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L954">get archived blind credentials</a></p><h4>/v1/archive/blind_credentials/&lt;id&gt;</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L911">get a list of revisions for an archived blind credential</a></p><h3>Roles</h3><h4>/v1/roles</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L89">Gets the list of IAM roles</a></p><h3>Grants</h3><h4>/v1/grants/&lt;id&gt;</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L229">Get grants for a service</a><br><strong>PUT: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L199">Add encrypt and decrypt grants for the service</a></p><h3>Misc</h3><h4>/v1/login</h4><p><strong>GET, POST: </strong><a href="https://github.com/lyft/confidant/blob/fa08086351d731feb45b9792ab62617ca59246bf/confidant/routes/v1.py#L33">Send user through login flow</a></p><h4>/v1/user/email</h4><p><strong>GET, POST: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L41">Get the email address of the currently logged-in user.</a></p><h4>/v1/client_config</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L54">Get configuration to help clients bootstrap themselves</a></p><h4>/v1/value_generator</h4><p><strong>GET: </strong><a href="https://github.com/lyft/confidant/blob/master/confidant/routes/v1.py#L1211">Generate a random string</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a83bfb3bd56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting a service’s credentials from Confidant]]></title>
            <link>https://medium.com/@arpith/getting-a-services-credentials-from-confidant-228b7cb72663?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/228b7cb72663</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Sat, 21 Jul 2018 02:33:17 GMT</pubDate>
            <atom:updated>2018-07-21T02:34:32.466Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://lyft.github.io/confidant/">Confidant</a> is Lyft’s open source secret management service. Last week I described how it uses <a href="https://medium.com/@arpith/how-confidant-uses-kms-for-authentication-4aa14d5f6b91">AWS KMS for authentication</a>. Here’s how the client fetches credentials from the server.</p><h3>Authentication</h3><p>I go into more detail in <a href="https://medium.com/@arpith/how-confidant-uses-kms-for-authentication-4aa14d5f6b91">last week’s post</a>, but the summary is that the token is generated by the equivalent of:</p><pre>$ aws kms encrypt --key-id confidant-key --encryption-context to=confidant-server,from=userid,user_type=user --plaintext &#39;{&quot;not_before&quot;:timestamp1, &quot;not_after&quot;:timestamp2}&#39; --region us-east-1</pre><p>The username looks like 2/user-type/userid where userid has to match the from field of the encryption context.</p><h3>Request</h3><p>The request is a GET request to /v1/services/service-name, with X-Auth-Token and X-Auth-From headers set to the token and username.</p><pre>$ curl CONFIDANT_URL/v1/services/service-name -H &quot;X-Auth-From: 2/user/from&quot; -H &quot;X-Auth-Token: CONFIDANT_TOKEN&quot;</pre><h3>Response</h3><p>The JSON response looks like this:</p><pre>{<br>  &quot;credentials&quot;: [<br>    {<br>      &quot;credential_pairs&quot;: {<br>        &quot;key&quot;: &quot;value&quot;<br>      },<br>      &quot;data_type&quot;: &quot;credential&quot;,<br>      &quot;enabled&quot;: true,<br>      &quot;id&quot;: &quot;credential id&quot;,<br>      &quot;name&quot;: &quot;credential name&quot;,<br>      &quot;revision&quot;: 1<br>    }<br>  ],<br>  &quot;enabled&quot;: true,<br>  &quot;id&quot;: &quot;service-name&quot;,<br>  &quot;modified_by&quot;: &quot;foo@bar.com&quot;,<br>  &quot;modified_date&quot;: &quot;Fri, 20 Jul 2018 19:21:24 GMT&quot;,<br>  &quot;revision&quot;: 1<br>}</pre><p>That’s all there is to it! This is <a href="https://github.com/lyft/python-confidant-client/blob/a30dde8aae587aacf5adac09188c0ccb1fd9fb4c/confidant_client/__init__.py#L275">pretty much</a> how the <a href="https://github.com/lyft/python-confidant-client">Python client</a>’s get_service option works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=228b7cb72663" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Confidant uses KMS for authentication]]></title>
            <link>https://medium.com/@arpith/how-confidant-uses-kms-for-authentication-4aa14d5f6b91?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aa14d5f6b91</guid>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Sun, 15 Jul 2018 00:46:22 GMT</pubDate>
            <atom:updated>2018-07-15T00:54:56.563Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://lyft.github.io/confidant/">Confidant</a> is an open source product from Lyft that lets you store credentials securely. Your server then makes a request to Confidant via its <a href="https://lyft.github.io/confidant/basics/client/">client</a> to fetch the credentials your code needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ktCjE1b08txJL-W7vdwTqg@2x.jpeg" /><figcaption>The workflow with Confidant</figcaption></figure><p>This post explains how the Confidant client generates usernames and tokens for KMS based authentication. They are passed in the request either through <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">basic auth</a> or as headers (X-Auth-Token and X-Auth-From).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__9ZnlICJEkSeXsWAW7M5A@2x.jpeg" /><figcaption>How the client handles authentication</figcaption></figure><h3>Token</h3><p>The Confidant client uses <a href="https://lyft.github.io/confidant/advanced/kms_auth/">KMS encryption</a> to generate a token, running the <a href="https://github.com/lyft/python-kmsauth/blob/aa2dd957a5d3e58c89fe51a55c6053ff81d9191e/kmsauth/__init__.py#L451">equivalent</a> of aws kms encrypt --key-id confidant-key --encryption-context to=confidant-server,from=username,user_type=user --plaintext payload --region us-east-1</p><ol><li>confidant-key is a KMS key that the Confidant server has access to</li><li>The from field of the encryption context is what is recorded as having performed the request</li><li>user_type is typically service, but it’s possible to allow users to make KMS auth based requests (you need to <a href="https://lyft.github.io/confidant/basics/configuration/#kms-authentication-for-end-users">set an environment variable</a>).</li><li>The payload looks like {&quot;not_before&quot;:timestamp1, &quot;not_after&quot;:timestamp2} where the timestamps are in %Y%m%dT%H%M%SZ format</li></ol><h3>Username</h3><p>The username <a href="https://github.com/lyft/python-kmsauth/blob/aa2dd957a5d3e58c89fe51a55c6053ff81d9191e/kmsauth/__init__.py#L438">looks like</a> 2/user-type/from where the user-type and from have to match the encryption context.</p><p>If you’re making requests as a service, you should use the service’s IAM role in the from field as Confidant <a href="https://lyft.github.io/confidant/advanced/kms_auth/#service-to-service-authentication">generates a grant</a> to allow a service to encrypt / decrypt using its key.</p><p>When authenticating as a user, it makes sense to use the AWS username — this can be checked by <a href="https://lyft.github.io/confidant/advanced/kms_auth/#user-to-service-authentication">adding an IAM policy</a> to the Confidant key to only allow encryption if the username of the person making the AWS request matches what’s in the from field of the encryption context.</p><p>Note that if the user is making the AWS request in an assumed role, attempting to match on the username will <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#policy-vars-infotouse">cause the request to fail</a>. You can use the AWS userid instead, which looks like role-id:caller-specified-role-name. This means you’ll have to pass the username and token in the request’s headers as the colon in the username will cause basic authentication to fail on the server side.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aa14d5f6b91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type checking Ruby with minimal effort]]></title>
            <link>https://medium.com/@arpith/type-checking-ruby-with-minimal-effort-ed1859e552c0?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed1859e552c0</guid>
            <category><![CDATA[type-checking]]></category>
            <category><![CDATA[recurse-center]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Sun, 25 Feb 2018 01:22:21 GMT</pubDate>
            <atom:updated>2018-02-25T01:22:21.251Z</atom:updated>
            <content:encoded><![CDATA[<p>This past week I took part in a mini retreat at the <a href="https://www.recurse.com/">Recurse Center</a>. I worked on <a href="https://github.com/arpith/kurangu">generating type annotations</a> for Ruby, heavily inspired by <a href="https://medium.com/u/a4c6efa67fe0">Instagram Engineering</a>’s <a href="https://github.com/Instagram/MonkeyType/">MonkeyType</a> project (check out this <a href="https://engineering.instagram.com/let-your-code-type-hint-itself-introducing-open-source-monkeytype-a855c7284881">blog post</a>!).</p><h4>Motivation</h4><p>There is a fun tool for adding types and type checking to Ruby called <a href="https://github.com/plum-umd/rdl">RDL</a>. <a href="https://www.youtube.com/watch?v=buY54I7mEjA">This video</a> explains it well! In RDL, types can be used to decorate methods:</p><pre>require &#39;rdl&#39;<br>extend RDL::Annotate</pre><pre>type &#39;(Integer) -&gt; String&#39;<br>def id(x)<br>  &quot;forty-two&quot;<br>end</pre><p>Running this code will throw an error if either the arguments or return type differs from the signature.</p><h4>Examples</h4><p>I thought it would be fun to automatically add the annotations, and it is! Given an input file called input.rb that looks like this:</p><pre>def the_answer()<br>  return &#39;forty-two<br>end</pre><pre>the_answer()</pre><p>Running kurangu input.rb updates it to look like:</p><pre>require &#39;rdl&#39;<br>require &#39;types/core&#39;</pre><pre>extend RDL::Annotate<br>type &#39;() -&gt; String&#39;<br>def the_answer()<br>  return &#39;forty-two&#39;<br>end</pre><pre>the_answer()</pre><p>It gets more interesting when you have an input file that looks like:</p><pre>def the_answer(x)<br>  if x<br>    return &#39;forty-two&#39;<br>  else<br>    return 42<br>  end<br>end</pre><pre>the_answer(true)<br>the_answer(false)<br>the_answer(nil)<br>the_answer(&quot;string&quot;)<br>the_answer(42)</pre><p>kurangu input.rb adds the following annotation:</p><pre>require &#39;rdl&#39;<br>require &#39;types/core&#39;</pre><pre>extend RDL::Annotate<br>type &#39;(TrueClass or FalseClass or NilClass or String or Fixnum) -&gt; String or Fixnum&#39;<br>def the_answer(x)<br>  if x<br>    return &#39;forty-two&#39;<br>  else<br>    return 42<br>  end<br>end</pre><pre>the_answer(true)<br>the_answer(false)<br>the_answer(nil)<br>the_answer(&quot;string&quot;)<br>the_answer(42)</pre><h4>How it works</h4><p>Kurangu uses <a href="http://ruby-doc.org/core-2.5.0/TracePoint.html">TracePoints</a> to <a href="https://github.com/arpith/kurangu/blob/master/lib/trace.rb">listen to method calls and returns</a>, and collect the runtime types for the arguments and return values.</p><pre>trace_call = TracePoint.new(:call) do |t|<br>  if File.dirname(t.path) == File.dirname(INPUT_FILE)<br>    s = &quot;#{t.defined_class}, :#{t.method_id}&quot;<br>    args = t.binding.eval(&quot;local_variables&quot;).inject({}) do |vars, name|<br>      value = t.binding.eval name.to_s<br>      vars[name] = value.class<br>      vars<br>    end<br>    stack[s] &lt;&lt; args<br>  end<br>end</pre><p>Then, using the <a href="http://ruby-doc.org/core-2.5.0/Method.html#method-i-parameters">method’s parameter</a> information, it creates a union of types for each parameter and updates the annotations file.</p><pre>trace_return = TracePoint.new(:return) do |t|<br>  if File.dirname(t.path) == File.dirname(INPUT_FILE)<br>    s = &quot;#{t.defined_class}, :#{t.method_id}&quot;<br>    args = stack[s].pop<br>    if args<br>      args.each do |arg, type|<br>        parameter_types[s][arg].add(type)<br>      end<br>      return_types[s].add(t.return_value.class)<br>      parameter_list[s] = t.self.method(t.method_id).parameters.map { |a | a[1] }<br>      line = t.self.method(t.method_id).source_location[1]<br>      signatures[s] = generate_signature(line, parameter_list[s], parameter_types[s], return_types[s])<br>      path = &quot;#{t.path}.annotations&quot;<br>      dir = File.dirname(t.path)<br>      write_annotations_paths(dir, paths.add(path))<br>      write_annotations(path, signatures)<br>    end<br>  end<br>end</pre><p>Note that it only generates annotations for files in the same directory as the input file. This is to avoid (for example) annotating the type checker itself! A future version could support including other directories.</p><p>The code that <a href="https://github.com/arpith/kurangu/blob/f7236b2823446e2016663a1db7bcc309d5674eb2/lib/trace.rb#L12-L15">generates the annotation</a> is very straightforward:</p><pre>def generate_signature(line, parameters, parameter_types, return_types)<br>  joined_parameters = parameters.map { |arg| parameter_types[arg].to_a.join(&quot; or &quot;) }<br>  &quot;#{line} type &#39;(#{joined_parameters.join(&quot;, &quot;)}) -&gt; #{return_types.to_a.join(&quot; or &quot;)}&#39;&quot;<br>end</pre><p>Once the <a href="https://github.com/arpith/kurangu/blob/master/test/the_answer_falsy/input.rb.annotations">annotation file</a> is generated with line numbers and annotations, the input file is read line by line and if there is a generated annotation for the line it is inserted (if there is an existing annotation it is replaced).</p><pre>lines = []<br>has_types = false<br>File.open(original_path, &quot;r&quot;) do |f|<br>  f.each_line.with_index do |line, index|<br>    whitespace = line.chomp(line.lstrip)<br>    if annotations.key?(index + 1)<br>      if lines.last and lines.last.start_with?(&#39;type&#39;)<br>        has_types = true<br>        lines.last = &quot;#{whitespace}#{annotations[index + 1]}&quot;<br>      else<br>        lines &lt;&lt; &quot;#{whitespace}extend RDL::Annotate\n&quot;<br>        lines &lt;&lt; &quot;#{whitespace}#{annotations[index + 1]}&quot;<br>      end<br>    end<br>    lines &lt;&lt; line<br>  end<br>end<br>if !has_types<br>  lines.unshift &quot;require &#39;types/core&#39;\n\n&quot;<br>  lines.unshift &quot;require &#39;rdl&#39;\n&quot;<br>end<br>IO.write(annotated_path, lines.join())</pre><p>Note that the white space is copied 😎</p><p>Overall, this was a super fun week! If you’ve been considering applying to the Recurse Center, you should definitely try it! It’s even better than you’ve heard 😊</p><p>Thanks to <a href="https://medium.com/u/4c5a8bb0adb2">Kamal Marhubi</a>, <a href="https://twitter.com/theindielives">Robert Hönig</a>, <a href="https://github.com/rgho">Rishi Ghosh</a>, <a href="http://www.a-tbd.com/">Ann Kidder</a>, <a href="https://github.com/connorwalsh">Connor Walsh</a> and <a href="https://twitter.com/quelledanielle">Danielle Pham</a> for helping me figure things out!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed1859e552c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stable Sorting]]></title>
            <link>https://medium.com/@arpith/stable-sorting-677453884792?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/677453884792</guid>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[stable-sorting]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sorting]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Thu, 19 Oct 2017 21:15:23 GMT</pubDate>
            <atom:updated>2017-10-20T16:52:38.193Z</atom:updated>
            <content:encoded><![CDATA[<p>A sorting algorithm is stable if elements with the same value appear in the same order in the sorted list as they do in the original list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*83FPSb1OMc1pL9Mjfft8wA.png" /><figcaption>Stable sorting maintains the original order if two keys are the same</figcaption></figure><p>For example, let’s say you have a class of students who have done a test. When grading them, you had their names in alphabetical order and you entered their score as you graded their answer papers.</p><p>Now you want to reorder the list so that it’s sorted by test score. What do you do when you have two (or more) students with the same score? A stable sorting algorithm would list them in alphabetical order (because that was the order in the original list).</p><pre>Alicia    5      Christina 8<br>Bob       5      Erykah    8<br>Christina 8  -&gt;  Alicia    5<br>David     3      Bob       5<br>Erykah    8      David     3</pre><h3>Bucket Sort</h3><p>Let’s look at an example of a stable sorting algorithm.</p><p>We’ll first set up a bucket for each possible grade. Then we’ll scan through our list of test scores, and if we see a 1 we’ll put it in bucket number 1, if the score is a 2 we’ll put it in bucket number 2, and so on until we’ve examined each score. We’ll also make sure the first item that goes in to a bucket is the first one out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kbMPbZyK9XT--gCUH90jw.jpeg" /><figcaption>Step 1 for Bucket Sort</figcaption></figure><p>Now to sort the results, we’ll first empty bucket number 10, then empty bucket number 9 and so on until we empty the last bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vY3HgUwsCs6v_7UoStZHoA.png" /><figcaption>Step 2 for Bucket Sort</figcaption></figure><p>If there is more than one item in a bucket, we know that the first item that was put in will be the first one out. This means the order of the original list is preserved within each score.</p><p>In Python, this would be:</p><pre>def bucket_sort(items_with_keys):<br>    &quot;&quot;&quot;Takes a list of keys and items,<br>    and performs a stable sort - if there are two<br>    items with the same key, they are in the same<br>    order in the sorted list as in the original list&quot;&quot;&quot;<br>    buckets = [[] for n in range(0, 10)]<br>    sorted_items = []<br>    for (key, item) in items_with_keys:<br>        buckets[key].append(item)<br>    for bucket in buckets:<br>        sorted_items.extend(bucket)<br>    return sorted_items</pre><p>Why is this cool? I’m glad you asked!</p><h3>Radix Sort</h3><p>Let’s say you’re now sorting items that range from 1 to a million. It would be a pain to keep track of a million buckets. Let’s stick with our 10 buckets (er… now they’re labeled 0, 1, … 9). Let’s also make the range 1 to 9999 so that my examples are easier to type out 😅 Finally, let’s sort them in ascending order this time 😆</p><p>We could first sort by the first digit in the number, then sort by the second digit, then by the third, and so on until we reach the end of the number. This is pretty much how you might think about years — you know that everything that happened in the 19th century happened before anything in the 20th century, and anything in 1950 happened before anything in the 90s, and so on.</p><pre>9999      0001      0001<br>0001      0100      0099 <br>0100  -&gt;  0099  -&gt;  0100<br>1000      1000      1000<br>0099      9999      9999</pre><p>That idea was easy to describe, but it sounds like a pain to actually implement — you have to make buckets within the zero bucket to sort the items that start with a zero, etc.</p><p>So let’s skip ahead and go straight to radix sort.</p><p>The idea behind radix sort is to sort the numbers from the least significant digit onwards to the most significant. This has the disadvantage of being counter-intuitive, but the very real advantage of being straightforward to implement! Once again, we’ll use the stable sorting algorithm we described earlier, and hopefully the reasons will be clear soon.</p><p>Note that we can use leading zeroes to help sort 7 and 1000 on digit 3!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*238fJA-TbNSOb1wDAG9mJg.png" /><figcaption>The first step in Radix Sort is to make sure we have digits to sort on 😃</figcaption></figure><p>Perhaps an example would be good here!</p><pre>9999    999<strong>0    </strong>10<strong>0</strong>0    1<strong>0</strong>00    <strong>0</strong>099<br>9990    100<strong>0</strong>    02<strong>0</strong>0    0<strong>0</strong>99    <strong>0</strong>100<br>1000    020<strong>0    </strong>01<strong>0</strong>0    0<strong>1</strong>00    <strong>0</strong>200<br>0200 -&gt; 010<strong>0</strong> -&gt; 99<strong>9</strong>0 -&gt; 0<strong>2</strong>00 -&gt; <strong>1</strong>000<br>0100    999<strong>9    </strong>99<strong>9</strong>9    9<strong>9</strong>90    <strong>9</strong>990<br>0099    009<strong>9    </strong>00<strong>9</strong>9    9<strong>9</strong>99    <strong>9</strong>999</pre><p>We’ve first sorted on the smallest digit in the number (on the right) and then the second smallest, and so on till we reach the left-most digit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSrpnYWN6aIctEaX6-fw3Q.png" /><figcaption>Starting with the right most digit, sort the numbers using a stable sorting algorithm</figcaption></figure><p>The individual steps don’t make much sense, but it’s helpful to notice two things:<br>1. Each step ensures that at least digit <em>i </em>is sorted.<br>2. If there are two numbers with the same value in digit <em>i</em>, they are in the same order they were in the previous step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hi9UJaP0LqmQ91ghAEKBwA.png" /><figcaption>At the last step, the numbers are sorted on all the digits!</figcaption></figure><p>So if there are two numbers with the same first digit (e.g. 0007 and 0100) by the second observation, since they have the same first digit, they are in the order in which they were in the previous step. Which is the order in which the second digit is sorted.</p><p>But wait, you say, is this really easy to implement? Yes!</p><pre>def get_digit_number_tuples(digit, numbers):<br>    &quot;&quot;&quot;Make a (digit value, number) tuple for bucket sort&quot;&quot;&quot;<br>    return [(get_digit(digit, n), n) for n in numbers]</pre><pre>def get_max_digits(numbers):<br>    &quot;&quot;&quot;Figure out how many leading 0&#39;s the numbers need<br>    to be padded with&quot;&quot;&quot;<br>    return len(str(max(numbers)))</pre><pre>def radix_sort(numbers):<br>    &quot;&quot;&quot;Sort from the least significant digit to<br>    the most significant digit&quot;&quot;&quot;<br>    for d in range(0, get_max_digits(numbers)):<br>        numbers_with_digits = get_digit_number_tuples(d, numbers)<br>        numbers = bucket_sort(numbers_with_digits)<br>    return numbers</pre><p>Radix sort is like four lines of code! Note that get_digit() is from <a href="https://stackoverflow.com/questions/39644638/how-to-take-the-nth-digit-of-a-number-in-python">this stack overflow answer</a>, modified to handle 0099 😃</p><pre>def get_digit(digit, number):<br>    # ** is integer pow() <br>    # // is integer division<br>    if number &lt; 10 ** digit:<br>        return 0<br>    return number // 10**n % 10</pre><p>Note that this sorting algorithm is linear (if the number of digits can be treated as a constant) 🎉</p><p>Thanks to <a href="https://medium.com/u/d7c14f220a59">Nathan Weeks Shane</a> and <a href="http://www.cipht.net/">Julian Squires</a> for their feedback and suggestions — one of the many joys of the <a href="http://recurse.com/">Recurse Center</a>!</p><p>I’m looking for summer internships for next year, <a href="/service/mailto: arpith@feedreader.co">get in touch</a> if you’re hiring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=677453884792" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[San Francisco on MacOS]]></title>
            <link>https://medium.com/@arpith/san-francisco-on-macos-69739cc875e2?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/69739cc875e2</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[san-francisco]]></category>
            <category><![CDATA[feeds]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typography]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Fri, 07 Apr 2017 17:05:37 GMT</pubDate>
            <atom:updated>2017-04-07T17:17:43.449Z</atom:updated>
            <content:encoded><![CDATA[<p>Inspired by <a href="https://booking.design/implementing-system-fonts-on-booking-com-a-lesson-learned-bdc984df627f">Booking.com</a> and <a href="https://medium.design/project-tnt-4b9b4ea97cda">Medium</a>, I decided to make the switch to <a href="https://developer.apple.com/fonts/">San Francisco</a> for <a href="https://feedreader.co/">feedreader.co</a>, my <a href="https://github.com/feedreaderco">open source</a> rss <a href="https://medium.com/@arpith/building-feedreader-co-757beb870b31">feed reader</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IoMb_CLZFoRVHq4hIGWHww.png" /><figcaption>Left: Helvetica Neue; Right: San Francisco</figcaption></figure><p>Before the upgrade, this is what <a href="http://feedreader.co/">feedreader.co</a> looked like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iCLtykx2cUifivWuZFx0iQ.png" /><figcaption>Helvetica Neue</figcaption></figure><p>Asking Safari and Chrome on macOS to render San Francisco required starting the font-family declaration with -apple-system, BlinkMacSystemFont</p><p>This meant our declaration <a href="https://github.com/feedreaderco/web/commit/16b7ec8eaa2a9a5b4f051a0d89d49577dc1171d6">now looked like</a>:</p><pre>font-family: -apple-system, BlinkMacSystemFont, ‘Helvetica Neue’, helvetica, sans;</pre><p>And this is what <a href="https://feedreader.co/">feedreader.co</a> looks like with San Francisco:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RK4VriGl17u2AEKpqjjZeA.png" /><figcaption>San Francisco on MacOS</figcaption></figure><p>Interested in following all your favorite websites in one place? <a href="https://feedreader.co/">Sign up here</a> or just <a href="/service/mailto:arpith@feedreader.co">email me</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69739cc875e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Raft: Appending Entries]]></title>
            <link>https://medium.com/@arpith/raft-appending-entries-b99613622abc?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/b99613622abc</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[recurse-center]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Wed, 17 Aug 2016 19:12:47 GMT</pubDate>
            <atom:updated>2016-08-17T19:12:47.822Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m <a href="https://medium.com/@arpith/adventures-with-mmap-463b33405223#.p04fv8pg5">building</a> a distributed <a href="https://medium.com/@arpith/go-sharing-memory-by-communicating-in-practice-4761bbe5dcf1#.olv99bmtk">key value</a> <a href="https://medium.com/@arpith/reading-a-go-map-safely-277bb08ed144#.gpk2xjurf">store</a> at the <a href="http://recurse.com/">Recurse Center</a>, and it <a href="https://medium.com/@arpith/raft-electing-a-leader-4062a3eea068#.xkzt4vhiy">uses</a> the <a href="https://raft.github.io/">Raft protocol</a> to replicate its log across nodes. Here’s how you append an entry to the log in Raft!</p><h4>Client Request</h4><p>When the leader gets a request from a client it <a href="https://github.com/arpith/mmapd/blob/c936e61b599b835e3a859fa86fab184af5728ea8/raft/appending.go">appends the entry</a> to its log and sends out requests to its followers to append this entry. It also increments its nextIndex and matchIndex values.</p><pre>func (s *server) appendEntry(command string, key string, value string, isCommitted chan bool) {<br>    entry := &amp;db.Entry{command, key, value, s.term}<br>    index := -1<br>    if command != &quot;&quot; {<br>        s.db.Log.AppendEntry(*entry)<br>        index = len(s.db.Log.Entries) - 1<br>    }<br>    respChan := make(chan followerResponse)<br>    for i := 0; i &lt; len(s.config); i++ {<br>        if s.config[i] != s.id {<br>            go s.sendAppendEntryRequest(i, index, respChan)<br>        } else {<br>            if command != &quot;&quot; {<br>                //Update nextIndex and matchIndex for self<br>                s.nextIndex[i]++<br>                s.matchIndex[i]++<br>            }<br>        }<br>    }</pre><h4>Append Entry Request</h4><p>The leader sends its term, and the index and term of the previous entry in its log. The follower will reject the request if the leaders term is lower than the follower’s current term — there is a newer leader! The request will also be rejected if the previous entry’s term doesn’t match with the term stored in the follower’s log.</p><pre>func (s *server) handleAppendEntryRequest(a appendRequest) {<br>    returnChan := a.ReturnChan<br>    req := a.Req<br>    if req.Term &lt; s.term {<br>        resp := &amp;appendEntryResponse{s.term, false}<br>        returnChan &lt;- *resp<br>    } else if req.PrevLogIndex &gt; -1 &amp;&amp;<br>        len(s.db.Log.Entries) &gt; req.PrevLogIndex &amp;&amp;<br>        s.db.Log.Entries[req.PrevLogIndex].Term != req.PrevLogTerm {<br>        resp := &amp;appendEntryResponse{s.term, false}<br>        returnChan &lt;- *resp<br>    } </pre><p>If the request isn’t rejected, the receiver then checks if it needs to step down — for instance, if it is a leader and the new leader has a term greater than the term it has stored.</p><pre>else {<br>    if req.Term &gt; s.term {<br>        s.term = req.Term<br>        s.stepDown(&quot;append entries RPC has term &gt; current term&quot;)<br>    }</pre><p>The receiver then deletes any entry in its log that conflicts with the entry sent by the leader, and all the ones after it, and then appends the entry!</p><pre>if len(s.db.Log.Entries) &gt; req.PrevLogIndex+2 {<br>    if s.db.Log.Entries[req.PrevLogIndex+1].Term != req.Term {<br>        // If existing entry conflicts with new entry<br>        // Delete entry and all that follow it<br>        s.db.Log.SetEntries(s.db.Log.Entries[:req.PrevLogIndex+1])<br>    }<br>    s.db.Log.AppendEntry(req.Entry)<br>}</pre><p>The receiver then sets its commit index to be the minimum of the leader’s commit index and the index of the last new entry (which in this case is the index after the leader’s previous log index).</p><pre>if req.LeaderCommit &gt; s.commitIndex {<br>    // Set commit index to the min of the leader&#39;s commit index <br>    // and index of last new entry<br>    if req.Entry.Command == &quot;&quot; || <br>        req.LeaderCommit &lt; req.PrevLogIndex+1 {    <br>        s.commitEntries(req.LeaderCommit)<br>   } else {<br>        s.commitEntries(req.PrevLogIndex + 1)<br>   }<br>}</pre><p>Finally, he follower responds with its current term and success set to true.</p><pre>resp := &amp;appendEntryResponse{s.term, true}<br>returnChan &lt;- *resp</pre><h4>Updating Commit Index</h4><p>After sending the append entry requests to the followers, the leader checks if there is an entry in the log with index greater than the current commit index (and term equal to the current term) that a majority of followers have successfully replicated. The leader then updates its commit index to be the index of this entry.</p><pre>for {<br>    _ = &lt;-respChan<br>    responseCount++<br>    for N := s.commitIndex + 1; N &lt; len(s.db.Log.Entries); N++ {<br>        //Check if there exists an N &gt; commitIndex<br>        count := 0<br>        for i := 0; i &lt; len(s.matchIndex); i++ {<br>            if s.matchIndex[i] &gt;= N {<br>                count++<br>            }<br>        }<br>        // Check if a majority of matchIndex[i] &gt;= N<br>        cond1 := count &gt; len(s.matchIndex)/2<br>        // Check if log[N].term == currentTerm<br>        cond2 := s.db.Log.Entries[N].Term == s.term<br>        if cond1 &amp;&amp; cond2 {<br>            // Set commitIndex to N<br>            s.commitIndex = N<br>        } else {<br>            break<br>        }<br>    }<br>    if s.commitIndex == index {<br>        isCommitted &lt;- true<br>        return<br>    }<br>    if responseCount == len(s.config)-1 {<br>        fmt.Println(&quot;Got all responses!&quot;)<br>    }<br>}</pre><h4>Responding to the client</h4><p>If the entry was successfully committed, the leader then stores the entry in the database and <a href="https://github.com/arpith/mmapd/blob/c936e61b599b835e3a859fa86fab184af5728ea8/raft/clientRequests.go">responds to the client</a>.</p><pre>func (s *server) handleWriteRequest(req writeRequest) {<br>    key := req.key<br>    value := req.value<br>    command := &quot;SET&quot;<br>    c := make(chan bool)<br>    go s.appendEntry(command, key, value, c)<br>    isCommitted := &lt;-c<br>    close(c)<br>    if isCommitted {<br>        m := db.WriteChanMessage{key, value, req.returnChan}<br>        s.db.WriteChan &lt;- m<br>    } else {<br>        m := &amp;db.ReturnChanMessage{errors.New(&quot;Couldn&#39;t Commit&quot;), &quot;&quot;}<br>        req.returnChan &lt;- *m<br>    }<br>}</pre><p>That’s it! Have thoughts, comments or feedback? <a href="/service/mailto:arpith@feedreader.co">Let</a> <a href="http://github.com/arpith">me</a> <a href="http://twitter.com/arpith">know</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b99613622abc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing your first Jepsen test]]></title>
            <link>https://medium.com/@arpith/writing-your-first-jepsen-test-ddcfee61a409?source=rss-8fcab1c95a89------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddcfee61a409</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[recurse-center]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Arpith Siromoney]]></dc:creator>
            <pubDate>Wed, 10 Aug 2016 19:02:17 GMT</pubDate>
            <atom:updated>2016-08-10T19:09:20.793Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/aphyr/jepsen">Jepsen</a> is a great library that lets you <a href="https://aphyr.com/tags/jepsen">test distributed systems</a>. I’m <a href="https://medium.com/@arpith/adventures-with-mmap-463b33405223#.mpzfjnpq3">building</a> <a href="https://medium.com/@arpith/raft-electing-a-leader-4062a3eea068#.1jmkhg7bi">a</a> <a href="http://github.com/arpith/mmapd">distributed database</a> at the <a href="http://recurse.com/">Recurse Center</a>, and eventually want to run Jepsen on it. Here’s how you write a simple Jepsen test that does nothing!</p><h4>Create an EC2 instance</h4><ol><li>Sign up for <a href="http://aws.amazon.com/">AWS</a></li><li>In Services -&gt; EC2, click “Launch Instance”</li><li>Choose the 64 bit Debian Jessie image</li><li>Hit review and launch</li></ol><p>Save your SSH key pair!</p><h4>Install Java</h4><p>SSH into your instance and open /etc/apt/sources.list in your favorite editor. Add jessie-backports to the file:</p><pre>deb http://ftp.debian.org/debian jessie-backports main</pre><p>Now run sudo apt-get update, and install the following!</p><pre>$ sudo apt-get install openjdk-8-jre openjdk-8-jre-headless libjna-java</pre><h4>Use Docker</h4><p>You need to <a href="https://docs.docker.com/engine/installation/linux/debian/">install docker</a> and <a href="https://docs.docker.com/compose/install/">docker compose</a>. Then <a href="https://github.com/aphyr/jepsen/blob/master/docker/README.md">spin up the containers</a>:</p><pre>$ git clone <a href="https://github.com/aphyr/jepsen">https://github.com/aphyr/jepsen</a> &amp;&amp; cd jepsen/docker<br>$ ./up.sh<br>$ docker exec -it jepsen-control bash</pre><h4>Write your test</h4><p>Create a new Leiningen project:</p><pre>$ lein new foo &amp;&amp; cd foo</pre><p>And edit src/jepsen/foo.clj — your first test! This does nothing!</p><pre>(ns jepsen.zookeeper<br>  (:require [jepsen.tests :as tests]))<br><br>(defn zk-test<br>  [version]<br>  tests/noop-test)</pre><p>Edit test/jepsen/foo_test.clj to look like this:</p><pre>(ns jepsen.foo-test<br>  (:require [clojure.test :refer :all]<br>    [jepsen.core :as jepsen]<br>    [jepsen.foo :as foo]))</pre><pre>(deftest a-test<br>  (is (:valid? (:results (jepsen/run! (foo/foo &quot;3.4.5+dfsg-2&quot;))))))</pre><p>That calls the test you just wrote (and passes it a version number).</p><p>Finally! Run your test:</p><pre>$ lein test</pre><p>And hopefully you get something that ends with:</p><pre>Everything looks good! ヽ(‘ー`)ノ</pre><p>That’s it! Special thanks to <a href="http://twitter.com/porterjamesj">James</a>!</p><p>Hiring? <a href="http://twitter.com/arpith">Get</a> <a href="/service/mailto:arpith@feedreader.co">in touch</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddcfee61a409" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>