perform inner join on same table in mysql

During application development, i was stuck in one mysql – query problem.  i don’t know whether this post title gives meaning or not. but I had used this title to search on google for my problem’s solution.  so i kept same here.

let me describe problem

+-------------------------+---------+
| switch                  | port_no |
+-------------------------+---------+
| 00:00:00:00:00:00:00:02 | 3       |
| 00:00:00:00:00:00:00:01 | 2       |
| 00:00:00:00:00:00:00:01 | 1       |
| 00:00:00:00:00:00:00:02 | 1       |
| 00:00:00:00:00:00:00:04 | 2       |

so i have such type of data in sla table.  and i want bellow output

Expected output

+-------------------------+---------+
| switch                  | port_no |
+-------------------------+---------+
| 00:00:00:00:00:00:00:02 | 3,1     |
| 00:00:00:00:00:00:00:01 | 2,1     |
| 00:00:00:00:00:00:00:04 | 2       |

so here is magic function which saved my life :)

Function :

Look at GROUP_CONCAT()

Query which return expected output

select switch,GROUP_CONCAT(port_no) from sla group by switch;

i know lots of newbie developers got such problem so i’m sharing here..
if anyone have best title for it .. plz suggest it in comment.

:)

REST Client Example in Ruby

REST Client – simple DSL for accessing HTTP and REST resources

A simple HTTP and REST client for Ruby, inspired by the Sinatra’s microframework style of specifying actions: get, put, post, delete.

I found this Ruby-Gem very useful while building App. so i will describe here how to use REST Client in Ruby

Simple example for REST Client POST Request.

require 'rest_client'


res=RestClient.post 'http://localhost:8080/wm/test/json', params.to_json, :content_type => :json, :accept => :json
result = JSON.parse(res)
return result.to_json

above example send post request to my local server, which takes few parameters in form of json and

result.to_json

return output in form of JSON.

likewise, you can use any method GET,PUT,DELETE.

Hope you’ll like dis :)

Posting JSON data to sinatra with JQuery

I guess this post is mainly useful when you want to build Restful API with Sinatra.   Let’s say you want to pass JSON data to Sinatra backend using JQuery. so you may got very first question is How to parse JSON POST Data in Sinatra rest api ?  am i right ?

so here is full example which demonstrate how to send JSON data to Sinatra REST API.

JQuery Code:

$.ajax({
url: '/test_api',
type: 'POST',
dataType: 'json',
contentType: "application/json",
data:JSON.stringify(data),
success: function(data){
}
})

let’s say data (json variable) contain complex data like

{
"topo": [
    {
      "dpid": "00:00:00:00:00:00:00:03",
      "ports": [
                 3,
                 2
                ]
    }
   ],
"app": "vm_migration"
}

Ruby Sinatra Rest Function

post '/test_api', :provides => :json do
  begin
     # bellow line get post json data
     params = JSON.parse(request.env["rack.input"].read) 
     # you can access key value like bellow
     app = params["app"]
     params["topo"].each do |topo|
            dpid = topo["dpid"]
            # getting each value of key using each
            topo["ports"].each do |port| 
                #Process Data
            end            
        end
  rescue Exception => e
    return e.message
  end
end

Hope it is useful..  plz do comment if it is useful for you..
:)

any question related to post, feel free to ask.

Getting started with NodeJS

node

Please read this to get basic information about node js. don’t like to write too much..

About me

How to install ?

You can google it.. or else I got one link please refer this.

let me go with basic example which is also given there in about me section. nodejs is really helpful for building a scalable network programs.

Basic Echo Server

var http = require('http');
var s = http.createServer(function(req,res){
	res.writeHead(200,{'content-type':'text/plain'});
	res.end("hello word");
});
s.listen(8000);

woow..  few lines of code and we’ve done with basic server..  :)

Run :

use bellow command to run this app

node basic_server.js

Fire request on our server

1) using curl : curl http://localhost:8000

2) using url : http://localhost:8000 (in browser)

All about Twitter Bootstrap

Jaydipsinh:

All about Twitter Bootstrap…!
Get all stuff related to bootstrap here.. no more google for bootstrap..

Originally posted on Jayesh Chandrapal:

Twitter Bootstrap

How to use?

To use Bootstrap in an HTML page, developer must compile one CSS file from the downloaded LESS stylesheets. This can be done with a special compiler. Then they need to integrate the generated CSS file into the HTML file. If JavaScript components are selected, they must be referenced along with the jQuery library in the HTML document.

JS Plugins

The JavaScript components of Bootstrap are based on the jQuery JavaScript framework.

It is out of Twitter

“Bootstrap will remain Twitter’s project on GitHub for the time being, but we’ve realized the project has grown beyond us and the Twitter brand. It’s a huge project playing a pretty awesome role in the web development industry, and we’re excited to see it continue to grow. To that end, we’ve begun working to move Bootstrap into its own open source organization. It will take time, but we’re dedicated to making it happen.”

Styles

View original 418 more words

Network Information API

How to detect Network Connection changes ??

Do you have same question sometime in ur mind ? hmm.. i got answer from MDN

This API provides information about the system’s connection, such as connection bandwidth of user device, or whether the connection is metered.

Usage :
This can be used to select hight definition and low definition content based on the user’s connection.

Detecting connection changes

var connection = navigator.connection || navigator.mozconnection 
|| navigator.webkitconnection;
function updateConnectionStatus(){
alert("connection bandwidth="+connection.bandwidth +"Mbs");
if(connection.metered){
alert("the connection is metered");
}
}
updateConnectionStatus();

Simple JS Code ..!!@@

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)
{
     $.ajax({
	type: "GET",
	url: "https://graph.facebook.com/"+id,
	contentType: "application/json; charset=utf-8",
	dataType: "json",
	success: function(data) {
	   alert(data.name);
	 }
	});
}

That’s it.. isn’t it simple… :)