C/C++ callback with sending object pointer

The callback was always confusing for me until today. Today, I wrote my own callback then put in the library. After that, In my c++ application I register my function to the callback. It was really cool the see my c++ function getting called from outside of my program.  Especially, when it is my own callback function.

While I was doing this I came across a website which is really good to learn for the different aspect of the writing callback. You can access the website from here 

If you go over the website and run the given examples, you will have a deep intuition of the callback function both in c and c++.

Have a wonderful day.

Some useful Git command

If you want to change default git’s editor.

git config --global core.editor "vim"

Change email and name

git config --global user.name "name"
git config --global user.email "email"

Let say you did some change in master branches and you want to move this change to another branch. It can happen at least it happened to me. Here is the solution
Create a branch any name. example test
git stash
git checkout test
git stash apply

It has been taken from here

 

Kinect linux

If you are using the kinect XBOX 360, follow this post

Ubuntu + Kinect + OpenNI + PrimeSense

Automatically transfer all data from USB

Hello Everybody,

Today I have done some something unusual. I write some script in Linux. My ultimate goal was trying to do copy all file from flash drive automatically when it is plugged into my computer. To achieve my goal I need to learn some new things 🙂

First I have to learn how to triggered my bash script when USB plugged in o computer. In Linux, one way to do this is udev rules. I wrote my own rule which any USB plugged into my computer will triggered my batch script that copy all the files from USB to my computer.

Here is very useful documentation for how to write udev rules. Here is my rule which it is specifically about my flash drive.

KERNEL=="sd*", ATTRS{idVendor}=="1d6b", ACTION=="add", SYMLINK+="NewUSB", RUN+="/home/username/auto_relay.sh"

auto_realy.sh script.

#!/bin/bash
/home/username/auto_import.sh & exit

auto_copy.sh

#!/bin/bash
sleep 5;
cd /home/username;
mkdir mountFolder;
mount /dev/NewUSB mountFolder;
mkdir fromFlash;
sleep 3;
cp -a mountFolder/* fromFlash/;
chown username:username -R fromFlash/;

You may want to mount different place and randomly create a new folder name for each flash drive plugged into computer.

This script and udev rule can be improved.

Some useful command;

sudo udevadm monitor

sudo udevadm info

sudo udevd –debug   // this command show all the things when USB plugged and unplugged.