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.

Counting Digits from given Range

Imagine you sell those metallic digits used to number houses, locker doors, hotel rooms, etc. You need to find how many of each digit to ship when your customer needs to number doors/houses:
1 to 100
51 to 300
1 to 2,000 with zeros to the left
The obvious solution is to do a loop from the first to the last number, convert the counter to a string with or without zeros to the left, extract each digit and use it as an index to increment an array of 10 integers.
I wonder if there is a better way to solve this, without having to loop through the entire integers range.
GitHub Link
Thanx to mathematician’s Post that helped me to understand the complexity of problem, i just understood the equation and converted it to code. Enjoy !

SSD vs HDD

This is era of the Ultrabook Laptops .. as we know in UltraBook there is no HDD like Hard Disk there is new technology Called SSD(Solid State Drive ) .. which more faster than HDD … lets check it out ..
These days most people are buying laptops for their computing needs and you have to make the decision between getting either a Solid State Drive (SSD) or Hard Disk Drive (HDD) as the storage component. So which is best to get, a SSD or HDD?  There’s no straight forward answer to this question, each buyer has different needs and you have to evaluate the decision based on those needs, your preferences, and of course budget.  Even though the price of SSDs has been falling and right now there is a tight supply of HDD drives due to Thailand floods, the price advantage is still strongly with HDDs.  But if performance and fast bootup is your top consideration, and money is secondary, then SSD is the way to go.  We’ll make a comparison of SSD and HDD storage and go over the good, the bad and the ugly of both.
What is a SSD?
We’ll make no assumptions here and keep this article on a level that anyone can understand.  You might be shopping for a computer and simply wondering what the heck SSD actually means?  To begin, SSD stands for Solid State Drive.  You’re probably familiar with USB memory sticks, SSD can be thought of as an oversized and more sophisticated version of the humble USB memory stick.  Like a memory stick, there are no moving parts to an SSD, information is stored in microchips.  Meanwhile, a hard drive uses a mechanical arm with a read/write head to move around and read information from the right location on a storage platter.  This difference is what makes SSD so much faster.  As an analogy, what’s quicker, having to walk across the room to retrieve a book to get information or simply magically having that book open in front of you when you need it?  That’s how an HDD compares to an SSD, it simply requires more physical labor (mechanical movement) to get information.
A typical SSD uses what is called NAND-based flash memory, this is a non-volatile type of memory.  What does non-volatile mean you ask?  The simple answer is that you can turn off the disk and it won’t “forget” what was stored on it.  This is of course an essential characteristic of any type of permanent memory.  During the early days of SSD rumors floated around saying stored data would wear off and be lost after only a few years.  Today this is not true, you can read and write to an SSD all day long and the data storage integrity will be maintained for well over 200 years.  In other words, the data storage life of an SSD can outlive you!
An SSD does not have a mechanical arm to read and write data, it instead relies on an embedded processor (or “brain”) called a controller to perform a bunch of operations related to reading and writing data.  The controller is a very important factor in determining the speed of the SSD, decisions it makes related to how to store, retrieve, cache and clean up data can determine the overall speed of the drive.  We won’t get into the nitty gritty of the details for the various tasks it performs such as error correction, read and write caching, encryption and garbage collection to name a few but suffice to say, good controller technology is often what separates an excellent from simply good SSD.  An example of a fast controller today is the SandForce SATA 3.0 (6 Gb/s) SSD controller that supports up to 500 MB per second read and write speeds.
Finally, you may be wondering what an SSD looks like and how easy it is to replace a hard drive with after market.  If you look at the images below you’ll see the top and underside of a typical sized 2.5” SSD, the technology is encased inside either a plastic or metal case and so it looks like nothing more than a battery might look like:
SSD Top Side
SSD Bottom Side
The form factor of the SSD is actually the same as a regular hard drive, it comes in a standard 1.8”, 2.5” or 3.5” size that can fit into the housing and connectors for the same sized hard drives.  The connector used for these standard sizes is SATA, there are smaller SSDs available that use what’s called mini-SATA (mSATA) and fit into the mini-PCI Express slot of a laptop.
What is an HDD?
Hard Disk Drives, or HDD in techno-parlance, have been around for donkeys years relative to the technology world.  HDDs were first introduced by IBM in 1956, yes folks this is nearly 60-year old technology, thank goodness vacuum tubes for TVs didn’t last so long!  An HDD uses magnetism to store data on a rotating platter.  A read/write head floats above the spinning platter reading and writing data.  The faster the platter spins, the faster an HDD can perform, typical laptop drives today spin at either 5400 RPM (Revolutions per Minute) or 7200RPM, some server based platters can spin at up to 15,000 RPM.
The major advantage of an HDD is that it is capable of storing lots of data cheaply.  These days 1 TeraByte (1,024 gigabytes) of storage is not unusual for a laptop hard drive, and the density continues to grow.  Cost per gigabyte is only around $0.10 / GB these days for an HDD, that’s amazing when you compare it to the near $1.75 / GB cost for an SSD.  If you want cheap storage and lots of it, using a standard hard drive is definitely the more appealing way to go.
HDDs predominantly use the SATA interface.  The most common size for laptop hard drives is the 2.5” form factor while a larger 3.5” form factor is used in desktop computers.  The larger size allows for more platters inside and thus more storage capacity.  Some desktop hard drives can store up to 4TB of data! HDDs look essentially the same from the outside as an SSD, below is an example of what an HDD looks like using the Seagate Barracuda 3TB hard drive:
HDD Top Side
HDD Bottom Side
SSD Vs HDD Comparison
Now it’s time to do some comparisons and determine which might be best for  your needs, an SSD or HDD?  The best way to compare items is a table with a side by side comparison of items in which a green box indicates an advantage:
Attribute SSD (Solid State Drive) HDD (Hard Disk Drive)
Power Draw / Battery Life Less power draw, averages 2 – 3 watts, resulting in 30+ minute battery boost More power draw, averages 6 – 7 watts and therefore uses more battery
Cost Expensive, in excess of $1.50 per gigabyte Only around $0.10 per gigabyte, very cheap
Capacity Typically not larger than 256GB for notebook size drives Typically 500GB – 1TB for notebook size drives
Bootup Time for Windows 7 Around 22 seconds average bootup time Around 40 seconds average bootup time
Noise There are no moving parts and as such no sound Audible clicks and spinning can be heard
Vibration No vibration as there are no moving parts The spinning of the platters can sometimes result in vibration
Heat Produced Lower power draw and no moving parts so little heat is produced HDD doesn’t produce much heat, but it will have a measurable amount more heat than an SSD due to moving parts and higher power draw
Failure Rate Mean time between failure rate of 2.0 million hours Mean time between failure rate of 1.5 million hours
File Copy / Write Speed Generally above 200 MB/s and up to 500 MB/s for cutting edge drives The range can be anywhere from 50 – 120MB / s
Encryption Full Disk Encryption (FDE)Supported on some models Full Disk Encryption (FDE) Supported on some models
File Opening Speed Up to 30% faster than HDD Slower than SSD
Magnetism Affected? An SSD is safe from any effects of magnetism Magnets can erase data
If we tally up the checkmarks the SSD gets 9 and HDD gets 3.  Does that mean the that an SSD is three times better than an HDD?  Not at all, it depends on your needs, the comparison here is just to lay out what the pros and cons are for each.  Here are some rules to follow in deciding which drive is best for you:
If:
  • You need lots of storage capacity, over 500GB
  • Don’t want to spend much money
  • Don’t care too much about how fast a computer boots up or opens programs then get a hard drive.
If:
  • You are willing to pay for faster performance
  • Don’t mind limited storage capacity or can work around that then get an SSD.

this Article is Copied from Storage Reviews 

Sync Subtitles With The Video In VLC

I can’t stress the usefulness of subtitles enough, especially when you’re watching a movie in a foreign language. I was watching Heavenly Forest, a Japanese romantic drama, a few days back. The movie was wonderful, but I wouldn’t have understood anything had it not been for those English subtitles. I even tend to use English subtitles while watchingEnglish movies, because you guys talk so fast (Americans) or so weird (British) that it’s hard for me to grasp!
Handy as they are, subtitles can turn extremely irritating if they’re out of sync with the video. They distract you, and you end up understanding even less than what you’d have without the subs. Thankfully, if you’re using VLC player to watch the videos, you can make use of a nifty feature in the program to sync the subtitle with the video! Do note that it’ll only temporarily sync the subtitles with the video, and the sync will be gone the next time you watch the video.
Anyway, lets get started with how to implement it. I’m assuming that you’ve already loaded the video and subtitle files into VLC (you can just drag them both into its interface). Now, carefully take a look at the video and the subs, and see whether the subs are lagging behind or running ahead of the video. If you’re watching a foreign movie, it may seem like a very difficult job, but just try a little hard and you should be able to make this out. For example, if you see a girl screaming and running around wildly, and the subs show “Help me! Help me!” 3 seconds after that scene, this means that the titles are 3 seconds behind the movie.
Once you’ve figured out the lag / lead of the subtitle, it’s time to sync it with the video. In VLC, navigate to Tools > Track Synchronization, where you’ll find the Subtitles/Video section. Now comes the important part – syncing the subtitle. If the subtitle is lagging behind the video, you’ve to provide a negative value to ‘Advance of subtitles over video’. Say the subs display 3 seconds after the video, the value you got to enter is –3.000 s. Note that you can adjust the sync time to upto a thousandth of a second, although adjusting to the tenths does the job in all cases. Similarly if the subtitle is ahead of the video, enter the required positive number of seconds. Hit the Refresh button at the top right corner of the window, and you should see the change immediately.