<?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 Terry Mun on Medium]]></title>
        <description><![CDATA[Stories by Terry Mun on Medium]]></description>
        <link>https://medium.com/@teddyrised?source=rss-6cf203a872c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ooR1KXsH1EGH9HwO.jpeg</url>
            <title>Stories by Terry Mun on Medium</title>
            <link>https://medium.com/@teddyrised?source=rss-6cf203a872c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 13:18:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@teddyrised/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[“Disappointed” is a choice word]]></title>
            <link>https://medium.com/life-journey/disappointed-is-a-choice-word-2358c4e8e6cf?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2358c4e8e6cf</guid>
            <category><![CDATA[disappointment]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Wed, 26 Apr 2017 15:28:51 GMT</pubDate>
            <atom:updated>2017-04-26T15:28:51.909Z</atom:updated>
            <content:encoded><![CDATA[<p>We are no strangers to disappointments, let alone being quite vocal about communicating that very same feeling to others. But do you know what burden does it carry?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sNMDx3ZLEoCY488l5v_-_g.jpeg" /></figure><p>Although I have always had a personal beef with the “I’m so <em>disappointed</em> in you” statement, it was a recent episode in my life that egged me on to consolidate — and eventually, jot down— my thoughts.</p><h3>To be used after, not before, perspective taking</h3><p>I figured that I detested the use of the word “<em>disappointment</em>” because it often implies an unjustified imposition of one’s belief, understanding, and perspective onto another person. We make the mistake of assuming that the view is the same on our side of the lawn as compared to theirs. It is easy for us to be disappointed with ourselves — because we often know what we are, how much we have done (or not). Our truth is what we based the statement upon.</p><p>Now ask yourself this: do you know the entire truth of the another person?</p><blockquote>But remember, we do not see the entire truth in another person, by simply being an observer. And by extension, “I am disappointed in you” is often misused, because we failed to realize somebody else’s version of the truth is not entirely congruent with ours.</blockquote><p>I am not proposing that we ban the use of the word outright — that would be, a-hah, <em>disappointingly </em>barbaric. However, I do believe that it is not a word to be used lightly. At least without considerable thought and perspective taking.</p><h3>A scapegoat for discharging internal discomfort</h3><p>“Feeling disappointed”, I suspect, is often seen as an all-encompassing panacea for the discharge of internal angst while we are too afraid or shy to admit that we are just mad on the inside. By saying that, you are not only abstracting the issue away from yourself and your ability to manage your anger, but you are discharging it in a very unhealthy way by guilt-tripping the other party.</p><p>Blame drives disconnection — and I have a feeling that by blatantly abusing the word “disappointed”, we are doing exactly the same. By saying you’re disappointed in someone when you are simply angry, you are actually blaming the person for letting you down. In one way, you are selfishly imposing your own expectations onto someone, especially when no proper communication and understanding has taken place.</p><p>Being disappointed means you have lost a parcel of trust in a person. Does being mad at that person equates to losing trust? If not, you might want to reconsider your choice of words.</p><p>Back to my story. I was travelling to a city where a friend of mine (let’s call him Jay) lives, simply for a quick weekend trip with no free time planned out for miscellaneous meetups. I guessed, perhaps by gleaning from my Instagram feed, that Jay realised I was in town.</p><p>“Wait a minute,” Jay thought, “Terry didn’t hit me up. I have asked him out when he was popping by, en route to a further destination some months ago, but he declined. Now he isn’t even telling me his plans.”</p><p>So long story short, I received a rather passive aggressive email at 4.30am on a Saturday, with the sentence:</p><blockquote>I’m honestly hugely disappointed seeing that…</blockquote><p>And my heart dropped. Reading through the message I have realized Jay made several assumptions that were entirely untrue, such as my boyfriend travelling with me (he was back at home working his shift at Crossfit), as well as my ninja-like avoidance and a general reluctance to meet.</p><p>It suddenly dawned upon me. Jay was disappointed in me based on a set of assumptions he had made, without actually figuring out my travel plans. Not only did he impose his version of intimacy and friendship on me, but he also made slippery assumptions about my travel partners, purposes of visit, and the likes.</p><p>I replied to Jay that I genuinely feel sorry that I have made him felt that way, but explained my situation — hoping that he realized he had missed out important details here and there. I haven’t heard back since, but I want to believe that I have said what I wanted to in a very restrained and friendly way.</p><p>So next time when you decide to pepper your statements with this choice word, do ask yourself: do you know all that is needed to know? Would any new, or alternate, knowledge alter your judgement? If yes, you might want to hold your tongue and the proverbial horses, and save that for later when things clarify.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2358c4e8e6cf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/life-journey/disappointed-is-a-choice-word-2358c4e8e6cf">“Disappointed” is a choice word</a> was originally published in <a href="https://medium.com/life-journey">Life Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Survivor’s guide to finding housing in Aarhus]]></title>
            <link>https://medium.com/aarhus/survivors-guide-to-finding-housing-in-aarhus-6b4a3de49b4b?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b4a3de49b4b</guid>
            <category><![CDATA[denmar]]></category>
            <category><![CDATA[moving]]></category>
            <category><![CDATA[housing]]></category>
            <category><![CDATA[aarhus]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Sun, 22 Jan 2017 21:51:18 GMT</pubDate>
            <atom:updated>2017-07-02T20:40:10.592Z</atom:updated>
            <content:encoded><![CDATA[<p>Congratulations, you are moving to Aarhus… <em>without having actually a place to call home, yet</em>. Aarhus is an amazing city—it has earned the liking of writers from <a href="http://www.nytimes.com/2011/10/15/arts/15iht-scdenmark15.html">New York Times</a>, <a href="http://www.forbes.com/sites/breannawilson/2016/10/31/the-20-best-things-to-do-in-aarhus-denmark-the-2017-european-capital-of-culture">Forbes</a>, <a href="http://www.thelocal.dk/20160525/aarhus-second-best-europe-lonely-planet">Lonely Planet</a>, <a href="http://www.telegraph.co.uk/travel/quality-on-board-meals/aarhus-food-scene/">Telegraph</a>, <a href="http://www.cntraveler.com/story/what-to-do-in-aarhus-denmark-2017s-european-capital-of-culture">Conde Nast Traveler</a> and many other publications; surrounded by gently rolling hills and sitting by the sea of Kattegat; enointed as one of the two cultural capital of Europe for 2017; and hailed as the exporter of the Danish concept of <em>hygge</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Y5fmLmxdEZ4SNOUzkvZHw.jpeg" /><figcaption>Sunrise from Guldsmedgade, from a penthouse apartment unit that very luckily got into my hands by dumb luck.</figcaption></figure><blockquote>Despite being rated one of the happinest city in Europe, finding housing in Aarhus can be frustratingly difficult.</blockquote><p>Being a predominantly student town, Aarhus faces an acute housing shortage like <a href="http://www.independent.co.uk/student/students-rents-increase-10-per-cent-housing-shortages-london-oxford-ucl-strike-a7300326.html">many of its similar counterparts</a>, ranging from Cambridge that is just across the North Sea to Perth that is halfway across the globe. The search for accommodation is a daunting task even for locals, let alone for international students and expats alike moving into the city.</p><p>I have written this guide, based mostly by my previous experience with house searching experience, and by talking to my peers about the issue. This article is <strong>by no means a legally binding document, nor does it constitute legal advice</strong>. It is a collection of <em>personal advice</em> that is not authoritative. In other words, use your common sense—even though I tried my very best to impart as much of what I have into this article.</p><blockquote>Disclaimer: this is an opinion piece based on my personal experience, and does not constitute legal advice.</blockquote><h3>For the less initiated</h3><p>A list of quick links if you don’t want to go through the entire guide:</p><h4>Housing search</h4><ul><li><strong>Student Housing Aarhus</strong> (<a href="http://www.studenthousingaarhus.com/">http://www.studenthousingaarhus.com</a>)</li><li><strong>BoligPortal</strong> (<a href="http://www.boligportal.dk/">http://www.boligportal.dk</a>)</li><li><strong>Housing in Aarhus </strong>(<a href="https://www.facebook.com/groups/housinginaarhus/">https://www.facebook.com/groups/housinginaarhus/</a>)</li><li><strong>Lejligheder til salg og leje i Aarhus </strong>(<a href="https://www.facebook.com/groups/minlejeboligaarhus/">https://www.facebook.com/groups/minlejeboligaarhus/</a>)</li></ul><h4>Home ownership and address validation</h4><ul><li><strong>Tinglysning</strong>; <em>Register</em> (<a href="https://www.tinglysning.dk/m/#/soeg">https://www.tinglysning.dk/m/#/soeg</a>)</li><li><strong>Den Offentlige Informationsserver</strong>; <em>The Public Information Server</em> (<a href="https://ois.dk/">https://ois.dk</a>)</li><li><strong>Boligejer</strong>; <em>Home ownership </em>(<a href="http://boligejer.dk/">http://boligejer.dk</a>)</li><li><strong>Krak</strong>; “<em>Crack</em>”, a local search engine, might not contain up-to-date results (<a href="http://krak.dk/">Krak.dk</a>)</li></ul><h4>Information and legal help</h4><ul><li>The Danish court for legal aid and representation (<a href="http://www.domstol.dk/">http://www.domstol.dk</a>); refer to this page for <a href="http://www.domstol.dk/saadangoerdu/bolig/Pages/default.aspx">housing-specific questions</a></li><li><a href="https://www.linkedin.com/pulse/new-danish-renting-rules-what-you-need-know-william-birgisson">Layman’s interpreration of the updated Danish Rental Act</a> (in effect since July 1st, 2015), by <a href="https://www.linkedin.com/in/williambirgisson">William Birgisson</a></li></ul><h3>The search: Sites and portals</h3><h4>You are a student</h4><ul><li>Student Housing Aarhus (<a href="http://www.studenthousingaarhus.com/">http://www.studenthousingaarhus.com</a>) is your best friend</li><li>Expect a rent of between 2,500–4,000DKK, depending on room type (single room, with/without en-suite bathroom and/or kitchen)</li><li><strong>Apply early!</strong></li></ul><p>If you are a student looking for house, the trick is to <strong>start looking early</strong>. In fact, once you have been accepted by an institution to study, or receive an education, in Denmark, you are typically automatically eligible to apply for student housing. <a href="http://www.studenthousingaarhus.com/">Student Housing Aarhus</a> (“<em>Ungdomsbolig Aarhus</em>” in Danish) is the <em>only</em> organisation that distributes and manages allocation of student housing in the city of Aarhus.</p><p>Student Housing Aarhus allows you to create an application up to 6 months before the start of your education, but <strong>you need to be able to provide proof showing that you have been accepted </strong>by one of their approved educational institutions (most people I know are either enrolled in Aarhus University or VIA University College, both of which are accepted).</p><p>The only exception is that if you are an <strong>exchange/Erasmus</strong> student: that means you are likely be in the talks with the international student services of your respective institutions, who will have a pre-allocated but <em>limited</em> number of rooms to give out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBwf4KmeeK8fv1SDG1MNcA.jpeg" /><figcaption>I was lucky enough to be given a room in Børglum Kollegiet in Risskov, during my stay in Aarhus as an exchange student</figcaption></figure><blockquote>There is no guarantee that the international student services of your educational institution will provide housing for you.</blockquote><blockquote>However, trust me that they are really trying their very best.</blockquote><p>When I was an exchange student with Aarhus University back in 2011, I was lucky enough to be given a room in Børglum Kollegiet in Risskov. It’s 15-minutes by bike from the university, close to amenities, and have non-square rooms (so you can go all funkytown arranging furniture in your rooms).</p><p>The trick to secure an apartment without toiling forever in the waiting list is simply to <strong>aim low</strong>. You can register for popular dorms, but be sure to include few of the less popular ones (those that are further out), which have shorter waiting list. Your modus operandi will be to <strong>secure a roof over your head first</strong>, and then worry about travel distances and conveniences later. When you are already in a dorm, you can still keep your application, remove the lower ranking dorms, yet remain on the waiting list for “nicer” ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*DWwDMbwxkZeWCOEJy8IeWg.gif" /><figcaption>The legend goes Rose waited for an apartment-type dorm in Aarhus…</figcaption></figure><blockquote>One-foot-in-the-door trick: Take advantage of “internal moving” in dorms that offer units of different types (rooms &amp; apartments)</blockquote><p>Some dormitories offer a mix of housing units, such as standalone apartments (en suite kitchen and bathroom/toilet) and dorm rooms (common kitchen, but bathrooms/toilets may be en suite). Standalone apartment units typically have exorbitant waiting times close to the <a href="https://en.wikipedia.org/wiki/Heat_death_of_the_universe">expected heat death of the universe</a> (joking, but they’re often <strong>&gt;5 years</strong>) and the truth is, you <strong>never get to wait it out</strong>. Internal residents get priority to “upgrading” via internal movement, meaning that the to-be vacant units are often snapped up by pre-existing residents before outsiders even get a chance. <strong>In other words, internally moving residents are always pushed to the top of the waiting list</strong>. In lieu with the “aim low” philosophy, gun for the dorm rooms first—then apply for internal movement at a later date.</p><p>Some helpful notes:</p><ul><li>Renew your application once a month, to accumulate seniority which will place you higher on waiting lists. Create a calendar notification for this monthly ritual—all you need is to <a href="http://www.studenthousingaarhus.com/faq/reapplying">log in every month</a>, no matter what day it is.</li><li>You are only allowed to reject housing offers 3 times before your account is deactivated (read: you lose all accumulated seniority).</li><li>Student Housing Aarhus is typically always swamped with requests, and stand by stipulated rules. <strong>Request of leniencies &amp; exceptions and etc. fall upon deaf ears</strong>.</li></ul><h4>You are employed (or if you’re a <em>very</em> desperate student)</h4><ul><li>BoligPortal (<a href="http://www.boligportal.dk/">http://www.boligportal.dk</a>) is your best friend. You can also try these two Facebook groups: <a href="https://www.facebook.com/groups/housinginaarhus/">Housing in Aarhus</a> and <a href="https://www.facebook.com/groups/minlejeboligaarhus/">Lejligheder til salg og leje i Aarhus</a> (“Apartments for sale and rent in Aarhus”)</li><li>Expect a rent of between 3,000–5,500dkk for a single room in a shared apartment</li><li>Expect a rent of between 6,000–10,000dkk for a two-room apartment; 8,500–15,000dkk for a three-room apartment. Prices are dictated mostly be location, not amenities. Studio apartments are uncommon to come by.</li><li>Avoid the peak periods of November–January, and July–September. These periods coincide with the start of university semesters, which means very impossibly stiff competition at price points that students go for, between 2,500–5,500dkk.</li><li><strong>Try your luck, send applications in Danish (whenever possible), and to as many places as you want</strong></li><li><strong>Watch out for scams</strong> (see section below)</li></ul><p>Unlike the sheltered existence of a student, you’re out and about in the <em>adult</em> world. That means that you don’t get curated listings that are guaranteed to be run by unscrupulous landlords or truthful, honest folks.</p><p>Typically, posters are swamped with a motherload of messages and are quickly overwhelmed by requests when their listing goes live. In other words, <strong>they do not have the time nor the incentive</strong> to process and reply every single message they receive.</p><blockquote>The modus operandi is straightforward.</blockquote><blockquote>Pick the first 25 respondents, interview those who made the second pass, and settle for the one special roommate whom they’ve made a personal connection with.</blockquote><p>Finding themselves knee-deep in requests, posters usually resort to picking the first dozen or so of respondents, and wither the list down to a few, and settle for one thereon. unless they’re hit by an unlucky stroke of 25 completely untenable applicants. Write a quick, concise, and courteous message—but not overly intimate, we all know Scandinavians are uncomfortable with invasion of personal space and strangers in general.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*q6HK6zKsjr29TFIK1uedGg.jpeg" /><figcaption>Yup, this is good enough for me.</figcaption></figure><p>An alternative tip towards securing housing if you have a slightly padded wallet/bank account is to actually rent an entire <strong>share-friendly apartment </strong>(“<em>delevenlig</em>” in Danish), and then either (1) sublet the rooms to, or (2) find co-signers to the same contract with, other people by posting ads on the aforementioned Facebook groups or housing sites.</p><p>Typically you will <strong>never</strong> have an issue finding someone to occupy the rooms. The only drawback is that for going for the first option (which is more convenient), is that you have to pay a hefty deposit and prepaid rent upfront, which you can only recover after finding subtenants to your apartment.</p><h3>Be smart</h3><p>I can understand the desperation that overwhelms you when you realise that you are facing the prospect of being homeless in Aarhus. However, that does not mean throwing caution to the wind. Watch out for the following signs that you are being scammed:</p><h4>Devil is in the details</h4><ul><li><strong>Overly generic descriptions</strong>. The listing information mentions things like “centrally located”, “quiet neighbourhood”, “close to grocery stores” (Which part of Aarhus? Where? What neighbourhood? Most landlords are keen to show off where the listing is, if in a decent neighbourhood), “rent is 500 euros” a month (Denmark <a href="https://en.wikipedia.org/wiki/Danish_euro_referendum,_2000">rejected adopting the currency back in 2000</a>, so there’s no reason why we would quote prices in euros), and the likes.</li><li><strong>Factual discrepancies</strong>. “Gas and electricity included in the rent”—welp, most homes in Aarhus are not fed by gas lines.</li></ul><h4>Validity of address and viewing opportunities</h4><ul><li><strong>Invalid address or address that is not on official records</strong>. Verify the address/unit with <a href="https://ois.dk/">OIS.dk</a>, <a href="http://boligejer.dk/">Boligejer.dk</a>, or <a href="http://krak.dk/">Krak.dk</a> (the former two of which are likely to contain more up-to-date information). Invalid addresses, even if they physically exist, suggests that the place has not been legally inspected and approved for occupancy, therefore will never allow CPR registration. It pays to do your homework. However, note that this does not stop potentially shady landlords from offering the same legitimate unit to multiple people.</li><li><strong>No chance to view, or difficulties in arranging for viewing, the place in person</strong>. A segue from the previous point. Con artists will come up with a myriad of excuses, ranging from vacationing to living abroad, to discourage you from viewing the apartment. You <em>have</em> to do it—either yourself, or have an acquaintance to it on your behalf.</li><li><strong>No possibility of CPR registration</strong> (see next section)</li></ul><h4>Money transfer &amp; payments</h4><ul><li><strong>Reluctance to accept bank transfers. </strong>Landlords that insist on wired transfers are shady as hell. Money is not traceable, and when it leaves your hand, it leaves you for good.</li><li><strong>Any, I mean <em>ANY, </em>mention of money transfer before seeing the apartment</strong>. This is it. If the landlord asks you to transfer any kind of money (typically via Western Union or MoneyGram), then <em>run</em>. <strong><em>RUN</em></strong>, and never ever look back. Any transactions should be performed through bank transfer (so that the money can be traced, although there’s no guarantee on recovery).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*_rchCMaGLLSsFJ6iAdysfA.gif" /><figcaption>This is the only sensible thing to do when your “landlord” instructs you to send money before ANYTHING. They’re the equivalent of demogorgons.</figcaption></figure><blockquote>Never transfer money until you have received and signed the contract. If you do, insist on a bank transfer.</blockquote><ul><li><strong>A sublease is priced higher than the original lease.</strong> Most, or virtually all, housing organisations (that includes Student Housing Aarhus) forbids subletting at a rent higher than what the tenant is paying. In other words, <strong>it is illegal to profit for subletting in almost all dormitories, and in some private residential units</strong> (depending on who owns them). If you are being offered a sublet of a dorm room, double check the price on the dormitory’s webpage—Student Housing Aarhus has a list of all the dormitories it manages. The only exception is when the housing unit is not administered by a housing organisation and does not have a clause in the contract forbiding profiteering through subletting.</li></ul><h3>CPR registration</h3><p>This issue is so persistent that it warrants its own section and a very declarative, stern warning on my behalf.</p><blockquote>Do not settle for a place without possibility for CPR registration. A legal and legitimate rental unit will ALWAYS allow for CPR registration.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*iBsisVB66v5NJSFZ1BYxUw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*x4zganlanUjNomoPPosOdA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*efPkatO8NKJOOOqJcIGrNQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*CKFhGLi3dN0fWYb9RbF-cg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*S8F8vYvdCxBTUP60alD3lw.jpeg" /><figcaption>A small collection of many postings on a Facebook group for housing opportunities in Aarhus, showing that some listings do not allow CPR registration.</figcaption></figure><p>I have come across so many examples when scouring through Facebook groups and postings about rental contracts without the possibility to “register your CPR”. Before I double down on this nasty piece of cake, a brief introduction to what CPR is: it is a civil registration number that is given to every single person who has the legal right to reside in Denmark. You will get one even if you’re just an exchange student.</p><blockquote>A simple motto to live by: no CPR registration, no go.</blockquote><p>CPR registration is crucial because it requires you to provide a valid address. By registering your CPR with Aarhus municipality, you will be able to access all services available to legal residents of Denmark, such as (and not restricted to):</p><ul><li>access to free healthcare</li><li>getting any kind of insurance</li><li>opening a bank account</li><li>receiving salary (through NemKonto; “<em>easy account</em>”)</li><li>entering a contract with your utility (heating, water, electricity), mobile phone, or Internet service provider</li></ul><p><strong>Without a CPR registration, none of the above is possible. CPR is a legal requirement for all residents of Denmark </strong>(defined as anyone residing in the country for longer than 3 months, or are paying taxes to the coffers).</p><blockquote>You are severely handicapped and uninsured if you have no CPR registration. Never settle for “no CPR registration” as an answer from a housing ad!</blockquote><p>A proper residential unit must allow you to register your CPR with it. If you cannot register your CPR at the address, it is very likely because:</p><ul><li><strong>it is not a legal residence unit</strong>, e.g. have not been approved by the municipality for residential occupancy due to safety reasons; the address is at maximum capacity and cannot legally accommodate another tenant; the address simply does not exist; or that it is an office/commercial space that has been illegally repurposed for residential occupancy</li><li><strong>your landlord is not allowed to rent his/her unit out</strong>. This is often the case when the he/she is not allowed to sublet under the conditions of the contract. I have seen one too many cases where students in from the International House attempting to sublet their room, for example (and this is explicitly prohibited)</li><li><strong>you’re getting a phony contract</strong>, likely to be not legally binding and therefore does not offer the chances of CPR registration</li></ul><p>If you are found to be residing at an address that you are not registered to, you risk immediate eviction by the municipality or relevant authorities, and will have no place to return to. I hope that this does not happen to anyone—and the best prevention is not to take up a shady unit at the first place.</p><h3>Let’s talk money: Deposits &amp; prepaid rent</h3><p>Most rental contracts offered in Aarhus include a 1- to 3-month deposit and a 1- to 3-month prepaid rent, <strong>in any combination thereof, or in values in between whatsoever</strong>.</p><p>The deposit is to protect the homeowner/landlord against damages incurred by the tenant(s) (although they can pursue further payments for extensive damages, such as smashing a gaping hole on the floor, or a collapsed ceiling—all of which I have heard of), and as some form of prepayment for refurbishment at the end of your stay. Landlords are <strong>prohibited to restore the apartment to “as new” conditions</strong> according to the new housing regulations signed into law in July 2015, but can still restore damages from normal wear and tear. William Birgisson has <a href="https://www.linkedin.com/pulse/new-danish-renting-rules-what-you-need-know-william-birgisson">written a rather comprehensive and easy-to-understand guide</a> towards the changes in the housing law.</p><p>The summarised gist:</p><ol><li><strong>Landlords cannot make you pay to refurbish your unit to be “as new”.</strong> They can only fix damages due to normal wear and tear.</li><li><strong>Landlords cannot stipulate a fixed increment in rent per annum</strong>, also known as a staircase rent (older contracts usually stipulate rent increments of 100–300dkk per year). This increment is only to be within the range of the inflation of the consumer price index.</li><li><strong>Landlords have the right to terminate your contract</strong>, but have to (1) provide at least a year’s notice; (2) intend to move into the unit him/herself; and (3) must have resided in the aforementioned unit previously</li></ol><p>The best case scenario is typically paying 1 month deposit with no or 1-month prepaid rent. The worst case scenario, which is annoyingly common (and exorbitantly expensive) but perfectly legal, is a 3-month deposit and 3 months prepaid rent. Considering that you also have to pay the first month’s rent upfront, that means up coughing up to 7 times the rental price upfront.</p><h3>Understanding your rental contract and obligations</h3><p>If you have secured a rental contract, and are confident that you are dealing with an apartment/room that actually exists, make sure that you understand it before signing it. You are most likely provided with the standard Danish housing contract—remember that if you also receive one in English alongside, it is a “good to have” but a <strong>non-legally binding version</strong>, in the event of incorrect/inaccurate translations.</p><h4>The dreaded §11</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*TYQrZqHk3uJevAzDdMcFrg.gif" /><figcaption>Susan didn’t read §11 properly. Susan is horrified when she finds out about the extra clauses. Don’t be Susan.</figcaption></figure><blockquote>Watch our for §11, the catch-all section where the landlord has the freedom to ammend any of the declared statements in previous sections.</blockquote><p><strong>Check out </strong>§<strong>11.</strong> That is the catch-all section that houses all the nasty little bits of details. All statements in this section can override any other statements previously declared in the statement. For example, if the landlord enforces that all tenants in the building to be jointly responsible for cleaning the common corridors/stairwells, it will probably end up in there. This section will either:</p><ul><li>reduce your rights, or</li><li>increase your responsibility,</li></ul><p>to statements found in §1 through §10.</p><h4>Moving in</h4><p>It is compulsory for the landlord to check the apartment with the tenant. <strong>Photograph and enumerate all damages</strong>, no matter how small or insignificant you <em>think </em>they are, and submit them to your landlord within 14 days of moving in.</p><h4>Terminating your contract</h4><p><strong>Your prepaid rent might not coincide with the period of advanced notice</strong> you need to give your landlord before moving out—e.g. you may have only paid 1 month of prepaid rent, but is contractually required to give 3 months notice prior to moving out.</p><p>Make sure you inform your landlord in ways that can be timestamped and documented. That can be done by sending an email, or a dated letter to your landlord—use these to complement any verbal communications between both parties.</p><h4>Moving out</h4><p>Most contracts require the tenant to evict the premises before the actual termination of the contract (e.g. 10 business days before), because the landlord needs the extra time to carry out repairs on, or to refurbish, the apartment. Therefore, it is often necessary to have another place to stay during this period, and most people have two weeks to a month of paying double rent. Make sure that you have accounted for this additional expense in your finances.</p><p>Before these works are carried out, make an appointment wiht your landlord and have him/her come by for a visit. Agree with him/her on all the repairs that has to be carried out. The repair/refurbishment costs are usually deducted from your deposit, and the remaining will be transferred back to you at some point after the contract expires.</p><h3>The Bottom Line</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*feIPkXb5Xcz8CLlSZqbUvQ.jpeg" /><figcaption>At Bellevue beach, in the height of Danish summer.</figcaption></figure><p>Finding housing in Aarhus can be a very trying experience. However, things are getting a little better—the redevelopment of Aarhus harbour (Aarhus Ø) means plenty of additional housing options for people moving to the city.</p><p>Keep trying, and don’t give up. With that, I wish you all the best in your search for housing in Aarhus. <em>Held og lykke!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaQcpqZLeZDXrvdY0ChfXQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*034v6LBZEERIL4wBEvIV2A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ALry0nkUUPudvUPYWYbl1w.jpeg" /></figure><p>Terry first came to Aarhus in 2011 as an exchange student, and subsequently stayed in the city of smiles from 2012 onwards a PhD student and post graduate researcher. He is still very much in love in the city.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b4a3de49b4b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aarhus/survivors-guide-to-finding-housing-in-aarhus-6b4a3de49b4b">Survivor’s guide to finding housing in Aarhus</a> was originally published in <a href="https://medium.com/aarhus">Aarhus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using InterProScan like a pro]]></title>
            <link>https://medium.com/computer-says-no/using-interproscan-like-a-pro-ad18b8c3ccc0?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad18b8c3ccc0</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Sun, 27 Nov 2016 23:12:20 GMT</pubDate>
            <atom:updated>2016-11-27T23:13:23.165Z</atom:updated>
            <content:encoded><![CDATA[<p>Biologists are often challenged with this question when working with proteins:</p><blockquote>Now… what does your protein do?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lGcYEnIGo6_quuurlYxvmA.jpeg" /><figcaption>View of protein <a href="http://www.rcsb.org/pdb/explore.do?structureId=4QCI">4QCI</a> generated using <a href="http://wwwtyro.github.io/speck/">Speck</a>.</figcaption></figure><h3>Domain prediction—best friend or worst nightmare?</h3><p>People want to know <em>everything</em> about your-favourite-protein-1 (YFP1). How does it look like? What are the predicted domains? Do these domains have any functions and processes associated with them? Are they located in specific parts of the cell?</p><p>A very simplified pipeline would be as follow:</p><ol><li>Check the amino acid sequence of YFP1 against various domain prediction programs</li><li>Obtain domain and/or structural predictions of YFP1</li><li>Infer biological function, molecular processes, and/or cellular components associated from said domain predictions</li></ol><p>However, there are so many domain prediction algorithms out there, and an overwhelming bunch of them using Hidden Markov Models. These algorithms—such as <a href="http://www.pantherdb.org/tools/hmmScoreForm.jsp">PANTHER</a>, <a href="http://phobius.sbc.su.se/">Phobius</a>, <a href="http://pfam.xfam.org/">Pfam</a>, <a href="http://supfam.org/SUPERFAMILY/hmm.html">SuperFamily</a>, <a href="http://www.cbs.dtu.dk/services/TMHMM/">TMHMM</a>—offer simple web interfaces that allows end-users to submit single (or a small number of, at best) sequences. EMBL-EBI offers <a href="http://www.ebi.ac.uk/interpro/">InterPro</a>, which integrates all of these prediction algorithms, but again only allows single sequence submission from their web interface.</p><p>There appears to be no simple way of submitting a set of protein sequence to multiple prediction algorithms—through a web interface, at least. If you are willing to dive into the world of command line interfaces, things start to look a bit better.</p><p>This article is written based on my experience with using InterPro, and my work with using RESTful services made available by EMBL-EBI on offering comprehensive <em>Lotus </em>data to legume researchers around the world.</p><h3>Example use case: Lotus Base</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*jdNIcz1_TKIx8YJsP2w9WA.png" /></figure><p>As the principle developer and designer behind <a href="https://lotus.au.dk/"><em>Lotus</em> Base</a>, I have worked on performing predictions on the entire set of predicted proteins using the most recently published <em>Lotus japonicus</em> genome — meaning 50,000+ predicted proteins in total that has to be parsed. The screenshot below shows an example of how I have pulled protein-specific data from a MySQL database built based on InterProScan’s domain prediction results, and merged the data with additional metadata obtained with the EB-eye REST service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TYJsgWMjbXx-XgR0OGcI1A.png" /><figcaption><a href="https://lotus.au.dk/view/transcript/Lj4g3v0281040.1">Domain predictions for my-favourite-gene, the flagellin receptor LjFls2</a>. Domain prediction graph made using <a href="https://github.com/d3/d3">d3.js</a>.</figcaption></figure><p>Of course, <em>Lotus </em>Base presents itself as a rather extreme use case due to the large volume of predicted proteins analysed. However, the methods described below would be just as applicable to a researcher who say, has obtained a list of proteins that are significantly enriched in one biological sample compared to another. The first step towards unraveling the functions of these proteins, based on their gene ontology predictions, would be to obtain their domain predictions first.</p><h3>InterProScan vs InterPro RESTful service</h3><p>You have two options from here on—if you are blessed with access to a computing cluster running on Linux, you can download and install a local version of <a href="https://github.com/ebi-pf-team/interproscan">InterProScan</a>, and run InterProScan with FASTA files containing <em>n </em>number of sequences in parallel or in queue. The second, less handy option—but also the most accessible one—is to take advantage of the <a href="http://www.ebi.ac.uk/Tools/webservices/services/pfa/iprscan5_rest">RESTful service</a> provided by EMBL-EBI. The latter can be run on any computer, although preferably one running Unix/Linux (because that’s what my code will be running on). The only drawback is that EMBL-EBI’s fair use agreement only allows you to run InterProScan on 30 sequences at any one time.</p><p>Both services will give you the most up-to-date domain predictions, and necessitates re-running your proteins if they have included additional datasets. When InterProScan includes additional prediction algorithms, you can simply select to run said algorithms—instead of the entire set—on your sequences, and simply join the output with existing predictions.</p><h3>Option A: Using EMBL-EBI’s InterPro REST service</h3><p>Using the REST service provided by EMBL-EBI is a way to perform domain predictions on your protein(s) of interest without needing to invest in an expensive computing cluster, or obtaining access to one. For this part of the tutorial to work, you will need to ensure that Python3 is installed (InterPro provides a Python2 client library, but that is not covered in this section).</p><h4>Explode FASTA file into individual sequence files</h4><p>As the InterPro REST service only accepts single sequences, the easiest way is to split a multi-sequence FASTA file into individual sequence files. If your FASTA files are formatted such that each entry takes up two lines — one for the header and one for the sequence — you can do something like:</p><pre>split -l 2 /path/to/your/fasta/file</pre><p>However, this is often not the case, as FASTA files are recommended to be broken into lines containing no more than 60 characters long. If that is the case, you might want to rely on BioPython to do the parsing for you:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/213f220f07db726983735b47e6aa141f/href">https://medium.com/media/213f220f07db726983735b47e6aa141f/href</a></iframe><h4>Hand individual FASTA file off to the REST service</h4><p>When you have generated We can then iterate through these individual FASTA files and pass them to InterPro’s REST service. InterPro has provided us with various clients to interface with their REST service—I have chosen to work with their <a href="http://www.ebi.ac.uk/Tools/webservices/download_clients/python/urllib/iprscan5_urllib3.py">Python3 client</a>. I did not modify their client script, with the exception of commenting out the line that prints the status in the clientPoll function, so that my console will not be crowded with RUNNING printouts.</p><p>It is important to respect the 30 sequences per batch limit of the InterPro REST service. Therefore, we will use a simple bash script that, while iterating through all individual FASTA file, stops after 30 files until the outcome from all 30 jobs have been returned:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7679b5a25e3c61de83e0509c146a6f0e/href">https://medium.com/media/7679b5a25e3c61de83e0509c146a6f0e/href</a></iframe><p>If you want to obtain other output formats, remember to modify the --outformat option. According to my experience, each batch (of 30 sequences) takes around 2 minutes to complete.</p><p>The major drawback of this method is that it is a rather nuclear option if you are attempting to scan the entire collection of predicted proteins/transcripts. <strong>Use InterProScan on a computing cluster, if ever possible.</strong></p><h3>Option B: InterProScan on a computing cluster</h3><h4>Installing InterProScan</h4><p>Follow the <a href="https://github.com/ebi-pf-team/interproscan/wiki/HowToDownload">published instructions on installing InterProScan</a>. I have ran into small hiccups, such as accidentally using an outdated version of Java (≤1.7) and having a dated GCC library. Loading the most updated one ensured that both InterProScan and the bundled BLAST+ package can be executed properly.</p><h4>Adding proprietary algorithms</h4><p>Note that InterProScan does not come with <a href="http://phobius.sbc.su.se/data.html">Phobius</a>, <a href="http://www.cbs.dtu.dk/services/SignalP/">SignalP</a>, and <a href="http://www.cbs.dtu.dk/services/TMHMM/">TMHMM</a> preinstalled. You will have to request for the compiled binaries of these algorithms, and upload them to their respective folders in the bin directory.</p><blockquote>If you are unable to get hold of these libraries, you will have to retrieve the output of these algorithms via InterPro REST service.</blockquote><p>A hitch with SignalP is that it assumes a fixed directory for loading the library files. This causes a fatal error where FASTA.pm cannot be loaded—remember to update the environment so that it points to the signalp directory (it will load libraries from the lib subfolder automagically).</p><pre># full path to the signalp-4.1 directory on your system (mandatory)<br>BEGIN {<br>    $ENV{SIGNALP} = &#39;&lt;path/to/interproscan&gt;/bin/signalp/4.1&#39;;<br>}</pre><h4>Check that all prediction algorithms are loaded</h4><p>After you’ve done that, ensure that interproscan.properties file is properly updated with the file paths of your binaries for the added libraries. After that, proceed to run ./interproscan.sh without any arguments. It will print out all the algorithms that were detected and loaded correctly. Ensure that none is left behind—InterProScan will inform you if any of them has failed to load.</p><p>Depending on the number of sequences you want to submit per batch, you will have to update</p><h4>Getting your FASTA files ready</h4><p>You would want to process FASTA files in batches instead of all at one go. I have decided to split a unified FASTA file that contains all 50,000+ of the amino acid sequences into files containing 500 entries each. If your FASTA files are formatted such that each entry takes up two lines—one for the header and one for the sequence—you can do something like:</p><pre>split -l 1000 /path/to/your/fasta/file</pre><p>…assuming that you want 500 entries per file. However, this is often not the case, as FASTA files are recommended to be broken into lines containing no more than 60 characters long. If that is the case, you might want to rely on BioPython to do the parsing for you. The first step is to create a filtered FASTA file that is formatted such that each entry occupies two lines, generating a filtered.fa file. The second step is to batch parse this filtered file using itertools, to create batches of FASTA files containing 500 entries (i.e. 1000 lines) each:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e23ac917a85c243c00f83e3f23f480c/href">https://medium.com/media/7e23ac917a85c243c00f83e3f23f480c/href</a></iframe><h4>Submit your jobs to iteratively to the computing cluster</h4><p>In this case, I am using SLURM for batch job submission. I will not go into details on how the job submission is done, as it is highly dependent on the configuration of individual clusters. The actual command is quite simple:</p><pre>/path/to/interproscan.sh \<br>-i /path/to/fasta.fa -dp -iprlookup --goterms --pathways</pre><p>Note that I have turned off precalcualted match lookup using the -dp flag because the computing cluster I am on blocks external connections for security reasons. Moreover, the <em>Lotus japonicus </em>proteins are yet to be submitted to UniProt so it is highly unlikely that we will find too many matching proteins in the public database.</p><p>Here is an example of how a batch job submission template you can use:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/075a573452e134028356b6eb2dcf1ace/href">https://medium.com/media/075a573452e134028356b6eb2dcf1ace/href</a></iframe><p>Boom! Run it and wait for magic to happen.</p><h4>Performance</h4><p>In the case of <em>Lotus </em>Base and our collection of predicted transcripts, we have 49,598 sequences scanned in batches of 1,000, creating 50 jobs. The jobs were run with an allocated 24Gb memory over 12 cores, on nodes equipped with Intel “Sandy Bridge” E5–2670 (2.67GHz)or “Haswell” E5–2680v3 (2.5GHz) CPUs. After normalizing for processor speeds and library sizes, the real time consumed per job stands at 2.50±0.28h (CPU time: 4.32±0.35h).</p><h3>Parsing InterPro/InterProScan outputs</h3><p>The file that contains all the juicy data is the TSV file, which you can easily import into a relational database such as MySQL. The <a href="https://github.com/ebi-pf-team/interproscan/wiki/OutputFormats#tab-separated-values-format-tsv">InterProScan wiki</a> has the information on what does each individual column in the TSV file contain.</p><p>For <em>Lotus </em>Base, I simply imported the TSV file <em>as-is </em>into a MySQL table, and used JOIN statements to merge transcript metadata from additional tables we have. It’s as simple as that!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-hn5r0B_TVE0KMltb8gtg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sKgPgOQLbPgKbGq_KGzAHA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x5m13sJXzzQ3YUIYbhUrMg.jpeg" /><figcaption>The person behind <em>Lotus Base (left) and where Lotus Base is mostly written (center, and right).</em></figcaption></figure><p>Terry is the principle designer and developer behind <a href="https://lotus.au.dk/"><em>Lotus</em> Base</a>, an integrated information portal for the model legume <em>Lotus japonicus</em>.</p><p>p/s: Our manuscript has been accepted for publication, and we can’t wait to announce it ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad18b8c3ccc0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/computer-says-no/using-interproscan-like-a-pro-ad18b8c3ccc0">Using InterProScan like a pro</a> was originally published in <a href="https://medium.com/computer-says-no">Computer Says No</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 still choose Airbnb]]></title>
            <link>https://medium.com/one-too-many-cents/why-i-still-choose-airbnb-bff5245839ea?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bff5245839ea</guid>
            <category><![CDATA[airbnb]]></category>
            <category><![CDATA[customer-experience]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Tue, 26 Apr 2016 03:48:16 GMT</pubDate>
            <atom:updated>2016-04-26T03:53:49.552Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRFqSYl77xsV5tNWcTZlvQ.jpeg" /><figcaption>The boy and I at an Airbnb listing in the heart of Toulouse, France.</figcaption></figure><p><strong><em>Sharing economy</em></strong><em> is the </em><strong><em>democratization</em></strong><em> of access to, and utilisation of, pre-existing </em><strong><em>excess capacity</em></strong><em>.</em></p><p>These words, haven’t we all hear them before? From the Uber car that you shoved your friend—who just had one too many mojitos—in, to the Wikipedia pages your college lecturers threatened you <em>not </em>to use for your essay’s citations, they are part of the sharing economy. In some cases, monetary transactions are involved between the consumer and the provider: like you linking your credit card to your Uber account, where fares are automatically deducted after a ride. And in some cases, money doesn’t change hands between the two: such as you benefiting from the useful tips of that lovely family-run hotel on Trip Advisor.</p><p>Some might argue that sharing economy is a misnomer—that when money is involved, it is an <em>access </em>economy where people who can pay for the services ends up consuming the service. But I will not dwell into such technicalities.</p><p>I am here to talk about one thing, and one thing only: Airbnb.</p><p>The first time I’ve ever heard of Airbnb was from, what media pundits call, a PR disaster. <a href="http://techcrunch.com/2011/07/27/the-moment-of-truth-for-airbnb-as-users-home-is-utterly-trashed/">An Airbnb host found her apartment in total disarray</a> after her guest(s) ransacked her home, stole her valuables and left a huge mess behind for her to clean up. I signed up for a membership curious about how it works. Being brought up in an era when Limewire was the only way to get music online via a 56kbps dial-up modem, I learned that Internet is a dangerous place. So many questions came to my mind.</p><p><em>How can I trust a stranger that I have never met before?<br>How can I live in an apartment that I have never seen myself?<br>How do I know that my host is not some serial killer masquerading as an overtly enthusiastic and friendly homeowner?</em></p><blockquote>The first time I used Airbnb was almost entirely out of desperation.</blockquote><p>I didn’t use the service until spring of 2013, when my parents from Malaysia popped by Europe for a grand tour. Working on a limited budget? Hotels and vacation homes were out of the question. Yearning for some private space to kick our shoes off after a long day of sight seeing? Hostels were a no-go. Just when I was pulling my hair out wondering how should accommodation be arranged, I suddenly remembered—I did have an Airbnb account. I never used it.</p><p>And that was the first time I used Airbnb, and only because I was out of options and desperately needed to settle the finer details of the little European trip my parents and I were embarking on.</p><p>Then I remembered my mom asking the very same questions again. How can we trust our hosts? I shrugged my shoulders and said I had read the reviews and looked at the photos for the places we had booked, they all checked out. A few clicks here and there, I booked a room in Vesterbro, Copenhagen; a cozy apartment in suburban Berlin; a chic one-bedroom unit in the bustling neighbourhood of Montmartre, Paris; a room in the industrial town of IJmuiden; and a tropical-themed bedroom in Stockholm.</p><blockquote>Before Airbnb realised it in a recent rebranding, we were not going to places. We were living in cities. Since 2013.</blockquote><p>We did not <em>travel</em> to Copenhagen. We lived there, with Melina showing us the little tricks of getting around the dizzying grid of the city, and the little park across the street she brought her kids to play on the rare Danish evenings with good weather (trust me, they’re hard to come by in springtime).</p><p>We did not <em>travel </em>to Berlin. We breathed there, with Michaela leaving us a scrapbook full of useful instructions on taking the metro, going to exhibitions and the galleries in town.</p><p>We did not <em>travel </em>to Paris. We explored the uncrowded parts of Montmartre, hiked up to see the Sacré-Cœur, passing smiling locals hanging out by the benches under the trees. We hobbled up steep, dark and creaky French stairwells. I practised my non-existent French at a local <em>supermarché</em>. “Bonjour!” “Ça, si’l vous plaît.” “Merci. Au revoir!”</p><p>We did not <em>travel</em> to Amsterdam. We lived in a quaint little rowhouse outside of the city, in an industrial port of IJmuiden. Marijke offered us a tour of the little city in her beat up car. She brought us to the sandy beaches of the town. She showed us the industrial remnants of the city’s port.</p><p>We did not <em>travel</em> to Stockholm. We had breakfast with Najila in her sun-filled dining room, with her daughter shyly colouring her book by the living room.</p><p>After sending my parents off at Copenhagen Airport at the end of the trip, I made a promise—I’ll give Airbnb another go again, when I want to <em>live</em>, not just to <em>travel</em>, to another city.</p><p>Fast foward a few seasons and I found myself somewhat in a hot seat in the winter of 2015. The details of my trip to Toulouse, France, had just been ironed out. I had to leave for the city in <strong>two weeks</strong>. Where, the hell, on earth, am I going to find accommodation?</p><p>Airbnb came to mind, again. Upon a friend’s suggestion, I looked for long term accommodation options on Airbnb, after finding local rooms locked behind cumbersome bureucracy and in severe shortage, and rental apartments priced exorbitantly out of reach—even for the ample stipend I receive as a Danish PhD student.</p><p><em>Voila. </em>I found several places after a few clicks. It was difficult finding a place that I could rent for my entire stay in the city, so I broke it up to 30-day periods, where I could stand to benefit from the monthly discounts (offered to rentals 28 days or longer) and yet stay long enough to I didn’t end up having to jostle around town with my luggage every other weekend.</p><p>The first two accommodations were not too bad. Each have their own benefits, but both were a bit too far from work. One was far north in the neighbourhood of Borderouge, and another in a slightly seedy area of <a href="https://agingmodernism.wordpress.com/lemirail/">Le Mirail</a>.</p><blockquote>The third accommodation came with a surprise. A nasty surprise in the form of a refrigerator caked in mould.</blockquote><p>By early April I’ve moved on to my third Airbnb long term rental, a studio apartment in the heart of Saint Cyprien neighbourhood. <em>How much better can this get? </em>I asked myself. Never did I expect something to go the opposite way shortly after I checked in and messaged the host: “Bonjour [name related] :) just want to let you know I’ve checked in, and the place is amazing! Thank you!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S5F-_gvQJrFwM29FPYHlhg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*oUHvJpMrh3bhInADK_RaYQ.jpeg" /><figcaption>Mouldy fridge in a nice studio apartment. Oh blimey.</figcaption></figure><p>Five seconds later I opened the fridge. <em>Cake </em>was the first word that came to mind. No, it didn’t have a welcome cake in it. It was <strong>caked in mould</strong>. Yes, you read it right. Every biologist’s wet dream in the wrong place: a rainbow of moulds thriving on the safety glass, by the door, in the rubber seals. There was mould everywhere.</p><p>I immediately whipped myself to work, but halfway through the cleaning I stopped myself. I almost forgot to document the little biosphere going on in the fridge. I need photos, if I ever have to talk to my host about the fridge, if the mould returns after I clean it. After a few shutter clicks, I sent the photos to my host—let’s call him Théo (just one of the popular baby boy names in France I picked up from Google). I was aghast when Théo replied:</p><blockquote>“Bad surprise … sorry for the inconvenience.”</blockquote><p><em>Really? That’s all?</em></p><p>After not hearing anything from the host for <strong>two days</strong>, and not being able to cook at all in the apartment with “kitchen” listed as one of its amenities, I reached out to Airbnb resolution center. I received a reply from a support staff, Kelsey, within the hour. After sending over proof of the refrigerator which was very much alive, Kelsey asked me for permission to contact my host, which I gladly consented.</p><p>Kelsey contacted Théo, and now the gears started to churn in Théo’s head. I don’t know what she said to him, but he finally got back to me, and offered to replace the refrigerator with a 180˚ change in attitude.</p><blockquote>“I am concerned about your comfort. I will come Saturday around 10am [to replace the refrigerator]”</blockquote><p>I was expecting some cleaning, so I was thrilled beyond belief. The issue was amicably resolved. Kelsey offered me some travel credit to use in the future with Airbnb. I was <em>doubly</em> thrilled beyond belief.</p><p>This is customer service done right.</p><p>Fast forward another three weeks. I was five days away from check out. Théo dropped me a call in the evening just as I stepped out of yoga class in the gentrified neighbourhood behind Jean Jaurés. He wanted to let me know of the checkout procedure, and I listened… and my heart sank.</p><blockquote>My Airbnb host was insistent that I wash and dry the bed linen and covers, at my own expense, <strong>at a laundromat.</strong></blockquote><p>Théo wanted me to strip, wash and dry the linen and cases that I have used, <strong>at my own expense at a laundromat</strong>. I got defensive quickly, telling him that it is not my responsibility to ensure that the next guests, checking in on Sunday, will have new, clean and dry sheets to sleep in.</p><p>If I was unwilling to do so, he proposed, I would have to pay a cleaning fee of 15€. I had to paraphrase what he said, since he conversed over the phone and I couldn’t confidently recount the exact words he used. He said that the cleaning fee was listed as part of the description of the listing. I checked, and it was really-fucking-there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iD8TjkX-BqxOOgHR9SE7oA.png" /><figcaption>My Airbnb host has his own list of extra charges.</figcaption></figure><p>The issue I faced was three-fold.</p><ol><li>I honestly could not remember reading that description, but I would give Théo the benefit of the doubt and assume that I missed it when reading through the listing’s description.</li><li>Am I supposed to pay for cleaning? There must be some kind of (unspoken, perhaps?) rule on Airbnb that the host is responsible for tidying up. Of course as a respectful guest, I will take out the trash, vacuum the place, do the dishes, and clear out the fridge when I’m leaving—but that is as far as my moral obligations will go.</li><li>Am I supposed to pay for the use of bed linen?</li></ol><blockquote>When does a guest end, and a cleaner start?</blockquote><p>I paid a whooping 800€ for a month in this studio apartment, and based on my previous experiences with Airbnb, I was never tasked with cleaning the place <em>and</em> prepping it for the next guest(s)—shouldn’t that be the responsibility of the host? Even though Airbnb operates under the premise that we are more akin to house guests than hotel guests, I am quite convinced that I am not contracted to clean the premise. I paid for the place. I did not pay to clean the place for you—I wasn’t even sure how much sense was his argument making.</p><p>I offered to put strip the linen and covers and place them in the washer, and start the cycle before I check out. He could come by later and dry them if he chooses to, or swap them out with fresh ones. I promised that I will vacuum and wash the floors, to clear out the refrigerator, to wipe down the kitchen and bathroom before I leave.</p><p>That wouldn’t do it for him. The washing machine in the apartment couldn’t dry the sheets and it wouldn’t be ready for the next guests, he argued. After listening to my astute refusal to dry the sheets, he taunted me to contact Airbnb support, “just like what you did when you find the mouldy refrigerator”.</p><p>He reared his ugly head, and turned me into the villain that he was. That conversation was no longer meaningful. I offered to get back to him later after checking out the precise terms and conditions, and ended the call.</p><p>And yes, taunt me all you want, but I will reach out to Airbnb for clarification. You may have fooled previous guests (see review below), but you won’t fool me—and even if you succeed at it, I will make sure I will be the last victim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SW-tqjDEQCQ56nkSLi03Bg.png" /><figcaption>It wasn’t just me who felt that Théo was charging excessively for bed linen, and that the charges were made outside of the Airbnb payment system—which is explicitly forbidden. I also couldn’t believe he advertised the place for four, because it’s barely large enough to fit two. Disclaimer: I was the one who gave the helpful vote.</figcaption></figure><blockquote>I wanted Théo to let know that he was messing with the wrong man. I would not let him pee on my leg and tell me it’s raining—thanks Judge Judy for the quote.</blockquote><p>After putting the phone down, I did hold myself back for a moment, and doubted myself. Was I having a runaway self-entitlement issue? Clouded by uncertainty, I reached out to Airbnb help center again—despite my host taunting me not to reach out to them. My reason was that if anything, or everything, was going south, I wanted to have my point of view, <strong>securely timestamped and logged by Airbnb</strong>, in the narrative, for science… I mean, for future reference.</p><p>Frustrated, I also reached out to @Airbnb on Twitter. They replied and got on my case swiftly:</p><h3>Terry on Twitter</h3><p>Nasty experience. Owner of my @Airbnb apartment wants me to washed the bed and dry it, at my own cost, before I leave. What the hell.</p><h3>Airbnb Help on Twitter</h3><p>@teddyrised Sorry to hear about this, Terry. Could you please DM us your email or phone number? Our team is here to help you.</p><p>Lily, a support staff, sent me an email soon after. She clarified with me that it is <strong>not the guests’ responsibility to clean and prep the accommodation for incoming guests</strong>—that responsibility lies solely on the host… which, <em>*drumrolls*</em>, makes perfect sense. I wonder if Théo flushed his common sense down the toilet that evening, along with his personality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29Q9I_hyazI1zYIjOoQiIA.png" /></figure><p>I informed Lily that I wouldn’t mind paying the 15€ and get the issue over with, but I expressed my concerns about Théo’s understanding his responsibilities and duties of hosting with Airbnb, so I asked if she could inform Théo that what he did is uncalled for and his demands were in contrary to the expectations set by Airbnb.</p><blockquote>Airbnb resolves conflicts by diplomatic, unbiased mediation, not through blindfold, tough and clinical rule enforcement.</blockquote><p>And guess what? Lily, on behalf of Airbnb, footed the cleaning fee, despite it being a ridiculous, frivolous charge that Théo isn’t entitled to get to begin with, and educated him about the rules of hosting. That gesture speaks volume of Airbnb caring not only for my concerns, but also honouring, albiet for the last time, an invalid rule set by host—likely giving Théo the benefit of doubt that he likely did not understand the rules of hosting with Airbnb in their entirety.</p><p>By doing so, Airbnb ends the game with a win-win situation: Théo gets whatever amount of money he expects from a guest who refuses to abide by his silly rules (and for the last time only) and a lesson on the rules of hosting, while I did not end up walking away with a souring taste in my mouth having to fork out money over an illegitimate “cleaning fee”.</p><p>I’m not sure what she said to Théo, but I hope that teaches Théo a lesson that he cannot simply bend the rules to his own advantage and bully guests into doing the dirty work for him, while he approaches hosting in a very <em>laissez-faire</em>, hands-off and irresponsible manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWHFJ10XxYRDD5jTHchHwA.png" /></figure><blockquote>Airbnb might not have the hardware, but it definitely has a <em>heartware</em>.</blockquote><p>What my experience with Airbnb is, especially after this episode, is that Airbnb does care for its users. Even though Airbnb is siding with me in this case, it doesn’t indicate that it consistently collludes with the guests only—Airbnb has also extended help to hosts who have encountered issues with problematic guests before.</p><p>There are many people deriding Airbnb—for how it prevents affordable housing from being release to the market by incentivising homeowners to lease their space out for profit; how it <a href="http://www.airbnbvsberlin.com/">inflates local rents</a> and prices; how it <a href="http://nypost.com/2014/11/23/how-airbnb-makes-cities-less-safe/">poses a safety risk to neighbourhoods</a>. Zak Stone wrote a <a href="https://medium.com/matter/living-and-dying-on-airbnb%E2%80%A6">very thought-provoking piece</a> after losing his father to an accident that occuring on a property they rented through Airbnb. But I am not here to discuss that aspect of Airbnb. I simply wish to highlight the excellent job that Airbnb is doing at customer service—and this is very likely the reason why, combined with its trust-based system of recommendations and reviews, makes it the most popular platform for accommodation options in the highly competitive sharing economy.</p><p>I would like to end this entry with a very positive note—that out of so many times I have used Airbnb before, this is the one and only sour experience I’ve had. And it wasn’t even Airbnb’s fault that the host, Théo, has his own convoluted way of perceiving responsibilies and appears to have confused or even conflated the roles of a host, and those of a guest. Airbnb has provided support that timely, effective and human, an experience that many online enterprises nowadays fail to offer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mq81SxX5quak61pVf7kofg.gif" /><figcaption>An animated gif from DesignStudio, the company behind the rebranding of Airbnb. Source: <a href="https://www.wearedesignstudio.com/works/airbnb-rebrand/">https://www.wearedesignstudio.com/works/airbnb-rebrand/</a></figcaption></figure><p>Like the popular saying in Singapore goes, Airbnb might not have the hardware, but it definitely has a <em>heartware</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bff5245839ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-too-many-cents/why-i-still-choose-airbnb-bff5245839ea">Why I still choose Airbnb</a> was originally published in <a href="https://medium.com/one-too-many-cents">One Too Many Cents</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I hurt myself today]]></title>
            <link>https://medium.com/life-journey/i-hurt-myself-today-4a9743cbf0b?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a9743cbf0b</guid>
            <category><![CDATA[short-story]]></category>
            <category><![CDATA[love]]></category>
            <category><![CDATA[boyfriend]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Tue, 08 Dec 2015 22:55:33 GMT</pubDate>
            <atom:updated>2015-12-08T22:57:05.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vAdCAgTWy4ToWCd5_CvF8Q.jpeg" /><figcaption>,We are always reaching for new heights—but sometimes that means stopping down and crawling through a thicket-filled valley before getting there.</figcaption></figure><p><em>…by hurting someone else.</em></p><p>I did something really silly. In hindsight, <em>silly</em> would not be my choice of word. A moment of clear, unbridled stupidity would be it.</p><p>The boy and I were lying in bed, cuddling. The topic shifted to a game that kids play—maybe those at his workplace, or maybe as a young kid in the old days, or maybe as himself (who I can rightfully describe as having a seven year-old stuck in an adult body). Then I said something incredibly, absolutely, horrifying stupid.</p><p>So stupid that I could see the mic drop before it left my hand. As the words rolled off my tongue, as I uncomfortably searched for a better substitute of words mid-sentence… it just happened. Like a sharp knife in the hands of a skilled sushi chef slicing through fish, it materialized so swiftly, with a speed so deadly I couldn’t believe I remembered every single microsecond that unfolded.</p><p>The churning of my stomach. The shiftiness in my gaze. The lump in my throat. The clammy, sweaty hands of mine as I held his.</p><p>And then my eyes met his. A mix of disappointment, shock, disdain and disgust, all perfectly orchestrated in a single electrifying gaze. Like a singer reaching for a crescendo, I breathed in deeply, and an apology escaped with my exhalation like clockwork.</p><p>I have hurt him. I knew it. No apologizing can ever take it back.</p><p>The next morning I woke up, alone in bed. He was dressing for work. As he walked into the bedroom for a goodbye kiss, setting off a series of signature creaks that our wooden floor squeaks, a wave of shame washed over me.</p><p>What have I done? As I sobered up from my winter morning stupor, I knew that I have dealt some serious damage. The perniciousness of my comment started to grow on me.</p><p>As I sat at work today, I thought about him a lot. How would I feel in his shoes? I would have felt horrible. Insulted by the rudeness of it, offended by the audacity of it, surprised by the suddenness of it, disappointed by the crudity of it.</p><p>I texted him, and he told me how hurtful my awful choice of words were. I apologised, again, and then I realised something: my hurtful words are collateral.</p><blockquote>For the hurtful words that I have said to him, I have hurt myself even more.</blockquote><p>There is a Chinese saying that goes “一言既出，驷马难追”, which roughly translates to “a word that is said cannot be taken back by a carriage drawn by four horses”. In other words, like spilled milk on a pavement, a word, once said, can never be taken back.</p><p>I was deeply mad and disappointed at myself—because I care for him so much, and it agonises me to see him distressed by such rudeness that was completely uncalled for. And the worst feeling is knowing that no amount of apologises, no number of pretty bouquets, no extent of lavish gifts or dinner spreads will ever make me take back what I have muttered in a moment of unbelievable imbecility.</p><blockquote>I hurt myself today by hurting someone I love.</blockquote><p>But instead of crying over said spilled milk, I have taught myself a very important lesson. Saying hurtful things to strangers only hurt them, but doing the same to the ones dearest to you ricochets like a bullet hitting concrete. Onto yourself.</p><p>Picking your words wisely is the safest way.</p><p>p/s: I love you, and I will never do this again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUgvxmyElkFT24pn75Kpcg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KVwN7zCZEUP-7hnvz00MOg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OxZwHue33WnTO8KY-gpvdw.jpeg" /><figcaption>❤</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a9743cbf0b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/life-journey/i-hurt-myself-today-4a9743cbf0b">I hurt myself today</a> was originally published in <a href="https://medium.com/life-journey">Life Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up SequenceServer]]></title>
            <link>https://medium.com/coding-design/setting-up-sequenceserver-edf9d992998c?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/edf9d992998c</guid>
            <category><![CDATA[passengers]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Mon, 16 Nov 2015 01:03:20 GMT</pubDate>
            <atom:updated>2015-11-16T01:03:20.224Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RMkOEK79QNHRkeHfnHqhXg.png" /><figcaption>A heavily modified SequenceServer that is running from the Lotus japonicus genomics and proteomics resource website, manuscript in preparation (Mun <em>et al., 2015)</em></figcaption></figure><p>I was recently tasked with setting up <a href="http://www.sequenceserver.com/">SequenceServer</a> on a work server in a production environment—the legacy NCBI wwwblast is extremely dated, and highly non-customizable. Deep integration with the API we have developed for a <em>Lotus japonicus </em>genomic and proteomic resource is not possible.</p><p>I have encountered several issues with setting up SequenceServer, but have managed to resolve all of them. I am therefore penning this guide for future users who might be interested in installing SequenceServer, but are at a loss of where to start, and what to do when they run into issues.</p><p>It is of course not possible to enumerate the installation instructions for all possible server configurations—therefore you should be warned that the SequenceServer I have installed is running off a RHEL7 server with a standard solution stack (Apache, PERL-CGI, PHP and MySQL) installed.</p><h3>Ruby on Rails</h3><p>If you have not installed Ruby on Rails on your server, you will have to do that. I strongly recommend using <a href="https://github.com/sstephenson/rbenv">rbenv</a> to install Ruby. It just makes life a lot easier ;) you may also follow <a href="http://mmclub.github.io/blog/2014/03/30/install-ruby-on-rails-on-centos/">this very handy guide</a> for more details.</p><pre><em>### Install Ruby using rbenv</em><br>$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv<br>$ echo &#39;export PATH=&quot;$HOME/.rbenv/bin:$PATH&quot;&#39; &gt;&gt; ~/.bash_profile<br>$ echo &#39;eval &quot;$(rbenv init -)&quot;&#39; &gt;&gt; ~/.bash_profile<br>$ git clone <a href="https://github.com/sstephenson/ruby-build.git">https://github.com/sstephenson/ruby-build.git</a> ~/.rbenv/plugins/ruby-build</pre><pre>$ source ~/.bash_profile<br><br><em>### Install ruby</em><br>$ rbenv install 2.1.0<br>$ rbenv rehash<br>$ rbenv global 2.1.0</pre><pre><em>### Update everything</em><br>$ gem update<br>$ gem update --system</pre><h3>Installing SequenceServer and its dependencies</h3><p>Here, I will go through the installation instructions for the dependencies for SequenceServer and SequenceServer itself.</p><h4>Dependencies</h4><p>The gem you need for SequenceServer to work is <a href="https://rubygems.org/gems/rails/versions/4.2.4">rails</a> and <a href="https://rubygems.org/gems/passenger">passenger</a>.</p><pre><em>### Install basic dependencies</em><br>$ gem install rails<br>$ gem install passenger<br>$ passenger-install-apache2-module</pre><p>If you want to build SequenceServer yourself, you will also need to install <a href="https://rubygems.org/gems/rack">rack</a> and <a href="https://rubygems.org/gems/rake">rake</a>.</p><pre><em>### Install basic dependencies</em><br>$ gem install rack rack-test rake</pre><p>However, if you run into additional issues, you might want to install development dependencies such as Rspec, Rubocop, Capybara, CodeClimate and qmake.</p><pre>### Install qmake<br>$ yum install qt-webkit-devel<br>$ find / -name *qmake<br>$ ln -s /usr/lib64/qt4/bin/qmake /usr/bin/qmake</pre><pre>### Install other development dependencies<br>$ gem install rspec rubocop capybara capybara-webkit codeclimate-test-reporter</pre><h4>SequenceServer</h4><p>As SequenceServer is available as a Ruby gem, you just have to run:</p><pre>$ gem install SequenceServer</pre><p>Yes, it is as easy as that—but wait, you are not really done yet. We need to specify where can SequenceServer run from, and we typically do not run it off a port (4567 by default), but off a subdirectory, like /blast/ or the likes. In order to run SequenceServer off a subdirectory, we need to run Passenger at the correct paths—this involves fiddling with the Apache httpd configuration file.</p><h3>Updating your Apache httpd configuration file</h3><p>As mentioned before, if you intend to run SequenceServer as a Passenger app in a subdirectory, you will have to give Apache a set of very specific instructions:</p><ol><li>Your choice of subdirectory where you intend to serve SequenceServer</li><li>The location of your SequenceServer public folder</li><li>The user that Passenger should run SequenceServer as</li></ol><h4>Info 1: Choice of subdirectory</h4><p>That is very simple. If you want to run SequenceServer from the /blast/ subdirectory of your URL, you will use “/blast”</p><h4>Info 2: Location of SequenceServer public folder</h4><p>This is a bit tricky. First, you will have to figure out where is SequenceServer installed. You can do this by running:</p><pre>$ gem env</pre><p>This will output something similar to the following in your terminal (emphasis my own):</p><pre>RubyGems Environment:<br>- RUBYGEMS VERSION: 2.2.0<br>- RUBY VERSION: 2.1.0 (2013–12–25 patchlevel 0) [x86_64-linux]<br><strong>- INSTALLATION DIRECTORY: /home/terry/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0</strong><br>- RUBY EXECUTABLE: /home/terry/.rbenv/versions/2.1.0/bin/ruby<br>- EXECUTABLE DIRECTORY: /home/terry/.rbenv/versions/2.1.0/bin<br>- SPEC CACHE DIRECTORY: /home/terry/.gem/specs<br># and more... #</pre><p>Look at the <em>INSTALLATION DIRECTORY</em> value (see bolded line). Your gems should be installed in the /gems folder located in that directory. For example, the SequenceServer that I have installed is located at:</p><pre>/home/terry/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/sequenceserver-1.0.4</pre><h4>Info 3: User that Passenger is running SequenceServer with</h4><p>The annoying thing is that processes spawned by Passenger, by Apache, is not by the user that is running Apache. If you want to <a href="http://serverfault.com/questions/125865/finding-out-what-user-apache-is-running-as">check who is running Apache</a>, just use the command:</p><pre>$ ps aux | egrep &#39;(apache|httpd)&#39;</pre><pre>apache    3932  0.0  0.0 498956 10292 ?        S    Nov15   0:00 /usr/sbin/httpd -DFOREGROUND<br>apache    3933  0.0  0.0 498956 10292 ?        S    Nov15   0:00 /usr/sbin/httpd -DFOREGROUND<br>apache    3934  0.0  0.0 498956 10292 ?        S    Nov15   0:00 /usr/sbin/httpd -DFOREGROUND<br>apache    3935  0.0  0.0 498956 10292 ?        S    Nov15   0:00 /usr/sbin/httpd -DFOREGROUND<br>apache    3936  0.0  0.0 498956 10292 ?        S    Nov15   0:00 /usr/sbin/httpd -DFOREGROUND<br>apache    3979  0.0  0.0 498956 10288 ?        S    00:15   0:00 /usr/sbin/httpd -DFOREGROUND</pre><p>To remedy this, you will need to find out who owns the file <em>config.ru</em> in SequenceServer’s installation directory (which you have obtained in Info 2). You can check it by running:</p><pre>$ cd /home/terry/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/sequenceserver-1.0.4<br>$ ls -l config.ru</pre><p>And it seems that it is me (user <em>terry</em>) not the Apache user (user <em>apache</em>):</p><pre>-rw-r — r — 1 terry terry 116 Oct 1 16:33 config.ru</pre><h4>Modifying Apache httpd.conf</h4><p>With all three information on your hand, you are ready to modify your Apache configuration. The location of the configuration file varies from server to server, but mine is located at <em>/etc/httpd/conf/httpd.conf</em>. If you want to play it safe, make a copy of your <em>httpd.conf</em> file and store it somewhere.</p><p>Nobody likes playing around with httpd.conf or .htaccess files, because they can be very difficult to understand at times. Therefore, I have made a template of what you should append to your httpd.conf file to get SequenceServer to work. Note that:</p><ul><li><strong>/path/to/app</strong> should refer to the directory of the SequenceServer gem itself (see Info 2)</li><li><strong>/path/to/app/public</strong> should refer to the directory of the public folder in the SequenceServer gem (see Info 2, just append “<em>/public</em>” to end of path)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/778d042f53d37d12f575be270697db41/href">https://medium.com/media/778d042f53d37d12f575be270697db41/href</a></iframe><p>And here is a <em>working example</em> of the portion of my <em>httpd.conf</em> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6eae15dcc7460ea35af06404184298d/href">https://medium.com/media/f6eae15dcc7460ea35af06404184298d/href</a></iframe><h3>Update SequenceServer’s configuration file</h3><p>SequenceServer needs some additional information before it can work. The most important two bits are:</p><ul><li>The location of NCBI BLAST+ executables</li><li>The location of your BLAST directories</li></ul><p>SequenceServer’s configuration file is located in the gem’s directory, named <em>config.ru</em>. In there you can specify it to load a configuration file located anywhere else on your server—as long as the user running Passenger and SequenceServer has access to it.</p><p>An example of my <em>config.ru</em> file:</p><pre>require &#39;sequenceserver&#39;</pre><pre>SequenceServer.init(:config_file =&gt; &quot;/home/terry/.sequenceserver.conf&quot;)</pre><pre>run SequenceServer</pre><p>I simply instructed SequenceServer to load additional configurations from the file “<em>/home/terry/.sequenceserver.conf</em>” upon initialisation. In that file I specify the number of threads SequenceServer should run on, and the location of both the NCBI BLAST+ binaries and BLAST directories.</p><pre>---<br>:num_threads: 4<br>:bin: &quot;/home/terry/bin/.sequenceserver/ncbi-blast-2.2.31+/bin&quot;<br>:database_dir: &quot;/home/terry/var/blast-db&quot;</pre><h3>Multiple SequenceServer instances?</h3><p>There might be edge use cases where you will want to have multiple SequenceServer instances. For example, you want to separate what databases the public has access to, and what databases your internal users (within your lab, or your research group for example) have access to. This can be done by:</p><ol><li>Having addition rules in your <em>httpd.conf </em>file — you can use IP-based access restriction to limit access to your private SequenceServer instance.</li><li>Having a copy of the SequenceServer’s <em>config.ru</em></li><li>Symlinking /public to original gem’s /public folder</li></ol><h4>Additional Apache httpd configuration</h4><p>You simply will have to duplicate the rules that make SequenceServer work, namely from the “alias” line to the end of the “&lt;/Directory&gt;” block. For example, if I want to serve SequenceServer from both the /blast and /blast-private directories, with IP-based access restriction on the latter, I can do this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6e0887e936154f836295eec6f738a43/href">https://medium.com/media/c6e0887e936154f836295eec6f738a43/href</a></iframe><p>Even though Apache 2.4 accepts legacy Apache allow/deny directives, you should migrate over to the require directive for future compatibility. There is a <a href="https://httpd.apache.org/docs/2.4/upgrading.html">handy guide on updating directives</a> when upgrading to Apache 2.4.</p><h4>A different <em>configuration file </em>for each SequenceServer instances</h4><p>Each SequenceServer instance is opened by a new <em>config.ru file</em>. For convenience’s sake, I have create another SequenceServer folder in the Ruby gems folder, called “<em>sequence-server-1.0.4-private</em>”, for example. In there, I have a new config.ru file—and that is all!</p><p>You may load different configurations for your <em>config.ru </em>files. For the public one:</p><pre># sequenceserver-1.0.4/config.ru</pre><pre>require &#39;sequenceserver&#39;<br>SequenceServer.init(:config_file =&gt; &quot;/home/terry/.sequenceserver.conf&quot;)<br>run SequenceServer</pre><p>…and for the private SequenceServer:</p><pre># sequenceserver-1.0.4-private/config.ru</pre><pre>require &#39;sequenceserver&#39;<br>SequenceServer.init(:config_file =&gt; &quot;/home/terry/.sequenceserver-private.conf&quot;)<br>run SequenceServer</pre><p>With different <em>.conf</em> file loaded, you can use different BLAST databases, binaries and etc.</p><h4>Symlinking /public folder to original gem’s /public folder</h4><p>Remember that since file paths are relative in the SequenceServer installation, you will be serving files in the /public folder from different directories where each <em>config.ru </em>is located in. To overcome this issue, you will have create symlinks to the original /public folder in the SequenceServer gem:</p><pre># Go to folder of alternative instance of SequenceServer<br>$ cd /home/terry/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/sequenceserver-1.0.4-private</pre><pre># Create symlink to the public folder in actual gem<br>$ ln -s public ../sequenceserver-1.0.4/public</pre><p>You may also use <em>.htaccess</em> to redirect requests for files in non-existent /public folder in other SequenceServer instances to the actual files, but I find that quite cumbersome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edf9d992998c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-design/setting-up-sequenceserver-edf9d992998c">Setting up SequenceServer</a> was originally published in <a href="https://medium.com/coding-design">Coding &amp; Design</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Preparing for prepared statements]]></title>
            <link>https://medium.com/coding-design/preparing-for-prepared-statements-619292bc4d8a?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/619292bc4d8a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Wed, 19 Aug 2015 10:59:03 GMT</pubDate>
            <atom:updated>2015-08-19T10:59:03.145Z</atom:updated>
            <content:encoded><![CDATA[<h2>Preparing for<br>prepared statements</h2><p>A guide towards migrating away from <em>mysql_</em> functions to PDO</p><p>· · ·</p><p>I have decided to pen this guide after encountering a multitude of questions concerning migration away from <em>mysql_</em> functions on StackOverflow, as well as my personal experience from updating the codebase of dated PHP files in my line of work.</p><p>This guide is written under the preface that you have some basic understanding of PHP and object-oriented programming (OOP), but believe me, when I started writing PDO I have no idea how OOP worked. It’s never a bad place or time to start now.</p><p>One of the major complaints I see while prowling through StackOverflow is that people are still using <em>mysql_ </em>functions. These functions will be rendered obsolete because of the <a href="https://wiki.php.net/rfc/mysql_deprecation">deprecation of the mysql function in PHP 5.5</a> and onwards, and marked for <em>removal </em>in PHP 7. In fact, if you attempt to execute a <em>mysql_</em> function with recent versions of PHP, you will be thrown an exception:</p><blockquote>Deprecated: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead</blockquote><p><em>Oh no!</em> You say. <em>Why is this happening?</em></p><blockquote>The mysql extension is not insecure…<br>but simply harder to use securely.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*P4nj9fJjSeJ9-c0rwSZqlg.png" /><figcaption>“<a href="https://xkcd.com/327/">Exploits of a Mom</a>”, an xkcd comic comically addressing the not-so-comical issue of sanitizing user inputs (or rather, there lack thereof).</figcaption></figure><p>There are many good reasons to why <em>mysql_ </em>functions are not worthy of future support. A commonly cited reason in support of migrating away from said functions is because of the inherent security flaws in the mysql extension. While not entirely true, using <em>mysql_ </em>functions requires the programmer, i.e. you, to take proactive, conscious steps to prevent attacks and hijacking attempts. In other words, mysql is not insecure, but simply harder to use securely compared to other available extensions, such as mysqli and PDO. The dated extension also <a href="http://stackoverflow.com/a/12860046/395910">does not support a variety of other recent features</a>, which makes it difficult to work with <em>mysql_</em> functions in the near future.</p><p>The reason why the mysql functions have stayed around for so long is for one simple reason — legacy support. Disabling the extension outright will disrupt plenty of dated web services and scripts that still use the mysql extensions, but this is no decent excuse to why you should start looking at alternatives <strong>this moment forward</strong>.</p><p>While suppressing <em>E_DEPRECATED</em> errors or, god-forbid, falling back to an older version of PHP, are quick and dirty tricks to tiptoe around this issue, your code will not be future proof. Since it’s introduction in the 1990s, no new functions have been added to the mysql extension since 2006, and it is not even being actively maintained anymore.</p><p>The two best alternatives out there are the mysqli and PDO extension. There is <a href="http://code.tutsplus.com/tutorials/pdo-vs-mysqli-which-should-you-use--net-24059">great amount of debate</a> which one is better, but I personally prefer the latter for very simple reasons — its support for other drivers than mysql itself, and that it accepts named parameters. Both are fast, object-oriented and supports stored procedures.</p><h3>Establishing a database connection</h3><p>We need several snippets of information in order to establish a database connection. When you define a new PDO object, it will ask you a few questions:</p><ul><li>What host name is the database located on?</li><li>Which database are we working with?</li><li>What are the logic credentials that allows me access to reading and/or writing to the said database?</li></ul><p>It is always safer to store these information in a configuration file, which you can use .htaccess (if you are on an Apache server) to block any requests for the file. This will keep your database connection information safe from (external) prying eyes. In this file, you can define named constants that will store these snippets of information, at the disposal of any database connection requests:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97c26fdcf1065c8858d033a283b5fc10/href">https://medium.com/media/97c26fdcf1065c8858d033a283b5fc10/href</a></iframe><p>With this information you can craft a database connection out of thin air, pronto! Below I am presenting a barebones database connection, followed by one that also defines a character set (here I am using utf8, but your flavours may vary) and port (defaults to 3306, but good to know):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e99083746dbd5f9b2967494bac532384/href">https://medium.com/media/e99083746dbd5f9b2967494bac532384/href</a></iframe><p>Easy peasy. Variables and objects declared are considered to exist throughout this article.</p><p>p/s: A little note for advanced users — if you’re using the try/catch method of retrieving errors, remember to enabled that via <em>setAttribute</em>():</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7063582bdee4b6857e54df6feb99a9d2/href">https://medium.com/media/7063582bdee4b6857e54df6feb99a9d2/href</a></iframe><p>By catching the exception and dealing with it manually prevents PDO from displaying a backtrace, which contains sensitive information about your database. The trace is very useful for troubleshooting in a development setting, but definitely a no-no for production.</p><h3>Querying</h3><p>Now the fun part—let’s construct some queries! But where do we start?</p><h4>Fetching data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*dtPdylpqV1-MJJ3pKWx0lA.gif" /><figcaption>Sorry, Miranda Priestly. I really just have to put this gif right here.</figcaption></figure><p>Let’s begin with the basics with an extremely reduced example — say you want to execute a MySQL query that will fetch user data from a database. How should you get around to do it?</p><p>For example, we want to know how many users from each country we have in our database. We are <strong>not supplying any user input</strong> at this point, and are only concerned about retrieving information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84c2e75909b3cee55ed4859eb5c26344/href">https://medium.com/media/84c2e75909b3cee55ed4859eb5c26344/href</a></iframe><h4>Accepting user inputs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*71rOisUJoJSc8B_oEZ7FZw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*vmC_aIWZ7Ev_9lEBCRgdcA.gif" /><figcaption>A typing cyborg. Ghost in the Shell by Production I.G.</figcaption></figure><p>Remember that mysql 101 rule — <strong>always sanitize your user input </strong>— nailed hard into your psyche by your programming teacher?<strong> </strong>Remember the countless times you have to use <em>mysql_real_escape_string()</em>? One of the reason why <em>mysql_ </em>functions are deprecated because the programmer will have to make a conscious effort to sanitize user input. For PDO, prepared statements come to the rescue. The magic behind PDO is that it sanitizes parameters for you during the process of parameterisation.</p><blockquote>PDO makes the need to escape or sanitize input redundant.</blockquote><p>This what what PDO actually does — unlike a <em>mysql_</em> function, it keeps the prepared statement and strings separate, and only combines them upon execution. It protects you from injection attacks, which happens when hackers know you are not sanitizing your data (properly).</p><p>In PDO, you are offered several options on how to combine your variables as strings into the prepared statement, before the latter is executed. This is done by:</p><ol><li>using named placeholders</li><li>using positional placeholders</li><li>binding parameters (by reference)</li><li>binding values</li></ol><p><strong>1 + 2: Named or Positional Placeholders</strong></p><p>Both named and positional placeholders work in a similar fashion —their corresponding values are passed as an array in the <strong><em>execute()</em></strong> statement. The only differences are that for the former, you use ‘<em>?</em>’ as a placeholder in your statement, while for the latter, you use ‘<em>:placeholderName</em>’ instead. Moreover, positional placeholders require you to order the array items in the order of which the placeholders appear in your statement, while named placeholders rely on object keys to identify the correct placeholders, therefore making order irrelevant.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/336df4db0de2b3d17ce760b092d645ae/href">https://medium.com/media/336df4db0de2b3d17ce760b092d645ae/href</a></iframe><p><strong>3 + 4: Binding Values or References</strong></p><p>Alternatively, you can choose to bind variables by reference or value before executing the prepared statement. The difference is that binding by reference (hence using <a href="http://php.net/manual/en/pdostatement.bindparam.php"><strong><em>bindParam()</em></strong></a>) will only evaluate the value of the reference upon execution, unlike binding by value (<a href="http://php.net/manual/en/pdostatement.bindvalue.php"><strong><em>bindValue()</em></strong></a>) which will bind an immutable value upon calling of the method which prevents further manipulation before execution. In majority of implementations, the difference is not of great significance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3cb093c22c8bb37275e3b0d292c1d81/href">https://medium.com/media/c3cb093c22c8bb37275e3b0d292c1d81/href</a></iframe><p>Along the same vein, you will have to be careful how you <a href="http://stackoverflow.com/questions/4174524/binding-params-for-pdo-statement-inside-a-loop">bind values or parameters to placeholders in a PHP for loop</a>. Since <em>bindParam()</em><strong><em> </em></strong>binds the reference and the reference only, you should modify the array elements directly by prepending the ‘&amp;’ sign, i.e.:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45491f11267fed15851bc4971eadcc3a/href">https://medium.com/media/45491f11267fed15851bc4971eadcc3a/href</a></iframe><p>However, this argument is moot considering that you can simply <strong>pass the entire array to the <em>execute()</em> command</strong> without the need of trigger the overhead of a for loop. This is the recommended way of dealing with multiple placeholders.</p><p>Further reading: <a href="http://stackoverflow.com/a/5077108/395910"><em>bindParam()</em> vs <em>bindValue()</em></a>.</p><h4>Placeholders don’t have a place<br>in the entire prepared statement</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*ou7Y7arVtilOEKaaYm6jDA.gif" /><figcaption>Just like how nice jeans are always priced beyond my reach.</figcaption></figure><p>Parameterised prepared statements are <strong>not an all-encompassing panacea</strong> when it comes to security concerns. Given that you can only bind parameters to placeholders within the <em>WHERE</em> clause, if you are accepting user inputs to (1) select tables or columns to query from, or (2) to dictate the grouping, order and limit of their results,<strong> performing sanity checks on user inputs</strong> is a reality that you cannot, and should not, run away from.</p><blockquote>Parameterisation is not a one-size-fits-all solution.</blockquote><p>A sensible solution would be to use a whitelist approach for parameters that have a limited range of keywords, like column and table names, for table and columns, and <em>GROUP</em> and <em>ORDER BY</em> clauses; and forced conversions to integers for the <em>LIMIT</em> clause.</p><p>One example: if you are allowing the end user to retrieve data from a list of tables, compare that user input against an internal list of tables — if there are any discrepancy, reject any attempts to connect to, or query from, the database:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd91af83a0e00cd88ba391a0eb0d2a02/href">https://medium.com/media/cd91af83a0e00cd88ba391a0eb0d2a02/href</a></iframe><h3>Advanced examples</h3><p>Here are some advanced examples that I feel should not be addressed in the main section in the guide simply because it requires basic understanding of constructing prepared statements and binding values or references to placeholders — which we have already conveniently covered in the previous section.</p><h4>Executing multiple statements</h4><p>If you want to execute multiple statements that differ only by values, such as inserting multiple rows of data into your database, you can use <em>beginTransaction()</em> and <em>commit()</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/687326c100c015ff46a9e310da986726/href">https://medium.com/media/687326c100c015ff46a9e310da986726/href</a></iframe><h4>Inquiring about IN queries</h4><p>Sorry for the pun. Jokes (or rather the lack thereof) aside, preparing <em>IN</em> queries is a bit of a challenge in PDO, but it isn’t exceptionally difficult. If you have an array of <em>n </em>size you want to pass into the IN query, you will have to <strong>duplicate the positional placeholder (‘?’) <em>n </em>number of times</strong> so that each positional placeholder will be assigned a value upon execution of the statement.</p><p>For example, if you have an array of values (10, 38, 56, 93) you want to query with, you will have to use the positional placeholders (?, ?, ?, ?) in your <em>WHERE</em> clause. The trick is to generate the correct number of placeholders so that each will be mapped back to your array of values.</p><p>With this in mind, you can use any of the following methods for an array of <em>n </em>size to generate the correct placeholders:</p><ol><li>Use <a href="http://php.net/manual/en/function.array-fill.php"><em>array_fill()</em></a> to fill an array with <em>n</em> placeholders, and then <a href="http://php.net/manual/en/function.implode.php"><em>implode()</em></a> it with a comma as the separator.</li><li>Use <a href="http://php.net/manual/en/function.str-repeat.php"><em>str_repeat()</em></a> to repeat the placeholder (‘?’) <em>n </em>times, and <a href="http://php.net/manual/en/function.str-split.php"><em>str_split()</em></a> it into a array, for which you then <a href="http://php.net/manual/en/function.implode.php"><em>implode()</em></a> using comma as the separator.</li><li>Use <a href="http://php.net/manual/en/function.str-repeat.php"><em>str_repeat()</em></a> to repeat the placeholder and its separator (‘<em>?,</em>’) <em>n </em>times, and remove the last comma with <a href="http://php.net/manual/en/function.substr.php"><em>substr()</em></a>.</li><li>Use <a href="http://php.net/manual/en/function.str-repeat.php"><em>str_repeat()</em></a> to repeat the placeholder and its separator (‘<em>?,</em>’) <em>n-1 </em>number of times, followed by appending by a closing placeholder (‘?’).</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7e3f945010a2b91459498eca27e44af/href">https://medium.com/media/a7e3f945010a2b91459498eca27e44af/href</a></iframe><p>Which method is the best? It is up to you. This is where personal style rules over sense, although I personally prefer the last method because it is the simplest (and likely to have the least overhead).</p><blockquote>Repeat n-1 times and append is the fastest.</blockquote><p>Which method is the fastest? To ask this question you are running the risk of micro-optimisation, and you would be better off spending time optimizing your query instead. However, for the sake of completeness, I have performed three independent tests with 100,000 repeated runs for each method, and verdict is clear: method 4 clenches the title of fast and furious:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yadkhzvvkDyj6LMEJtFZpQ.png" /><figcaption>Execution time, measured in microseconds, of 100,000 iterations of methods 1 through 4. Values represent arithmetic averages from three independent runs. Error bars represent standard deviation.</figcaption></figure><h4>Preparing LIKE queries</h4><p>Sometimes you would want to query your database using the LIKE operator, which allows you to use ‘%’ as a wildcard symbol. The best part about using prepared statements is that they will automatically parse the ‘%’ as a wildcard symbol when appended and/or prepended to your variable:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28fa45bb0635e679078b227cd68c0811/href">https://medium.com/media/28fa45bb0635e679078b227cd68c0811/href</a></iframe><h4>Counting rows</h4><p>At times it is desirable to either access the number of rows returned, or to determine if any rows have been returned from the query. This can be done by using <em>rowCount()</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44757a69afef4b4c4ea275502108f54e/href">https://medium.com/media/44757a69afef4b4c4ea275502108f54e/href</a></iframe><p>Note: While using FETCH_ALL is a possible alternative, it is memory inefficient, especially for very large datasets.</p><h3>Closing the connection</h3><p>By default, the PDO connection is only open when the PHP script is running and will be closed once the script end. Closing the conection is as simple as assigning <em>null </em>to the PDO object, i.e.:</p><pre>$db = null;</pre><p>Closing the connection is considered good practice as it frees up resources for other incoming database connections, although not absolutely necessary — PHP scripts typically have a finite execution time, and will be terminated anyway if it exceeds a pre-determined threshold set by the server. Terminating it will close the connection, but that also means that the database connection might be held open for an unnecessary amount of time.</p><p>For the interested:</p><ul><li><a href="http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059">Why you Should be using PHP’s PDO for Database Access</a></li><li><a href="http://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly--net-25338">PHP Database Access: Are You Doing It Correctly?</a></li></ul><p>If you have any more useful tips about migrating to PDO, or have spotted any mistakes in my Gists, do let me know! Leave a note, or tweet me at @teddyrised.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=619292bc4d8a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-design/preparing-for-prepared-statements-619292bc4d8a">Preparing for prepared statements</a> was originally published in <a href="https://medium.com/coding-design">Coding &amp; Design</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[We need to talk about him]]></title>
            <link>https://medium.com/one-too-many-cents/we-need-to-talk-about-him-1b25ba24e240?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b25ba24e240</guid>
            <category><![CDATA[lee-kuan-yew]]></category>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[singapore]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Wed, 25 Mar 2015 10:48:09 GMT</pubDate>
            <atom:updated>2015-03-26T21:11:49.013Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QX0L3fyqKYwaMgfMzjtQZQ.jpeg" /></figure><h2>We need to talk<br>about him</h2><p>On the 23rd of March of 2015, Singapore lost not only a man, but a leader. A fierce, unforgiving politician who brought the small little island of Singapore to prominence, wealth and prowess, Lee Kuan Yew transformed Singapore from a British colonial port into the economic powerhouse it is today.</p><p>It pains me to write this article, because the death of Lee deeply polarised my circle of friends, and worse — it’s not along the line that separates friends and acquaintances. But I feel like I owe people an explanation of why I feel like I have to speak up.</p><p>One camp, where many of my close friends are in, feels that it is disrespectful to be critical of Lee in the days immediately after passing — that we should revere him as the leader of Singapore, the person who brought Singapore up from the slums of a fishing village (which is not exactly true, for Singapore being quite the bustling port, although mismanaged in many ways, during British colonial times). One acquaintance accused me for being a foolish idealist who engages in a “circle jerk of free speech”.</p><p>The other felt that meaningful conversation should take place, and that all views should be heard, especially the objectives ones. The moment of mourning presents itself the perfect forum for meaningful discussion, as the whole nation comes to the realization of a profound loss of a founding father and starts to shape a distinctive memory of this undeniably impactful and unforgettable character.</p><h3>Founding father</h3><p>Founder of the People’s Action Party (PAP), Lee spearheaded many political movements and changes in Singapore. He constructed the legal system for the sustenance and growth of business entrepreneurship. He implemented one of the world’s best (<a href="http://theconversation.com/why-is-singapores-school-system-so-successful-and-is-it-a-model-for-the-west-22917">here</a> and <a href="http://www.uesf.org/singapore/">there</a> are just a few) — or some say <a href="http://www.oecd.org/pisa/keyfindings/PISA-2012-PS-results-eng-SINGAPORE.pdf"><em>the </em>best</a>, based on what metrics you are measuring with <em>— </em>education system, on the basis of meritocracy and equality, unlike the race-based policies implemented by an immediate neighbour to the north. He nurtured close ties with China, recognizing that Singapore will thrive and benefit greatly from this relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*J6Kf-486kgzzKNgStl3GTg.png" /><figcaption>Singapore ranks 5th in 2012 and 7th in 2014, as one of the least corrupted countries in the world. Data gleaned from <a href="https://www.transparency.org/cpi2014/results">https://www.transparency.org/cpi2014/results</a>.</figcaption></figure><p>Through the enactment of strict laws, corporal punishment and what many would see as a hard-handed leadership, Lee ensured that Singapore thrived under a stable civil and political landscape. He <a href="http://www.channelnewsasia.com/news/singapore/lee-kuan-yew-tackled/1734794.html">effectively, tirelessly and rentlessly bulldozed corruption</a> in all levels of hierarchy within the government with the Corrupt Practices Investigation Bureau, making Singapore one of the cleanest, corruption-free country in the modern world. But what is most remarkable, is that Singapore is by far <strong>the only Asian</strong>, and by extension, <strong>Southeast Asian country</strong>, that claims a position in the top-1o position on the corruption index that is Western-dominated.</p><p>However, at the price of stability, the political landscape of Singapore has never quite changed since it gained independence. The ruling party PAP has been in power for five decades, with a smattering of opposition parties holding miniscule amount of seats in the Parliament. Singapore has often been cited as a <a href="http://www.quora.com/What-does-Fareed-Zakaria-in-The-Future-of-Freedom-mean-by-%E2%80%98illiberal-democracies%E2%80%99">classical textbook example of illiberal democracy</a>. While I am not in a position to comment on how this pseudo-democracy Singapore has been operating on since time immemorial has affected the island country, and how a true democracy would have changed the course of the country, we all have to admit that <strong>Singapore did flourish under some degree of political oppression</strong> — our education has never been better, the nation’s GDP has never been higher.</p><p>Lee believed in autonomous right to subscribe to any religion to all. He allowed religions to flourish in Singapore. Based on <a href="http://www.telegraph.co.uk/news/worldnews/asia/singapore/11489177/Lee-Kuan-Yew-his-most-memorable-quotes.html">Lee’s description and his take on religion</a>, he is more of an agnostic than an atheist:</p><blockquote>“I wouldn’t call myself an atheist.<br>I neither deny nor accept that there is a God.<br>So I do not laugh at people who believe in God.<br>But I do not necessarily believe in God — nor deny that there could be one.”</blockquote><h3>On LGBTQ issues</h3><p>While washing the government’s hands clean of ensuring equal rights for the LGBTQ community, Lee was <a href="http://www.yawningbread.org/arch_1998/yax-127.htm">quoted, in 1998</a>, much to the relief of many in the community, that the government will “leave people to live their own lives so long as they don&#39;t impinge on other people”.</p><blockquote>“I mean, we don&#39;t harass anybody.”</blockquote><p>Lee addressed the issue again in 2007, believing that homosexuality is genetically imprinted and therefore should be accepted as it is presented. However, the <a href="http://en.wikipedia.org/w/index.php?title=Section_377A_of_the_Penal_Code_(Singapore)">penal code 377A</a>, an archaic law — inherited from Singapore’s British colonial rulers — criminalizes sex among consensual males and comically leaves out female-on-female sex, still stands (emphasis my own):</p><blockquote>Any <strong>male person</strong> who, <strong>in public or private</strong>, commits, or abets the commission of, or procures or attempts to procure the commission by any male person of, any <strong>act of gross indecency with another male person</strong>, shall be punished with imprisonment for a term which may extend to 2 years.</blockquote><blockquote>— Section 377A of the Penal Code</blockquote><p>As a homosexual man comfortable in his own shoes, I was admittedly surprised by Lee’s admission — I have lived in Singapore for ten years, a society that I would describe as orthodox and conservative, and highly influenced by religion. I wouldn’t expect him to agree on every single detail on the laundry list of the modern gay rights movement, from gay marriages to adoption by same-sex parents, but his openness and acceptance, do pave a small but not insignificant road towards gender equality in Singapore.</p><h3>My two cents</h3><p>Rephrased and further refined from an earlier Facebook status update I have shared, I wish to humbly share my opinion about Lee’s passing.</p><p>When a fellow member of academia, despite in a different field, <a href="http://wishcrys.com/2015/03/23/mr-lee-kuan-yew-and-the-spectacle-of-death-the-first-twelve-hours-on-social-media/">was attacked over her apparent clinical analysis</a> of the social media landscape hours after Lee’s passing, I felt that I have to speak up and lend voice to the middle-ground minority. Some commentators, whipped up by the emotional frenzy perpetuated on the state-controlled media, accused her of being disrespectful to the grieving Lee family.</p><p>But how should we look back from the future — near or far — and comment, view, appreciate, commemorate, remember this national event of Lee’s passing, and the accompanying public mourning, realization and acceptance — objectively — should one never document and chronicle the event from a third party’s objective?</p><p>As much as I have the deepest respect for Lee for how he transformed the island of Singapore and put our little red dot formidably on the world map, as an academic, I also respect the due process of documentation and observation by a neutral party. The presentation of facts, of what Lee has contributed to historical and contemporary Singapore, of his dreams and nightmares, of his legacy and faults, of his character and personality, are all important towards shaping a public memory of him, a repository of his mark on Singapore and the world.</p><p>When Margaret Thatcher passed, some mourned, some celebrated. For she was a <a href="http://www.independent.co.uk/news/obituaries/margaret-thatcher-obituary-the-most-divisive-political-leader-of-modern-times-8564559.html">divisive character in British politics</a>. She was praised for her iron-fisted rule; yet she was reviled by many for her indifference towards the plights of miners and the unemployed. There were few who shared a middle ground — who remembered her for her iron-fisted rule, but who also remembered her for her struggle to join politics as a lower-middle class underdog, a member of the less represented sex, and more.</p><p>Lee was an equally divisive character. When Singapore was forced to leave Malaya, he shed tears — the second and last time ever known, the first being after his mother’s passing. He was worried of Singapore, of how, deprived of almost any form of natural resources, could thrive. In the interest of the newborn nation’s sovereignty, he immediately sought recognition from UN as an independent state. He institutionalized compulsory conscription of all able-bodied Singaporean male to join the military. He reinforced the armed forces in Singapore, with the help of countries with advanced military knowledge, so that she can defend herself against neighbours in a hostile geopolitical landscape. He <a href="https://www.transparency.org/cpi2014/results">wiped out corruption</a>, made kids in Singapore one of the brightest in the modern world. And more importantly, under his rule, Singapore flourished,<strong> for nine years straight</strong>, as the <a href="http://www.bbc.com/news/business-29813383">most desirable location to conduct business</a> in the world.</p><blockquote>Without Lee, Singapore will not be where it is today.</blockquote><p>Yet he silenced the opposition, jailed those who crossed his path and even sued those who stood against him into bankruptcy. The legal system was <a href="http://www.nytimes.com/2010/04/04/opinion/04pubed.html">alleged to be rigged in favour of the government</a>, and people who <a href="http://www.dailymail.co.uk/wires/afp/article-2980675/Singapore-blogger-fined-contempt-court.html">criticized it were taken to court</a>. The media and telecommunication companies operate under government control, many say. You even have to apply for a permit in order to speak freely, despite <a href="http://en.wikipedia.org/wiki/Article_14_of_the_Constitution_of_Singapore">Article 14(1)(a) and (b) guaranteeing the freedom of speech</a> — the oxymorous of it is profoundly baffling.</p><blockquote>There will be no Singapore without Lee.</blockquote><p>But from now on, Singapore will have to lead a life without his physical presence. She will be hobbling in unchartered territory, but despite this, his legacy lives on — every transformational touches he has on the sunny little tropical island will be evident to the generations that are yet to be birthed. <strong>His stories should be told </strong>— every triumph, every fall; every victory, every defeat. Lee, like many of us, carry the burden of human conditions, for we are never born without our faults.</p><p>It is of great comfort to know that Singapore’s society has matured over the years. <a href="http://www.channelnewsasia.com/news/singapore/good-samaritans/1740480.html">Acts of altrusim</a> <a href="http://www.todayonline.com/rememberinglky/growing-lines-prompt-acts-kindness">were observed</a> as the line for people paying tribute to the first prime minister grew in length, snaking through underground pedestrian crossings, corridors of heritage buildings, tree-lined boulevards. This is the Singapore that Lee envisioned, I felt. A city that does not only have hardware to show, but <a href="http://news.asiaone.com/News/Latest+News/Singapore/Story/A1Story20120811-364850.html"><em>heart-ware</em></a><em> </em>to bolster.</p><p>I am a product of Lee’s legacy. I was born in Malaysia, in a country that shows scant respect towards equality and meritocracy. At the age of thirteen I moved to Singapore in search for a better education system, and I have benefited greatly from it. But does that mean I cannot think for myself, or that I relinquish the exuberance of choosing not to agree all that is said — wholesale, blithely, blindly? Would I not be doing this world-renowned education system a disservice and labelling it a farce, if I have not learned how to speak for myself, objectively and neutrally, especially during events of great public interest?</p><p>I encourage people to speak. We need to talk about Lee. The good, the bad. The stories, the shortfalls. He is just human. Just like how we remember the fallen and the dead for the deeds they performed and the mistakes they made, why should we deprive Lee of this very human experience of grieving, remembrance and mourning?</p><p>We need to speak about Lee, and distill what he has contributed to Singapore to further the country forward, to propel the island country to the cutting edge of success and prowess. We listen and observe his stories — what can we learn from him that made Singapore so successful? What mistakes can we avoid committing again, so that we can make things even better? It is with humble appreciation that we learn from his experience, extract the essence of what is good, learn the shortfalls that serve as a reminder, and let these virtues guide us in the age of post-Lee Singapore.</p><p>I know that speaking up for myself will cost me. I will be crucified, berated, marginalized, picked on, for whatever neutral ground I choose to stand in. I will lose some friends, annoy a magnitude of acquaintances, tick off many patriots — for them choosing, at their own accord and with their rosy, tinted glasses, the “least respectful way” of honouring Lee’s legacy. But I am not.</p><blockquote>I just feel that we need to listen and observe.</blockquote><p>What is hearing for when we do not listen? Listening is very different from abetting, let alone disrespectful.</p><p>What is vision when we do not observe? Observing is decidedly distinct from agreeing, let alone contemptuous.</p><p>I am not trying to be flippant, ungrateful, discourteous or blasphemous — unless you unfortunately choose to see so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*im7hb5HQ_UAaEtFCSI1u0Q.png" /></figure><p>RIP, Lee Kuan Yew.</p><h3>Further reading:</h3><ol><li><a href="https://medium.com/@wishcrys/mr-lee-kuan-yew-and-the-spectacle-of-death-the-first-twelve-hours-on-social-media-739fae14219b"><em>Mr Lee Kuan Yew and the spectacle of death: The first twelve hours on social media</em></a> — by Crystal Abidin, an academic researcher who <a href="https://medium.com/@wishcrys/behind-the-scenes-on-surviving-four-days-of-viral-hate-dd25952e45d2">accused of dissing and being disrespectful</a> in the period of national mourning</li><li><a href="http://www.jeraldinephneah.me/2015/03/lee-kuan-yew-death.html"><em>A Middle Ground Perspective on Lee Kuan Yew’s death</em></a> — by Jeraldine Phneah, who received a lot of flak for her middle-ground and fact-based opinion</li></ol><p>Terry is a confused molecular biologist who decided to have a go at writing some months ago. He used to describe himself as politically apathetic, but now takes on a liberal, center-left stance. Currently based in the small Danish city of Aarhus, he lived in Singapore between the years of 2002–2012.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b25ba24e240" width="1" height="1" alt=""><hr><p><a href="https://medium.com/one-too-many-cents/we-need-to-talk-about-him-1b25ba24e240">We need to talk about him</a> was originally published in <a href="https://medium.com/one-too-many-cents">One Too Many Cents</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lessons from MMXIV]]></title>
            <link>https://medium.com/life-journey/lessons-from-mmxiv-c0a550f245cd?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a550f245cd</guid>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Sat, 03 Jan 2015 14:32:08 GMT</pubDate>
            <atom:updated>2015-01-04T12:28:56.578Z</atom:updated>
            <content:encoded><![CDATA[<p>A review of a 365-day journey</p><p>It’s the time of the year again. Facebook users were presented with an option to review their year — I chose to do otherwise. There is definitely more I can do than merely plastering a bunch of photos into a collage, when the time of the year offers the opportunity to reflect with greater depth.</p><p>I am no life coach, nor a meditating monk in recluse. But that does not mean I would allow myself to kick back on my comfortable chair, giggle through the deluge of new year resolutions on every single social media stream I can think of, come up a few of my own and call it a year.</p><p>Resolutions are how we welcome the new. A kaleidoscopic, often optimistic view of what we want to see ourselves in at the end of the next coming year. What is sorely lacking though, is hindsight. Before the formidable clock strikes twelve on the night of December 31st, I want to go back in time, examining every part of my 365-day journey through the looking glass.</p><p>What have I learned? Many—perhaps <em>too many</em>, and where should I start? This year has been one earmarked by turbulent personal emotions, which on the bright side, spurred my personal growth; while less so about my skills.</p><h3>1. Wanderlust</h3><p><em>From solo backpacking in Greece to hiking in Møns Klint,<br>I explored the world around me a little more.</em></p><p>This year had been a rather fruitful year for me as a wanderlust — I have travelled both with friends and alone, abroad and locally. There is so many things to see in Europe, but even more so in the tiny country of Denmark, despite its relative geographical blandness (“It’s all plains!” I hear people wince).</p><p>Jörg, this crazy Swiss-German guy who shares the apartment with me, loves the outdoors — way more than I do, I&#39;d say. He invited me on trips to Skagen, the northernmost point of Denmark; and Samsø, the charming little island off the eastern coast of Jutland.</p><h4>Samsø</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzC-03lQvGLDn2qUU_it6Q.jpeg" /><figcaption>Our ferry piercing through the morning fog at a glacial speed.</figcaption></figure><p>On a cold, foggy morning set somewhat in the midst of the winter-spring transition, we travelled to the island of Samsø by getting Jörg’s little red car on a ferry that shuttles between the harbour of Odder and the island of Samsø.</p><p>Set in the sea of Kattegat and a mere 15 kilometers off the coast of Jutland, Samsø is an island known for its <a href="http://www.huffingtonpost.com/stefanie-penn-spear/samso-worlds-first-100-re_b_5303237.html">enthusiasm for clean, renewable wind energy</a> and unbelievably popular (and exorbitantly priced, at £100) “first” potatoes.</p><p>April is definitely <em>not </em>the month for tourists. We encountered almost zero road traffic, and likely to be the only group on the ferry that didn&#39;t speak Danish natively. We took that in great stride though — you don&#39;t need to wait till it’s summer to visit Denmark.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sGClkIf-w73WWvnM_DV3Vw.jpeg" /><figcaption>We navigated around Samsø based on a trusty map tucked in the side door pocket and Jörg’s previous experience of working on the island.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kR9WQi5mwYR_1RrM4T3plQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tlv5oMfad3RXmWfR76WBgg.jpeg" /><figcaption>The desolate landscape of Issehoved.</figcaption></figure><p>Covered by a gentle turf and dotted with a variety of shrubs and trees of stunted growth, the windswept, tundra-like landscape of Issehoved was an equal mix of tantalising and breathtaking. We walked along the beach littered with pebbles well-eroded by the untamed waves, hiked up little hills which offered 360˚ panoramic view of Issehoved.</p><p>Samsø is extremely popular among Europeans for summertime field work. Students and young adults from neighbouring countries flock to the island to pick the plentiful harvests in the apple, pear and strawberry fields, just to name a few. Jörg had worked with one of the farmers before, and he got into touch with the latter who gladly showed us not one, but <em>three</em>, hulking windmills he bought for a few million Danish kroners ten years ago.</p><p>He was one of the pioneers of wind energy adoption, where farmers purchase windmills at a subsidized price, getting their money back by feeding surplus energy generated back into the local electricity grid. Thanks to strong government support and foresight of those living and working on the island, Samsø is a leading textbook case of renewable energy —the island is <a href="http://cleantechnica.com/2013/10/29/introducing-samso-100-wind-powered-island/">entirely powered by wind alone</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvLFozn8zuC4OrzZ73h3FA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZX2Mvvk388WWqf39PNRvbQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EUHYXC_a6Y4kgz5v72LsFg.jpeg" /><figcaption>With Jörg’s contact, we managed to visit a private windmill farm and were even offered the chance to climb up an operating windmill. It was scary!</figcaption></figure><h4>Nordjylland &amp; Skagen</h4><p>Later in the summer, Jörg dragged me onto yet another road trip — this time round it’s destination nordjylland (North Jutland). North Jutland, especially the western coast facing the formidable North Sea, is famous for their majestic sand dunes, including Northern Europe’s largest moving sand dune, <a href="http://www.skagen-tourist.dk/danmark/raabjerg-mile-gdk640523">Råbjerg Mile</a>. It also holds the northernmost point of Denmark, in a small but famous city called Skagen. Yes, it is also the birthplace of the <a href="http://www.skagen.com/gb/en/country-select.html">watch brand Skagen</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Gip9G3ZhqPuWusbYHmFLA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6IQfOhq_55WsSsZq7tA3A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wMbXKv1TMzMHU-mU4gI9mQ.jpeg" /><figcaption>Top: Råbjerg Mile, the largest moving sand dune in Northern Europe. Bottom: At Skagen, dipping our feet; and the North Atlantic Wall.</figcaption></figure><p>We also dropped by the famous Rubjerg Knude fyr (<em>Rubjerg Knude lighthouse</em>) on our way back. Constructed in 1899 and first lit in the December of 1900, the lighthouse now faces a slow but inevitable fate of plunging into the sea. The strong winds and moving sand not only crushed the small buildings around it, but also eroded the shoreline up to 1.5m annually. Originally 1.2km away from the shoreline, the lighthouse now stands close to a steep precipice, awaiting it’s final resting destination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWL7uYfyfW-VUDVnC7BI_A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoqoCL860xuY1XyFgGJsIA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3XdEG2JEHEVFAGvjrDnq6A.jpeg" /><figcaption>Rubjerg Knude lighthouse, from afar and upclose.</figcaption></figure><h4>Sydsjælland &amp; Møns</h4><p>In the summer, Peter invited me for a visit to Copenhagen and we did a rather impromptu road trip to (sydsjælland) southern Sealand and Møns. Southern Sealand is an extremely popular summer vacation destination among locals and tourists from neighbouring countries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SK4fdjRIlD8ACmDe1-lKJQ.jpeg" /><figcaption>The harbour in the small town of Præstø.</figcaption></figure><p>On our way to the island of Møns we popped by the small little town of Præstø, where Peter bought a load of organic food stuff from a store he had always wanted to visit.</p><p>The chalk cliffs stand 120m at their tallest from the rocky beaches below, and just like the coastline of Northern Jylland, they face constant erosion from the unforgiving Baltic Sea. Landslides and cliff face collapses happen every now and then — a recent landslide (see <a href="http://nyhederne.tv2.dk/article.php/id-6278354:m%C3%B8ns-klint-er-lukket-for-f%C3%A6rdsel.html">news report in Danish</a>) in 2007 took out a good chunk out of the unique geological formation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0bRdrfecTqWmwBLBC_Ibcg.jpeg" /></figure><h4>Greece</h4><p>This summer, I travelled as a solo backpacker to the country of white-washed houses, cerulean blue rooftops and eternal sunshine — Greece, that is. People think I am crazy — be it my parents, or the Greeks I got acquainted with during my backpacking trip in Greece. Travelling alone in a country that I have never been to before was a scary idea, but the experienced turned out to be an exciting, humbling and eye-opening one.</p><p>I went island hopping — starting from the historical city of Rhodes, and took a (gruelling 10-hour) ferry to Santorini, moved on to Athens a few days later, visited Skopelos and doubled back to Rhodes to catch my return flight to Denmark.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cDsOU3eIaVK9an0ThcMwg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kt-H-vMR1GgtuhiZslWpjA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0yRJuZUovKOH6LrcAjO4Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D7-529n0wdzCGz4y5WGQag.jpeg" /><figcaption>Clockwise from top left: Rhodes, Santorini, Athens and Skopelos.</figcaption></figure><p>I adore the unique medieval architectural style of the buildings in Rhodes, unseen in other Greek islands; I recall the breathtaking view of the Santorini caldera, overlooking the active but dormant volcano <em>Nea Kameni</em>; I miss the enigmatic, mysterious and dynamic vibe of Athens; I vividly remember the calmness and tranquility that permeated through the narrow, steep and slippery alleys of Skopelos.</p><p>But more importantly, I met people. I was shy, but I made myself to seize the opportunity to talk to travellers I would not have otherwise interacted with if I was not travelling alone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Onu-vgJrrLYZFePYBgmDag.jpeg" /><figcaption>Joseph, Crystal and Alena.</figcaption></figure><p>In Santorini I shared the same dorm room with Alena, a bubbly American girl backpacking across Europe and Crystal, a quick-thinking and fiercely intelligent surgical nurse working for the USMC, stationed in the city of Naples, Italy. Crystal introduced me to her colleague Joseph, and despite our inherent differences, all four of us had an obscene amount of fun together — be it tanning on the black sandy beach of Perissa, or joining the boat tour of the Santorini caldera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hlGB53uQq2WN0O98b7jLzA.jpeg" /></figure><p>In Athens I met George, a shy but knowledgeable programmer who has a great eye for detail and design. He brought me to places in Athens that I would have not discovered myself or found on trip advisor recommendations. We toured the Acropolis Museum, with him dishing out all the history of Athens in splendid grandeur.</p><p>My trip to Skopelos stood out from my backpacking trip as the one that felt the furthest removed from the experience— the lack of hostels on the island means I get the rare opportunity of splurging in a tiny little hotel room, which unfortunately deprived me of any meaningful social interaction with other travellers. I signed up for a boat trip to the Alonissos Marine Park, and only to find myself surrounded by couples. I was the only single person on the boat! When I was dreading that I’ll be all alone and awkward in the whole trip, a Greek couple next to me hit me up for a conversation. That’s why I met Efi and John, a fun-loving and energetic power couple that made my solo trip to Skopelos so much better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UDJPVgKBkKz4TeLS2bHUOw.jpeg" /><figcaption>Efi and John.</figcaption></figure><p>Both Efi and John are living in a city close to Thessaloniki. John owns and runs a grocery store and is an avid photographer himself, while Efi is furthering her education in a university.</p><p>2014 has been extremely rewarding not only in the sense of satisfying my inner wanderlust, but also getting to know different people of decidedly different backgrounds in my trips. Travelling solo has taught me a lot of things by forcing me into situations where I would not typically encounter as a partnered traveller. It taught me to be independent, resourceful, alert and responsible. I was accountable for my own safety, even more so when travelling alone when the luxury of assistance and help is sacrificed.</p><h3><em>2. Dear Grandpa</em></h3><p><em>The passing of a fatherly figure.</em></p><p>The phone tossed and turned in my pocket. It was mom, calling at an uncanny hour.</p><p>“Grandpa… he passed away today morning.” The trembling and sadness in my mothers voice betrayed her careful choice of words.</p><p>He’s gone. The curious scholar who is perpetually charmed by my knowledge of the planets and the stars; the father figure who loved and cared for me as a child in every single way possible; the formidable character who taught me the art of qi-gong — lost forever, from the moment he expired his final breath on a hospital bed.</p><p>My heart took a perilous tumble, freefalling into unknown depths. Colour faded from my face. My hands, shaking from the shock, struggled to return the phone to my pocket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FF_C-rC8lVCb3vl_3KjSkw.jpeg" /><figcaption>Grandpa in 2008.</figcaption></figure><p>I knew we were <a href="https://medium.com/life-journey/losing-him-to-a-prison-of-the-mind-88115c953b70">losing him to dementia </a>— I even penned a story, dedicated to this experience, earlier in the year.</p><p>Memories were erased, faces were scrambled. We were losing him to the prison of the mind — his eyes no longer light up like the constellations in the night sky when we meet. I could only see a sense of loss and confusion, unmasked by the cloudiness in his eyes.</p><p>However, I was not expecting this. A few days ago he was admitted to a hospital ward because of a minor infection, likely due to excessive mucus and fluid accumulation in the lungs. He had breathing difficulties, but the doctors got the offending muck out. “He should recover in no time.” My parents visited him, and he was in high spirits, happily brandishing the victory sign at the camera as they snapped away.</p><h4>Loss</h4><p>As much as I willed myself to, I found it exceptionally difficult to deal with grandpa’s passing. Over my short and insignificant presence in the human realm, I have lost my uncle to an industrial accident and my great grandmother to old age. I <a href="https://medium.com/life-journey/bidding-mystery-goodbye-f506a61f118d">lost a close friend to cancer</a>. However, losing grandpa struck me at a very soft spot. I can find his presence, imprinted in various nooks and crannies of my childhood memories. He is the part and parcel of my life.</p><p>We went on vacations often. He would follow us into the misty strawberry fields, our clothes damp from the morning dew and our footwear bespeckled with mud. He joined us for short walks in the evening, bathed in the empyreal twilight.</p><p>Acceptance was tough. I cried myself to sleep every night — the nights one week after receiving the news were exceptionally rough, when everything started to sink in. Like a dying flare in the wind, I withered on the inside, for not being able to attend his wake and cremation.</p><p>I found myself unable to focus at work. Tears would flood my vision, out of the blue. I would run out of our weekly common breakfast, in the middle of meetings, in the midst of my experiments, to seek comfort and solace in the darkness of a toilet cubicle.</p><p>There, I could cry. Without being ridiculed. Without being bombarded with questions from genuinely concerned and worried coworkers. Without having to deal with real life as I know it.</p><p>I all wished it was a dream — a nightmare that I was simply unable to awaken from. It wasn’t. Two weeks down the road, I forced myself to confront reality — that life has to go on despite grandpa’s passing. He would be extremely upset if he learned about how weak I was, I reassured myself.</p><h4>Rebuild</h4><p>Slowly but surely, I got back up on my two feet. I showed up on time for work again. I no longer cry. I no longer have sleepless nights where I stare at the stark white ceiling, doubting whether I have done any wrong to deserve such emotional turmoil.</p><p>I learned that I was selfish for not willing to let go. You have had a blessed, fruitful life. You have a caring, dutiful and loving wife who took extremely good care of you, and were by yourself regardless of illness and healthy. You witnessed, and survived, the second world war, and thrived well in the local community after moving to Malaysia. You started a small businesses, sold the first colour televisions in town. You watched the broadcast of the moon landing. You fathered five little rascals who grew up to be sensible adults, my mother included. You have a dozen of grandchildren who loves you with all their hearts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Hhkj9panS-Se7ym6edrPQ.jpeg" /><figcaption>Grandpa in 2014. This is the last photo I took for him, just minutes before we left my grandparents’ place.</figcaption></figure><p>I learned that for each and every passing, a person leaves a legend behind him — my grandpa is no exception, too. He taught me generosity, of how one can achieve happiness by being philanthropic and empathetic. He bestowed me kindness and patience, something that I sorely lack at times.</p><p>He’s at a better place — free from the bindings of life, suffering of illnesses, infirmity of his legs, stuttering of his speech, delay of his mortal vessel.</p><p>I will do enough good to meet you up there, grandpa. Have a safe trip home, and I hope we will meet again.</p><blockquote>Do not stand at my grave and weep.<br>I am not there I do not sleep.</blockquote><blockquote>I am a thousand winds that blow.<br>I am the diamond glints on snow.<br>I am the sunlight on ripened grain.<br>I am the gentle autumn rain.</blockquote><blockquote>When you awaken in the morning’s hush<br>I am the swift uplifting rush<br>Of quiet birds in circled flight.<br>I am the soft stars that shine at night.</blockquote><blockquote>Do not stand at my grave and cry;<br>I am not there. I did not die.</blockquote><blockquote>— Mary Elizabeth Fyre, 1932</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*4Wt5BirBykUyVfroHeRoHQ.jpeg" /><figcaption>Visuals inspired by a Black Mirror episode, titled “White Christmas”</figcaption></figure><h3>3. Cut</h3><p><em>How does it feel to be cut out of someone’s life abruptly?</em></p><p>Let’s call him <em>Mathias*</em>. That is, of course, nowhere close to his name, changed for reasons of anonymity.</p><p>I picked up the ball and threw it across the court. I wrote to Mathias, and he wrote back. We hit off like old friends — both intellectuals, with him almost finishing his education in medicine and me halfway through my PhD in molecular biology. Both of us secretly like The Devil Wears Prada — so much so that we can utter witty lines from Andrea Sachs, or ramble on with zesty remarks delivered by Miranda Priestly.</p><p>We had dinners at each other’s homes, we made food together. We laughed at the silliest things, choked on the driest red wines. We confided in each other, sharing our little pieces of secrets. One day I made up my mind — I wanted him to be part of my life.</p><p>I invited him to meet my friends, together we went out to grab drinks. We took walks in the uncharacteristically warm Danish autumn evenings. We sat on the couch, cuddled against each other inseparably so, and fell asleep halfway through the screening of Skyfall.</p><p>Mathias was there when I defended my master thesis. I was undeniably nervous to the point of being nauseous. For some reason, his quiet, unassuming presence in the room assured me. I could see it in his eyes, that everything will be okay.</p><p>When I received news about my grandfather’s passing, Mathias was the one standing next to me. He made sure I was alright. I was devastated, but he was never shy of letting me know in his own silent way that he will always be there for me.</p><p>I was invited to a <em>julefrokost</em> (Christmas dinner) at a coworker’s place. His girlfriend cheekily suggested that I should bring a plus one… nobody else by Mathias. I wrote to Mathias about the invitation, he gladly accepted. “We are going to have so much fun!” I wrote excitedly. “We should also talk about what to bring.”</p><p>Out of the blue, Mathias stopped replying to my texts. Once. Twice. Thrice. And then I stopped trying. I am not desperate, nor am I too undignified to grovel for attention. However, his silence caught me by surprise. We no longer talk. We no longer see each other. Static dominated our radio waves, for he had ceased all communications with me.</p><p>He remained friends on Facebook. He was, and is, alive and well. Last played song on Spotify updated every other five minutes or so. His presence was undeniably evident, but his absence was hurting me. He was within and without.</p><p>Christmas rolled around. For once I picked up the courage and texted him again. Merry Christmas. I do not know what happened, but I wished him well — and promised that it will be the last he would hear from me. I received the obliged holiday greetings, obviously written out of politeness, and nothing more.</p><p>Mathias cut me out of his life. And so would I. There is no need to linger on the past. Did it even matter that we shared so much in common? Did it even matter if he confided in my close friend that he likes me? It’s all gone with the wind, like snowflakes lost in the winter breeze.</p><p>I am not angry at Mathias, but at myself. For being so trusting, so hopelessly romantic, so naïve, so stupidly in love. When Mathias blocked me out of his life, I knew that there is no turning back. Masquerades were abandoned, promises were abruptly dropped. That tiny, glowing hope I have for a significant other simply snuffed out. Extinguished. Suffocated.</p><p>I have been single for the longest period of time, and I think I will keep it just like that for a little longer.</p><h3>4. A Healthier Self</h3><p><em>Gym + Road cycling + Running + Winter bathing + Yoga</em></p><p>I find it impossible to pen this section without sounding like a fitness junkie, but trust me, I am not. My miniscule, lanky frame betrays my gym membership. My thin calves will tell you nothing about my enthusiasm in road cycling and running. My inflexibility will make you scoff at my yoga class attendance.</p><p>However, I do all of this not to be that hyper-muscular guy you see on the beaches in summer. I simply wanted to be healthier, perhaps feel a little more alive, and to inject some sort of discipline into my life.</p><p>I have been lazy for too long — binge watching movies and TV shows, camping by my computer doing a lot of programming work in my free time, scouring StackOverflow for unanswered questions, staring into Photoshop and Lightroom performing photo post-processing. As much as I was comfortable with a sedentary lifestyle, I felt that I could use a change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1DbqpDBAHGpAxhLlNoINYA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFimiTbkkE2Tm_4CAHLvjw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qjbofe_vJLrxhNIVy5NHMA.jpeg" /><figcaption>Top: My (new) road bike. Bottom left: Fields of wheat from Jelshøj. Bottom right: The first time I conquered the 120m Jelshøj.</figcaption></figure><p>I purchased a second-hand Centurion road bike for a mere 2000DKK — a fucking bargain I&#39;d say — and started going on cycling trips. So far I have clocked in around 950km this year, majority of it accumulated from 20- or 30-km bike rides around Brabrand Lake, along the coastlines north of Aarhus, or up the tallest point in Aarhus, <a href="http://da.wikipedia.org/wiki/Jelsh%C3%B8j">Jelshøj</a>.</p><p>After recuperating for a year following a knee injury, I picked up running again and clocked 21-ish minutes for the 5km DHL run in Autumn. Pretty proud of myself, I would say. I would not want to see myself as a professional runner, but I would love to try my hands on a 10km run, or even the Aarhus half marathon next summer.</p><p>In autumn I was introduced to ashtanga yoga. Estrella from work tried all year to convince me to join and I finally gave in to her stubbornness. I remembered started off knowing little about yoga, and my inflexibility was causing me great embarrassment (to myself), even though Mira, our ever so patient instructor, assured me that flexibility will come in due time. Over the course of two months I felt an almost magical transformation in my body — my back and hamstrings gained the flexibility that I lost since I was a kid. I was able to touch my toes when I bend forward — for once!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfxOmxjv3cSN1wgnxrPuKg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9bKOu7fFAXwZt1orPUK7A.jpeg" /><figcaption>At the lounge area of Den Permanente, where I go for winter bathing. Nothing beats a hearty breakfast after winter bathing!</figcaption></figure><p>Winter bathing is a huge hit with many of my colleagues, and with Yasu and Ania’s insistence I decided to give it a try. Despite getting slowly acquainted to the cold — I lived in the tropics all my life before moving to Denmark — winter bathing was totally out of the question… at least until now. It turned out to be a lot more <em>hygge</em> and welcoming than I thought, and the experience totally changed me. I never had a healthy body image, and dreaded the slightest idea of being nude in front of others. I signed up for a gym membership one year ago with Fitness World and was horrified by the common showers. <a href="http://jomsborg.vinterbadning.dk/">Winter bathing at Jomsborg</a> taught me that people do come in all shapes and sizes, and that I shouldn&#39;t flog myself over a lousy body image.</p><h3>5. Fluidbox</h3><p><em>The creation and maintenance of a jQuery plugin.</em></p><p>Last, but not least, a little about my second identity as a programmer and web designer. Slightly more than a year ago I authored <a href="https://github.com/terrymun/Fluidbox">my first jQuery plugin</a>, named <em>Fluidbox</em>, which effectively <a href="https://medium.com/coding-design/presenting-fluidbox-9c7fe9db92c7">replicates the lightbox effect</a> seen on Medium. I never expected it to receive any attention, but it did. It was featured on several articles and even got a mention from the venerable designer/illustrator <a href="http://veerle.duoh.com/">Veerle Pieters</a> (<a href="https://twitter.com/vpieters">@vpieters</a>):</p><h3>Veerle Pieters on Twitter</h3><p>Fluidbox, a nice lightbox module. Here&#39;s the tutorial: https://medium.com/coding-design/9c7fe9db92c7 ...</p><p>Even though I am educated as a molecular biologist and is, in fact, working on my PhD project as we speak, I am extremely interested in web development and programming. Authoring Fluidbox not only helped me with sharpening and updating my own (limited set of) skills, but also taught me how to maintain an open source project, maintaining a Git and collaborating with like-minded and more experienced veteran programmers.</p><p>I have received a lot of feedback and help from other Git users along the way during the development of Fluidbox, and I am still trying hard to make it better, if ever possible.</p><h3>Hello, MMXV</h3><p><em>Happy new year.</em></p><p>I experienced the loss of my grandfather. I went through a near-relationship that didn’t work out, crashed and burned. These experiences, though appearing negative on the surface, spurred tremendous growth — emotionally and spiritually. They made me stronger, and perhaps, a little wiser. They taught me that we deal with goodbyes on a daily basis — and that we should never be afraid of them, because they will not stop coming. Instead, I learned how to embrace loss and farewell — and the art of attaining closure and inner peace.</p><p>I travelled alone in Greece. I started to lead a healthier lifestyle. I embraced programming and design as a hobby. These experiences put me in new situations that I have not experienced before, forced me into uncomfortable scenarios. They pushed my personal limits, nudged me out of the comfort zone that I have very convenient sequestered myself in.</p><p>All in all, 2014 has been a great year. I wish I say the same one year down the road. What will the future bring?</p><p><em>p/s: </em>Happy new year, and thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a550f245cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/life-journey/lessons-from-mmxiv-c0a550f245cd">Lessons from MMXIV</a> was originally published in <a href="https://medium.com/life-journey">Life Journey</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing better AJAX]]></title>
            <link>https://medium.com/coding-design/writing-better-ajax-8ee4a7fb95f?source=rss-6cf203a872c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ee4a7fb95f</guid>
            <category><![CDATA[jquery]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ajax]]></category>
            <dc:creator><![CDATA[Terry Mun]]></dc:creator>
            <pubDate>Mon, 15 Dec 2014 23:27:49 GMT</pubDate>
            <atom:updated>2015-05-08T11:02:04.042Z</atom:updated>
            <content:encoded><![CDATA[<p>A guide towards writing better AJAX calls in jQuery</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U611c8JlRH8Wq50PI3gfFA.jpeg" /><figcaption>Illustration: Terry Mun</figcaption></figure><p>For awhile, the standard way of making an AJAX call using jQuery is rather simple — by using the <a href="http://api.jquery.com/jQuery.ajax/"><strong><em>$.ajax()</em></strong></a> function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83e7657b252eca4cd91f736ee96f8f68/href">https://medium.com/media/83e7657b252eca4cd91f736ee96f8f68/href</a></iframe><p>Looks easy peasy, but there are several drawbacks to this method:</p><ol><li><strong>Excessive nesting.</strong> Functions and events dependent on the returned AJAX data has to be wrapped in the <strong><em>success</em></strong> handler, because AJAX is by nature, <em>asynchronous</em>. Along the same line, this reduces the readability of your code.</li><li><strong>Difficulty in chaining and compounding.</strong> It is difficult and overwhelmingly complex to evaluate outcomes of multiple AJAX requests — we are unable to predict how long does it take for all AJAX requests (each running asynchronously) to return a response.</li><li><strong>Deprecation warning.</strong> As of v1.8 and above, <strong><em>jqXHR.success()</em></strong>, <strong><em>error</em></strong> and <strong><em>complete </em></strong>callbacks have been officially deprecated.</li></ol><h3>Promises and deferred objects</h3><p>Thankfully, promises and <a href="http://api.jquery.com/jQuery.Deferred/">deferred objects</a> are implemented natively in the <strong><em>$.ajax()</em></strong> method:</p><ul><li><a href="http://api.jquery.com/deferred.done/"><strong><em>.done()</em></strong></a> as a replacement for <strong><em>.success()</em></strong></li><li><a href="http://api.jquery.com/deferred.fail/"><strong><em>.fail()</em></strong></a> as a replacement for <strong><em>.error()</em></strong></li><li><a href="http://api.jquery.com/deferred.always/"><strong><em>.always()</em></strong></a> as a replacement of <strong><em>.complete()</em></strong></li></ul><p>As per other native jQuery methods, you can chain them, i.e.:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02c5c055c4e155c1a43e89427b7fd2b9/href">https://medium.com/media/02c5c055c4e155c1a43e89427b7fd2b9/href</a></iframe><h4>Chaining works, just as usual</h4><p>Even better: assign the <strong><em>$.ajax()</em></strong> method to a variable, for which you can chain promise callbacks to. Chaining has always been a hallmark of jQuery, which allows one to reuse a cached selector, for example. In this case, the <strong><em>$.ajax()</em></strong> method returns a promise object natively, which we can use for chaining, too:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c55ac0d898ec5fae3c5412317389399b/href">https://medium.com/media/c55ac0d898ec5fae3c5412317389399b/href</a></iframe><p>See that how the <strong><em>.done()</em></strong> callback is on the same level as the AJAX call itself, without requiring complicated nesting within the call <em>per se</em>? While this advantage may seem trival on a cursory glance, it greatly improves the readability of your code, especially in a production environment where your code is likely to be cluttered with multiple asynchronous calls.</p><p>It also allows you to inject code between the AJAX call itself and resolving the promise delivered by the call, allowing for greater flexibility in coding.</p><p>In other words, you can see that promises and deferred objects, implemented since jQuery v1.5 onwards, in relation to synchronicity of code execution, is akin to event bubbling in the DOM, listened on by the <a href="http://api.jquery.com/on/"><strong><em>.on()</em></strong></a> method.</p><h4>Multiple AJAX calls</h4><p>Compounding several AJAX calls has never been made easier with promises. All you have to do is to listen to their status via <a href="http://api.jquery.com/jQuery.when/"><strong><em>$.when()</em></strong></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f27eed26648a06b588fd01b8215bc03/href">https://medium.com/media/8f27eed26648a06b588fd01b8215bc03/href</a></iframe><h4>Dependence chain of AJAX requests</h4><p>You can also chain multiple AJAX request — for example, when the second AJAX call relies on returned data on the first call. Let’s say the first call retrieves the session ID of a user, and we need to pass that value off to a second script. Remember that <a href="http://api.jquery.com/deferred.then/"><strong><em>$.then()</em></strong></a> returns a <em>new</em> promise, which can be subsequently passed to the <strong><em>$.done()</em></strong> or even another <strong><em>$.then</em></strong>() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/514a463792aa78d9fe698b1c3a58570c/href">https://medium.com/media/514a463792aa78d9fe698b1c3a58570c/href</a></iframe><h4>Modularizing AJAX requests</h4><p>More often than not, one might want to modularize their code and delegate a single function to make dynamic AJAX requests. How should we invoke the AJAX call individually, and access the promise returned, in this case? It turns out to be beyond simple: simply <em>return</em> the AJAX object after you make a request.</p><p>Let’s say we want to make two AJAX calls, which basically uses the same parameters except for the <em>data</em> and <em>url</em> parameters:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bad2ef107ea425d0733370f20d85c7c7/href">https://medium.com/media/bad2ef107ea425d0733370f20d85c7c7/href</a></iframe><p>No more messy nesting, and no more the need to repeat the <strong><em>$.ajax()</em></strong> method over and over again.</p><h4>Handling arrays of returned deferred objects</h4><p>Sometimes you would want to use <strong><em>$.when()</em></strong> on an <em>array</em> of deferred objects. An example situation would be: making a series of AJAX calls (number of calls dynamically changes, perhaps?), and then checking when all of them are done. How does that work?</p><p>There are two options:</p><ol><li>The easier to understand method would be to construct an empty array, use <strong><em>$.each() </em></strong>to make AJAX calls iteratively and then push the returned promise into the array.</li><li>The preferred method (personally) would be to use <strong>.map()</strong> to construct an object containing returned promises, which we then use <strong><em>.get()</em></strong><em> </em>to return an array</li></ol><p>After that it’s all easy: simply use <strong><em>$.when.apply($, array)</em></strong> to evaluate all AJAX calls performed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f55e11b1d649cc9d11616062da447375/href">https://medium.com/media/f55e11b1d649cc9d11616062da447375/href</a></iframe><p>You can see that using promises and deferred object offers an unparalleled advantage over nesting <strong><em>jqXHR.success</em></strong> callbacks when making iterative AJAX calls that should be evaluated as a whole.</p><h3>Final notes</h3><p>Of course, the aforementioned promises and deferred objects can also be used for <a href="http://api.jquery.com/jQuery.get/"><strong><em>$.get()</em></strong></a> and <a href="http://api.jquery.com/jQuery.post/"><strong><em>$.post()</em></strong></a> methods, which are basically reduced shorthand functions for the <strong><em>$.ajax()</em></strong> method using the GET or POST methods.</p><p>This writing is inspired by my visits to StackOverflow, where occurrence of jQuery-based AJAX-related questions is rather common.</p><p><strong>Further reading</strong></p><ul><li><a href="http://davidwalsh.name/write-javascript-promises">Writing Better JavaScript with Promises</a> by David Walsh</li><li><a href="https://learn.jquery.com/code-organization/deferreds/examples/">Deferred examples</a> on the official jQuery API</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ee4a7fb95f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-design/writing-better-ajax-8ee4a7fb95f">Writing better AJAX</a> was originally published in <a href="https://medium.com/coding-design">Coding &amp; Design</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>