Recursion!

RSS

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.

C++ or Java

Instagram Engineering: Sharding & IDs at Instagram

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…

Aug 8

Multicore CPUs and the concurrency changes they bring

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

Aug 8

Just hosted my first node.js project on nodejistu

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 :)

Follow me on GitHub

https://github.com/ankurvsoni

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);
    });
  }

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)
      }
    }
  }
}

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

ilovecharts:

America is the easiest country in the world to fire workers, according to the OECD
Scale from 0 (least stringent) to 6 (most restrictive)

ilovecharts:

America is the easiest country in the world to fire workers, according to the OECD

Scale from 0 (least stringent) to 6 (most restrictive)