Explore Linux

How to add a menu with “Open terminal here”?

sudo apt-get install nautilus-open-terminal
nautilus -q
How to add "open as admin"? 

32 bit- Direct link from ubuntu.mirror.cambrium.nl

64 bit- Direct link from ubuntu.mirror.cambrium.nl

Once downloaded right click on the .deb > extract here. In the extracted contents, Browse tousr/lib/nautilus/extensions-2.0, inside will be libnautilus-gksu.so

As root (To enter root open terminal and enter gksu nautilus) copy the file from above in to/usr/lib/nautilus/extensions-3.0 folder in your filesystem

Simply using terminal:
 sudo cp ~/Downloads/nautilus-gksu_2.0.2-5ubuntu2_i386/usr/lib/nautilus/extensions-2.0/libnautilus-gksu.so /usr/lib/nautilus/extensions-3.0
Stopping WIFI LED blinking 

sudo -i echo 'options iwlagn led_mode=1' >> /etc/modprobe.d/wlan.conf modprobe -r iwlagn && modprobe iwlagn    Update Kernel update-initramfs -u -v -t -k all   de-install kernel dpkg --purge linux-imageXXXXX 

Change folder permissions 
sudo chown -R usrname:group simulator
for example: sudo chown -R jingzhe:jingzhe simulator

backup whole system

tar czvf – /root/code >; /tmp/code_bak.tgz backup

tar xzvf /tmp/code_bak.tgz /root/code Recover

uninstall software
Apt-get install –reinstall
Apt-get –purge remove …….

install camera

<code>sudo apt-get install camorama xawtv</code>

simply install my favorite camera display software xawtv, the drivers will automatically be installed.

create compress file

tar jcvf <filename>.tar.bz2 dir1 dir2 file1 file2 …

Learning Enthusiasm

After years I have been through, I’ve realized that in order to keep learning new things and be productive, need to keep interests on it and be proud of what I am doing. I always remember those moments that I was thrilled by resolving a big problem or approaching to solve it. Back four years ago, when I was a sophomore at college, I was so crazy about reading the tech magazine about IT and computer stuffs and of course I was proud of it at that time. I treated myself as a professional engineer. I still clearly remember that reading at library during nights and couldn’t stop until the library time was over.

One way to keep me interested on tech is that always watch the news about new technology, new stuff coming out of industry and startups. See how positive the world is going on and be ready for the next big thing happens. Maybe the next one would happen on me. How knows? Being sensitive and involved into the world makes me to have a sense which would be more likely to be the step moving me to the success.

Every big success in my life is like a gift of my hard work. If I didn’t quit my job at China and concentrated on preparing GRE and TOEFL, I wouldn’t be at America right now. If I didn’t promote myself to Prof. Yan meng, I wouldn’t get a chance to do the research project at Stevens. If I didn’t work so hard to make the research project in a nice progress, I wouldn’t be a teaching assistant, then, which gave me a lot of good things in the memory. If I didn’t search and apply so hard to find a job day by day, I wouldn’t be possible to work at Harsco, set at a neat office and earn a good money now, when others are still seeking for a job. Therefore, every results or success came from certain reasons. The reason is that I need to be myself, and concentrated on one single thing!

What should I do right now? I thought it’s a nice job working at Harsco, but when I got into the door, started to realize that no, this is a new start! The technology Harsco is using is so old, If I don’t learn new stuff by myself, after several years, I won’t be competitive anymore in the market and hard to improve in the career by then. I cannot stop here, this is not my ultimate goal! I wanna big success on the career and maybe one day in the future I can really make something happens!

So just wanna write these words to remind me keeping growing and learning! I need to be more successful than others, so I need to put more efforts on it to make it happens!

Kernel Modules Versus Applications

While most small and medium-sized applications perform a single task from beginning to end, every kernel module just registers itself in order to serve future requests, and its initialization function terminates immediately.

Another major difference between event-driven applications and kernel code is in the exit function: whereas an application that terminates can be lazy in releasing resources or avoids clean up altogether, the exit function of a module must carefully undo everything the init function built up, or the pieces remain around until the system is rebooted.

an application can call functions it doesn’t define. i.e. “printf” is not a internal of system, but a function belonging to C library. A module, on the other hand, is linked only to the kernel, and the only functions it can call are the ones exported by the kernel; there are no libraries to link to.

Another important difference between kernel programming and application programming is in how each environment handles faults: whereas a segmentation fault is harmless during application development and a debugger can always be used to trace the error to the problem in the source code, a kernel fault kills the current process at least, if not the whole system.

Something about Pointers — Part B

Pointer to Pointer

These is an advanced behavior that **ptr, which has two dereference operators before the name ptr. It’s called Pointer to pointer.

void func(int** ppInt);


if an example like this:

exchange(int* p1, int* p2)


Int *Temp = p1;

pt1 = pt2;

pt2 = Temp;


Exchange two values of pointers, but if you pass two pointers to p1 and p2, after calling this function, these two pointers that is out of the range of this function will not be changed.

This problem can be normalized. Think about the purpose of arguments. We need arguments to pass a value that a function is going to use or modify. But for the matter of efficiency, we always pass a reference rather than a “physical” value. As usual, we define a pointer to point a int or char to get use of this value. However, if we need to manipulate a pointer and meanwhile maybe we need to modify the value which the pointer pointes, we require a pointer to pointer.

So that *pp points to *p, which can modify the attribute of pointer which points to the value. **pp can touch one step further modifying the value indeed.

Something about Pointers — Part A


You must consider that at the moment of declaring a pointer, the asterisk (*) indicates only that it is a pointer, it is not the dereference operator(*) (although both use the same sign: *). Remember, they are two different functions of one sign. Thus, we must take care not to confuse the previous code with: 

int number = 2;
Int* pt = &number; 

Equal to:
int number=2;
Int *pt;
Pt = &number;

int *pt;
*pt = &number; 

Int *pt = 49; //You are trying to determine the memory address to the pointer!?


Void pointers:

The void type pointer is a special type of pointer in C/C++, which points to a value that has no type. For this characteristic, before using or dereferencing it, we will always have to cast the address into some other concrete data type, letting computer knows that which kind of data type you tend to present.

// increaser
#include <iostream>
using namespace std;
void increase (void* data, int psize)
  if ( psize == sizeof(char) )
  { char* pchar; pchar=(char*)data; ++(*pchar); }
  else if (psize == sizeof(int) )
  { int* pint; pint=(int*)data; ++(*pint); }
int main ()
  char a = 'x';
  int b = 1602;
  increase (&a,sizeof(a));
  increase (&b,sizeof(b));
  cout << a << ", " << b << endl;
  return 0;


At this example, void* data as a void argument of increase function. When the function is called in main function, like void* data = &a.


Reference value VS. Pointer

This is always a point that easily gets confused when I define and pass an argument into a function. Let’s take about these two a little bit.

When declaring a reference value: int& y = *x, this is simply make y = *x. but it sounds meaningless, so rarely have programs have this kind of code. But it’s very common using in declaration of arguments. Foo(int &y, int *p);. When we call this function, foo(f, &f), that makes us a little bit convenience to write down the function omitting ampersand(&).

When I understand that passing argument is exactly the same as declaration a variable, the confusion is clearly solved.

Char-version string in C/C++

Today when i was practicing a problem about reversing elements in a string using c/c++, I found out something interesting. 

void reverse(char* str)
char *charSt;
charSt = str;

int count=0;
char temp=0;
while (*str != NULL)
temp = *str;
*str– = *charSt;
*charSt++ = temp;


int main()
char* words = “as12ps”;

This code snippet looks fine and non-error when compiling, but it has error in the running time. sounds wired. 

After second thought, I found out where is the problem:

I defined a pointer, char* words = “as12ps”, in the main function as a argument passing into reverse function. In fact, I define a const char array in the memory storing “as12ps” and assign the starting address to the pointer words. Do you realize what’s kind of problem it is?

How can we manipulate const values in the latter? Yes, this is the place that the issue appears. So instead of defining a char pointer, I declare a char array carries “as12ps”

char words[7] = “as12ps”  // you have to define it has 7 elements, not 6, because c/c++ will add a “NULL” at the end of array to indicate the completion of the array. 

As you defined a char array, then we pass the starting address of the array to reverse function. The problem solved!

precise timer in c/c++

In windows:

#include <windows.h>
#include <stdio.h>
int main(int argc, char **argv)
LARGE_INTEGER start_t, stop_t;
double exe_time;
fprintf(stdout, “The frequency of your pc is %d.\n”, freq.QuadPart);
exe_time = 1e3*(stop_t.QuadPart-start_t.QuadPart)/freq.QuadPart;
fprintf(stdout, “Your program executed time is %fms.\n”, exe_time);
return 0;


In linux:

double mytic()
double result = 0.0;
struct timeval tv;

gettimeofday( &tv, NULL );

result = tv.tv_sec*1e6 + tv.tv_usec;

return result;

void fun()
double start, stop, exetime;
start = mytic();
// some computation…
stop = mytic();
exetime = stop – start;