<?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 Raam Danger Rosh-Hai on Medium]]></title>
        <description><![CDATA[Stories by Raam Danger Rosh-Hai on Medium]]></description>
        <link>https://medium.com/@raamdanger?source=rss-a2044c175a32------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*AAWwWSEJI832BeYl.jpg</url>
            <title>Stories by Raam Danger Rosh-Hai on Medium</title>
            <link>https://medium.com/@raamdanger?source=rss-a2044c175a32------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 07:49:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@raamdanger/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 to Block Facebook on iOS]]></title>
            <link>https://medium.com/@raamdanger/how-to-block-facebook-on-iphone-ios-12-2-8864a7e9b243?source=rss-a2044c175a32------2</link>
            <guid isPermaLink="false">https://medium.com/p/8864a7e9b243</guid>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Raam Danger Rosh-Hai]]></dc:creator>
            <pubDate>Wed, 01 May 2019 19:35:01 GMT</pubDate>
            <atom:updated>2019-05-11T18:20:19.388Z</atom:updated>
            <content:encoded><![CDATA[<p>open settings app and pull down to search “Restrictions”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*7tdxcHGNbkeX_6K_h-wfNg@2x.jpeg" /></figure><p>make sure you turn on content and privacy restrictions:</p><p>and press content restrictions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*4FmI1vIf_feRtORiiQXYFw@2x.jpeg" /></figure><p>press Web Content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*0BXTemiYEfsd_Sl2tdQtpg@2x.jpeg" /></figure><p>and allow Limit Adult Websites</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*grOlwo1CP_mi-l4y9wczRg@2x.jpeg" /></figure><p>press add website and write “facebook.com”</p><p>in case you want to unlock some site simply add it to the allowed sites</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*YTV385LH-3v9vS78mXcsXA@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8864a7e9b243" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Fearing Haskell]]></title>
            <link>https://medium.com/@raamdanger/nosedive-into-haskell-b5631bb9e33a?source=rss-a2044c175a32------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5631bb9e33a</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[haskell]]></category>
            <dc:creator><![CDATA[Raam Danger Rosh-Hai]]></dc:creator>
            <pubDate>Wed, 08 Feb 2017 14:24:51 GMT</pubDate>
            <atom:updated>2017-02-10T20:35:52.443Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqLhLZCz94L3sbAxV98LwQ.png" /><figcaption>Not this kind of nosedive</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fb9e6163bee8048fddb99590cd685bc/href">https://medium.com/media/6fb9e6163bee8048fddb99590cd685bc/href</a></iframe><p>I would love to hear your feedback, hit me up here or on twitter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5631bb9e33a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simple introduction to scala type classes]]></title>
            <link>https://medium.com/@raamdanger/a-simple-introduction-to-scala-type-classes-a881b5d0444f?source=rss-a2044c175a32------2</link>
            <guid isPermaLink="false">https://medium.com/p/a881b5d0444f</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[typeclass]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Raam Danger Rosh-Hai]]></dc:creator>
            <pubDate>Wed, 08 Feb 2017 13:54:56 GMT</pubDate>
            <atom:updated>2017-02-08T14:10:03.437Z</atom:updated>
            <content:encoded><![CDATA[<p>I found myself using Java’s `SimpleDateFormat` in order to construct paths in s3, they contain dates that have to be formatted in a certain way to fit our s3 file schemas.</p><p>I created a class that holds a string (usually a hash of the spark dataframe schema) and a date:</p><pre>case class SchemaName(s: String, d: Date)</pre><p>an obvious way was to add a this formatting functionality would have been:</p><pre>case class SchemaName(hash: String, d: Date){<br>  val format = new SimpleDateFormat(“yyyyMMdd”)<br>  def toFormattedString = s”${format.parse(d)}$hash” <br>}</pre><p>But I didn’t want to create a strong dependency between my models and their string representation and was looking for something that will be flexible enough to reuse in many places.</p><p>Instead we will create a Type Classes.<br>the objective is add the definition of <em>toFormattedString</em> to any Case Class and let all of these instances share the same formatting.<br>This way we can eliminate cross dependency between modules and we will have a general way to format date strings. It’s time to demystify the magic.</p><p>We define a trait that formats strings, it currently holds only one format and a single function that will have access to this format (and future ones):</p><pre><br>trait StringFormatter[T] {<br> val flatDateFormat = new SimpleDateFormat(“yyyyMMdd”)<br> def toFormattedString(a: T): String<br>}<br></pre><p>we have several ways to decorate traits:</p><pre><br>implicit object SchemaNameStringFormatter extends StringFormatter[SchemaName] {<br> def toFormattedString(sm: SchemaName) = s”${flatDateFormat.format(sm.date)}${sm.hash}”<br> }<br> def toTimeFormattedString[T](a: T)(implicit ev: StringFormatter[T]) = ev.toFString(a)<br> val sm = SchemaName(java.sql.Date.valueOf(“”), “myHashValue”)<br> toTimeFormattedString(sm) //20170101myHashValue <br></pre><p>The compiler can find <em>SchemaNameStringFormatter</em> as evidence that <em>SchemaName</em> has this functionality implemented <br>and the program happily compiles. <br>This is already pretty nice, we are using our old classes and give them new life, and let them stay well typed. <br>However I wanted the nice syntax that emulates methods so we can do:</p><pre>val sm = SchemaName(java.sql.Date.valueOf(“”), “myHashValue”)<br>sm.toTimeFormattedString</pre><p>so we define an implicit class <em>FormatStringsOps</em>, this class will be called implicitly each times its:<br>1. in scope <br>2. there is a StringFormatter implementation for the given type. (in this case the compiler finds <em>SchemaNameStringFormatter</em>)</p><pre>implicit class FormatStringsOps[A: StringFormatter](thing: A) {<br> def toTimeFormattedString = StringFormatter[A].toFormattedString(thing)<br>}</pre><p>so every SchemaName is implicitly being wrapped in <em>FormatStringOps</em> if it’s in scope and let’s us <br>use it’s <em>toTimeFormattedString</em> method.</p><p>For this to work we need an object that will create these classes:</p><pre><br>object StringFormatter {<br> def apply[T: StringFormatter]: StringFormatter[T] = implicitly<br>}</pre><p>that’s great so why do we need the cryptic implicitly keyword and the StringFormatter object? <br>quite simply FormatStringsOps won’t compile without it, the reason is that trait can not be instantiated like that you have to use the new keyword but then the compiler will complain toFString is not implemented yet.</p><p>so we use a companion object which <em>can</em> be instantiated in this way. Great now we have syntactic sugar, but how does it work?</p><p>let’s look at the signature</p><pre>def implicitly[T](implicit e: T) = e //for summoning implicit values from the nether world` (sic) </pre><p>w00t? <br>It’s just the `identity` function but it looks for an implicit value in scope and wraps it up with in our case with the StringFormatter <strong>object</strong>.<br>the scala convention is to call the companion object same as the trait so it will be nice to import but it’s a little confusing. this could be written as:</p><pre>object CoStringFormatter {<br>  def apply[T: StringFormatter]: StringFormatter[T] = StringFormatter[T]<br>}</pre><pre>implicit class FormatStringsOps[A: StringFormatter](thing: A) {<br>  def toTimeFormattedString = CoStringFormatter[A].toFString(thing)<br>}</pre><p>so now we have everything in place to tell the compiler to look for the concrete implementation</p><pre>implicit object SchemaNameStringFormatter extends StringFormatter[SchemaName]<br></pre><p>SchemaNameStringFormatter act as the thing: A parameter for the FormatStringsOps class and let’s us use this convenient interface.</p><pre>val sm = SchemaName(java.sql.Date.valueOf(&quot;01-01-1984&quot;), “weDidIt”)<br>sm.toTimeFormattedString //19840101weDidIt</pre><p>Have corrections or questions? I would love to hear about it in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a881b5d0444f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Even Simple Bugs Costs Time]]></title>
            <link>https://medium.com/@raamdanger/datalength-0-or-my-stupidest-bug-5227927d624e?source=rss-a2044c175a32------2</link>
            <guid isPermaLink="false">https://medium.com/p/5227927d624e</guid>
            <dc:creator><![CDATA[Raam Danger Rosh-Hai]]></dc:creator>
            <pubDate>Mon, 29 Jun 2015 19:26:42 GMT</pubDate>
            <atom:updated>2015-07-07T07:34:17.118Z</atom:updated>
            <content:encoded><![CDATA[<p>I truly hope this will help someone but I am actually writing to help myself.</p><p>after the second time this has happened, and wasted hours of my life I am I will find this post on google just before banging my head against the wall blacks me out.</p><p>it is silly, stupid and so minor it happened to me twice!</p><h3>base 64 encoding exhausts a stream</h3><pre><strong>val </strong>streamMD5 = <strong>new </strong>String(Base64.<em>encode</em>(resultByte))</pre><p>will exhaust a stream (since it is reading it, very reasonable actually)</p><p>so passing that mutable stream around will obviously cause error since it will seem empty or dataLength=0.</p><p>and will make amazon fire:</p><blockquote>Data read has a different length than the expected data=0</blockquote><p>the solution is to reset the stream after working with it.</p><pre>stream.reset()<br><strong>val </strong>putRequest = <em>s3client</em>.putObject(<strong>new </strong>PutObjectRequest(bucketName, keyName, stream, meta))</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5227927d624e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>