Sunday, October 13, 2013

Fibonacci - Golden Ratio

In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence: 0, 1, 1,2, 3, 5, 8, 13, 21, 34, 55, 89, 144 ...

I have always done the one with recursion (or iteration). But mathematics says we could do it with the Golden Ratio ..


Tuesday, October 8, 2013

Js for Sublime

Setting up a build system for Sublime Text for js

Let your interpreter be Node. If you don't have Node, I would recommend installing it from here. It uses the Google V8 Engine.

Open Tools -> Build System and select a New Build System
Name it whatever you want it to be (this will show up in the Build Options)
Add the following to it


 "cmd": ["node", "$file", "$file_base_name"], 
 "working_dir": "${project_path:${folder}}", 
 "selector": "*.js
}

The syntax could be understood from this link.

Restart sublime and open the file. Goto Tools -> Build System and set the build system to the name you gave.

Run Command + B and it will work !

All the build files go into /Library/Application Support/Sublime Text 2/Packages/User

:)

Wednesday, October 2, 2013

Statsd

During the last couple of days, I was trying to find myself around Statsd from Etsy. It seems to be a wonderful tool which lets users send stats (or tracking) to a server which in turn could be visualized using tools like Graphite.

The set up is quite simple. Add the Statsd gem to your application's Gemfile and then write a Rack Middleware which sends out information to the predefined server. Before sending out information, we need to setup the Statsd NodeJS Server and give the IP and port for the Gem to work.

Matt Aimonetti has written a great post about setting up the service.

I have found it damn hard to set up Graphite.

The download is easy. git clone the 3 repositories and then run check_dependencies.

Install all the required libraries using pip. Now comes the hard part. A 2D graphics library called Cairo is a dependency for Graphite and a library called py2cairo (pycairo if python >2.7) is to be installed.

I would suggest installing cairo using

sudo brew install cairo

Homebrew is better than MacPorts.

Install pycairo using pip

sudo pip install pycairo

Or

easy_install pycairo

You might get errors when importing the module for cairo. This might be because you installed it via easy_install.

If it does not work (it did not because I have 2 versions of python), symlink from the site-packages/Cairo to the place where python searches for site-packages.

Then run check_dependencies again and you are good to go. I still have to setup Graphite. But I hope I'll have less obstacles after this.