Unix Timestamp in .NET

October 16, 2008

In one of my current projects, I’m required to calculate Unix Timestamps in my .NET classes. Unix Timestamp is defined as number of second elapsed since January 1, 1970 00:00:00.

.NET also provides a very useful class System.DateTime for Date and Time calculation. Unlike Unix standard, DateTime type in .NET represents date and time values from 12:00:00 midnight, January 1, 0001 A.D. through 11:59:59 P.M., December 31, 9999 A.D. measured in 100-nanoseconds units called Ticks.

Using above facts, here is the simple code for DateTime conversion between these two standards:


long ToUnixTimestamp(System.DateTime dt)
{
    DateTime unixRef = new DateTime(1970, 1, 1, 0, 0, 0);
    return (dt.Ticks - unixRef.Ticks) / 10000000;
}
DateTime FromUnixTimestamp(long timestamp)
{
    DateTime unixRef = new DateTime(1970, 1, 1, 0, 0, 0);
    return unixRef.AddSeconds(timestamp);
}
Advertisements

Economical Numbers

October 11, 2008

There are 10^11 stars in the galaxy. That used to be a huge number. But it’s only a hundred billion. It’s less than the national deficit! We used to call them astronomical numbers. Now we should call them economical numbers.


Richard Feynman

TeaBreak Tea Party!

July 27, 2008

I attended Tea Party by TeaBreak.pk today and all I can say that it was a “Mind blogging experience” :)

TeaBreak.pk is a small start-up by two of my friends Asim and Ammar. It provides an opportunity for Pakistan Bloggers community to meet on a single platform. I think the most important aspect of TeaBreak is that it gives a community concept to local bloggers and by arranging such gathering, it provides opportunity to meet with popular bloggers in person. More about TeaBreak is here.

The discussion among bloggers in party was also good but I missed an interesting discussion about regulation of blogs which in opinion will kill the spirit of “Freedom” on internet.

Here are few snaps:

From Teabreak TeaP…

From Teabreak TeaP…

From Teabreak TeaP…

From Teabreak TeaP…

From Teabreak TeaP…

Tagged

March 14, 2008

Tagged by Ali.

Following text is from the book “Rebel Code”. Jay Walker gave me this book to read few weeks ago but still I’m unable to find time to read it. He has also written review of this book here.

From chapter “Learning from Berkeley”:

Sending the university e-mail to the right place was no longer a simple matter, and the system employed by Delivermail couldn’t cope with the various kinds of networks that were being hooked into Berkeley. Allman decided that he needed to rewrite Delivermail so that machines could be configured without fiddling with the software itself, and to build more intelligence into the program so that it could decipher from the e-mail addresses where messages should be sent.

He called the result Sendmail. Its success was driven in part by the new flexibility it offered. “If you had a new network, you could integrate that into Sendmail more quickly than you could into the others,” Allman explains, “This was long before everyone was doing Internet, and so new networks would show up, mushrooms in the night.”

Plan Your Trip

February 19, 2008

I am not a very frequent flyer but during my recent trips I found following two tools really very useful:

TripIt
TripIt is an unbelievably convenient way to manage your online itineraries. As Joel Spolsky discussed here, it’s really magical. Just forward your trip related emails to plans@tripit.com and all done! It’ll automatically generate you a beautiful itinerary and send you back the URL of it. You don’t even need sign-up. Your email address will differentiate you from others.

SeatGuru
I love this site because today I just had a very comfortable flight because of it. If you’re tall like me and have traveled in economy class, you can easily guess the pain I face in long flights :-)

SeatGuru can guide you what seats suit you best. For example, if you are a tall person, you definitely need some extra legroom and this site can tell you which seats have extra legroom in your aircraft. Not only this, it also lists out seats which you should beware of.

A 26 Hours Day – Finally in Bahrain

January 19, 2008

Finally in Bahrain!

Connecting flights, 3 hours long stay at Dubai Airport, delays in deprture.. Ah, it was a long tiring day!
Yea really longer than usual because I had to move my watch 2 hours back :)

But it was fun!

Here are the few snaps of not so good quality:

From Bahrain

From Bahrain

From Bahrain

We (I, Khawer and Tuaha) just came back to our apartments after having a nice dinner at a popular food court of the city. Bahrain is really a small, quite and beautiful country and I’m loving it. Weather is terribly cold now and I find it difficult to even type this post. Maybe I should go to sleep now.

New Year, New Beginnings

January 18, 2008

A whole year passed with silence here. But in reality 2007 was not at all a silent year for me. It was a year full of interesting and learning experiences. A year which I’m not gonna forget easily.

A lot has happened. ProCom, NetCom, Softec, PDC 07, MIC, FYP, Graduation and a lot more. With some tough and life changing personal experiences which are simply unforgettable.

In July, just after my graduation, I joined E-Banking dept. of Avanza Solutions as Software Engineer. A good thing about my company is that Avanza is totally focused on developing solutions for banking and it’s been really great to learn about this domain. I’ll write more on my job experience later in separate post. By the way, in few hours, I’ll be leaving for Bahrain for few weeks for a project implementation in Khaleeji Commercial Bank(KHCB). It’s my first site visit so I’m excited! :)

2008 seems a lucky year for me. On the very first day of the year, I got a great news from Microsoft that I’ve been awarded MVP (Microsoft Most Valuable Professional) award as Recognition for my activities in developer communities! It was a great surprising moment! Thanks Microsoft :)

I hope this will be a great start for whole year. There are many things planned to do and I’m really looking forward for a productive year. And unlike 2007, I’ll force myself to update my blog more frequently to prove that I’m a generous Memon :P

Anyways, a happy (belated) new year to everyone!

Imagine Cup Launch and Workshop on Web Development in Campus

January 14, 2007

Wow it was quite an amazing day!

FAST.net user group and IEEE-NUCES organized Imagine Cup 2007 Launch and a 3 hour workshop on Web development using ASP.net on Friday, 12th January. Due to vacations many students couldn’t participate but those who attended this event appreciated it a lot. I and Ali Raza Shaikh were the speakers:

From Imagine Cup L…
From Imagine Cup L…

During the imagine Cup session, we showed promo videos and interviews of past winners to motivate students. We also distributed free CDs of Visual Studio and SQL Server 2005 Express Edition to help them in getting started.

From Imagine Cup L…

Workshop on ASP.net also went great and I believe student learned many new things. Since most of the students were from junior and sophomore batches, we didn’t go in much technical depth.

From Imagine Cup L…
From Imagine Cup L…

The most fun part of the event was Q/A session where we asked questions to student for Goodies like ASP.net WebMatrix Book, MSDN Magazine, Development Resource CDs. Thanks to Microsoft Pakistan and INETA for sending those goodies.

From Imagine Cup L…

I’d also like to thank all participants for making this event successful and I hope we’d be able to continue this series of workshops on web development with the support of Microsoft and INETA.

TechEd Student Blogging Competition Results

December 21, 2006

Wooho! I just received an email from Mr. Vaqar Khamisani, announcing official results of TechEd Student Blogging Competition and I am very happy to see my name in Runners-up list !

Here are the complete results:

Winners:

  • Julien Chable, France – Visit here.
  • Goncalo Filipe Macanjo Lopes Chaves, Portugal – Visit here.
  • Prizes: Xbox 360 E3 Faceplate, Xbox 360 Laptop Bag and Mug

Runners Up:

  • Munir Usman, Pakistan – Visit here.
  • Lucian Baciu, Romania – Visit here.
  • Prizes: Xbox 360 Laptop Bag and Mug

Congratulation to Julien, Chaves and Lucian too.

It has been more than a month since I last posted anything on this blog as after coming back from Barcelona, I got caught with so many important things including studies :-(. But I will try to post more about TechEd Developer Conference and our Barcelona tour very soon.

At Dubai!

November 7, 2006

So finally the day came when I crossed the boundaries of my homeland. Right now, I am chilling at Dubai International Airport, waiting for other MSPs from Islamabad, and writing this blog entry using high speed wireless internet. Still 4 hours remain for next connecting flight i.e. Dubai to Amsterdam.

Dubai International Airport is really a cool place. First time I am seeing so many people from different countries and cultures at one place. It is really a great experience for me!

Here are the few of pics I have taken:

Karachi International Airport Me at Karachi International Airport UAE From Sky

Entertainment Console in Emirates Dubai Duty Free 1 Dubai Duty Free 2

Visit here for more.