PHP Routing

If you’ve ever written web applications in Python using Pylons or TurboGears (>=1.1), you’re probably familiar with an incredibly handy tool known as Routes. It’s modeled after the Ruby on Rails routes system and does quite a marvelous job at mapping friendly, SEO URLs to useful code. If you’re not aware of it, you really should check it out.

However, I was curious to see if it were possible to create a Routes-inspired PHP library that would perform essentially the same task. I’m sure there’s an already-written PHP routes system, and I’ve allowed myself to fall into the not invented here trap. But, that’s part of the fun in coding: If you don’t like what someone else wrote or you want to give it a hand yourself, no one is stopping you. It’s great.

Thus, I’ve written Routing, the PHP routes system. It’s similar in syntax and intent to Python Routes with the exception that it’s PHPized (in other words: bastardized). If you read the sources, you might be able to see a little Python influence here and there (along with my frustrations toward PHP as a language vented in silence). I wouldn’t recommend it as anything short of entertainment as yet; I haven’t cleaned up the sources, and I expect they’re going to be really messy for a little while. The route search mechanism is awful, and I plan on refactoring it in a future revision. For now, the system works, and that’s good enough. (That’s my INTJ side talking.)

So, if you’re curious enough to take a look, head over to the Routing Trac page. I have some downloads posted there in a variety of formats (.zip, .tar.gz, and .tar.bz2). There’s no API documentation yet. I’m going to add it soon. Since Routing was born on Wednesday, August 5th, 2009 it’s quite young. However, I have some preliminary unit tests written (also incomplete) that you can read to get a general understanding of how Routing works. If you’re more interested in the principle behind Routing, you might want to read the documentation for Python Routes. Routes and Routing work roughly the same with the exception that Routing, unlike Python Routes, is extraordinarily buggy. I hope I can evolve this into something of an acceptable sibling to Routes but that will take time and a whole lot of effort. I have a few additional ideas, too.

1 comment.
***

Links: August 5th

I have a lot of stuff for you today. Eat up. (Minor updates: Corrected some incorrect usage/typos/miscellaneous sleep-deprived stupidity. Also corrected attribution for Yesudeep’s site; see the comments for more.)

Do It Yourself

Ever had jet lag and just couldn’t get over it? Well, now you can in a single day.

Games and Gaming

Crytek, the same company responsible for Far Cry, Crysis, and Far Cry 2, is considering leaving Germany under threat of domestic laws that may ban the creation of violent video games.

Government

Looks like the State Department is pretty retarded. Undersecretary Patrick Kennedy claims that using Firefox instead of IE is an “‘expensive question.'” Gizmodo contributor Dan Nosowitz speculates Undersecretary Kennedy’s mindless ranting may have been the result of his attempt to CYA. Until personnel in powerful positions finally get a clue about technology (hint: won’t happen), things like this will never fully be resolved. Browsers, like IE, will continue to be exploited, and on site security within our government will remain poor at best. To be fair to Mr. Kennedy, MSIE is also “free,” and there are certain costs related to software deployment that have to be evaluated. Worse, some organizations still make use of archaic ActiveX applications that require MSIE6 to run. Helpless are those organizations that cannot upgrade to even the latest version of Internet Explorer without breaking things!

History

My father sent me a really fascinating link to an e-book collection of General George A. Custer’s various works. If you’re interested in the Old West, you might find this a worthwhile read.

Miscellaneous: Why 9-5 Must Die

Tom Martin writes in an essay on why 9-5 must die: “[I]n today’s knowledge based economy, [the 9-5 work schedule] is an antiquated thought that I believe stifles the most creative of workers.” Whether you agree or not, it’s an interesting notion. I tend to do my most creative work during the late evening when I’m not being bothered by the typical disruptions in work flow.

News: Ridiculous things

There is speculation that the Florida Bay’s ecology is almost certain to collapse. In a strange twist of irony, efforts made to save the bay have been met with lawsuits–filed by environmentalist groups. The agency in charge of the Bay’s restoration knows how to move toward preserving the area, but they’re being blocked with intense litigation! Ridiculous? I think so.

A man stole a car only to be arrested about a week later after falling asleep in a car wash.

News: People like this make me Sick

Yesterday, a man entered a fitness class killing three women and injuring many others. The reason for his violent slaughter? He was rejected before, hadn’t had a date in over a year, and claims it was 19 years since he had sex. Seriously, what’s wrong with people? Rejection happens–get over it. Why couldn’t he have just killed only himself if he were that miserable? Murdering others for one’s own despair is just disgusting, sickening, and evil.

News: War on Terror

The AP reminds us that the midwest was home to foreign detainees in the past. I don’t recall Germans strapping bombs to themselves, however. While the Germans did have a kamakazee-like program toward the end of the war, the pilots were expected to ram their planes into allied bombers, bail out, and return to do it all over again. Source: History Channel’s Dogfights, the “Luftwaffe’s Deadliest Mission.”

News: Weird Things

In Cambodia, landmine awareness has gotten a leg up on the government–for now. In a queer and slightly morbid twist, a Norwegian fellow decided that it would be a good idea to create a Miss Landmine Cambodia pageant. The winner will be awarded a custom-made prosthetic leg. Truth is stranger than fiction.

In Mongolia, there is a journalist hunting for a lightning-farting, acid-spitting death worm. Big foot and Nessie–watch out! Cryptozoology has a new hero.

*NIX

This article is written specifically for Linux but it can be applied to other Unix and Unix-like OSes. If you’ve ever wondered what, exactly, the load averages from uptime really meant, wonder no more. It’s a great read and explains in terms anyone can understand exactly what the load averages stand for.

Programming

Mario is at it again. This time, you can participate in a competition to create an AI version of the mushroom massacring plumber.

Doug Hellmann (menacing name, I love it) writes about in-memory data structures in Python. Check it out if you need a little extra performance in your code.

Joe Marshall has a fun two-part series on “How Not to Write Code.” Go here to read part one and part two. If you’ve enjoyed horror stories from the tech world, this would be a great place to spend some time.

In yet more PHP frustrations, Chris Shiflett writes about how addslashes() and mysql_real_escape_string() work differently. PHP has always been quite good at violating the principle of least surprise but things like this sometimes amaze me. This is also why I’ve been fond of the PDO since it was released: Prepared statements may not be a silver bullet, but they can sure help insulate the developer from stupid library bugs. (Unless the prepared statements are implemented poorly, but you get the idea.)

Steven Levithan (what is it with cool-sounding names today?) covered in 2007 several issues relating to various trim() implementations using regex in JavaScript, why they work well (or don’t work well at all), and how to improve them. If you do a lot of text manipulation client-side, this might be a worthwhile read. It’s an old article, but it still holds a great deal of application even today!

I discovered the article above as a link from another blog post musing the topic of trim() implementations. In this post, Yesudeep J. Mangalapilly (yet another really awesome name which I thought was a handle) explains why a script added by one of the commenters to Steven Levithan’s post blew everyone one else away. Yesudeep also goes into excruciating detail to explain why. It’s a great read.

Updated Thanks for correcting my brain-dead comment in this link, Yesudeep. I had no idea that was your real name. Way to go on my Western-centric stupidity for parsing names weirdly (I blame the various 13 year olds who like using “u” in a lot of things and subsequently pervert real names–go me!).

Why is C# better than Java? Whether you agree or not here are some compelling reasons.

Reviews

Ever wondered what it’d be like to spend a couple of nights in the Las Vegas Riviera Hotel and Casino? Maybe you shouldn’t.

Software

A new site has been launched about Microsoft’s Internet Explorer version 6. No, it’s not a fan site. It’s a site “run by a group of people who want to see IE 6 disappear as soon as possible.” I like these guys, and they’re right: IE6 is a pain in the neck to develop for.

I read an article that reviewed a new WebKit-based browser called Arora. It’s a cute little browser, and it’s fast. It lacks some utility (you have to go to the View menu to view the page source rather than right-clicking on the document) but it makes up for its shortcomings in speed. I haven’t tested it with 300+ tabs yet. Maybe I will…

Technology

Apple is at it again. This time, they’re banning the use of offensive words in a specific application sold via the App Store. Sounds good? Well, not when it’s a freaking dictionary. What sweet irony it is that the same company that made the Macintosh famous in a commercial parody of George Orwell’s book by the same name would censor the English dictionary.

I stumbled across another rant relating to how awesome Apple is. In How IBM and Apple are Kicking Google’s and Microsoft’s Butt, Rob Enderle discusses internal conflicts and focus issues suffered by Microsoft and Google alike and why IBM and Apple are poised to defeat them. It’s a little optimistic, in my opinion, because Apple is well known to do stupid things that piss off their customer base. (See the link above.) Apple may win the day, but if history has anything to show about it, even offering the company an entire industry on a silver platter cannot save Apple from itself. What happens when a company used to catering to niche markets suddenly finds itself immensely popular? Well, we don’t know. I can’t imagine it’s a very good thing. (Anyone else noticing all the articles popping out of the woodwork praising Apple as of late especially when Apple is quite literally slapping customers in the face?)

Is Google killing general knowledge? That’s the million dollar question, isn’t it? I haven’t much to say about this other than someone else has already done it for me. Sarcastically. Quote: “Are books killing the oral tradition?” Same idea, same dilemma. Alarmist topics like the one in the article linked here just bug me.

Wanted to see the evolution of Amazon’s shopping cart? Well, now you have.

Weird and Unusual

Van Halen’s contractual requirement to eliminate brown M&Ms is true. There’s a reason for it, however. It makes sense.

5 comments.
***

NoSleep Released

So, I finally got around to writing a suitable replacement for the little Python script I was using to kill power management on my Thermaltake external USB/eSATA drive. But first, some history.

I didn’t mention it in the assembly guide I wrote for the Thermaltake enclosure, but as it turns out, the SATA chipset Thermaltake opted to use suffers from a rather annoying problem: If you leave it idle for more than about 15-20 minutes, it will turn the disk off. Since I like to have control over when the disk turns off, I had to write a script to periodically write a (blank) file to the disk. The idea being, of course, that if you can force some sort of activity, the drive will never go to sleep. (Edit: This isn’t entirely correct; based on information I received from Mike Fisher, it appears the source of the power down is actually the choice of hard disk–a Seagate ST3500410AS–that enters standby mode. I’ll update this accordingly once I find out if there is a means of stopping this.) As it turns out, this information isn’t completely correct either. If you’ve purchased one of these cases, it appears that the chipset will power the disk off only if it’s plugged in via USB. If you plug the bay in via eSATA, the disk will never shut off unless the OS commands it to.

The thing is, I had forgotten at least once or twice to browse to the root of my external enclosure where I kept the little Python script that did the trick. What’s more, it also required (under Windows anyway) a DOS prompt to exist as long as the application was running. Neither of these seemed to be suitable options.

Enter NoSleep

I decided to write NoSleep as a replacement for the little Python script that could. In fact, the replacement is even better–you don’t know it’s running. That’s the idea, anyway. Here are some highlights:

NoSleep…

  • Installs as a service. You don’t know it’s running in the background.
  • Isn’t invasive.
  • Scans for all removable media when you first turn the service on or install.
  • Monitors for new connected media.

This means that no matter what you do, be it unplugging an external disk and plugging it back in, NoSleep will keep an eye out. Whenever it spots something that could potentially go to sleep, it’ll start polling the disk. I use the same technique borrowed from the little Python script, too. Every once in a while, NoSleep will write to the contents of a file fittingly called .nosleep (the leading dot is intentional) and force the chipset on the drive to take note of activity, halting its sleep timer.

Why NoSleep?

Why? That’s a good question. Frankly, there are other applications out there that do the exact same thing. The thing is, all of the ones I found ran in the system tray and you had to add them to the startup folder (or the registry–though, at least one such application added itself automatically). I wanted something that would run without any indication it was running. I didn’t want a tray icon. I didn’t want to have to double-click an application every time I connect my poorly behaved enclosure. I just wanted it to work.

That’s reason enough.

So What’s the Catch?

There is none. NoSleep is free. In fact, I released it under the GPLv3. You can even browse the sources if you like. NoSleep does depend on my WMIDiskUtils library. I have released the latter under the LGPLv3, so you can use it in your own projects even if they’re closed source.

System Requirements

NoSleep does have some system requirements. First, it requires the .NET Framework version 3.5 or higher. While it should work on Windows 2000, I have only tested it in Windows XP SP3 and Windows 7. So long as you have .NET installed, I don’t imagine there would be much of a problem.

Take a look at the NoSleep Trac page if you need to file a bug report.

2 comments.
***