Sohan's Blog

Living the Developer's Life

Rails: Please Include a JS Test Runner

For an opinionated framework like Ruby on Rails, I expect it to come pre-bundled with a CoffeeScript based test framework and test runner. Here’s why:

  • Teams don’t need to waste time deciding which one to use among the mess of Jasmine, Mocha, Expect, Sinon, Chai, Bower, Grunt, Teaspoon, Npm… you name it.

  • It’d work better than what’s out there since the Rails team will focus on clean integration with Rails and will have a much larger user base to collect contribution from.

I’d prefer Jasmine to be the test framework and a runner similar to teaspoon that can run the specs both on the command line and on the browser, with asset pipelines enabled.

Rails made a huge promise to test automation by shipping with a nicely structured way to test the ruby code and doing the same for JS would make life better for so many people like me, I believe.

You Can Haz Automated REST API Documentation

Let’s face it, the manual process of documenting REST APIs sucks big time. The process goes like this:

  1. Craft a cURL request for an API Endpoint.
  2. Copy the response.
  3. Narrate the API, paste the cURL and response on an editor.
  4. Edit the response, describe necessary request and response headers, query parameters etc.
  5. Repeat steps 1-4 for each of your tens of Endpoints.
  6. Publish the documentation on the web.
  7. Repeat these steps for each release.

This is a laborious process. However, it doesn’t have to be this way. Meet SpyREST to see how it produces purely organic, automated, replayable, published, version aware and customizable API Documentation for you.

This is how it works:

  1. You script the API calls using any scripting you prefer, including bash/cURL, automated test frameworks, etc. For example, using a test framework:
1
2
3
4
5
6
7
describe 'gists' do
  it "List a user's gists since a time:" do
    response = Github.get '/users/smsohan/gists?since=20140101T00:00:00Z', @common_options
    assert_equal 200, response.code
    refute_nil response.body
  end
end
  1. Use the SpyREST http proxy http://SpyREST.com:9081 to perform this call on a real API.
  2. You get the same response, and SpyREST produces a fully baked API documentation as you see here:

Try here if you want to see for yourself:

1
curl -k -x "http://spyrest.com:9081" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/users/YOUR_GITHUB_USER_NAME/gists"

See the documentation at

http://spyrest.com/api_resources/gists?api_host=api.github.com&api_version=v3

Drop me a line if you’d like to use this to publish your API documentations.

2015

This is a much shorter new year post. 2014 was the year of focusing on health, soft-skills, Haskell, social contribution and PhD in addition to typical everyday stuff. Hoping 2015 will be the year of:

reconnecting with friends and relatives

perfection

While Facebook and Twitter make it easy to browse through my friends’ photos and status updates, I feel quite reluctant to interact on these media. Also, this passive mode of keeping in touch sucks, since my friends are largely unaware of the fact that I still care. So, 2015 will be the year when I regularly call people, and talk to them on the phone/skype/in person.

Perfection. On most occasions I’m happy if something I tried yielded just enough. 2015, I’ll strive for perfection beyond just enough.

Wishing everyone a joyful 2015, Happy new year.

Lessons Learned: Entrepreneurship and Innovation Course

This fall semester, I signed for the Entrepreneurship and Innovation course (ENTI 781) at the Haskyne Business School of University of Calgary. Wanted to capture my thoughts on this course for my readers here.

First, the course was unconventional since there are very little academic material to teach entrepreneurship and innovation. The teacher, Olga Petricevic, did a decent job of collecting materials comprising of academic papers, case studies, newspaper articles and YouTube videos as well as bringing in a local entrepreneur for a lecture one day. But none of these were the highlights for me.

The course had a few assignments and I liked a couple to be specific. In one assignment, the students were asked to find a project in Indigogo or Kickstarter to put their own money. This was eyeopening, as I had hard time finding a project that looked to have any potential to become a successful venture. Moreover, even if I liked it, there were almost no incentive to “donate” your money since all you got was a token for your money in a way that you bear the risk without any potential for a profit.

The other assignment was about compiling a list of 50 things that bug me in everyday life. This was the most fun assignment of the semester and I had a decent list with bugs such as:

1. Did I leave the stove on while leaving the house?
2. Vacuum cleaning the stairs.
3. Finding a plumber NOW.
4. Waiting at airport.
...

All in all, the worst assignment was the group assignment. The group I worked with was very collaborative and did a great job in keeping everyone in sync with clear messaging around individual expectations. However, the project itself sucked. We were asked to create a stupid business plan for a venture around “watervate” - innovative solution to save water that could turn into a profitable business. In an entrepreneurship course, the deliverable was a business plan, with detailed text on the product, marketing, strategy, financial data etc. that were completely fake. The fakeness of the whole assignment made it super boring for me.

After finishing this course, I actually have a better trust in online education. The course was unplugged, so students had to keep digital devices off. But on one class the rules were lax because it was about presenting. I saw people browsing sports scores, watching memes, playing games and random youtube videos etc. right in the class. These students are mostly MBA students, holding a good day job, but it hurt my eyes to see them paying so little respect to the fellow students presenting.

Online education on the other hand, is so much so for self driven students that, I expect them to carry much respect for their own time. I suggest people taking online courses to save their money and time and also to learn better than traditional classroom settings.

What’s Wrong With the Default Alert Rendered by the Browser?

Browsers have carefully crafted the alert and confirm dialogs for everyone under really simple APIs as follows:

1
2
alert('Failed to send the email. Check your network connection.');
confirm('Are you sure you want to delete this email?');

While writing cross-browser JavaScript is not as painful today, custom implementation of these natively supported dialogs seem to be a complete waste of money and time to me. With all the different browsers that we have to support today, including the mobile browsers, it seems a lot of wasted effort in trying to render a custom alert and confirm dialog under any circumstance. I’ve never implemented one, but if you ever attempted, you probably know how much work it is to get it right and consistent. Here’s a short list of requirements if you want to build one:

  1. Should work on all browsers.
  2. Needs to disable all other controls on the website.
  3. Needs to be on the view port so the user can take an action immediately.
  4. Should not leak any memory if used repeatedly on a single screen.
  5. Should be fast.

While I’ve seen some magicians to make these requirements look silly and do a decent job of implementing a custom version of the alert and confirm dialogs, I’m yet to see one that satisfies all the above essential requirements, and does a better job than the browser’s native implementations. If you haven’t looked recently, see the current rendering of the confirm dialogs across different browsers:

Safari Chrome FireFox iPhone

If you look carefully, you’ll see subtle things. For example, did you notice the nice shadows around the confirm dialogs rendered on Chrome and Safari? There are live effects on the cancel and ok buttons as well, where you’ll see a little shining effect on the ok button. These are carefully crafted buttons. The Cancel and OK button are perfectly sized for fat fingers on the iOS safari. Also, these are familiar to the users, so they immediately know what they are clicking on. Keyboard navigation works as expected. And lastly. the buttons will change labels based on your preferred language settings. All for free. Now, try to replicate that on your custom control, across all these browsers and show me how it does any better.

If your sole business is indeed building these custom dialogs, you can probably invest the time and money here. But as far as I’m concerned, I’d not put a single $ from my pocket if I was funding a project to either build such custom implementations or using your custom implementation. I’m aware of the fact that, even if it’s free and open source, it still requires additional maintenance dollars.

As a user of web, I’ve never been bothered by the websites that show me these familiar browser rendered alerts and confirms. Were you?

100 Miles, a 100 Miles…

So, on the 18th of October, 2014, I’ve completed my goal of running a 100 miles in 50 days and wanted to share some data for my readers. Enjoy!

50 Miles!

In my previous post about the 100 Miles Challenge, I shared my goal to complete a 100 mile run in 50 days. And I’m happy to reach the 50 Miles milestone on day 24, happened this Saturday! 46 Miles to go now, but the target sure looks reachable from here.

I changed a few things on my end. After running for the first couple of weeks, I found my legs weren’t feeling great. So, I decided to swap 700 metres of swimming as a replacement for 2 miles of running on some days. It takes me about 20 minutes to complete the 700 metres swim, and as a bonus, I get to take Shopoth for a swim lesson. So far, I’ve been going to Crowfoot YMCA for swimming, which is a nice 15 min walk from my home, or just a 3 minute drive. And they have open lanes pretty much any time of the day, making it quite convenient.

About running, I’m following a stepped pattern of speed on the trademill as shown in the following graph:

This pattern helps me since I can slow down to catch a breathe and then get back to speed, allowing the whole 2M run to finish under 20 minutes.

So far the act of running and swimming without a partner is not feeling weird anymore. Still early to declare victory, but I’ m genuinely feeling really excited internally. Will report back once I’m done with my 100 miles, hopefully in the next 3 weeks time.

A few people showed some interest in participating in the 100 miles challenge, including Mo Khan, and I’m hoping to see some adoption in the near future. Even if that doesn’t happen, thank you for wishing me good luck. Insipiration matters, both intrinsic and extrinsic.

On Keeping Things Simple

Software architecture, or any design for that matter, needs to strike a fine balance between simplicity and power. Sometimes, the design needs to deliberately remove elements that’d make life better in some way but also cause a lot of frictions in other ways, ways that may not really impact the designer.

A few examples to explain this. Client side MVC frameworks on top of a server side MVC framework. Client side URL routing on top of server side URL routing. Persisting data in many different databases.

All these examples have one common theme: they offer some value in exchange of additional complexity, often time the complexity grows with time as future developments happen, eventually costing more than the value gained.

Monolith vs Microservices

Microservices are talk of the town these days. I wanted to share my thoughts on microservices based on some experiments that we are running into at our current project.

minons

SOURCE: https://www.flickr.com/photos/31366276@N03/9327275207/in/photostream/

Recently, we deployed a microservice for two-step verification feature on one of our projects. This was a strict business requirement, because having a separate server to store your 2nd-factor authorization provides additional security in case the servers hosting your primary factor are compromised.

We operate on a cloud environment, so spinning up new servers is a simple process. The source code for this whole Ruby on Rails based two-step verification service is no more than a couple hundred lines. So, in theory, it should be very easy to deploy such a service. However, it proved to be a lot of work in the end.

For example, to deploy this service, we actually had to spin a few servers for each of our staging and production environments. They also had to be load balanced for obvious reasons. They needed their own database for the business requirements, which also needed automated periodic backups. Networking and VPN related configurations as well as DNS configurations were also required. Monitoring tools had to be configured so we can get alerts in case things were about to fail. Deployment scripts had to be written for this service as well.

All in all, I’d say it took 20x the time to deploy this microservice than writing the code for it.

Really. No kidding.

Since it has been deployed, we didn’t ship changes as often to this service compared to our main project. This is what I find to be the primary benefit of this approach, since it doesn’t require as big a regression test during our releases.

However, when things go wrong, our debug efforts are harder since more infrastructural pieces are involved. Considering the additional work required and the value gain, I’m really not sure if microservices provide any real ROI.

The additional complexity of dealing with many servers as opposed to a larger app may or may not be worth it. I agree with Martin Fowler on the prerequisites of microservices. Unless, you have streamlined an automated way to provision new servers with all required parts, it may actually be best for you to keep working on the monolith. It’s not the end of the world, and you’ll have more time to spend with the family!

100 Miles in 50 Days Challenge

Weightloss is a tough chase. I’ve attempted many times and failed.

5K Run

Here’s a photo of day 2, when I ran my first 5K in years.

Last year I decided to change the focus. Instead of aiming for weightloss, I started aiming for a better lifestyle. To some extent, that worked. But I can’t say it really made a big difference of any sort.

I always thought I was a team sport person and hated doing anything only by myself, so much so that, I need a partner even for swimming. After an introspection, I realized that, this is not gonna work, and things needed to change if I really wanted a better lifestyle.

In came the Treadmill. A second hand, barely used, Livestrong treadmill on a discount price of $400 (new one costs $1,700). Having this in the basement, overlooking the wall mounted TV, makes it such a big difference. Specially in a place like Calgary, where a lot of preparation is required to set foot out of the door in the winter months.

After I bought the Treadmill in October 2013, I ran my first 100 miles on it in the next 4 months, running 2 miles on each session. It felt so good every time I completed the 2 miles. The confidence found from this first 100 miles shapes my next goal.

Run 100 miles in 50 day challenge

Today is day 4. I’ve completed 9 miles or 9% so far. Hoping to report back once I’ve reached 50%.

Hope this gets you started if you are thinking about a change and like taking a challenge. If you are taking this challenge, let’s team up and keep each other motivated along the way.