Wednesday, December 28, 2016

new keyboard

My corsair k70 RGB broke a little while ago and I was relying on my Macbook keypad for most of the typing. Coming from mechanical keyboards, it was a difficult choice to stick to laptop keyboard especially when sitting when you are on a desk. I decided to have a backup keyboard. My hunt started with few specific needs.
  1. Should be mechanical type
  2. Not heavy on the pockets
  3. Compact
Now That the Cherry's patent has expired for the mechanical switches, we can find tons of imitation keyboards on the market. I found few keyboards online which falls under this bracket. 

AUKEY Mechanical Keyboard

Though I have few products from Aukey, I was a bit reluctant looking at the specs and the images. [ My impression is purely by the specs and published images ] 

LINGBAO JIGUANSHI Mechanical 

First thing that caught my eye was the size. This is a compact size 87 keys. Look wise its alright. But to make decisions purely on the aesthetics is not wise. 

Qisan / MagicForce 68-Keys Mini Design 
This one looked interesting aesthetically. It uses Cherry MX - Red. My previous keyboard was Brown. This comes in different flavors. You could choose OUTEMU Or Kailh or Cheery Mx. I was a bit surprised to see these option from one manufacturer. I chose the cherry MX Red which at the time of purchase was £63 on Amazon. I Will leave the link for all the 3 variants below. They have one without backlight. But, who would want one without backlight! I have been using MagicForce for over a month now and I am pleasantly surprised how good It feels. And the build quality is amazingly good for the price I paid. I am so comfortable with this that my K70 is in the drawer, I could not find time to fix that. Qisan Mechanical Keyboard Cherry MX Red http://amzn.to/2hqTIJz 
Qisan Mechanical Keyboard Cherry MX Brown http://amzn.to/2hLhBcz 

Cheaper option without backlight Qisan OUTEMU switch http://amzn.to/2hlCLgm

Friday, November 25, 2016

Embed git commit hash in a scala web service

One of the Scala service I was working on needed an endpoint which would inform what version of the code has been deployed on the server.

There are multiple ways of doing it. Embedding it into Manifest files is one easy way, but I found this https://github.com/sbt/sbt-buildinfo plugin.  It works by generating a scala source file from build definition. Full details can be found here

Project name, Version and other build time details are already defined in build.sbt file of the sbt project. Now I need git details to be added to this BuildInfo.scala source file.

https://github.com/sbt/sbt-git plugin does exactly what I need. It's a plugin which offers git integration with sbt.  Now I can use sbt-git to fetch commit SHA and use BuildInfo plugin to generate scala source which stores this information at build time.

build.sbt file looks like this

import Dependencies._

name := "myService"
version := "0.1"
scalaVersion := "2.11.8"
libraryDependencies ++ testLibraryDependencies
val gitCommitString = SettingKey[String]("gitCommit")

gitCommitString := git.gitHeadCommit.value.getOrElse("Not Set")

lazy val root = (project in file(".")).
  enablePlugins(BuildInfoPlugin).
  settings(
    buildInfoKeys := Seq[BuildInfoKey](version, gitCommitString),    
    buildInfoPackage := "buildInfo",   
    buildInfoOptions += BuildInfoOption.ToMap,    
    buildInfoOptions += BuildInfoOption.ToJson
  )

After compiling my project, buildinfo plugin will generate BuildInfo.scala source file in target->scala-{version}->src_managed directory. This source contains the app version and git commit hash




 BuildInfoOption.ToJson
Above line enables it to render into json format.

I added a new route for the service  /version
package com.brainchunk.routes

import akka.http.scaladsl.server.Directives._
import buildInfo.BuildInfo

trait VersionApi {
  private val resource = "version"
  val versionApi =
    path(resource) {
      get {
        complete(BuildInfo.toJson)
      }
    }
}

Now the endpoint should return json as below

$ curl localhost:8081/version

{"version":"0.1", "gitCommit":"23962adddf6e55d3f43466283cd3418a9133ee6c"}


Note:
IntelliJ IDEA is not very happy with this BuildInfo being in target/../src_managed location. Workaround has been mentioned here

https://youtrack.jetbrains.com/issue/SCL-7182#u=1402953965717


Sunday, July 03, 2016

Image classification with TensorFlow

Lately I am spending time experimenting with scikit-learn and TensorFlow (Google) open source library for Machine Learning.

Using image recognition library from TensorFlow, I hacked together a web service with an end point where I can send an image and get back with prediction for the content of the image.
To consume the API, initially I thought of making an Android app, later it made sense to follow up on my previous post and use a chat bot. My experimental project was simple, I should be able to send an image to my chat-bot in WhatsApp, and get back the prediction.

Tensorflow is easy to learn and use and it has decent documentation. I trained the model using sample image database downloaded from google example. To create the web endpoint, I used flask, a python web framework.
Now I can test, my web service by uploading my test image
          


Prediction :
[
  {
    _score: "0.623313",
    _string: "catamaran"
    },
    {
      _score: "0.099451",
      _string: "dock, dockage, docking facility"
    },
    {
      _score: "0.0621891",
      _string: "liner, ocean liner"
    },
    {
      _score: "0.0246246",
      _string: "fireboat"
    },
    {
      _score: "0.0244034",
      _string: "speedboat"
    }
]
Prediction engine is 62% sure that the image is of a catamaran. Close enough.

Now, I could hook this up to my WhatsApp bot. I used yowsup python library to get this up and running. I just had to register my spare mobile number with WhatsApp server. With a bit of fiddling around, the bot was ready to talk to the prediction API.
Now I can send a picture, and get back the prediction in JSON format.

Screenshot_20160619-183759.png