CEB Power Cut App (idea)

Surprises are not fun! Except when it is 13 flashing her tits. As an software engineer and systems administrator I get a lot of surprises. Some times in the middle of the night. But the worst kind of surprise is when you don’t have power, it is a planned down time, and you didn’t know it, and had a lot of plans.

I would like to suggest the CEB or who ever is interested in to make an app that will push notifications to users on pending service down times. I can also join the fun, but at the moment, I am quite busy.

I am thinking…

  • it could be general (the CEB, Water Board etc)
  • Would need push notifications to user devices
  • Any thing else? yah and be AD free

Any body? Pretty please!!!

JSON API v1 with Rails 3 - Libraries

This is the Part 2 of my experience on implementing an API on a Rails 3 app on JSON API v1 specifications. Part 1 is recommended to be skipped as it is ‘boring’.

Rails has a lot of resources when it comes to implement an API in compliance with JSON API v1 specifications. But unfortunately that requires Rails 4+. I had to settle with JSON API Serializers gem (which supports Sinatra and other Ruby frameworks too) and manually dealing with the rest.

For API documentation, I decided to settle with Swagger. I believe it doesn’t require justification.

Finally I ended up using the following…

  • Grape v0.7
  • Grape Swagger v0.8
  • Grape Entity v0.4.8
  • Grape Swagger Rails v0.3
  • JSON API Serializers v1.0.0

Let me elaborate.

Grape v0.7

Grape is framework / DSL for building APIs. It doesn’t require Rails. Initially we were going to make the API standalone but later decided to mount it on the existing Rails application.

As I remember bundler choose grape v0.7. I tried to use a later version of Grape and ended up updating multiple gems version. Finally I had to update the Ruby version to 2.2 and Rails had to be updated to 3.2.22. Unfortunately the app was not functional at that point.

You may have better fortune and be able to install a better version of grape depending on your actual dependencies and if you can update to Rails 3.2.22.

Grape Swagger v0.8

In case you don’t know, grape-swagger is the lib that generates the definitions the swagger-ui require to display. This gem will introduce some helper methods that you can describe the API neatly.

This is not the newest grape-swagger version, it is many years old, but it will do. There is a compatibility chart in the master branch of the grape-swagger gem but it doesn’t cover old versions like grape v0.7.

I went through many versions to find a match. This version will give us Swagger 1.2 compatible JSON definitions.

Grape Entity v0.4.8

The idea of grape entity is to model requests and responses. For example we may have a User model but we may only want to expose fields like first_name, last_name and email. This does just that. With grape-wagger we are able to define the data types as well so it gets documented.

Documentation is the whole reason why you will need to get grape-entity involved. But I later found out that it is not ideal, but that is all we have.

Grape Swagger Rails v0.3

Grape Swagger Rails is a rails mounted Swagger UI. If you are not using Rails you don’t need to use this. Instead you can simply host the configured static Swagger UI separately.

This is no compromise. This is the latest version and supports swagger 1.2 compatible definitions.

Thats the libraries I have used and why I have used them.

this article is wip

JSON API v1 with Rails 3 - Intro

Time undoes all, or so they say! Ruby on Rails 3 may be a relic, but it is far from gone. Just when I thought I was done with Rails 3; I took over another Rails 3 project a couple weeks ago as part of an UpWork contract. The primary job was to implement an API in compliance with JSON API v1 specifications.

My first impression was to update the application to Rails 5. But I chose to go for the API first, because…

  • The app is fairly large (150 models and 100 controllers)
  • I noticed some code that will break in rails 4/5 upgrade
  • Poor test coverage and existing tests not running without some fixing
  • The app is live (obviously)
  • The API was urgent

I did a lot of research off the clock and I thought of writing them down hoping it will save some time of another.

I will breakdown my experience to few articles and link them below as I write them.

this article is wip

Google Maps No Roads in BS Modal

Google Maps is one of the sweetest tools I have ever got to use. I loved it since our first date 7 years ago as an engineering student. But since, my involvement has been minimal. I had the pleasure to play with Google Maps yesterday. This time it also involved Google Street View. This is about a problem that bugged me for a few minutes.


Make sure you run the map init on the modal show.

# Waiting for the modal to show. If it is not a modal
# then make sure to watch for the completion of the
# element rendering.
modal.on '', ->
  center = new google.maps.LatLang(lat, lng)
  map = new google.maps.Map document.getElementById('map'),
    center: center,
    zoom: 12
  street = new google.maps.StreetViewPanorama
  # rest of the code

I had done some thing like this…

$('[data-trigger="street-view-modal"]').on 'click', ->
  # code before

  # Note that the modal will not show immediately. Instead
  # we should use the '' event to init the
  # Google map.

  center = new google.maps.LatLang(lat, lng)
  map = new google.maps.Map document.getElementById('map'),
    center: center,
    zoom: 12

  # rest of the code



I had a table with a Google Street View image on display of locations of interest. The admin will click on the image and it will open a Bootstrap modal with the Google Street View and Google Maps pared. The user will use the map to position the user and street view will be used to get POV heading and POV pitch. Given we know the latitude and longitude we can generate an image which we use temporarily.


The Google map was firing, but

  • There were no roads and the background was grey.
  • When center the map, it would go to the top left corner.
  • Google Street View Panorama is working but seemed a bit broke


I had one modal in a list view. When a link is clicked I will show the modal + init the map in the same go. The map should be initialized once the dom is ready.

Once I used the event for the modal shown and initialized the map only then it worked as expected.

Hoping this post was of help, happy hacking!

SLMC Bombed - How convenient!

Doctors (GMOA in particular) have been in the spot light. They launched an island wide inconveniencing hundreds of thousands of patients in dire need of medical attention. The they tried to raise black flags in Vesak. The people responded they should rather shove the flags up their arses. Not many days from then a bomb lands in their head office…

Here are the important points of the news coverage…

  • A grenade
  • No CCTV coverage of the incident
  • Grande didn’t blow
  • Happened at night

There is only one thing I need to say how convenient!.

History in short

  • Doctors strike against free Indian ambulance service - many lives saved for today
  • Doctors strike against reducing car-permits to once in 10 years - to reduce tax on poor
  • Doctors strike when automobile taxes increased by Rs. 5000 - to reduce tax on poor
  • Doctors strike against nurses receiving degrees
  • Doctors stops lecturing AHS students at University of Peradeniya (so much for free education)
  • Doctors against allied-health-science (AHS) degree

I bet I missed a lot! But that is all for now!