Michael de Silva's Blog

Software Engineer. Rubyist and Roboticist.

Michael de Silva's Blog

Software Engineer. Rubyist and Roboticist.

Got an app in mind?

Since 2010, I have crafted apps for mobile and web for clients around the world via my consultancy — Inertialbox. My specialities include Rails, client-side Javascript frameworks such as Backbone & Ember.js, TDD/BDD, and DevOps — just to name a few.

We should talk.

Cookies and Session Management in NodeJS

Here's a snippet from a recent NodeJS app with Express

app.use(cookieParser());

...

var session_secret = process.env.SESSION_SECRET;
app.use(session({
  secret: session_secret,
  store: new RedisStore({
    port: 6379
  }),
  resave: true,
  saveUninitialized: true
}));

/**
 * Load current user from session.
 */
app.use(function (req, res, next) {
  req.user = req.session.user;

  /**
   * Help troubleshoot cookies
   */
  // if (app.get('env') === 'development') {
  //   console.log('Session ID: ', req.sessionID);
  //   console.log('Cookies: ', req.cookies);
  //   console.log(req.session.cookie);
  // }

  // if (app.get('env') === 'development') {
  //   console.log('Logged in user set as ', req.user);
  // }

  return next();
});

Uncommenting the troubleshooting middleware, yields the following debug info. Notice how the session ID is stored by way as part of the cookie sid. The [format used is `[sid].[signa ...(continued)

Rapid Learning: Google App Engine (GAE) Cloud Apps (in Python)

I like to look at new technologies (at least new to me, in the sense that I haven't tinkered with something directly or long enough — and long enough usually equates to at least one to two years) and YouTube is a fantastic resource, especially channels such as the excellent Google Chrome Developers.

This is a very short series where Paul Lewis provides a walk through on how he goes about to build the Chrome Dev Summit site — what's great is this is full of great advances such as Service Workers a la Polymer and so many other fun stuff.

What's interesting though, is there are some valuable frontend juju that Paul uses, that I haven't seen (or thought of!) before, especially some fantastic use of SVG and clip-path.

For the purposes of this blog post, and for my initial poking about, and given that I haven't had ti ...(continued)

Extending nvie's Successful Git Branching Model

Recently I've been working on a project where certain devs are not privvy to client-specific details, and this aspect has lead to a rather interesting build workflow.

As such, devs are only able to build debug specific Android releases, and release type releases for debugging purposes. However, actual release-builds require certain changes to the specific app Gradle config, and this is why I am maintaining a dedicated release branch alongside dev. It should be noted, that the release branch was infact a fork of dev.

This workflow is based on the excellent Successful Git branching Model by nvie and cutting a release has a couple extra steps.

-> % git co dev
-> % git co -b release-0.1.7
Switched to a new branch 'release-0.1.7'

-> % mvim CHANGELOG.md

-> % git st
## release-0.1.7
M  CHANGELOG.md
M  MyApp/app/build.gradle

-> % git c "Bump version for release"
[release-0.1.7 0 ...(continued)

Instrumenting Android UI with Espresso and AndroidJUnitRunner

August 2016, and I cannot believe the number of hoops I had to jump through, and several hours of Googling just to be able to Setup Espresso in Android Studio.

The bit that I needed was to perform a certain exclusion,

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2')
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support:support-annotations:24.2.0'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
    exclude group: 'com.android.support', module: 'support-v4'
}

Works great with an API 23 app I'm working on for a client. Just make sure that you add testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" into your app/build.gradle's defaultConfig block.

First CryptedIoT Dev Boards (PCBs)

The very first boards have arrived and they are looking rather purdy...

Looking to the Future

Some may wonder as to the drastic drop in blog posts over the past couple months but it's due to my being far more engaged with both work, family, and life in general.

I've been able to take time out from my work as a Consultant and spent a glorious get away at Peace Haven Anantara in Tangalle, Sri Lanka (second time around) availing all the delights of both private butler service and our very own private villa and plunge pool as well as spending around 3-nights at the newly opened Shangri-La resort in Hambantota, as well as catching up with family visiting us from Switzerland.

This time has allowed me to reflect on my past achievements, strengths and weaknesses, areas for improvement and generally where I want to take my career over the next 10 years. It's similar to how in most interviews, you get tossed that eventual question of "Where do you see yourself in the next 10-years?" — well that is what I've been asking myself as well.

My work with global brands s ...(continued)

Why Constant Learners All Embrace the 5-Hour Rule

Benjamin Franklin did this one hour a day, 5 hours a week. Why you should do it too.

At the age of 10, Benjamin Franklin left formal schooling to become an apprentice to his father. As a teenager, he showed no particular talent or aptitude aside from his love of books.

When he died a little over half a century later, he was America's most respected statesman, its most famous inventor, a prolific author, and a successful entrepreneur.

What happened between these two points to cause such a meteoric rise?

Underlying the answer to this question is a success strategy for life that we can all use, and increasingly must use.

The 5-Hour Rule 

Throughout Ben Franklin's adult life, he consistently invested roughly an hour a day in deliberate learning. I call this Franklin's 5-hour rule; 1 hour a day on every weekday.

Franklin's learning time consisted of:

  • Waking up early to read and write.
  • [Setting personal growth goals](h ...(continued)

CAP and Concurrency with Multiple Worker Processes

Anyone who's played with distributed systems knows the kind of pain one would end up with. There's mutex/transaction locking, pessimistic locking, and then there's the joy of dealing with multiple concurrent workers, running jobs asynchronously

Having played with Searchkick I stumbled on an interesting discussiong on race conditions which ultimately led me to 'Preventing Race Conditions With Fencing Tokens In Rails'.

And if you haven't heard of it before, this falls under CAP theorem.

Thankfully a friend of mine was to the rescue regarding a particular usecase of mine with,

Multiple workers can't get into a split-brain if they're all talking t ...(continued)

You can get US$200 for FREE from Amazon. Cold hard cash.

Here's how you can make some free cash, if you're living in the US.

First, go order an Amazon Fire TV Stick for $39.99 (use free shipping of course!). Now, order 2x units of Amazon Echo Dot = $179.99 outlay.

Sell it sealed on eBay as an auction - look at the past auctions. These go for $160-190 each!

You're set to basically make ~$120 or more if you keep the Fire stick. Otherwise, you can turn a profit of $160-$200 quite easily. Just return that Fire stick.

Using BrowserSync and Gulp with the Rails Asset Pipeline

I have detailed this approach in a simple gist which allows you to run BrowserSync along side a Rails app and its asset pipeline quite nicely — I have tested with a Rails 5 app that I'm currently working on for a client.

A while back I created a Yeoman Foundation Generator that included BrowserSync and getting a similar work-flow for Rails has been on my TODO list. For the longest time, I've relied on Rack::LiveReload and guard-livereload, which has its downsides — as CSS injection doesn't always work, and the browser takes a while reloading.

You simply need to add in the gulpfile.js as detailed below and make sure you install dependencies via npm install -g npm and npm install --save-dev gulp browser-sync. If you're already injecting Rack::LiveReload into your app middleware, stop doing that and you'll be set!

<script ...(continued)

Post Archive