How to determine your machine is “Little Endian” or “Big Endian”.

What is big and Little Endian ?

Little and big endian are two ways of storing multibyte data-types ( int, float, etc). In little endian machines, last byte of binary representation of the multibyte data-type is stored first. On the other hand, in big endian machines, first byte of binary representation of the multibyte data-type is stored first.

Big Endian(Wikipedia)

Little Endian(Wikipedia)

Is there a quick way to determine endianness of your machine?
There are n no. of ways for determining endianness of your machine. Here is one quick way of doing the same.

#include <stdio.h>
int main()
{
   unsigned int i = 1;
   char *c = (char*)&i;
   if (*c)   
       printf("Little endian");
   else
       printf("Big endian");
   getchar();
   return 0;
}

In the above program, a character pointer c is pointing to an integer i. Since size of character is 1 byte when the character pointer is de-referenced it will contain only first byte of integer. If machine is little endian then *c will be 1 (because last byte is stored first) and if machine is big endian then *c will be 0.

Restoring lost commits in git

Hey i am writing post after a long time.

I was working in git and committed some changes, i forgot to pushed to branch and i forgot the commit too. I reseted the HEAD :(.

So, you just did a git reset --hard HEAD^ and threw out your last commit. Well, it turns out you really did need those changes. . Don’t fear, git should still have your commit. When you do a reset, the commit you threw out goes to a “dangling” state. It’s still in git’s datastore, waiting for the next garbage collection to clean it up. So unless you’ve ran a git gc since you tossed it, you should be in the clear to restore it.

$ git show-ref -h HEAD
  7c61179cbe51c050c5520b4399f7b14eec943754 HEAD

$ git reset --hard HEAD^
  HEAD is now at 39ba87b Fixing about and submit pages so they don't look stupid

$ git show-ref -h HEAD
  39ba87bf28b5bb223feffafb59638f6f46908cac HEAD

So our HEAD has been backed up by one commit. At this point if we wanted it back we could just git pull, but we’re assuming that only our local repository knows about the commit. We need the SHA1 of the commit so we can bring it back. We can prove that git knows about the commit still with the fsck command:

$ git fsck --lost-found
  [... some blobs omitted ...]
  dangling commit 7c61179cbe51c050c5520b4399f7b14eec943754

You can also see the that git knows about the commit still by using the reflogcommand:

$ git reflog
  39ba87b... HEAD@{0}: HEAD~1: updating HEAD
  7c61179... HEAD@{1}: pull origin master: Fast forward
  [... lots of other refs ...]

So, we now have our SHA1: 7c61179. If we want to get immediately apply it back onto our current branch, doing a git merge will recover the commit:

$ git merge 7c61179
  Updating 39ba87b..7c61179
  Fast forward
    css/screen.css |    4 ++++
    submit.html    |    4 ++--
    2 files changed, 6 insertions(+), 2 deletions(-)

This command will bring your lost changes back and make sure that HEAD is pointing at the commit. From here you can continue to work as normal! You could also checkout the SHA1 into a new branch, but really a merge is the fastest and easiest way to restore that lost commit once you have the hash. If you have other ways let us know in the comments!

Thanx to gitReady for this valuable post.

Some of the most interesting & Shocking In formations about Cricket.

Hello Guys this is my first non-technical post, I would love to share some of the most shocking, interesting information about Cricket History.

1. Sanath Jayasuriya has more ODI wickets than Shane Warne : Yes it’s correct Shane warne took 293 wickets in his ODI career and Sanath took 321 wickets. It was shoking for me too.

                     

2. On 12th January 1964, Indian spinner Bapu Nadkarni bowled 21 consecutive maiden overs vs England at Chennai. His figures were 32-27-5-0 which is an economy rate of 0.15 per over which is the lowest of all bowlers where 10 or more overs were bowled.

                                           

3. Wilfred Rhodes took 4,204 wickets in First Class cricket. No, it’s not a typo. He actually did take more than Four Thousand wickets. He also happened to score 39, 969 runs.

                     

4. Sachin is not the highest Centuries hitter, Sir Jack Hobbs scored 199 centuries in his First Class career.

                     

5. In a World Cup Match, chasing 335, Sunil Gavaskar scored an unbeaten 36 off 174 balls. In the Prudential World Cup of 1975, in the match between India and England, England set the target of 335 runs in 60 overs. Sunil Gavaskar batted throughout the innings and scored only 36 runs of 174 balls. India managed to score only 132 runs in 60 overs with 7 wickets in hand.

                   

6. Sachin + Zaheer = (Almost) Kallis.

                    

7. Sir Don Bradman has just hit 6 sixes in his entire career.

8. The England Cricket Team is the only team in ODI history to lose a 60 over ODI Final (1979 World Cup), a 50 over ODI Final (1992 World Cup and 2004 Champions Trophy) and a 20 over ODI Final (2013 Champions Trophy) in ICC tournaments.