neo4j graph database replication using solr replication hook

I am not going to share any code, but will let you know how i achieved neo4j graph database replication using solr.

So, based on how a neo4j database index works is that it puts everything inside a folder, and creates a lock in the indexes if any one is accessing it.

Solr has it’s own replication hook which works like a charm, it also provides support for replication of config files specified the configuration. Please note you have to specify the file names. Now how do we use this feature to enable replication of neo4j database whose file names can vary after each update in your graph.

Now i hope you have your code written to update your graph database indexes and you have control over to lose the reference to the graph and close the graph instance and know when the state of database is stable.

At this stable point , what you do is lose the reference to the database and compress your graph database directory into a single file. Specify the same file path into solr replication configuration of config files.

The way solr replication works, is that the slaves is going to poll the master for any updates. If the slaves finds any updates, it asks for indexes and  checksum of the config files, then if the slave finds any change in the configuration it’s going to replicate the file for you. At this point once it fetches the file, it’s going to rename the original file if previously present and place the new file with name.

Ok at this point you have master slave replication configuration setup with the new graph database in compressed  form at the path specified in solr config. How  do use it now ? Solr provides a hook to plugin your custom replication handler which is let’s you provide a hook to put in your code, at this point write some code which unzips the files and put it a particular position.

Now create a hook that in your neo4j code which when triggered reloads the reference of it’s graph with the directory that you just unzipped. Trigger this hook via something like a HTTP call or something.

 

That should work fine if implemented correctly. Nothing out of the box, you have sit down write some code to get this working.

If it works for you , buy me a beer if you can.

Magic Picture : Fun with images

Magic Picture i understand it’s weird for a name. But this one is a simple script that given a image and a text to be repeated creates a html file with each character of color picked up from the input image.

In simple term creates a ascii art from the image and text.

Possible use case, use a image of your other half, use something romantic , hidden text as a input and ask them to open in a browser and keep on reducing the font size and voila you can see the original awesome image.

Here is the link of github repo

https://github.com/bipul21/magicpicture

A sample output:

screenshot

 

 

 

Business of API hackathon : iSphero

A while back i got a chance to be a part of Business of API hackathon in Bangalore, India. It was a 48 hours hackathon and was very exciting due to kind of API’s that we can use. Mainly Linkeding, twilio and sendgrid’s

The first day i got a sphero, a amazing robotic ball by Sendgrid as a audience price for some during the session thing. You can checkout more on sphero here http://www.gosphero.com/ and sendgrid http://www.sendgrid.com

Essentially during the hackathon i built a webapp by which you can control the sphero from anywhere (you have to be a geek to follow the steps though)

Here is a snapshot.

Console

How to use this. Just clone the git repo from. https://github.com/bipul21/isphero/

To run this go inside the dir and run python manage.py runserver

Now connect your sphero with your computer via blutooth.
You will see something on localhost:8080 if everything is fine (Else debug or install dependencies)

Now the part where you can give control of your sphero to anyone anywhere. For that read about localtunnel here
http://progrium.com/localtunnel/ This will give you a link, share this with anyone and give control.

Also here is a video with me controlling the sphero using the same .

Please let me know if you don’t like my writing or need more details.

Hack Day at flipkart

flipkart is a one of the best e-commerce company in India that let’s gives their user a amazing online shopping experience.

But i feel  really sad for people who cannot enjoy online shopping just because of the fact that they don’t have computers,  don’t know how to use computers or don’t have internet connection which is very common in india.

Also people having access to cell  phone is very common in India. So my hack was directed to mobile domain. I had some previous experience with SMS apps so i thought and build something that let’s people search items on flipkart using sms.

Me at flipkart hack day

Here is what i finally came up with

Continue reading

Google Url shortener in google app engine

This is my first post so here is something pretty simple

Python snippet to use Google URL shortener  API

so for url https://bipuljain.wordpress.com get a shortened url as in goo.gl/ABCDE

To use google url shortener API, you need either a API KEY or you need to use a oauth model.

Preferring API Key approach

from django.utils import simplejson as json
from google.appengine.api import urlfetch

G_API_KEY='1234567890987654321'
g_api_base='https://www.googleapis.com/urlshortener/v1/url?key='+G_API_KEY
def shorten(long_url):
   try:
#long_url is Long url to be shortened   and converting it into json format
      values = json.dumps({'longUrl' : long_url})
      headers = {'Content-Type' : 'application/json'}  #setting header type to json
      result = urlfetch.fetch(g_api_base,payload=values, method='POST', headers=headers)   #Sending the request
      output=json.loads(result.content)   #Converting in json response into a python dictionary 
      short_url=output["id"].replace("http://","")  #Further removing http:// from url 
      return short_url
   except:
      pass #Do something here

here g_api_base is a url to which you are supposed to send a POST request with your URL in json encode format along with the API_KEY as a query parameter.

Thankyou,
Hope you like it