Text

#KaunAaya

Last couple of weeks I have been itching to do some fun weekend project. After some searching, I thought doing a Raspberry Pi project would be fun. The idea was to build a light-weight intruder detection system for our home.

This system would start once all the people in the house would leave the premises. Once started it would start clicking pictures of the house at regular intervals. It would then try to compare the last two clicked pictures. If the pictures are different, the system would upload the latest picture to my Dropbox account and eventually notify me.

With this in mind, I started stitching together different pieces of the puzzle. Firstly, I bought a Raspberry Pi Kit from Amazon. Another challenge was to build the messaging mechanism from phone to raspberry pi app and vice versa. Although simple build, I didn’t want to re-invent the wheel and use my time efficiently. I decided to use IFTTT service to wire up my app. If you haven’t used this service earlier, you should give it a spin. It basically lets you create different recipes of the format “if-this-then-that”. I created following recipes on IFTTT:

  • If you enter an area, then push a note to Pushbullet.
  • If you exit an area, then push a note to Pushbullet.
  • If new item in Dropbox folder, then send a notification.

Once these rules were in place, it was time to code. The raspberry pi kit I bought came with a SD card pre-installed with Raspbian OS. Getting Raspberry Pi up and running was very easy and there are lot of tutorials online. Then I installed pi camera using this tutorial. Just for fun, I decided to write my app using Python. I am not a python expert but got to learn a few things python virtual environment, GIL, etc. while doing this project. I have shared my code on github at (your feedback is much appreciated):

Finally, I named my app “KaunAaya” which means “Who came?” in Hindi. That’s it! I hope you will get ideas of your own after reading this. I intend to do more fun stuff using Raspberry Pi in future. Stay tuned! 

Text

Status Update on 10gen Education

10gen:

We’re working hard to get the content for the first two education courses live on education.10gen.com. We were affected by today’s AWS outage, but are optimistic that we will get the courses up late tonight. As soon as the materials are available, we will send an email to everyone who is enrolled.

Thanks for your patience.

(Source: 10gen)

Link
Link

instagram-engineering:

With more than 25 photos & 90 likes every second, we store a lot of data here at Instagram. To make sure all of our important data fits into memory and is available quickly for our users, we’ve begun to shard our data—in other words, place the data in many smaller buckets, each holding a part of…

Link

Why thread-based application parallelism is trumped in the multicore era

Link

It uses a combination of highcharts and twitter REST api to show top twitters on currently trending topics.

If you like it - let me know :)

Link
Text

Stock Ticker in Node.js

Trying out stock ticker in Node.js. Suggestions are welcome :)

var fs = require('fs')
    , http = require('http')
    , socketio = require('socket.io')
    , connect = require('connect');

console.log("===Stock Ticker Application===")
 
var server = connect.createServer(
                connect.static(__dirname)
             ).listen(8080, function() {
                console.log('Listening at: http://localhost:8080');
             });

var io = socketio.listen(server);
 
io.sockets.on('connection', function (socket) {
    socket.on('message', function (ticker) {
        console.log('Message Received: ', ticker);
        setInterval(getStockQuote, 5000, ticker, socket);
    });
});

function getStockQuote(ticker, socket) {
    var options = {
        host: 'finance.google.com',
        port: 80,
        path: '/finance/info?client=ig&q=' + ticker,
        headers: {
            Host: "www.google.com"
        }
    };

    http.get(options, function(res) {
      var data = '';
      res.on('data', function (chunk) {
            data += chunk;
      });
      res.on('end',function(){
        var obj = JSON.parse(data.substring(3));
        var lastPrice =  { "ticker" : ticker , "last" : obj[0].l };
        //console.log(lastPrice)
        socket.emit('message', lastPrice);
      })
    }).on('error', function(e) {
      console.log("Got error: " + e.message);
    });
  }
Text

Stock Ticker in Scala

I started to learn Scala last weekend and this is my first attempt write some code. I thought writing a stock ticker would be a good hello world application.

package com.scala.ticker
import java.net.URL
import scala.io.Source
import scala.xml.XML
import java.util.Timer
import java.util.TimerTask

object StockTicker {

  def main(args: Array[String]): Unit = {
    println("===Stock Ticker Application===")
    StockQuoteProcessor.start
    var tickers = readLine("prompt> ")
    while (true) {
    	println("====Fetching quotes with actors====")
    	tickers.split(",").foreach(s => StockQuoteProcessor ! s)
    	Thread sleep 5000
    }
  }
}

Scala actor to process stock tickers

package com.scala.ticker

import scala.actors.Actor._
import java.net.URL
import scala.xml.XML
import scala.actors.Actor
import java.util.Timer
import java.util.TimerTask

object StockQuoteProcessor extends Actor {
  def act() {
    loop {
      react {
        case ticker: String => getStockQuote(ticker)
      }
    }
  }

  def getStockQuote(ticker: String): Unit = {
    val url = new URL("http://www.google.com/ig/api?stock=" + ticker)
    val body = url.openStream()
    val xml = XML.load(body)
    val threadId = Thread.currentThread().getId
    val threadName = Thread.currentThread().getName()
    for (node  None
        case Some(lastPrice) => println("Thread [" + threadId + "-" + threadName + "] " +ticker + " = " + lastPrice)
      }
    }
  }
}
Text

potatow:

> Someone ask if “this” can ever be null in Java

> Answer from stack overflow: “It’s like asking yourself “Am I alive?” this can never be null

Guys call me whatever you want but I found this ridiculous funny! XD