Thursday, December 26, 2013

Mysql dump for a single table with data only, no drop and table creation commands

mysqldump -uroot -ppassword --compact -t papaya_development users > users.sql


for more detail type mysqldump --help command on terminal.

Thursday, December 5, 2013

Build and run Blackberry app in simulator

I new requirement is to build the blackberry application and run it in the blackberry simulator. I created a application using phonegap, now next task is to run in the blackberry simulator.

I have to setup the simulator locally. Step as follows:-
  • Install Jdk.
  • Install vmware.
  • download the simulator from blackberry site.

Now you are done with the  simulator setup. You have to start the simulator in the vmware  and enable the development mode.

The one this you have to note the ip-address of the simulator which is present in the bottom left.

you have to setup the couple of things:-
  • blackberry 10 sdk
  • apache
  • ant
after you done with the setup you have to do couple of settings changes in the project properties file.

  1.  update the
    qnx.bbwp.dir =
  2. qnx.sim.ip =
now you are done with all the settings.
go to project directory and type couple of commands
  1. ant qnx build
  2. ant qnx load-simulator
 

Thursday, November 28, 2013

How to load the server page in mobile application using jquery mobile

My application requirements is to show the dynamic pages on the mobile application using the jquery mobile.

Here is my approach
1) bind the pagebeforechange event.
2) Call the javascript function inside the pagebeforechange function.
3) Inside the function call the ajax and insert the content in the page.
4) Onsuccessfull ajax request trigger the pagechange event.


Here is sample code:
1) $(document).on('pagebeforechange', function (e, data) {
      if (typeof data.toPage === "string") {
           if (u.hash.search(/^#action_url/) !== -1) {

                populate_content(u, data.options);

                e.preventDefault();
            }  
     }
});


2) function populate_content(u, options) {
  
    $.ajax({url: remote_location_url,
                success: function (result) {
                      insert content here ............
                }
              
            });

            $.mobile.changePage($('#page_change'), options);

        } 

}

Thursday, November 14, 2013

Cookies are not set in AJAX request

I am setting the cookies to browser by an .js ajax request. After some time when i am sending the .html extension ajax request  my browser is not sending cookies along with the request in ajax call. After some googling i found that i have to set the

xhrFields: {
           withCredentials: true
}

in my ajax call.

Thursday, November 7, 2013

Get the controller object in model rails

My Site require a audit trail functionality who did activity, what are changes he made, from which ip address and lot more details. So i written the after_create, after_update, and after_destroy ActiveRecord callback in the ActiveRecord::Base class. It solves my purpose but i need who did it, from which ip he did it.

So i added a before filter in application controller which add the controller instance to current thread,

 Thread.current.thread_variable_set('controller', self)

As in the same thread the operation happening on the ActiveRecord.

So i can get back the controller instance and call the current_user method on it

Thread.current.thread_variable_get('controller').current_user

now i have to make my current_user method public and to avoid it calling from browser as action i have to hide it by

hide_action :current_user

Monday, June 24, 2013

Whitelisting the system tray in ubuntu 13.04

As you probably know, the Unity notification area (systray) whitelist is no longer available in Ubuntu 13.04 so you can't whitelist applications to be able to use the systray.  

If you can't live without an application that still uses the old notification area, here's how to get the Unity systray whitelist back in Ubuntu 13.04 


sudo add-apt-repository ppa:timekiller/unity-systrayfix
sudo apt-get update
sudo apt-get upgrade
 
 

You install Skype and expect it to work as it used to. But if you close the main window - you soon notice that Skype icon is not being displayed in top panel.

To fix this you will need to run a few commands. So open up your terminal and run this:
 
gsettings get com.canonical.Unity.Panel systray-whitelist

You should get something like this:

 
['JavaEmbeddedFrame', 'Wine', 'Update-notifier'] 
 
Basically this means, that Skype is not whitelisted, thus is not allowed by default to display 
its tray icon. We need to fix this. Append 'Skype' to the list so that you have something like this:
 
settings set com.canonical.Unity.Panel systray-whitelist "['JavaEmbeddedFrame', 'Wine', 'Update-notifier', 'Skype']" 

Now just copy this to your Terminal and execute the command. Reboot afterwards. Now you should see the icon.

Thursday, June 20, 2013

How to connect RJ-45 connector to ethernet cable

The connector at the end of a CAT-5 cable is called an
RJ-45 connector. It allows you to plug your cable into a wall jack or the
network port of a network device like a computer.

Each wire in the cable goes into a slot inside the RJ-45 connector, and
this connects it to a pin in the connector.

So which wire goes where?

The position of each wire is important.

When you plug an RJ-45 connector into a jack, the pins on the
connector make contact with pins in the jack. If the wires are in the
correct position, this allows information, in the form of electrons, to
flow. If the wires are in the wrong position, the information won’t be
able to get through.

The order of the wires in an RJ-45 connector conforms to one of two
standards. These standards are 568A and 568B.

568A and 568B are cabling standards that tell you which order your wires
need to go in when fitting an RJ-45 cable.

  • The 568A wire order
    If you’re following the 568A wiring standard, you use the following wire order:
    Striped green, solid green, striped orange, solid blue, striped blue, solid orange,striped brown, solid brown.
  • The 568B wire order
    If you’re following the 568B wiring standard, you use the following wire order instead:
    Striped orange, solid orange, striped green, solid blue, striped blue, solid green, striped brown, solid brown.

The 568B wire order is like the 568A wire order but with the position of
the green and orange wires switched around.

Can you see any similarities between the 568A and 568B wire orders? The
order for each standard is basically the same except the orange and green
wires are switched over.

So which standard should you use?
When you attach an RJ-45 connector, the key thing is that both ends of
the cable use the same standard. Before fitting a new RJ-45 connector, take
a look at the other end of the cable. If the other end of the cable uses
standard 568A for the RJ-45 wire order, then fit your new RJ-45 connector
using the 568A standard. If it uses 568B, then use this standard instead.

Ethernet cable color coding and their meaning

Ethernet cable is category-5(cat-5) standard cable.

The color and their meaning as follows:-
  • Orange pair sends data.
  • Green pair receives data.
  • Blue and Brown wire are kept for future mainly to increase the bandwidth.
 note :- Blue and brown wires don’t do anything yet, but they will in the
future. The cable standards folks designed CAT-5 with the extra
colored wires so that they could be used for higher bandwidths in
the future.


More wires = more bandwidth

Now we also have cat-5e and cat-6 ethernet cables as well.

Friday, March 22, 2013

Difference between a compiler and interpreter

What is the difference between a compiler and interpreter?

First, what is a program?
Program is set of instruction which tells computer what to do.

Compiler is a program who understand the instruction written by you in a particular language and outputs a new program and now new program is given to computer to act on.

Where interpreter does does both tasks at once.

What exactly it means when we say i have 2.5 GHz cpu

One day i thought what is exactly means when we say i have 2.5 GHz cpu in my system.

I was very confused some says its the speed how fast your computer can executes your program, but computer executes every thing in cycles. After some google i found the answer.

We know speed of light

299 792 458 meters / second  
1 meter = 100 centimeter
1 nanosecond  = 1/1000000000 seconds 

distance traveled by light in one nanosecond would be around
29.9 792 458 cm

2.5 GHz = 2.5 billion cycles per second
i.e 2.5 billion equals to 2500000000 cycles per second

when we talk in nano seconds it comes 2.5 cycles in 1 nano seconds



1 nano  = 29.9 792 458 cm in term of light
1 nano  = 2.5 cpu cycles

when we compare cpu cycle with distance traveled by light

1 cycle  =  29.972458/2.5 = 11.9889832 cm 

so cpu completes one cycle when the light travels only 11.9889832 cm
 
Imagine......:-)


Friday, February 1, 2013

How Super keyword works with inhertance and mixings in ruby

Today i decided to find how super keyword works in inheritance and including a module in  ruby and how the ladder of function calling build. i made couple of examples in this process, here they are :-

Example 1 :-

class Test

def show
puts "i am in Test show"
end
end

class Test1 < Test

def show
puts "i am in Test1 show"
super
end
end

t = Test1.new
t.show

outputs:-
i am in Test1 show
i am in Test show

its works as expected :-)

Example 2 :-

Some rubiest ( atleast me) think that super calls the parent class method.
Now i create a module have the same name function in it. so that method should not be called. Here is the example :-

module A
 def show
 puts " i am in module A show method"
end
end

class Test

def show
puts "i am in Test show"
end
end

class Test1 < Test

include A
def show
puts "i am in Test1 show"
super
end
end

t = Test1.new
t.show

Output :-
i am in Test1 show
i am in module A show method


Explanation :-

Here as per my simple terminology function i calls it ladder concept of function calling. So when our class loads it creates a function calling ladder as i shown below (its completely my way of understanding the concept ).  when our Test1 starts loading our interpreter see it is inherited from Test it goes to Test class and start making the ladder for show function and puts Test show at level 0. Now control comes back to Test1 class here we include the module A now control goes there and see ohhh here another show method is here so interpreter inserted the show method Just after the Test1 class show method.

Example 1                                                           Example 2
(show method ladder)                             (show method ladder)


| Test1 show|                                           |    Test 1 show   |
----------------                                            ---------------------
|  Test show |                                           | module A show |
----------------                                            ---------------------
                                                               |    Test Show      |
                                                                ----------------------

So super doesn't call the parent class method it just calls the next level function which we make as per our ladder ruby concept.



hmmmmmmmm

What will happen if i write super keyword inside module A show method. As per our ladder concept it should call the Test show

Example 3 :-

module A
 def show
 puts " i am in module A show method"
 super
end
end

class Test

def show
puts "i am in Test show"
end
end

class Test1 < Test

include A
def show
puts "i am in Test1 show"
super
end
end

t = Test1.new
t.show

Output :-
i am in Test1 show
i am in module A show method
i am in Test show


So My Ladder concept works here :-)



hmmmm


Example 4 :-
What will happen if i  include the module after the definition of show method like below

module A
 def show
 puts " i am in module A show method"
 super
end
end

class Test

def show
puts "i am in Test show"
end
end

class Test1 < Test


def show
puts "i am in Test1 show"
super
end
include A 

end

t = Test1.new
t.show

Output :-
i am in Test1 show
i am in module A show method
i am in Test show


Last Example

What will happen if i have another module similar to A

module A
 def show
 puts " i am in module A show method"
 super
end
end

module B
 def show
 puts " i am in module B show method"
 super
end
end

class Test

def show
puts "i am in Test show"
end
end

class Test1 < Test


def show
puts "i am in Test1 show"
super
end
include A 
include B
end

t = Test1.new
t.show

Output :-
i am in Test1 show
i am in module B show method
i am in module A show method
i am in Test show


 Explanation :-

Show Function ladder

                            |    Test1 Show    |
                             ---------------------
                            | module B show |
                            ----------------------
                            | module A show |
                             ---------------------
                            |    Test Show     |
                            ----------------------

 Here module B given preference because our interpreter comes to intereact with Line include B after include A and as per our ladder rule it insert in the ladder just after the class method