How to get the facebook details using id?

Hello guys,

Today I gonna explain you how to get Facebook user’s basic detail using user id. bellow function useful when you are developing authentication system of your site using facebook so there you need basic detail of your visitor.


function getUserInfo(id)
	type: "GET",
	url: ""+id,
	contentType: "application/json; charset=utf-8",
	dataType: "json",
	success: function(data) {

That’s it.. isn’t it simple… 🙂

Ruby Mysql Connectivity

This post shows you how you can connect to MySQL in Ruby.   I’m assuming that you already aware with basic SQL Operation like how to create database, table and insert, delete, update statement. So I’m directly dive in coding part, as I believe that more theory can confuse us. so I gonna explain you straight to the point.

okay so first we try to connect to the MySQL server and fetch all rows from table “test”.

require 'mysql'
con ='localhost', 'root', 'root', 'test')  
rs = con.query('select * from demo')
rs.each_hash do |row|
    puts row['uid'] + " " + row['name']

to run this basic example you need to use following command

ruby fetchallrow.rb

for insert statement you can use following code.

con.query("INSERT INTO demo values('"+id+"','"+name+"','"+mno+"')")

now you can able to perform basic insert,update and delete statement in same way.

That’s It.!

Enjoy d code.. 🙂

Designing a RESTful API with Python and Flask

In recent years REST (REpresentational State Transfer) has emerged as the standard architectural design for web services and web APIs.

if you are new to Flask please go to Flask Docs and get basic concept of flask.  let’s dive in to coding part. I am going to explain very basic example of designing RESTful API with Flask.    let’s start with hello world application.

from flask import Flask

app = Flask(__name__)


def index():
return "Hello, World!"

if __name__ == '__main__':, debug=True)

now you need to run this hello world application.


above command used to run python application.

okkY , now lets go ahead..

next, i gonna explain you how to create RESTful Web application.

Before creating Dynamic Web Application with Flask, you must need to understand the directory structure of flask.

/templates :  you must need to put all your template files (.html) inside this folder

/static: you can put all your static files usually JavaScript and CSS files

you need to use this syntax to include css or js files from static folder.

url_for('static', filename='style.css')

lets go for very basic web app

from flask import Flask, render_template
#from flask import Flask, jsonify, render_template, request
app = Flask(__name__)

def index():
    return render_template('main.html')

if __name__ == '__main__':, debug=True)

you need to put main.html file inside templates folder as mentioned above.

main.html file contain simple hello world. that you can do it urself.

=== now lets create dynamic application which return JSON data to front end html file and i will show you how to send ajax request to REST API. ===

This application provides facility to make addition of two numbers. so html file contain two inputs and while submitting form using JQuery it will request to Rest API (_add_numbers)

Python Code:

from flask import Flask, jsonify, render_template, request
app = Flask(__name__)

def index():
return render_template('index.html')

def add_numbers():
"""Add two numbers server side, ridiculous but well..."""
a = request.args.get('a', 0, type=int)
b = request.args.get('b', 0, type=int)
return jsonify(result=a + b)

if __name__ == '__main__':, debug=True)


create layout.html

<!doctype html>
<title>jQuery Example</title>
<script type=text/javascript
<script type=text/javascript>
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
{% block body %}{% endblock %}

create index.html

{% extends "layout.html" %}
{% block body %}
<script type=text/javascript>
$(function() {
var submit_form = function(e) {
$.getJSON($SCRIPT_ROOT + '/_add_numbers', {
a: $('input[name="a"]').val(),
b: $('input[name="b"]').val()
}, function(data) {
return false;
$('a#calculate').bind('click', submit_form);
$('input[type=text]').bind('keydown', function(e) {
if (e.keyCode == 13) {
<h1>jQuery Example</h1>
<input type=text size=5 name=a> +
<input type=text size=5 name=b> =
<span id=result>?</span>
<p><a href=# id=calculate>calculate server side</a>
{% endblock %}



hope you all like this .. congrats now you can develop beautiful RESTful Dynamic Application on Flask.  🙂