Sunday, January 13, 2013
How to take screenshot on Mac Book Air / Pro laptops
1. Whole Screen, press "Command + Shift + 3": it takes screenshot of whole screen
2. A region on the screen, press "Command + Shift + 4": changes mouse pointer which helps to select a specific region of the screen and takes snapshot when mouse click is released
3. A window, press "Command + Shift + 4 + Space Bar": changes mouse pointer to camera icon. now click on any window and it takes snapshot of that window
Note that these screenshots will get saved on desktop.
getting started with GIT - an introduction
Git is an open source distributed version control system.
The screen shots were taken from youtube presentation by Scott Chacon.
Traditional version control systems used to have a single storage where all the developers used to connect and operate. This lead to a single point of failure.
In git, there is no single server which maintains the history. All parties/developers's machine become node in the distributed system and they can work in isolated fashion as well. Basically the system behaves as loosely coupled.
Below is the comparison between traditional VCS and Git. Git stores the file contents along with the checksum which relieves it from managing the change log and plenty of indirected connections between file versions.
Git stores all the checksum as directed graph which helps it easily identify what and how to merge code.
Below are the basic commands for doing any file modifications:
when we do 'git checkout' it creates index database and then creates a local directory where stores all the contents. Running 'git add' puts the file contents along with the checksum in the Index database. The final 'git commit' does a commit from Index database to local repository. Note that 'commit' doesn't look at the local files, it only looks at Index database for final commit to repository. What it means is after doing 'add', we can delete the local file however 'commit' will still continue without loosing the change.
Merging: git does merging by looking at the changes between current branch 'master' and the branch to be merged 'branchA'. It basically walks through the directed graph and tries to find the common ancestor. If found then it does a fast-forward merge which means it moves the head pointer to 'branchA'.
Simple merge (fast forward). merge of branch iss53:
Simple delete: if Head can reach the branch directly then it deletes else skips. so it has a safety mechanism.
git branch -d iss53
i18n can't be reached from head so using below command forcefully deletes it. Hard delete.
git branch -D i18n
steps of code push.
scott pushes the change
git does a fast-forward merge in origin master repo because it sees a common ancestor between origin master and scott's master.
Now Nick tries to push but that will fail as origin master in Nic's local repo and in origin remote repo are pointing to different commit versions.
so Nick does a 'git fetch' first.
then he does merge. because (pull = fetch + merge).
now things look good and origin master points to right commit version. and hence the collaborated delivery completed gracefully,
How to create Aliases?
Git subsets
answer is: git log i18n ^master
What is the change in iss53 which is not in i18n?
answer is the highlighted commit histories:
...Quizes...
Git Incoming? its the change which is in origin/master and not in local master. solution: fetch will pull in the change.
here is how to check what changes we are missing in local:
git log origin/master ^master
Git outgoing? its the change which is in local master and still not got pushed to origin/master. solution: git push will deliver the change
here is how to check what changes we still did not merge to origin/master from local:
git log master ^origin/master
Friday, January 11, 2013
Which is bigger e^pi or pi^e? - a mathematical approach

π = Pi = 22/7 (22/7 is approximate value of pi more accurate value is 355/113)
Lets Assume pi^e > e^pi
now taking natural log (Log of base e) on both sides.
Log (pi^e) > Log (e^pi)
eLog(pi) > piLog(e)
eLog(pi) > pi ---> Log e is 1 because its Log of base e. (LOGe(e) = 1)
Log(pi) > pi/e
since we know that Pi > 1 and hence Log(pi) >1,
then above becomes
1 > pi/e
e > pi - which is false (pi = 3.14, e = 2.72)
Therefore our assumption (pi^e > e^pi) is not correct
hence pi^e is less than e^pi.
Thursday, January 10, 2013
Add Application to Windows context menu
Here is how to add any application to the Context Menu when you right click on any Folder. This way you do not have to always go to the Start Menu. When you right click on any folder, you can have access to that application, the same as using Sent To.
1. Open RegEdit
2. Go to HKEY_CLASSES_ROOT\Folder\shell
3. Add a new Key to the "Shell" Key and name it anything you like.
4. Give it a default value that will appear when you right click a folder, i.e. NewKey (use an "&" without the quotes, in front of any character and it will allow you to use the keyboard)
5. Click on the Key HKEY_CLASSES_ROOT\Folder\shell\NewKey
6. Add a New Key named Command
7. Set the (Default) value of the application you want to run
8. For example: c:\program files\internet explorer\iexplore.exe (Include the full path and parameters if you need them)

Saturday, January 5, 2013
How a computer scientist failed in solving Fermat Theorem?

here is the puzzle:
A computer scientist claims that he proved Fermat theorem is correct for the following 3 numbers:
x=2233445566, y=7788990011, z=9988776655
He declared that the below equation satisfies for N:
x^N + y^N = z^N
Later the scientist was proved wrong by a 10 year old kid. How come he do that even without the help of the computers?
Here is the solution:
x=2233445566, y=7788990011, z=9988776655
square the last digits of each numbers and notice that the last digit of the result remains same.
which proves that for any value of N, the last digits remains same.
6 * 6 = 36 , 1 * 1 = 1 , 5 * 5 = 25
hence x^N ends with 6, y^N ends with 1, z^N ends with 5
try out the equality with the last digits: 6 + 1 != 5
this proves that the values of x,y and z doesn't satisfy Fermat's theorem.
Tuesday, December 4, 2012
Automatically take screenshots every few seconds from a video
The MPlayer tool could be used to do it on a command line.
download mplayer from http://www.mplayerhq.hu/design7/dload.html
The below command will capture the frame at 10 seconds interval till the end of the video (video length - 1 second):
mplayer -vo jpeg -sstep 10 -endpos 499 myvideo.avi --- suppose video is 500 seconds long
People could use this tool to generate pictures out of video and upload to get feedback from their friends/users.
Friday, November 30, 2012
mutex Vs read-write lock
what is the diff between mutex and readwrite lock?
Mutex:
A Mutex is an OS object which supports a state of ‘locked’ or ‘available’. What it means is that if multiple threads attempt to lock the Mutex, only one will ‘own’ that lock while others will be waiting in the queue behind each other.
The waiting threads will block the function call from where they are initiated until Mutext is unlocked ‘available’ and a thread gets chance to claim it.
There are two types of Mutex, ‘named’ and ‘unnamed’. A named Mutext can be accessed from different processes running on the system whereas unnamed Mutex can only be used from inside a single process. On Windows OS, the Mutex is replaced with Critical Section which is faster, unnamed and can be used from a single process only.
Read-Write Lock:
It is a file system construct that works over peer-to-peer file sharing or any other file sharing schemes.
They are similar to Mutex with the difference that once the file is locked, other threads are denied the lock request and are not being put in the waiting queue.
File locking supports ‘shared-read’ request. What it means is threads requesting for reading the file, get the lock and can read the file however there can be only one file write access.

























