<?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 mLuby on Medium]]></title>
        <description><![CDATA[Stories by mLuby on Medium]]></description>
        <link>https://medium.com/@mluby?source=rss-9cb393bd01f0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*MOEoYpp86yMYzOBkDipchw.png</url>
            <title>Stories by mLuby on Medium</title>
            <link>https://medium.com/@mluby?source=rss-9cb393bd01f0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 01:42:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mluby/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[Mostly Parallel Elm]]></title>
            <link>https://medium.com/@mluby/mostly-parallel-elm-7d4efce777c9?source=rss-9cb393bd01f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d4efce777c9</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[mLuby]]></dc:creator>
            <pubDate>Sat, 14 Sep 2019 19:26:04 GMT</pubDate>
            <atom:updated>2019-09-14T19:29:26.496Z</atom:updated>
            <content:encoded><![CDATA[<p>Note: this was a draft from 2+ years ago, so I’m publishing it incomplete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*ma95xs-c1DxjlSUv.gif" /></figure><p>I’m just a <em>sapling</em> in the Elm forest but I’ll share my experience of a hard winter on the edge of the Grove of Examples.</p><p>As I’m considering using Elm for a side project, I decided to redo a coding challenge in it to see if Elm would be nice to work in.</p><p>The challenge was simple:</p><blockquote>Using react/redux, fetch 12 cat facts and 12 cat pics from separate APIs and display them as 12 cards on the page that the user can individually delete.</blockquote><p>&lt;Recruiting side-note&gt; it’s a good challenge because it tests a bunch of <a href="https://facebook.github.io/react/">React</a>/<a href="http://redux.js.org/">Redux</a> and AJAX skills, as well as being quick and easy if you know what you’re doing. I’ve found more advanced candidates less enamored with blowing a whole weekend building a toy app for some company. &lt;/Recruiting side-note&gt;</p><p>Looking through the Elm docs, I discovered to my delight <a href="https://guide.elm-lang.org/architecture/effects/http.html">a cat gif-fetching example</a> — just what I needed! And indeed, it didn’t take much tinkering with the example to get it close to what I wanted. There was just one small difference…</p><p><strong>How to execute multiple Http requests per action?</strong></p><p>In Ye Olde JavaScript, this is easy. If you have promises, you can use</p><pre>Promise.all([<br>  fetch(&quot;http://catsapi.com&quot;),<br>  fetch(&quot;http://catsapi.com&quot;),<br>]).then(values =&gt; …).catch(error =&gt; …)</pre><p>Where <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all">Promise.all</a> takes an array of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Examples">Promises</a> and runs them in parallel. If they all resolve, their individual values are passed as an array to the next .then block. If any Promise rejects with an error, the entire Promise.all rejects immediately.</p><p>If you don’t have Promises, you can create this behavior yourself with some trickery:</p><pre>parallelize([<br>  function (callback) { return httpGet(&quot;<a href="http://catsapi.com/">http://catsapi.com</a>&quot;, callback) },<br>  function (callback) { return httpGet(&quot;<a href="http://catsapi.com/">http://catsapi.com</a>&quot;, callback) },<br>], function (error, values) { console.log (error, values) })</pre><pre>function parallelize (requests, callback) {<br> let pendingRequestCount = requests.length<br>  const results = []<br>  requests.forEach(function (request, index) {<br>    request(onRequestComplete(index))<br>  })<br>  function onRequestComplete (index) {<br>   function (error, result) {<br>      if (error) {<br>        pendingRequestCount = -1<br>        callback(error) <br>      } else {<br>        results[index] = result<br>        pendingRequestCount = pendingRequestCount - 1<br>        if (pendingRequestCount === 0) { callback(null, results) }<br>      }<br>   }<br>  }<br>}</pre><p>The key part here is that parallelize has wrappedpendingRequestCount and results in closure, so as the requests are completing they can each insert their result and decrement the counter. The last request to complete notices the counter at zero and completes the parallelize callback. (As before, this fails early and permanently on error.)</p><p>So how do we accomplish multiple Http requests in Elm? (BTW, we will be mostly talking about request Tasks, but Elm Http requests are a different type that can be <a href="http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http#toTask">taskified</a>.) We have a few options:</p><ol><li>We can <a href="http://package.elm-lang.org/packages/elm-lang/core/latest/Task#sequence">Task.sequence</a> the requests. This is the most straightforward, since the results of each task can be passed through to the end, but crucially the first request must complete for the second to start, and so on. So it’s actually quite slow.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*6TYqMppsXPc0yo95nyisPA.gif" /><figcaption>If each request is 1s, that’s 12 seconds to load.</figcaption></figure><p>2. Send the <a href="http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Platform-Cmd#batch">Cmd.batch</a> the requests with <a href="http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http#send">Http.send</a>. This has the advantage of being completely parallel, but the disadvantage that the requests come back in no particular order. So it’s fine for appending results, but not if you need to know what requested what (as we do to merge cat facts and pics).</p><p>3. Build some custom hackery to achieve Promise.all in Elm. After trying options 1 and 2, this is the path I went down. Sparing you a lot of experimentation (not particularly easy in Elm with such a strict compiler), this is the end result:</p><p><a href="https://github.com/mLuby/cats-elm/blob/master/Parallel.elm#L128-L154">mLuby/cats-elm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d4efce777c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brain Hacks to Keep New Year Commitments]]></title>
            <link>https://medium.com/@mluby/brain-hacks-to-keep-new-year-commitments-122524c60d04?source=rss-9cb393bd01f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/122524c60d04</guid>
            <category><![CDATA[new-years-resolutions]]></category>
            <category><![CDATA[sales]]></category>
            <category><![CDATA[motivation]]></category>
            <dc:creator><![CDATA[mLuby]]></dc:creator>
            <pubDate>Sun, 03 Jan 2016 01:40:44 GMT</pubDate>
            <atom:updated>2016-01-03T01:40:44.652Z</atom:updated>
            <content:encoded><![CDATA[<p>Just in time for the new year!</p><p>Last time we learned how <a href="https://medium.com/@mluby/just-say-yes-8fadc4860ce4#.cp2rfvmxt">reciprocity can force you to say yes</a>. Now Dr. Cialdini investigates the strangely effective phenomenon of commitment and consistency. If you’ve ever felt the dread of knowing you’re cornered into doing something you don’t want to do, you’ve felt the power of these principles:</p><ol><li><strong>Consistency </strong>“Aren’t you a healthy person? So put the Twinkie down.”</li><li><strong>Commitment</strong> “You already bought that gym membership, so use it.”</li><li><strong>Inception</strong></li></ol><p>Humans have a (frankly odd) desire to appear consistent to ourselves and others. Cialdini suggests this is because <strong>consistency</strong> signals rationality, good judgement, honesty, and mental wellness while inconsistency suggests irrationality, poor choices or memory of them, duplicity, and possible mental illness. So when we say—or are coaxed to say—we agree with something, say being interested in health, it’s much more difficult for us to then say no to someone selling a health product because that would make us inconsistent.</p><p>Once we’ve expressed a <strong>commitment</strong>, we often internalize it, essentially coming to believe that we are the kind of person we have committed to being. This is great when we try to be better people, committing to be more generous, healthy, friendly, etc. But either by knowing our commitments or making us commit to new ones can leave us vulnerable to consistency appeals. For example, if a charity or politician can get us to donate a small amount, we often will feel committed to helping their cause, and may if prompted donate more that we intended.</p><p>There are a number of tactics that utilize these forces of commitment and consistency to great effect:</p><ol><li>extract some small commitment from the target (a written one if possible)—when you ask for a second, larger favor, they will feel the strong need to be consistent with their previous commitment.</li><li>Lowball them by making an inaccurately low offer, getting them to commit to it, then reveal the error and the actual (higher) price. They’ve already committed to the product, and to be consistent they’ll often accept the change.</li><li>A written or recorded commitment gains special force because it is (or can be made) public. Thus having people write down agreements can enforce larger commitments in the same vein.</li></ol><p>One rather strange result the researchers discovered involves the longevity of our commitments. They found that a strong external reason like a reward or threat only enforces a commitment as long as it is in effect, while a limited incentive makes us more likely to self-reinforce our commitment. Surprisingly, this means that a “just good enough” incentive can make people commit to a course of action, and when removed, they will come up with other reasons to maintain their commitment. <strong>Inception</strong> complete!</p><p>Hopefully we can harness the powerful forces of commitment and consistency to keep our new year’s resolutions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=122524c60d04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Just Say Yes: The Shackles of Reciprocity]]></title>
            <link>https://medium.com/@mluby/just-say-yes-8fadc4860ce4?source=rss-9cb393bd01f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fadc4860ce4</guid>
            <category><![CDATA[sales]]></category>
            <category><![CDATA[psychology]]></category>
            <category><![CDATA[marketing]]></category>
            <dc:creator><![CDATA[mLuby]]></dc:creator>
            <pubDate>Sun, 27 Dec 2015 19:18:34 GMT</pubDate>
            <atom:updated>2016-01-03T01:42:23.288Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been reading the Psychology of Persuasion by Robert Cialdini, and it contains fascinating insights into behaviors I’ve seen but couldn’t explain.</p><p>1. <strong>Reciprocity</strong>: “I did something for you, now you do something for me.”</p><p>2. <strong>Contrast</strong>: “The deluxe model is $500, but this one is only $300.”</p><p>3. <strong>Concession</strong>: “If you won’t buy it, how about just giving me a referral?”</p><p>These rules combined into a “<strong>rejection-then-retreat</strong>” tactic are particularly effective at getting people to agree to your suggestion.</p><p>Cialdini posits that the drive to <strong>reciprocate</strong> is such an effective tool for cooperation human societies that we internalize <em>strong</em> motivations not to break the rule. So leading off an interaction by doing a small favor for the other person puts significant pressure on them to reciprocate. If you then ask for something in return, you can dictate the manner of their reciprocation.</p><p>The <strong>contrast</strong> rule (similar to anchoring) suggests that we evaluate options in relation to their temporal and spatial surroundings. So showing someone a $100 appliance then a $300 appliance will make them think the $300 one is pricy. But showing the $500 appliance before the $300 item makes the latter seem inexpensive.</p><p>A <strong>concession</strong> in this context is backing down from a high initial request to something more reasonable. This triggers both the reciprocity and contrast, so the requestee has a strong compulsion and bias toward agreeing to the second lower request.</p><p>These sociological and psychological phenomena can be combined to create the <strong>rejection-then-retreat</strong> tactic. The seller opens with a high initial price (but not so outlandish as to seem in bad faith), which the buyer rejects. Then the seller concedes some ground by offering a lower price (their target all along). At this point the buyer is fighting their own compulsion to reciprocate the concession, as well as perceiving the second price to be more reasonable.</p><p>Starting a rejection-then-retreat scenario off with a small gift like lunch or a drink only adds to the reciprocity pressure!</p><p>In the next section, we’ll learn how to <a href="https://medium.com/@mluby/brain-hacks-to-keep-new-year-commitments-122524c60d04#.p1yu7883q">extract and enforce commitments</a>, even new year’s resolutions…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fadc4860ce4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>