PHP-to-Ruby Rails Plugin

December 29th, 2006

Aight, the alpha-version of my php/rails plugin is up. There is a ton of work left to do on it. I’ve yet to compile the various snippets that I have scattered amongst my projects, but this should get some aspiring neophyte php programmers into switching to the non-Dark Side of web development.

Install it with


./script/plugin install svn://ahgsoftware.com/php_compat/trunk

And here are some examples

1
2
3
4
5
6
7
8
9
10
# Dates
PhpCompat.date("F j, Y, g:i")   # Translated to Time.strftime chars
PhpCompat.time  # Integer unix timestamp

# Posix methods
PhpCompat.get_pwnam('localusername') # Struct with passwd info

# File methods (not network enabled... yet!)
PhpCompat.file_put_contents('/tmp/file.txt',"yo yo yo")
PhpCompat.file_get_contents('/tmp/file.txt')

A few caveats..

  1. The php date-format to ruby Time-strftime translations are about 90% complete. There aren’t any convenient fallbacks, so certain formatting characters will not translate at all.
  2. The posix functions are POSIX functions!! So don’t expect much luck on Windows, although, they work great on OS X (naturally ;) )
  3. File methods don’t work on url’s yet
  4. There are some functions that I’ll never translate, as some things you just HAVE to do the ruby way. Its so much more concise, readable, and effective when you do it the ‘matz way’.

Since the main focus of this plugin is to make software migrations a bit less painful, the next set of methods that I wanna stick in there, is the mysql functions. I’ve used this in migrating thousands of lines of php code to ruby, so, I hope it helps someone else out too!

Crypt for ruby?

December 29th, 2006

Alright, fellow php-turned-rails coders… I’m working on a plugin that lets you have a php compatibility layer for all those precious functions that you can’t seem to let go of! I’m developing it on a ‘code-a-function-as-i-need-it’ basis.

One thing had me COMPLETELY discombobulated for a while though, and that is the lack of an obvious ‘crypt’ function for generating DES/MD5 encryptions suitable for system/mail passwords (not the hex_digest kind). In php, it was a simple as…

1
2
3
$string = "i should have read the docs";
$salt = "$1RbeoAkQobvI"; // make sure the length matches the type
 echo crypt($string, $salt).

It turns out, that my favorite trusty RDoc widget had the answer all along! The ruby String object has a built-in crypt method that takes a salt parameter..


p "i should have read the docs".crypt("$1RbeoAkQobvI")

I shall have my rather skimpy plugin ready for you guys next week, check back for the svn url by Jan 3rd 2006!

OO Babies

December 28th, 2006

Being a geek can be a sad thing. I love my daughter to pieces, but, all I can think of is how big a pain it is to change diapers. In a perfect world, I’d just…

1
2
3
4
5
6
7
8
9
10
@infant = Baby.find :first,
                                  :gender=>"female",
                                  :age=>"1.5",
                                  :needs_diaper=>true

@infant.change_diaper!

pp @infant

"No pp, we just changed her"

Queue up the laughter from the few rails geeks who are also proud dads. Seriously, that’d be great, I could then script up a free baby changing service using my

Programmatic Infant Interface
(P.I.I. for short, not to be confused with the Wii).

Here’s my little bugger…

Say Hi Breanne!

AHG on Rails

December 26th, 2006

Howdy Ho, y’all. It is Christmas, and I’ve decided to update my blog by putting it on Typo!!

I have had a slew of plans/ideas for my site, including, using it as a super-dynamic interface for my clients. I envision, a login/dashboard where they can see progress and comment on various aspects of their commissioned projects! I know, I know, Basecamp could serve this function, but, I want mine to be highly gimmicky, useful, gaudy, and just fun to use.

Oddly enough, word-of-mouth has turned my business into a full-fledged development service. The advertising usefulness of AHG Software is near non-existant! My poor site has suffered, but, alas, no longer shall it remain devoid of content. I’ll stick any ideas, ruby-isms, or apps that I code, here for your daily perusal!

Anywayz, Peace out, A Merry Christmas to all of you that believe in such things, and a Happy New Year to the rest of you!

 

Michael Cerna Chicago-based Rails Developer and Avid Musician. More ...

Search

Categories

  • Home (15)
  • Rails Plugins (5)
  • Pages (9)
  • Archives

    Tags

    BlogRoll