Sunday, January 13, 2013

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

Here are the mathematical definitions of e and π (pi):

e = 1 + \frac{1}{1} + \frac{1}{1\cdot 2} + \frac{1}{1\cdot 2\cdot 3} + \frac{1}{1\cdot 2\cdot 3\cdot 4}+\cdots
π = Pi = 22/7  (22/7 is approximate value of pi more accurate value is 355/113)

Now we will take mathematical approach in solving the equality problem.

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

Adding an Application to the Right Click on Every Folder

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)

right_click.png

 

Saturday, January 5, 2013

How a computer scientist failed in solving Fermat Theorem?

Fermat's last theorem was "states that no three positive integers a, b, and c can satisfy the equation a^n + b^n = c^n for any integer value of n greater than two".



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

Planning to take screenshot of your favorite video or generating the thumbnail for 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.

Friday, October 19, 2012

Little note on Algorithms and Data Structures - Part 1

Is O(2^n) equal to O(3^n)? Why?

No. O(f(n)) = O(g(n)) if and only if f(n)/g(n) is bounded between two positive real numbers for all sufficiently large values of n; but as n increases, the ratio 2^n / 3^n tends to zero.

 

What is the expected run-time of quicksort? What is the worst-case run-time?

The expected run-time of quicksort (for random inputs) is O(n log n). The worst-case run-time of quicksort is O(n^2).

What is the difference between a binary tree (that should be binary search tree) and a B-tree? When and why does this difference matter?

Internal nodes in a binary tree have at most two children, while internal nodes in a B-tree can have many children (depending on the block size). This is useful when the tree data is stored in a manner which exhibits large read latencies (e.g., on disk) since the higher fan-out means that the height of a B-tree is less than the height of a corresponding binary tree.

 

Name the heap operations used by heapsort and the asymptotic running time of each.

There are two operations: Heapify, which takes n elements and builds a heap out of them in O(n) time; and pop-max, which deletes the largest element from the heap and returns it in O(log n) time.

 

Describe an algorithm that determines if a graph is bipartite.

Attempt to 2-colour the graph as follows:

  1. Pick an uncoloured vertex; if there are none remaining, return success.
  2. Colour that vertex red.
  3. Perform a graph traversal (depth-first search and breadth-first search both work) starting from the vertex we picked. Every time we reach a vertex, colour it green if all its coloured neighbours are red, or red if all of its coloured neighbours are green; if it has both red and green neighbours, return failure.
  4. Go to step 1.

The graph is bipartite if and only if the 2-colouring algorithm did not fail.