Converting DateTime.Ticks into a Unix timestamp in PHP

I needed a way to convert the number of ticks from the DateTime.Ticks property in .NET into a Unix timestamp in PHP. So I wrote up this solution that makes this possible. The solution works by taking the number of ticks that I want to convert into a Unix timestamp and subtracting it with the number of ticks of the Unix epoch.

To figure out the number of ticks of the Unix epoch, I used C# (it is possible to do this in a different .NET language) using these two lines of code to find the number of ticks of the Unix epoch in a simple Console Application:

DateTime unix = new DateTime(1970, 1, 1, 0, 0, 0);
System.Console.WriteLine(unix.Ticks);

This ends up printing out:
621355968000000000

I then took this number, which is in one hundred nanoseconds, and created a PHP function which subtracts the number of ticks to be converted by the number of ticks of the Unix epoch and then divides it by 10000000 to convert the now Unix timestamp from one hundred nanoseconds to seconds as Unix timestamps in PHP are handled in seconds.

function ticks_to_time($ticks) {
	return floor(($ticks - 621355968000000000) / 10000000);
}

This is an example of this function in use:

// 11/24/2010 9:20:45 PM UTC in DateTime.Ticks
$time = ticks_to_time(634262304450000000);
echo "$time\n";
echo date("F j Y g:i:s A T", $time) . "\n";

Which should output:
1290633645
November 24 2010 1:20:45 PM PST

So there we have it, a function that makes it easy to convert the number of ticks from the DateTime.Ticks property in .NET into a Unix timestamp in PHP.

How to Revert Your SVN Repository on Assembla

There is no simple way to revert your repository to a previous revision on Assembla. However, a reversion is possible by following these steps.

First, export the SVN repository in your space. This can be done under the Import/Export section of your repository. It’ll take a minute for the dump to be created. Once that has completed, download the repository dump.

Then, extract the contents of the ZIP file to a temporary directory, then run the following commands in the temporary directory:

svnadmin create REPO_NAME
svnadmin load REPO_NAME < rXX.dump
svnadmin dump -r 1:YY REPO_NAME --incremental > rYY.dump
gzip rYY.dump

Replace XX with the current revision of your repository, YY with the revision you wish to revert to, and REPO_NAME with any name, such as your repository’s name. This name will not be carried over later.

Afterwards, delete the repository tool on Assembla by going to Admin -> Tools, then clicking Delete next to it which is located on the right. Now re-add the Source/SVN repository tool.

Finally, import the dump to the newly created repository by going to the Import/Export section and uploading the gzipped SVN dump. The process will take from a few to several minutes depending on how large your repository is.

Your repository should now be reverted back to the revision you specified.

There is no simple way to revert your repository to a previous revision on Assembla. However, a reversion can be done following these steps.

First, export the SVN repository in your space. This can be done under the Import/Export section of your repository. It’ll take a minute for the dump to be created. Once that’s finished download the dump.

Then, extract the contents of the ZIP file to a temporary directory, then run the following commands in the temporary directory:

svnadmin create REPO_NAME
svnadmin load REPO_NAME < rXX.dump
svnadmin dump -r 1:YY REPO_NAME --incremental > rYY.dump
gzip rYY.dump

Replace XX with the current revision of your repository, YY with the revision you wish to revert to, and REPO_NAME with whatever you like. The temporary repository name will not be carried over.

Afterward, delete the repository on Assembla by going to Admin -> Tools, then Delete it on the right. Now re-add the Source/SVN repository.

Finally, import the dump to the newly created repository by going to the Import/Export section and uploading the gzipped SVN dump. The process will take a few to several minutes depending on how big your repository is.

You’re repository should now be reverted.

Ruby on Rails Sucks? I Don’t Think So

I have been playing around with Ruby on Rails for a while. You know how to program and know the commands for it, you’ll think it’s cool. Ruby on Rails is a MVC framework for the language Ruby. MVC stands for Model-View-Controller. The model is the database logic, the controller is the application logic, and the view is the presentation logic. Using this style, it keeps things organized.

People will think Ruby on Rails suck because they don’t know how to catch on to it. I admit, I was originally one of them, until I read Agile Web Development with Rails, Third Edition (Amazon). This book showed me how powerful this framework was and how much it was capable of doing. Doing validations is a breeze, embedding variables and Ruby code is a breeze in the views, routes are easy to configure (no .htaccess), database migrations to keep things in order, ActiveRecord to ease querying, updating, and inserting (no more SQL queries), and there’s so many other cool things with it. There is even loads of plugins on the Internet and on Github that do kickass things.

Does Ruby on Rails use a lot of RAM? From what I have notice from playing around with it I haven’t notice it take so much RAM. Besides, if I needed more RAM later and I was generating the money from the site, I’d just upgrade the server, piece of cake.

I plan on developing new sites using Ruby on Rails. PHP is just getting old (the new namespace delimiter is \, and that’s an escape character!)