Sunday, February 28, 2016

How to figure out static dependencies of a library for example libxml-2.0

Alright, this is fairly common question when you are trying to generate a static binary or have come across situations when you want to find out all the dependencies of a library.

The problem: How the hell do I figure out all the static dependencies of libxml-2 ?

The solution: Its easy, use pkg-config !!

Here is how to list all the static dependencies of libxml-2

Run the below command:

pkg-config --static --libs libxml-2.0

and this returns a list

-lxml2 -lpthread -lz -lm

Saturday, February 27, 2016

All permutation of a string using Go (Golang)

I have been playing around a bit with Golang and I thought the best way to learn about a prog. language is to write some code.

The problem: Write all permutations of a given string

The solution:

Run code here :

Saturday, January 16, 2016

Dockerizing Sinatra app with reloading (Docker + Sinatra + foreman + rerun)

Lately I have been trying to learn more about Docker, so I picked up a task to dockerize a Sinatra app.

Here is an excellent training material which includes 3 hours of video about docker:

Here is another introduction to docker by Codeship:

  1. You have a Sinatra app up and running using foreman.
  2. You have docker machine installed. We will be using docker compose to dockerize

Lets get started:

Step 1: Create a file named Dockerfile in the root of your project with the following content

Step 2: Create a file named docker-compose.yml in the root of your project with the following content

Step 3: Lets get reloading Sinatra app on changes working (ONLY if you want to reload your Sinatra app on changes using rerun gem)

At the moment to get rerun to work properly with Docker you have to supply --force-polling option
as mentioned here

The catch is that the supporting code is only in master(as of now) and is not pushed to the latest gem.
So chances are if you install the latest version of rerun gem, you might not get the force-polling option 

use this in your gemfile development section to load the master branch of the gem
gem 'rerun', :git => ''
gem 'foreman'

Step 4: And thats all the config thats needed. Run
    a) docker-compose build
    b) docker-compose up

Saturday, April 4, 2015

Ever wondered how good is a restaurants kitchen ?
Wana check how good a restaurant is for real in NYC. ?

NYC Restaurants Grades is the place to go. Checkout

Check most recent NYC restaurant inspections and grades. You can also see past NYC restaurants inspections results and grades.

Website -

Saturday, September 6, 2014

Binary Tree using HTML5 Canvas and JavaScript

Hi Guys -

I was just playing around with HTML5 Canvas and thought it will be fun to create a binary tree implementation using JavaScript.

I tried this a few years ago with Java and applets. Well, yeah u guessed it, it was a PITA.

With JavaScript and Canvas, it was a smooth ride.

The code below is only for the purpose of demo. Some nodes might overlap if the tree has a lot
of nodes.

Tested on Google Chrome

1 - Create a file index.html and add the below code to it.
      It contains an
      a - Input box where the user will enter the number to be added
      b - A button to add entered number
      c - A canvas element
      d - A script tag

2 - Next we will add a node object. Node, as the name suggests, represent a node in the tree
     Add the below code in the script tag of the index.html


3 - Next we will add code to draw a line from parent to child. Add the below code to the script tag    

4 - Next we add the core logic of a binary tree. To understand that logic, you should know how
     a binary tree works. Add the blow code the script tag


5 - Now we  need to create a binary tree object to which we can add node
     Add the below code to the script tag

     var btree = new BTree();

6 - Ok. We are almost done. We just need to wire the input box and add to tree button
     Add the below code to the script tag


Thursday, August 21, 2014

Elasticsearch 101 - How secure is it ?

So, I wanted to add full text search functionality to one of my projects and after doing some research I decided to go with Elasticsearch.

While reading the docs, I came across two RESTful apis which were good but also dangerously exploitable.

So what are those apis - (assuming that a local instance is running on port - 9200 )

1 - curl XGET 'http://localhost:9200/_nodes?pretty=true'
     Run this command from your terminal and you will see a lot of details about your machine

  • Paths - 
    • logs: /Users/I/am/a/hacker/logs
    • home: /Users/I/can/see/your/home
  • OS info -
    • cpu details
    • memory details
    • and yeah JVM details
  • Network info - 
    • IP address
    • mac address

2 - curl -XPOST 'http://localhost:9200/_cluster/nodes/_master/_shutdown'   or
     curl -XPOST 'http://localhost:9200/_shutdown'

     Any user can execute the above command and bring down your whole cluster. 
     Still most big companies have pretty good firewall setup so its hard to get access to a machine but
     still, imo, there should be some kind of permission to execute these commands

Anyways these are some interesting things which I came across while reading the docs.

Sunday, April 6, 2014

Connecting To MongoDB From Node.js Beginner's Basic

Ok guys - Here we will create a simple file that will connect to a local instance of Mongo and read data from the 'test' database.

Assumptions - 
1 - A local Mongo server is running at port 27017 (default port)

Step 0 - Create a directory called 'testing' and cd into it.

Step 1 - Connect to mongo using a mongo shell
Step 2 -  Add some data to a collection named 'heroes' in the test db.
              use test
             db.heroes.insert([{name: 'Super Man'}, {name: 'Bat Man'}]) 

Step 3 - Create a file called simple_connect.js and the following content to the file


Step 4 - If you haven't already installed the 'mongodb' module, run
             npm install mongodb

Step 4 - Run
             node simple_connect.js