<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Yasith Fernando</title><link>https://www.yasithfernando.com/</link><description>Recent content on Yasith Fernando</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 13 Nov 2026 18:00:00 +1100</lastBuildDate><atom:link href="https://www.yasithfernando.com/index.xml" rel="self" type="application/rss+xml"/><item><title>Handy Bar: Dictation That Lives in the Menu Bar</title><link>https://www.yasithfernando.com/blog/handy-bar/</link><pubDate>Fri, 13 Nov 2026 18:00:00 +1100</pubDate><guid>https://www.yasithfernando.com/blog/handy-bar/</guid><description>&lt;p&gt;I dictate a lot these days (messages, notes, prompts for coding agents), and &lt;a href="https://github.com/cjpais/handy"&gt;Handy&lt;/a&gt; has been my go-to for it. It&amp;rsquo;s open source, fast, and the transcription runs entirely on your Mac.&lt;/p&gt;
&lt;p&gt;The one thing I wanted was for it to get out of the way. No window, no Dock icon, just a little icon in the menu bar. So I forked it and made &lt;a href="https://handybar.yasithfernando.com"&gt;Handy Bar&lt;/a&gt; 🎙️&lt;/p&gt;
&lt;p&gt;&lt;img src="https://www.yasithfernando.com/attachments/handy-bar/handy-bar-popover.png" alt="Handy Bar&amp;rsquo;s menu bar popover: microphone picker and the latest transcripts" loading="lazy" decoding="async"&gt;
&lt;/p&gt;</description></item><item><title>Spotlight Stopped Indexing My Apps</title><link>https://www.yasithfernando.com/blog/spotlight-stopped-indexing/</link><pubDate>Fri, 06 Nov 2026 09:00:00 +1100</pubDate><guid>https://www.yasithfernando.com/blog/spotlight-stopped-indexing/</guid><description>&lt;p&gt;For a while Spotlight couldn&amp;rsquo;t find any of my recently installed apps (Herdr, Orca, etc.), and it turns out it had quietly stopped indexing anything for about six weeks. My Mac had been up for 132 days (apparently it was running a software &lt;del&gt;factory&lt;/del&gt; kitchen :D), and at some point Spotlight&amp;rsquo;s index process (&lt;code&gt;mds_stores&lt;/code&gt;) restarted and never properly reconnected to the main daemon (&lt;code&gt;mds&lt;/code&gt;), so search kept working off the old index while nothing new made it in.&lt;/p&gt;</description></item><item><title>How I AI - 2026 Nov Update</title><link>https://www.yasithfernando.com/blog/how-i-ai-2026-nov/</link><pubDate>Tue, 03 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/blog/how-i-ai-2026-nov/</guid><description>&lt;p&gt;I always enjoy chatting about how folks use AI and what tools they use. Partly because everything is changing all the time and you never know if you are missing out on the best tool ever, because let&amp;rsquo;s be honest, it&amp;rsquo;s easy to miss, given the torrent of AI-related information coming out every day.&lt;/p&gt;
&lt;h1 id="opus-55"&gt;&lt;a href="https://www.anthropic.com/claude/opus"&gt;Opus 5.5&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The GOAT, enough said!&lt;/p&gt;
&lt;h1 id="chief-of-staff--firstmate"&gt;Chief of Staff / Firstmate&lt;/h1&gt;
&lt;p&gt;Most of my work now happens through a firstmate-type session that manages other &amp;lsquo;worker&amp;rsquo; sessions. The firstmate&amp;rsquo;s job is to talk to me and manage the other agents for me. These are not subagents but full &lt;a href="https://claude.com/claude-code"&gt;Claude Code&lt;/a&gt;/&lt;a href="https://openai.com/codex/"&gt;Codex&lt;/a&gt; sessions. This really allows me to scale and do more. While I do lose some visibility into the actual details in the process, I can always jump into an individual session and chat directly if I want to. Which I sometimes still do, but not that often.&lt;/p&gt;</description></item><item><title>The Software Engineer Who Don't Code: My AI Engineer Melbourne 2026 Talk</title><link>https://www.yasithfernando.com/blog/ai-engineer-melbourne-2026-talk/</link><pubDate>Fri, 05 Jun 2026 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/blog/ai-engineer-melbourne-2026-talk/</guid><description>&lt;p&gt;I spoke at &lt;a href="https://webdirections.org/ai-engineer-melbourne-26/"&gt;AI Engineer Melbourne&lt;/a&gt; about &lt;a href="https://webdirections.org/ai-engineer-melbourne-26/speakers/yasith-fernando.php"&gt;&amp;ldquo;The Software Engineer Who Don&amp;rsquo;t Code&amp;rdquo;&lt;/a&gt;. It was a bit daunting to get on stage 😅 but it was also super energising to meet other smart and kind people who are thinking about the same problem space!&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve always been a fan of the &lt;a href="https://ai.engineer"&gt;AI Engineer&lt;/a&gt; series and have watched many of the talks on &lt;a href="https://www.youtube.com/@aiDotEngineer"&gt;YouTube&lt;/a&gt;. But flying to SF just for a conference is a bit expensive, so I&amp;rsquo;ve never really been to one (maybe it&amp;rsquo;s time!). When they came to Melbourne I knew I had to go. And speakers get in free! 😉&lt;/p&gt;</description></item><item><title>Claude Sonnet 4.5 and Claude Code 2 Initial Impressions</title><link>https://www.yasithfernando.com/blog/claude-sonnet-4.5-and-claude-code-2-initial-impressions/</link><pubDate>Thu, 02 Oct 2025 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/blog/claude-sonnet-4.5-and-claude-code-2-initial-impressions/</guid><description>&lt;p&gt;I&amp;rsquo;ve been playing with 4.5 and Claude Code 2 for a few days now. And I&amp;rsquo;ve used it via Claude Code and via API in Zendesk App Builder. In general it seems better and faster and tool calls definitely seems faster compared to the pervious version. Also I&amp;rsquo;ve noticed Claude Code taking more notes. And I&amp;rsquo;m yet to notice any &lt;a href="https://cognition.ai/blog/devin-sonnet-4-5-lessons-and-challenges"&gt;context anxiety&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Overalls it feels like an definite improvement. However, I struggle to quantify these improvements as a user. Like it&amp;rsquo;s better but it feels evolutionary not revolutionary. And it seems that Anthropic is listening to the community and watching whats happening among builders and then taking these lessons to the model training stages. For example, externalizing context/memory to the file system. This is great but I&amp;rsquo;m not feeling the AGI here, and it&amp;rsquo;s not a bad thing! :)&lt;/p&gt;</description></item><item><title>LowFi Wireframes</title><link>https://www.yasithfernando.com/blog/lowfi-wireframes/</link><pubDate>Thu, 02 Oct 2025 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/blog/lowfi-wireframes/</guid><description>&lt;p&gt;Low-fi wireframes are the best (these are from codex-cli)!&lt;/p&gt;
&lt;p&gt;They are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LLM and terminal friendly&lt;/li&gt;
&lt;li&gt;Low on tokens&lt;/li&gt;
&lt;li&gt;Quick &amp;amp; easy validation of UI before you move to more high fidelity mockups or just straight to implementation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src="https://www.yasithfernando.com/attachments/codex-lowfi-wireframes.png" alt="" loading="lazy" decoding="async"&gt;
&lt;/p&gt;
&lt;p&gt;Don&amp;rsquo;t think I&amp;rsquo;ve seen these much in Claude Code, but I&amp;rsquo;m sure Claude will oblige if I ask :)&lt;/p&gt;</description></item><item><title>Migrating form Ghost to Hugo</title><link>https://www.yasithfernando.com/blog/migrating-from-ghost-to-hugo/</link><pubDate>Tue, 26 Aug 2025 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/blog/migrating-from-ghost-to-hugo/</guid><description>&lt;p&gt;It&amp;rsquo;s 2025 and it&amp;rsquo;s time to resurrect my blog from the dusty backups. And ChatGPT told me to use Hugo and host it on cloudflare pages, apparently thats how you host a static site these days. So that&amp;rsquo;s what I did. The whole setup was pretty straight forward. The only real migration I had to do was to restore the backup from my previous Ghost blog.&lt;/p&gt;
&lt;p&gt;It wasn&amp;rsquo;t all that difficult but it did have a few gotchas. If you are ever in the same boat you can use this python script: &lt;a href="https://github.com/thekindofme/ghost-to-hugo-converter"&gt;ghost-to-hugo-converter&lt;/a&gt; to help you out. Always double check the imported posts before you publish them, of course.&lt;/p&gt;</description></item><item><title>Obsidian and writing notes</title><link>https://www.yasithfernando.com/blog/obsidian-and-writing-notes/</link><pubDate>Thu, 21 Aug 2025 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/blog/obsidian-and-writing-notes/</guid><description>&lt;p&gt;So I&amp;rsquo;ve just discovered Obsidian. It&amp;rsquo;s pretty neat. What&amp;rsquo;s neat about it you ask? Well it&amp;rsquo;s the whole vision and the idea around it. And graphs! Or should I call them mindmaps. Mindmaps always made sense to me as a way to organize content. So it would be cool to try them out for my notes, blog posts..etc. I also get the feeling that it was designed by some engineers who wanted a tool for themselves.&lt;/p&gt;</description></item><item><title>Routing all requests to Rails via WebMock during tests</title><link>https://www.yasithfernando.com/blog/routing-all-requests-to-rails-via-webmock-during-tests/</link><pubDate>Wed, 27 Sep 2017 16:05:45 +0000</pubDate><guid>https://www.yasithfernando.com/blog/routing-all-requests-to-rails-via-webmock-during-tests/</guid><description>&lt;p&gt;&lt;a href="https://github.com/bblimke/webmock"&gt;WebMock&lt;/a&gt; allows you to route all HTTP requests made during tests to a rack app with &lt;a href="https://github.com/bblimke/webmock#rack-responses"&gt;&lt;code&gt;to_rack&lt;/code&gt;&lt;/a&gt;. You can use this method to route the same traffic to a Rails app as well.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;stub_request(:any, /account.envato.com/).to_rack(Rails.application)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="http://guides.rubyonrails.org/rails_on_rack.html"&gt;&lt;code&gt;Rails.application&lt;/code&gt; is the rack object in a Rails app.&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Disable Swap Navigation with Scrolls for Chrome</title><link>https://www.yasithfernando.com/blog/disable-swap-navigation-with-scrolls-for-chrome/</link><pubDate>Sun, 20 Mar 2016 07:58:04 +0000</pubDate><guid>https://www.yasithfernando.com/blog/disable-swap-navigation-with-scrolls-for-chrome/</guid><description>&lt;p&gt;Sometimes in Chrome, I try to scroll down and I end up going back. This is the single most annoying thing that happens to me when I&amp;rsquo;m using chrome. Fortunately you can disable this.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://apple.stackexchange.com/questions/21236/how-do-i-disable-chromes-two-finger-back-forward-navigation"&gt;Here is how, on stackexchange&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="tldr"&gt;TLDR;&lt;/h2&gt;
&lt;h4 id="disable-it-only-for-a-specific-application"&gt;Disable it only for a specific application&lt;/h4&gt;
&lt;p&gt;To disable it for Chrome, open up a terminal and execute:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool FALSE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Similarly you can disable it for any app, just replace com.google.Chrome with whatever app you want this gesture disabled on.&lt;/p&gt;</description></item><item><title>FAQ: Moving to Australia for Software Developers</title><link>https://www.yasithfernando.com/blog/faq-moving-to-australia-for-software-developers/</link><pubDate>Sun, 13 Mar 2016 08:24:57 +0000</pubDate><guid>https://www.yasithfernando.com/blog/faq-moving-to-australia-for-software-developers/</guid><description>&lt;h2 id="context"&gt;Context&lt;/h2&gt;
&lt;p&gt;I am a ruby developer based in Melbourne. And quite a few friends have asked me the same question(s) related to the title of this post. Hence this post. It &lt;strong&gt;MIGHT&lt;/strong&gt; be useful to you if you are software developer (there is a bias towards Ruby) looking to move to Australia.&lt;/p&gt;
&lt;h2 id="do-i-need-to-get-pr-before-applying-for-a-job"&gt;Do I need to get PR before applying for a job?&lt;/h2&gt;
&lt;p&gt;No. You can get a job with a employer who is willing to sponsor your &lt;a href="http://www.border.gov.au/Trav/Visa-1/457-"&gt;457 visa&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Thoughts on YOW 2015 Brisbane</title><link>https://www.yasithfernando.com/blog/thoughts-on-yow-2015-brisbane/</link><pubDate>Wed, 09 Dec 2015 12:46:14 +0000</pubDate><guid>https://www.yasithfernando.com/blog/thoughts-on-yow-2015-brisbane/</guid><description>&lt;p&gt;Thanks to my employer, my self and some of my colleagues attended YOW 2015 Brisbane this week. It was a positive experience and I wanted to write down my thoughts about it.&lt;/p&gt;
&lt;h3 id="whats-yow"&gt;What&amp;rsquo;s YOW?&lt;/h3&gt;
&lt;p&gt;YOW is the biggest &amp;lsquo;software development conference&amp;rsquo; in Australia. It&amp;rsquo;s a two day evennt, held yearly in Sydney, Melbourne and Brisbane. IMHO YOW gets some really good speakers down to Australia from all over the world. And it&amp;rsquo;s has a general focus on the whole of software industry (in contrast to say RubyConf which is focused on Ruby).&lt;/p&gt;</description></item><item><title>Upgrading VIM with lua support on OSX</title><link>https://www.yasithfernando.com/blog/upgrading-vim-on-osx/</link><pubDate>Fri, 27 Nov 2015 12:21:22 +0000</pubDate><guid>https://www.yasithfernando.com/blog/upgrading-vim-on-osx/</guid><description>&lt;p&gt;Recently I installed a new vim version on my system to get rid of the following warning:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;neocomplete does not work with this version of Vim.
It requires Vim 7.3.885 or later with Lua support (&amp;#34;+lua&amp;#34;).
Press ENTER or type command to continue
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id="steps"&gt;Steps&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Install &lt;a href="http://brew.sh"&gt;homebrew&lt;/a&gt; if you don&amp;rsquo;t have it installed already.&lt;/li&gt;
&lt;li&gt;brew update&lt;/li&gt;
&lt;li&gt;brew install vim &amp;ndash;with-lua&lt;/li&gt;
&lt;li&gt;create an alias vim pointing to /usr/local/bin/vim (as system vim is still there at /usr/bin/vim)
&lt;ul&gt;
&lt;li&gt;on zsh you can add the following snippet to your .zshrc, to create an alias, if a brew installed vim is present in the system.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# use brew vim if present
/usr/local/bin/vim --version &amp;gt; /dev/null 2&amp;gt;&amp;amp;1
BREW_VIM_INSTALLED=$?
if [ $BREW_VIM_INSTALLED -eq 0 ]; then
alias vi=&amp;#34;/usr/local/bin/vim&amp;#34;
fi
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Cheers!&lt;/p&gt;</description></item><item><title>Compressing scanned PDF files on OSX</title><link>https://www.yasithfernando.com/blog/compressing-scanned-pdf-files-on-osx/</link><pubDate>Thu, 24 Sep 2015 10:30:47 +0000</pubDate><guid>https://www.yasithfernando.com/blog/compressing-scanned-pdf-files-on-osx/</guid><description>&lt;p&gt;I&amp;rsquo;ve been scanning a lot of documents using preview recently(!) and the resulting PDFs are often super huge. You can always use one of the online PDF compressing services if you only have a few documents. However, this can get really slow if you have a significant number of docs to process. Or you can use ghostscript :)&lt;/p&gt;
&lt;h4 id="install-ghostscript"&gt;Install Ghostscript&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;brew update
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;brew install gs
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id="compress"&gt;Compress!&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf scanned_document.pdf
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Refer the &lt;a href="http://www.ghostscript.com/doc/current/Use.htm"&gt;ghostscript manual&lt;/a&gt; for more info.&lt;/p&gt;</description></item><item><title>Rails Camp Sydney 2015</title><link>https://www.yasithfernando.com/blog/rails-camp-sydney-2015/</link><pubDate>Tue, 23 Jun 2015 08:08:55 +0000</pubDate><guid>https://www.yasithfernando.com/blog/rails-camp-sydney-2015/</guid><description>&lt;p&gt;I want to write down my thoughts on the last &lt;a href="http://railscamp-sydney-2015.ruby.org.au/"&gt;Rails Camp&lt;/a&gt; that I went to. So here goes.&lt;/p&gt;
&lt;h2 id="the-camp"&gt;The Camp&lt;/h2&gt;
&lt;p&gt;The camp was in Broken Bay, Hawkesbury River, Sydney. It was an awesome location. Very scenic with beaches and plenty of trails to hike on. But this being Sydney in the middle of winter it was cold at night (duh).&lt;/p&gt;
&lt;p&gt;The food was absolutely amazing for a camp. The slow cooked beef served on Sunday night was the highlight of the camp :P&lt;/p&gt;</description></item><item><title>Dropping HTTP Requests and Connection Efficiently on Nginx</title><link>https://www.yasithfernando.com/blog/dropping-http-requests-and-connection-efficiently-on-nginx/</link><pubDate>Wed, 03 Jun 2015 15:25:18 +0000</pubDate><guid>https://www.yasithfernando.com/blog/dropping-http-requests-and-connection-efficiently-on-nginx/</guid><description>&lt;pre tabindex="0"&gt;&lt;code&gt;location /banned/url {
return 444;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;From &lt;a href="http://nginx.org/en/docs/http/request_processing.html"&gt;How nginx processes a request&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;hellip;and a special nginx’s non-standard code 444 is returned that closes the connection.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Basically, match the URL/pattern..etc that you want to handle and then do a return 444; It will make nginx drop the connection without even bothering to return a response to the client.&lt;/p&gt;</description></item><item><title>Note-to-self: Setting up a new mac for development</title><link>https://www.yasithfernando.com/blog/setting-up-a-new-mac-for-development/</link><pubDate>Mon, 18 May 2015 21:29:21 +0000</pubDate><guid>https://www.yasithfernando.com/blog/setting-up-a-new-mac-for-development/</guid><description>&lt;p&gt;I recently got a new development machine (yay!). And went through the process of setting it up. Getting new toys are always fun. But setting them up from scratch can be a bit of a pain. So I am documenting all the steps I took as a reference for the future.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Setup and enable Find my mac&lt;/li&gt;
&lt;li&gt;Enable FileVault&lt;/li&gt;
&lt;li&gt;Copy over personal ssh private keys&lt;/li&gt;
&lt;li&gt;Set proper permission on the keys (chmod 600 your_key.pem)&lt;/li&gt;
&lt;li&gt;Create home dir structure
&lt;ul&gt;
&lt;li&gt;development&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Apps to install&lt;/li&gt;
&lt;li&gt;Chrome
&lt;ul&gt;
&lt;li&gt;Setup Lastpass&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;BetterSnaptool&lt;/li&gt;
&lt;li&gt;Evernote&lt;/li&gt;
&lt;li&gt;Homebrew
&lt;ul&gt;
&lt;li&gt;Developer tools&lt;/li&gt;
&lt;li&gt;Git
&lt;ul&gt;
&lt;li&gt;gem install git-smart&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;ansible&lt;/li&gt;
&lt;li&gt;brew tap homebrew/services&lt;/li&gt;
&lt;li&gt;mysql&lt;/li&gt;
&lt;li&gt;phantomjs&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Cask
&lt;ul&gt;
&lt;li&gt;Virtualbox&lt;/li&gt;
&lt;li&gt;Vagrant&lt;/li&gt;
&lt;li&gt;Github OSX&lt;/li&gt;
&lt;li&gt;Iterm2&lt;/li&gt;
&lt;li&gt;Dash
&lt;ul&gt;
&lt;li&gt;Download your needed doc sets&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;sequelpro&lt;/li&gt;
&lt;li&gt;hipchat&lt;/li&gt;
&lt;li&gt;spotify&lt;/li&gt;
&lt;li&gt;teamviewer&lt;/li&gt;
&lt;li&gt;java (Oracle JRE)&lt;/li&gt;
&lt;li&gt;skype&lt;/li&gt;
&lt;li&gt;tunnelblick&lt;/li&gt;
&lt;li&gt;truecrypt&lt;/li&gt;
&lt;li&gt;iBrowse&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Rubymine&lt;/li&gt;
&lt;li&gt;RVM
&lt;ul&gt;
&lt;li&gt;rvm list known&lt;/li&gt;
&lt;li&gt;rvm install ruby-2.2&lt;/li&gt;
&lt;li&gt;gem install bundle&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Setup YADR (dotfile repo)
&lt;a href="https://github.com/skwp/dotfiles"&gt;https://github.com/skwp/dotfiles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;When cloning large Git repos from Github&amp;hellip; things can get really really slow. If this happens just copy the repo over from the old machine using a USB drive. Old school I know. But it works.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hopefully the future me would find this helpful.
Cheers!&lt;/p&gt;</description></item><item><title>Credit Card Number (with a separator in between) Validation Regex</title><link>https://www.yasithfernando.com/blog/credit-card-number-with-a-separator-in-between-validation-regex/</link><pubDate>Mon, 11 May 2015 11:57:11 +0000</pubDate><guid>https://www.yasithfernando.com/blog/credit-card-number-with-a-separator-in-between-validation-regex/</guid><description>&lt;p&gt;The following will validate Visa and Master card numbers that’s in the following format&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-regex" data-lang="regex"&gt;^(?:4[0-9]{3}(?:-[0-9]{4}){2}-[0-9](?:[0-9]{3})?|5[1-5][0-9]{2}(?:-[0-9]{4}){3})$
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex="0"&gt;&lt;code&gt;4111-1111-1111-1111 (note the ‘-‘)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Regex adapted from: &lt;a href="http://www.regular-expressions.info/creditcard.html"&gt;http://www.regular-expressions.info/creditcard.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Tip: Also found this super AWESOME regex testing site: &lt;a href="https://regex101.com/#javascript"&gt;https://regex101.com/#javascript&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Nginx, AWS ELB, DNS resolution, Nginx resolver directive and Black magic</title><link>https://www.yasithfernando.com/blog/nginx-aws-elb-dns-resolution-nginx-resolver-directive-and-black-magic/</link><pubDate>Fri, 08 May 2015 10:52:26 +0000</pubDate><guid>https://www.yasithfernando.com/blog/nginx-aws-elb-dns-resolution-nginx-resolver-directive-and-black-magic/</guid><description>&lt;p&gt;We use Nginx to reverse proxy traffic to our app servers in a few places (on our Varnish servers we have a Nginx proxy that reverse proxy traffic to our backend servers and the backend servers them selves reverse proxy traffic to other app servers). And all our servers are hosted on AWS and they all sit behind ELBs.&lt;/p&gt;
&lt;p&gt;So just like a lot of people on the inter webs (look at the references section bellow) we found out that Nginx is only resolving the ELB DNS once on startup and then not refreshing it. This caused some of our servers to break because AWS changes IPs for ELBs on the fly.&lt;/p&gt;</description></item><item><title>Things to do after you buy a new gaming laptop</title><link>https://www.yasithfernando.com/blog/things-to-do-after-you-buy-a-new-gaming-laptop/</link><pubDate>Fri, 08 May 2015 10:23:12 +0000</pubDate><guid>https://www.yasithfernando.com/blog/things-to-do-after-you-buy-a-new-gaming-laptop/</guid><description>&lt;p&gt;Please note that I am not a gamer(!!!). This is from the POV of a some what casual gamer who likes to game SOME of the time.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Choose a good OS: I chose Windows 8.1 Pro because this machine’s main purpose was gaming. Might end up installing Ubuntu on the side so I can use this for development on the side. But that’s a big ‘might’.&lt;/li&gt;
&lt;li&gt;Decide on how to partition the disk(s). In my case I decided to have one big partition on my 250 SSD.&lt;/li&gt;
&lt;li&gt;Install Anti theft software. I installed Pray.&lt;/li&gt;
&lt;li&gt;Get the latest drivers in general.&lt;/li&gt;
&lt;li&gt;Update your graphics card drivers (duh!). Actually do a bit of research on the games you want to play and the current drivers. In my case a particular game I wanted to play didn’t work well with the latest drivers (so I should have gone with something older that worked fine with the game in question).&lt;/li&gt;
&lt;li&gt;Update SSD drivers: Mine came with a Samsung 840 Evo. So I downloaded and installed Samsung Magician. Which takes care of a lot of things. Including updating your SSD firmware if need be.&lt;/li&gt;
&lt;li&gt;If you are using a SSD, make sure you have TRIM turned on.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That’s all that I can think up for now. Gonna add on to this post in the future if anything comes up.&lt;/p&gt;</description></item><item><title>Stub/Mock Rails view helpers in RSpec</title><link>https://www.yasithfernando.com/blog/stubmock-rails-view-helpers-in-rspec/</link><pubDate>Thu, 18 Dec 2014 14:19:08 +0000</pubDate><guid>https://www.yasithfernando.com/blog/stubmock-rails-view-helpers-in-rspec/</guid><description>&lt;p&gt;This was not as easy to find on the inter webs as it should be.&lt;/p&gt;
&lt;h3 id="example"&gt;Example&lt;/h3&gt;
&lt;p&gt;If you want to stub out a view helper (view_helper_method_x) in your view spec.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ruby" data-lang="ruby"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;allow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:view_helper_method_x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;return_value_goes_here_as_usual&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The spec should look something like bellow&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ruby" data-lang="ruby"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# encoding: UTF-8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;spec_helper&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;erb&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:each&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;allow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:view_helper_method_x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="n"&gt;blah&lt;/span&gt; &lt;span class="n"&gt;blah&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39; do
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; render
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s1"&gt; expect(rendered).to_not have_css ‘.test_id&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That’s all folks!&lt;/p&gt;</description></item><item><title>Testing Rails Controller Helper Methods Using RSpec</title><link>https://www.yasithfernando.com/blog/testing-rails-controller-helper-methods-using-rspec/</link><pubDate>Wed, 17 Dec 2014 15:21:11 +0000</pubDate><guid>https://www.yasithfernando.com/blog/testing-rails-controller-helper-methods-using-rspec/</guid><description>&lt;p&gt;If you are new to this. First &lt;a href="https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/controller-specs/anonymous-controller"&gt;read this article about Anonymous Controller&lt;/a&gt;. That should answer 98% of your questions. However, if you run in to problems the following tid bits of information might help ;)&lt;/p&gt;
&lt;h2 id="summary-of-anonymous-controller"&gt;Summary of Anonymous Controller&lt;/h2&gt;
&lt;p&gt;(code stolen from &lt;a href="https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/controller-specs/anonymous-controller"&gt;https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/controller-specs/anonymous-controller&lt;/a&gt;)&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ruby" data-lang="ruby"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApplicationController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActionController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AccessDenied&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;StandardError&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;rescue_from&lt;/span&gt; &lt;span class="no"&gt;AccessDenied&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:with&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ss"&gt;:access_deniedprivate&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;access_denied&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;/401.html&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;rails_helper&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;controller&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;AccessDenied&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;handling AccessDenied exceptions&amp;#34;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;redirects to the /401.html page&amp;#34;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="ss"&gt;:index&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;redirect_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;/401.html&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="gotchas"&gt;Gotchas&lt;/h2&gt;
&lt;h3 id="missing-helper-methods"&gt;Missing helper methods&lt;/h3&gt;
&lt;p&gt;If RSpec is having problems finding your helper methods within the Anonymous controller (it shouldn’t, because by default the controller should inherit from the controller you are testing), try the following.&lt;/p&gt;</description></item><item><title>Varnish cache purging from dynamically instantiated EC2 instances behind a ELB using HTTP header based authentication</title><link>https://www.yasithfernando.com/blog/blog-post-varnish-cache-purging-from-dynamically-instantiated-ec2-instances-behind-a-elb-using-http-header-based-authentication/</link><pubDate>Thu, 06 Nov 2014 12:01:37 +0000</pubDate><guid>https://www.yasithfernando.com/blog/blog-post-varnish-cache-purging-from-dynamically-instantiated-ec2-instances-behind-a-elb-using-http-header-based-authentication/</guid><description>&lt;p&gt;We use a Varnish cache server to do basic page caching for our Rails apps. The application instances are automatically instantiated by a ASG(auto scale group) and all these instances sit behind a ELB. Usually Varnish cache purge requests are only allowed from a few white listed IPs.&lt;/p&gt;
&lt;p&gt;Like bellow:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;acl purge &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;localhost&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;192.168.55.0&amp;#34;&lt;/span&gt;/24&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sub vcl_recv &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# allow PURGE from localhost and 192.168.55... &lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;req.method &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;PURGE&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;!client.ip ~ purge&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;synth&lt;span class="o"&gt;(&lt;/span&gt;405,&lt;span class="s2"&gt;&amp;#34;Not allowed.&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;purge&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However, because an ELB doesn’t have a static IP (it changes with time, depending on various factors) and also because our application instances themselves are dynamically instantiated and have no static IPs associated with them, we can’t simply use a white list to allow PURGE requests from our app servers.&lt;/p&gt;</description></item><item><title>npm ERR! cb() never called! (on npm 1.4~)</title><link>https://www.yasithfernando.com/blog/npm-err-cb-never-called-on-npm-1-4/</link><pubDate>Wed, 29 Oct 2014 11:02:45 +0000</pubDate><guid>https://www.yasithfernando.com/blog/npm-err-cb-never-called-on-npm-1-4/</guid><description>&lt;p&gt;If you are getting the bellow error on a recent version npm (1.4~)&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;npm ERR! cb&lt;span class="o"&gt;()&lt;/span&gt; never called!
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;npm ERR! not ok code &lt;span class="m"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Chances are you are facing this issue:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;npm shrinkwrap install - npm ERR! cb() never called! (Linux / OS X)&lt;/strong&gt; &lt;a href="https://github.com/npm/npm/issues/5920"&gt;https://github.com/npm/npm/issues/5920&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Unfortunently there is no fix avialable as of yet (29th Oct 2014). The only solution seems to be rolling back to a old version of npm unaffected by the bug.&lt;/p&gt;</description></item><item><title>Set Ansible Variables from the Command Line</title><link>https://www.yasithfernando.com/blog/set-ansible-variables-from-the-command-line/</link><pubDate>Fri, 24 Oct 2014 17:06:10 +0000</pubDate><guid>https://www.yasithfernando.com/blog/set-ansible-variables-from-the-command-line/</guid><description>&lt;p&gt;If you ever wanted pass in &amp;lsquo;parameters&amp;rsquo; to your Ansible playbooks via the command line when you are running the playbook through ansible-playbook here is the way to do it.&lt;/p&gt;
&lt;p&gt;Command line&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ansible-playbook --extra-vars &lt;span class="s1"&gt;&amp;#39;{&amp;#34;NODE_ENV&amp;#34;:&amp;#34;staging&amp;#34;,&amp;#34;GIT_BRANCH&amp;#34;:&amp;#34;develop&amp;#34;}&amp;#39;&lt;/span&gt; playbook.yml
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;or the shorter version (thanks mpdehaan)&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ansible-playbook &lt;span class="s2"&gt;&amp;#34;-e &amp;#39;NODE_ENV=staging GIT_BRANCH=develop&amp;#39;&amp;#34;&lt;/span&gt; playbook.yml
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here you are setting NODE_ENV and GIT_BRANCH variables (if it wasn&amp;rsquo;t obvious).&lt;/p&gt;
&lt;p&gt;Now inside your playbook you will have something like the following&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-yml" data-lang="yml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;- &lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;Node apps deploy&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;all&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;gather_facts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;no&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;vars&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;git_branch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;{{ GIT_BRANCH|default(&amp;#39;develop&amp;#39;) }}&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;node_env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;{{ NODE_ENV|default(&amp;#39;staging&amp;#39;) }}&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="l"&gt;command echo &amp;#34;{{ node_env }}&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="l"&gt;command echo &amp;#34;{{ git_branch }}&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s about it.&lt;/p&gt;</description></item><item><title>Setting up Centralized Logging to S3 with logrotated</title><link>https://www.yasithfernando.com/blog/setting-up-centralized-logging-to-s3-with-logrotated/</link><pubDate>Wed, 27 Aug 2014 17:24:11 +0000</pubDate><guid>https://www.yasithfernando.com/blog/setting-up-centralized-logging-to-s3-with-logrotated/</guid><description>&lt;h3 id="what-we-are-trying-to-do-here"&gt;What we are trying to do here&lt;/h3&gt;
&lt;p&gt;Get all logs to be backup to S3 whenever logrotated runs or whenever the machine is shutdown/restarted (so that if you have AWS auto scaling enabled, you won&amp;rsquo;t loose any logs).&lt;/p&gt;
&lt;h3 id="basic-steps"&gt;Basic Steps&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Install s3cmd&lt;/li&gt;
&lt;li&gt;Setup a script to upload logs to S3 (that&amp;rsquo;ll be called via logrotated)&lt;/li&gt;
&lt;li&gt;Setup a init.d script to run logrotated -f (forced) on shutdown/restart&lt;/li&gt;
&lt;li&gt;Setup logrotated scripts to call your S3 upload script&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="install-s3cmd"&gt;Install s3cmd&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt-get install s3cmd
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;setup s3cmd by running&lt;/p&gt;</description></item><item><title>Using Varnish (v4) as a reverse proxy cache with Rails</title><link>https://www.yasithfernando.com/blog/using-varnish-v4-as-a-reverse-proxy-cache-with-rails/</link><pubDate>Fri, 22 Aug 2014 14:26:08 +0000</pubDate><guid>https://www.yasithfernando.com/blog/using-varnish-v4-as-a-reverse-proxy-cache-with-rails/</guid><description>&lt;h2 id="setting-up-varnish"&gt;Setting up Varnish&lt;/h2&gt;
&lt;p&gt;You can install varnish by following the official installation guide (this one is for Ubuntu, but you can find a official guide that supports your OS) at: &lt;a href="https://www.varnish-cache.org/installation/ubuntu"&gt;https://www.varnish-cache.org/installation/ubuntu&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Make sure to edit /etc/default/varnish and change DEAMON_OPTS so that varnish listens on port 80&lt;/p&gt;
&lt;p&gt;&lt;em&gt;/etc/default/varnish&lt;/em&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;DAEMON_OPTS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;-a :80 \
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; -T localhost:6082 \
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; -f /etc/varnish/default.vcl \
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; -S /etc/varnish/secret \
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; -s malloc,256m&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="caching-only-selected-requests-white-listing-what-to-be-cached"&gt;Caching only selected requests (white listing what to be cached)&lt;/h2&gt;
&lt;p&gt;The following code will ensure that Varnish will only cache whatever that matches the filters define. Everything else will be passed to the backend.&lt;/p&gt;</description></item><item><title>Using MongoDB 2.6 with TravisCI Builds</title><link>https://www.yasithfernando.com/blog/use-mongodb-2-6-with-travisci-builds/</link><pubDate>Fri, 11 Jul 2014 10:50:03 +0000</pubDate><guid>https://www.yasithfernando.com/blog/use-mongodb-2-6-with-travisci-builds/</guid><description>&lt;p&gt;At the time of writing this post TravisCI uses mongodb 2.4 (when you put in mongodb under services in .travis.yml) and does not support the new version 2.6 ‘out of the box’. However, if you do need 2.6 for your code to run properly you could easily install it your self. You can add the following to your before_install (in .travis.yml) to do that.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;.travis.yml&lt;/em&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-yml" data-lang="yml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;before_install&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="s2"&gt;&amp;#34;sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="s2"&gt;&amp;#34;echo &amp;#39;deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen&amp;#39; | sudo tee /etc/apt/sources.list.d/mongodb.list&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="s2"&gt;&amp;#34;sudo apt-get update&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="l"&gt;&amp;#34;sudo apt-get install mongodb-org-server”&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;References
&lt;a href="https://github.com/travis-ci/travis-ci/issues/2246"&gt;https://github.com/travis-ci/travis-ci/issues/2246&lt;/a&gt;
&lt;a href="https://github.com/kraih/mango/blob/master/.travis.yml"&gt;https://github.com/kraih/mango/blob/master/.travis.yml&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Configuring TravisCI and Coveralls for a node.js project</title><link>https://www.yasithfernando.com/blog/configuring-travisci-and-coveralls-for-a-node-js-project/</link><pubDate>Fri, 30 May 2014 10:47:58 +0000</pubDate><guid>https://www.yasithfernando.com/blog/configuring-travisci-and-coveralls-for-a-node-js-project/</guid><description>&lt;p&gt;First include your coveralls token in.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;.coveralls.yml&lt;/em&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-yml" data-lang="yml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;service_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;travis-pro&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;repo_token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;your_token&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We were already using &lt;a href="https://www.npmjs.org/package/mocha"&gt;mocha&lt;/a&gt;. And to get the coverage data I’ve added &lt;a href="https://www.npmjs.org/package/istanbul"&gt;istanbul&lt;/a&gt; plus the &lt;a href="https://www.npmjs.org/package/coveralls"&gt;coveralls&lt;/a&gt; module for actually submitting that data to coveralls.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;package.json&lt;/em&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;&amp;#34;devDependencies&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;mocha&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;~1.19.0&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;istanbul&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;^0.2.10&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;coveralls&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;^2.10.0&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;Makefile&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In the Makefile, I’ve added a build step called test-coveralls&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;test-coveralls:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; @NODE_ENV&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt; ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha */test/*.js --report lcovonly -- -R spec -t &lt;span class="m"&gt;30000&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Which, when run will generate coverage data and save it in&lt;/p&gt;</description></item><item><title>Solving 'Rails bug': 3.0.20: UTF8-encoded JSON request params result in Encoding::CompatibilityError</title><link>https://www.yasithfernando.com/blog/solving-rails-bug-3-0-20-utf8-encoded-json-request-params-result-in-encodingcompatibilityerror/</link><pubDate>Fri, 16 May 2014 13:35:44 +0000</pubDate><guid>https://www.yasithfernando.com/blog/solving-rails-bug-3-0-20-utf8-encoded-json-request-params-result-in-encodingcompatibilityerror/</guid><description>&lt;p&gt;So I ran acrross a bug: 3.0.20: UTF8-encoded JSON request params result in Encoding::CompatibilityError (&lt;a href="https://github.com/rails/rails/issues/9136("&gt;https://github.com/rails/rails/issues/9136(&lt;/a&gt; in Rails 3.0.20. Which is no longer supported. And ended up writing the Rack middlewear listed below as a &amp;lsquo;fix&amp;rsquo;.&lt;/p&gt;
&lt;p&gt;My code is heavily inspired by this post here by Pivotal Labs: Sanitizing POST params with custom Rack middleware (&lt;a href="http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/"&gt;http://pivotallabs.com/sanitizing-post-params-with-custom-rack-middleware/&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Rack Middlewear for force_encoding request bodies to UTF-8&lt;/p&gt;
&lt;h3 id="jsonscrubber"&gt;JSONScrubber&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ruby" data-lang="ruby"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# config/initializers/json_scrubber.rb&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;uri&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;JSONScrubber&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="vi"&gt;@app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="vi"&gt;@routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:routes&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;scrub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="vi"&gt;@app&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kp"&gt;private&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;scrub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="vi"&gt;@routes&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;include?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;PATH_INFO&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;rack_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;force_encoding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Encoding&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;UTF_8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;StringIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rack_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;ensure&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;rewind&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;middleware&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;insert_before&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;JSONScrubber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;/api/some_action_here.json&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="jsonscrubberspec"&gt;JSONScrubberSpec&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ruby" data-lang="ruby"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# json_scrubber_spec.rb&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# encoding: UTF-8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;spec_helper&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;JSONScrubber&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;let&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;app&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="ss"&gt;:middleware&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="no"&gt;JSONScrubber&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;/api/some_action_here.json&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;converts non UTF-8 (ASCII-8BIT) encoded response bodies (with special characters) to UTF-8 encoded response bodies&amp;#39;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;http://app.abcapp.com.au/api/some_action_here.json&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;request_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;set_input_and_call&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;ASCII-8BIT&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_array&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_array&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;UTF-8&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;process UTF-8 encoded response bodies (with special characters) without issue&amp;#39;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;http://app.abcapp.com.au/api/some_action_here.json&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;request_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;set_input_and_call&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;UTF-8&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_array&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_array&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;UTF-8&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;will only modify requests who&amp;#39;s paths match the given path options&amp;#34;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;http://app.abcapp.com.au/api/dont_touch_me.json&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;request_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;set_input_and_call&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;ASCII-8BIT&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_array&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_array&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;ASCII-8BIT&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;env_for&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="no"&gt;Rack&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MockRequest&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;set_input_and_call&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;rack_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%q(&amp;#34;{&amp;#34;data&amp;#34;:{&amp;#34;name&amp;#34;:&amp;#34;Name ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ☎ ❄ ♫ ✂ ▷ ✇ ♎ ⇧ ☮ ♻ ⌘ ⌛ ☘&amp;#34;,&amp;#34;email&amp;#34;:&amp;#34;email@gmail.com&amp;#34;,&amp;#34;org&amp;#34;:&amp;#34;Sch☂ ☻ool&amp;#34;,&amp;#34;day&amp;#34;:&amp;#34;Teacher&amp;#34;}}&amp;#34;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;StringIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rack_input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;force_encoding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;rack.input&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;rewind&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;middleware&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This should force_encode all request bodies to UTF-8. So if they happen to have any special unicode characters it won&amp;rsquo;t break your code.&lt;/p&gt;</description></item><item><title>Ruby Time.parse, Time. strptime and Time zones</title><link>https://www.yasithfernando.com/blog/ruby-time-parse-time-strptime-and-time-zones/</link><pubDate>Wed, 14 May 2014 14:40:32 +0000</pubDate><guid>https://www.yasithfernando.com/blog/ruby-time-parse-time-strptime-and-time-zones/</guid><description>&lt;p&gt;This is a note to myself. So it might not be entirly useful to other folks.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: my system&amp;rsquo;s time zone is set to +1000 Brisbane time.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Recently I stumbled accross a bug in our code base where, Time.parse was used (incorrectly) to create a Time object from a string. Time and specially Time.zone related stuff tend to be very complicated and is quite easy to misunderstand.&lt;/p&gt;
&lt;p&gt;The whole codebase was full of lines of code like the following:&lt;/p&gt;</description></item><item><title>Installing gems with native extensions on TravisCI</title><link>https://www.yasithfernando.com/blog/installing-gems-with-native-extensions-on-travisci/</link><pubDate>Tue, 13 May 2014 10:32:40 +0000</pubDate><guid>https://www.yasithfernando.com/blog/installing-gems-with-native-extensions-on-travisci/</guid><description>&lt;p&gt;I was mucking around with TravisCI recently. And when I was setting up a Rails project with travis. I hit a wall trying to get a ruby gem (&lt;a href="https://github.com/da4nik/geoip2"&gt;https://github.com/da4nik/geoip2&lt;/a&gt;) with a native extention (&lt;a href="https://github.com/maxmind/libmaxminddb"&gt;https://github.com/maxmind/libmaxminddb&lt;/a&gt;) to get to install on travis.&lt;/p&gt;
&lt;p&gt;Thanks to GeoIP2-python (&lt;a href="https://github.com/maxmind/GeoIP2-python/blob/master/.travis.yml)'s"&gt;https://github.com/maxmind/GeoIP2-python/blob/master/.travis.yml)'s&lt;/a&gt; travis.yml I figured out how to solve the issue.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s pretty straight forward really. Travis builds your project on a Ubuntu machine on cloud. So you&amp;rsquo;d install anything on it just as you would on a Ubuntu box.&lt;/p&gt;</description></item><item><title>virt-resize --shrink : Resizing a KVM VM Storage Image (which is a LVM partition)</title><link>https://www.yasithfernando.com/blog/resizing-kvm-vm-storage-image-lvm-virt-resize-shrink/</link><pubDate>Sun, 13 Apr 2014 17:25:32 +0000</pubDate><guid>https://www.yasithfernando.com/blog/resizing-kvm-vm-storage-image-lvm-virt-resize-shrink/</guid><description>&lt;p&gt;I had to do some work relating to kvm last week. Including resizing (shrinking) a existing VM and then making a clone of it. I had to do a fair bit of googling and tinkering around to figure out how this can be done. Below is a summary of what I ended up doing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;
The fact that the storage images of the VMs were infact LVM partitions played a part in how I had to go about doing the resizing. In retrospect, if LVM was out of the picture (and the if the images were just files) things would have been much easier. Of course this does not mean that LVM + KVM is a bad thing. It makes things a little bit more complicated though.&lt;/p&gt;</description></item><item><title>Renting a room in Australia</title><link>https://www.yasithfernando.com/blog/finding-accommodation-in-queensland-australia/</link><pubDate>Tue, 22 Apr 2014 22:25:17 +0000</pubDate><guid>https://www.yasithfernando.com/blog/finding-accommodation-in-queensland-australia/</guid><description>&lt;p&gt;I recently moved to Gold Coast, Queensland, Australia. Finding accommodation seemed a bit daunting at first. I was looking to a rent a room, or shared accommodation in other words. If you are in the same situation the following information should make things a bit easier for you.&lt;/p&gt;
&lt;p&gt;And of course most of the information bellow is not Queensland specific.&lt;/p&gt;
&lt;h2 id="sites"&gt;Sites&lt;/h2&gt;
&lt;p&gt;Best sites to find rooms for rent (housemates, flatmates, house share&amp;hellip;etc)&lt;/p&gt;</description></item><item><title>How I went about finding a new programming Job</title><link>https://www.yasithfernando.com/blog/how-i-went-about-finding-a-new-programming-job/</link><pubDate>Tue, 01 Apr 2014 16:42:54 +0000</pubDate><guid>https://www.yasithfernando.com/blog/how-i-went-about-finding-a-new-programming-job/</guid><description>&lt;p&gt;&lt;em&gt;Disclaimer:&lt;/em&gt; As the title mention these are the things that I did when finding a job. It may or may not apply to you. Depending on your background as a candidate and your preferences when finding a job. This information might also be location/role/tech…etc specific.&lt;/p&gt;
&lt;p&gt;And if you are a rockstar developer, you won’t need any of this. You can join pretty much any startup you fancy. And the odds are you already have a zillion people spamming you with job offers. But if you are not, this might help you.&lt;/p&gt;</description></item><item><title>Blogging from a mobile</title><link>https://www.yasithfernando.com/blog/blogging-from-a-mobile/</link><pubDate>Fri, 17 Jan 2014 23:38:27 +0000</pubDate><guid>https://www.yasithfernando.com/blog/blogging-from-a-mobile/</guid><description>&lt;p&gt;So I am now typing this post from my iPhone. And I kind of miss auto-correct. typing a post with the mobile keyboard is not as smooth as doing the same with a desktop. however, it&amp;rsquo;s quite possible. Ghost seems to be emulating a text field in the browser. as in I am typing this post in a none native text field. So this is the reason that I miss some of the features that I&amp;rsquo;ve come to expect from a mobile keyboard. Including but not limited to auto capitalization of letters, spelling correction and auto completion of words. I had a lot of trouble selecting the text box to start editing it aswell. And this is my biggest complain so far. Other than that I think this works fine. Certianly a step in the right direction.&lt;/p&gt;</description></item><item><title>Starting off with Ghost</title><link>https://www.yasithfernando.com/blog/starting-off-with-ghost/</link><pubDate>Fri, 17 Jan 2014 23:17:27 +0000</pubDate><guid>https://www.yasithfernando.com/blog/starting-off-with-ghost/</guid><description>&lt;p&gt;So I finally brought in to the Dighital Ocean hype and brought a server at 5 USD/month (thats cheap!). And now that I have a server sitting idel, what do I do with it? Setup a VPN server of course! But once I finished with that I wanted to try out Ghost. The latest blogging platform running on node.js.&lt;/p&gt;
&lt;p&gt;Setting it up was a breez although, I did hit a few road blocks along the way. I set it up with nginx, everyone&amp;rsquo;s favorite web server. I was then asked to sign up for an admin account, which I did. And I was ready to go!&lt;/p&gt;</description></item><item><title>About</title><link>https://www.yasithfernando.com/about/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/about/</guid><description>&lt;p&gt;Hello! 👋 I&amp;rsquo;m Yasith (ya-sith), a software engineer based in Melbourne, Australia. I love building things and experiementing with all the shiny new AI toys.&lt;/p&gt;
&lt;h2 id="connect-with-me"&gt;Connect With Me&lt;/h2&gt;
&lt;p&gt;Feel free to reach out or connect with me on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/yasith/"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://x.com/meaningful"&gt;X (Twitter)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/thekindofme"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thanks for visiting!&lt;/p&gt;</description></item><item><title>Projects</title><link>https://www.yasithfernando.com/projects/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://www.yasithfernando.com/projects/</guid><description>Apps and side projects I have built.</description></item></channel></rss>