Monthly Archives: July 2013

.bash_profile vs .bashrc

WHEN working with Linux, Unix, and Mac OS X, I always forget which bash config file to edit when I want to set my PATH and other environmental variables for my shell. Should you edit.bash_profile or .bashrc in your home directory?

You can put configurations in either file, and you can create either if it doesn’t exist. But why two different files? What is the difference?

According to the bash man page.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

What is a login or non-login shell?

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.

Why two different files?

Say, you’d like to print some lengthy diagnostic information about your machine each time you login (load average, memory usage, current users, etc). You only want to see it on login, so you only want to place this in your .bash_profile. If you put it in your .bashrc, you’d see it every time you open a new terminal window.

Mac OS X — an exception

An exception to the terminal window guidelines is Mac OS X’s, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.


Most of the time you don’t want to maintain two separate config files for login and non-login shells — when you set a PATH, you want it to apply to both. You can fix this by sourcing .bashrc from your.bash_profile file, then putting PATH and common settings in .bashrc.

To do this, add the following lines to .bash_profile:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc

Now when you login to your machine from a console .bashrc will be called.


downgrade nexus s from 4.1.x to 2.3.6

after upgrading nexus s to 4.1.2, it’s not straight forward to downgrade to 2.3.6. A error occurs when fastboot -w update


fastbooot flash recovery recovery-clockwork- (which is downloaded from the Internet)

boot to bootloader, enter recovery mode, install rom (zip file in sdcard) from zip, which is downloaded from the Internet.

I’m not sure the rom is official rom as later there comes errors, A flashable rom is a zip file with boot.img, bootloader.img, radio.img and system folder, recovery folder and META-INF folder.

After that, the older version android is installed.

But when the system starts, there comes a lot of package crash errors and I’m not able to enter the system.

Then I flash the older version factory img with regular steps. It succeeds.


Ps: nexus S adb driver need to be downloaded from Samsung,



    evercookie is a javascript API available that produces
    extremely persistent cookies in a browser. Its goal
    is to identify a client even after they've removed standard
    cookies, Flash cookies (Local Shared Objects or LSOs), and
    evercookie accomplishes this by storing the cookie data in
    several types of storage mechanisms that are available on
    the local browser. Additionally, if evercookie has found the
    user has removed any of the types of cookies in question, it
    recreates them using each mechanism available.
    Specifically, when creating a new cookie, it uses the
    following storage mechanisms when available: 
     - Standard HTTP Cookies 
     - Local Shared Objects (Flash Cookies)
     - Silverlight Isolated Storage 
     - Storing cookies in RGB values of auto-generated, force-cached 
        PNGs using HTML5 Canvas tag to read pixels (cookies) back out
     - Storing cookies in Web History 
     - Storing cookies in HTTP ETags 
     - Storing cookies in Web cache 
     - caching
     - Internet Explorer userData storage
     - HTML5 Session Storage 
     - HTML5 Local Storage 
     - HTML5 Global Storage 
     - HTML5 Database Storage via SQLite
    TODO: adding support for:
     - Caching in HTTP Authentication 
     - Using Java to produce a unique key based off of NIC info
    Got a crazy idea to improve this? Email me! 

Static class declarations, nested classes

In order to understand the use of the static keyword in class declaration, we need to understand the class declaration itself. You can declare two kinds of classes: top-level classes and inner classes.

Top-level classes

You declare a top-level class at the top level as a member of a package. Each top-level class corresponds to its own java file sporting the same name as the class name.

A top-level class is by definition already top-level, so there is no point in declaring it static; it is an error to do so. The compiler will detect and report this error.

Inner classes

You define an inner class within a top-level class. Depending on how it is defined, an inner class can be one of the following four types:

1. Anonymous. Anonymous classes are declared and instantiated within the same statement. They do not have names, and they can be instantiated only once.

The following is an example of an anonymous class:

okButton.addActionListener( new ActionListener(){
   public void actionPerformed(ActionEvent e){

Because an anonymous class doesn’t have a normal class declaration where it’s possible to use static, it cannot be declared static.

2. Local. Local classes are the same as local variables, in the sense that they’re created and used inside a block. Once you declare a class within a block, it can be instantiated as many times as you wish within that block. Like local variables, local classes aren’t allowed to be declared public, protected, private, or static.

Here’s a code example:

//some code block .......{
   class ListListener implements ItemListener {
      List list;
      public ListListener(List l) {
         list = l;
      public void itemStateChanged(ItemEvent e) {
         String s = l.getItemSelected();
   List list1 = new List();
   list list2 = new List();
   list1.addItemListener(new ListListener(list1));
   list2.addItemListener(new ListListener(list2));

3. Member. Member classes are defined within the body of a class. You can use member classes anywhere within the body of the containing class. You declare member classes when you want to use variables and methods of the containing class without explicit delegation.

The member class is the only class that you can declare static. When you declare a member class, you can instantiate that member class only within the context of an object of the outer class in which this member class is declared. If you want to remove this restriction, you declare the member class a static class.

When you declare a member class with a static modifier, it becomes a nested top-level class and can be used as a normal top-level class as explained above.

4. Nested top-level. A nested top-level class is a member classes with a static modifier. A nested top-level class is just like any other top-level class except that it is declared within another class or interface. Nested top-level classes are typically used as a convenient way to group related classes without creating a new package.