Posts Tagged 'Code'

Updated URL shortening rewrite

Something I’d meant to do since the day I did it was to add the rewrite rule so that I could exclude the l? from URL shortened links my social bookmarker generated. (I had been repeatedly poked for leaving this out too) The original idea->implementation was 30 minutes, so this takes it up to 35 minutes for the project, and only took a few months to implement. My entire .htaccess including the WordPress business is:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]{3,3})$ l.php?$1 [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

And everything seems to be working as it should. That brings me up to 122 characters for the messages that accompany my URLs!

Of Nick and DRM…

So I didn’t think I had an essay in me today, but after reading about how Ubisoft’s new uncrackable DRM was cracked in a day I just had to rant a bit.

A bit of background first. Ubisoft is a game developer who makes games that I largely don’t care about. Their most recent DRM (Digital Rights Management, previously known as copy-protection) required a constant connection to Ubisoft’s server farm while playing. If the connection dropped, your game would be paused until it came back. That means if your connection is flakey, you aren’t going to have a good time; if Ubisoft connection is flakey, you aren’t going to have a good time; if there is a major internet deroute, you aren’t going to have a good time. I chose to ignore those who don’t have a persistent internet connection because this is 2010 and thats just barbaric! It’s awful DRM and makes for an awful user experience.

DRM in the PC world is largely anti-user. PC game publishers deliver games with compatibility issues solely due to DRM, and in that sense, DRM is awful. However I have a problem with the crowd that thinks DRM is bad because piracy is good and that software should be free.

More background though. I spent my early years in the pre-internet days trading cracked games on BBS’, followed by my high school and university years spent in a top-level cracking group releasing video games. This may seem hypocritical to now have a problem with software piracy but let me explain. Back in the day, the cracking scene was a very small group of individuals, at first hundreds, then thousands. They were kids competing to see who could crack a game first. It wasn’t really about free software, it was a game itself. A mere drop in the bucket compared to the hundreds of millions of people who steal software nowadays. Thats the problem. Piracy is ubiquitous with software and media amongst the current generation of high school and university students.

A generation of kids have grown up consuming all the software and media they can handle for free. Movie rentals? Why bother, just hit up a torrent site. Borrow a friends CD to see if you like it? Why bother, hit up any number of p2p sources. Need a new distraction from exams? Just download a dozen new games and see if you like any of them. The problem is that people expect everything for free on the internet. Many people argue that these people stealing the software/media wouldn’t have purchased it anyway. This is partially true, people now consume a lot more media and software than they’d purchase, but they would have purchased some. The problem is that piracy has become so pervasive in the internet culture, many people aren’t buying anything. Adults who pirate games will buy the ones they like, but thats our generation. The younger generation has grown up not buying media, they will continue to buy nothing. Thats right, I am asserting that this current generation is not pirating games as a form of try-before-buy, they just want free games…

People get angry that PS3/Xbox360 games are too expensive, they are not. SNES and N64 games reached $90-100+ CAD in the mid 90s. $100 10-15 years ago was a lot more money than it is today, so $70 in 2010 money isn’t really that bad… It is suggested that another business model is required. High quality games cost money to develop, a lot of money. More money than could be generated through ad supported software, so that model won’t work. The open source model has worked for amazing software packages like Linux, Apache and MySQL, and indeed would work for decent games given you could find talented artists, musicians and writers with enough free time; but the bulk of people are going to reach an age where they want to use their free time for something other than another job.

So my argument is that people nowadays just steal too much, and too many people just buy nothing. Maybe another business model is required for software sales, but that model does not exist. We are a capitalist society, most of us earning a living enjoy that, whether we are empathetic or not to those who don’t. The real problem is that PC DRM in its current incarnations are not the answer.

DRM on the PS3 is great. People argue that it stops homebrew and personal backups, but these are niche. Homebrew is nice, but there are lots of great platforms to write emulators and run linux on. The greatest of these is known as the PC, you already have one. After all, your PS3 was sold to you as a video game console, not a personal computer. Personal backups is a term heavily abused. Some people have this notion of personal backups that dates back to the time of floppy discs, which did readily wear out. DVDs, don’t, unless there is something drastically wrong with your hardware. However the majority of people who claim to desire personal backups just are saying they want to pirate games.

In the end I obviously don’t have a solution. My only point is that both sides demonize the other stupidly. Wide spread piracy is not acceptable, nor is DRM that does nothing but hurt legit consumers. Another sales model for games would be acceptable, but changing the culture that demands everything for free is likely a better solution. Until then, PC gaming will continue to die.

(Sorry for the bold, I just feel ranty)

Of Nick and hosting geo-diversity…

If you look at the biggest websites and internet applications, you can pretty much divide them into two groups. Those that are geographically diverse and those that aren’t. It’s kinda shocking that in 2010, the majority of major internet properties still are located in a single (large) datacenter. Though to be fair there is a good reason for that, geo-diversity has many challenges. Problems like directing traffic to the fastest/closest/cheapest/most available location are pretty easy to solve: most people go with BGP AnyCast, targeted DNS responses, or a combination of both. The real challenge though is making sure your actual served content is coherent among all the locations. It would be terrible for a user to upload a photo, sent the URL to their friends, only for the friends to see nothing or worse, the wrong image.

For static content, this is easy, even RSYNCs will be scalable to push out changes to your content amongst your farm. User uploaded content is quite a bit trickier. Within a single datacenter you can efficiently (though not always affordably) solve this using shared storage, iSCSI or NFS. Then applications pretty much can work as if they’re on a single server, session management can be tackled by using cookie or host persistence on the load balancers to make sure a user stays on the same server. What about servers in different locations though? NFS and iSCSI will not be terribly effective over transit.

You will have to push content between your locations then. If you are trying to geographically distribute your own application, you would just write functionality in to immediately push any user uploaded content out to other locations as its created.  Google/Youtube are great examples of this. When you hit content they’ve hosted, it isn’t even hosted on every server, and they direct you to the closest server that has said content. If that content isn’t available locally to you yet, or at all, they can stream it over their own fiber backhaul and out your closest Google POP.

But what if you are hosting a variety of 3rd party software. To my knowledge none of the popular blog packages, forum software, etc has any sort of geo-diversity designed into them. You could of course fork them and write your own, but then you end up supporting N different software packages for your N clients, not affordable or reasonable.  Rsync would do this task but unfortunately it is very intensive and doesn’t scale particularly well because it md5′s your entire tree constantly to see if things changed. As your content scales, the rsyncs would get slower and slower just seeing if changes occurred, eventually leading to massive delays on syncing out user created content.

In the end, its a cool problem, a problem that not too many people have tackled so far. We came up with our own solution, which I unfortunately probably shouldn’t disclose. I wrote the basis of the software last month, though it still needs some bug fixes, testing and more modules to be written for it. It is a difficult problem to tackle, but having worked in telecommunications, no facility is bullet proof, no power is bullet proof, no connectivity is bullet proof, no hardware is bullet proof: geo-diversity is a must going forward in this highly demanding world where everyone expects connectivity and content 24/7

Of Nick and UI…

So my true weakness when it comes to end-to-end application development is always the UI. I think like a developer, am happy with terminals and verbose logging, I nitpick positioning and sizing endlessly, and I generally am never too happy with what I generate.

Now the beauty of the iPhone SDK is that it uses XCode’s interface builder, and Cocoa / CocoaTouch support directly loading polished NIB at runtime.  NIB is of course NextStep Interface Builder, and though they actually use a .xib (XCode Interface Builder) file while you develop them, at runtime and pretty much everywhere else they’re called NIB files. (Because Cocoa *IS* NextStep)

So back to the topic at hand. I have always liked the way Visual Studio did interface building, as it took the coding out of creating a UI and let it be about what it should be, an art*. XCode offers the same experience but with a bit more of a learning curve. The real challenge though is that on the iPhone, you have a lot to live up to. There are a lot of very attractive apps out there. Creating a tool for sysadmins to receive and handle alerts doesn’t require the polish and pizzaz of lets say a Twitter client, but it can’t be ugly or clunky either.

So in Cocoa Touch we have the Navigation Controller (UINavigationController, which provides a bar at the top with text a button on the left and right to navigate through views) and the Tab Bar Controller (UITabBarController, which provides a bar across the bottom with any number of iconable tabs that represent different views) Of course you have the freedom to come up with whatever UI you want outside these, however these conform to Apple’s User Interface Guidelines (a fascinating read, and the iPad guidelines were an even cooler read) and match the look and feel of the iPhone, making it easier for users to navigate. In fact you can even combine the two types and create navigated views within a tab, or a set of tabs within a navigated view. The sky is the limit and its easy to do, which is whats the most fun about XCode and Cocoa Touch.

So I decided to go with the Tab Bar. We are dealing with alert handling here, I know from experience that there are only a finite number of tasks that are required after hours, so we can stuff those as tabs a long the bottom. On Ken’s advice I added a More… tab which contains lesser used but still useful utilities like short cuts to compose emails to common distribution lists @FM, a long with access to the two ticketing systems outside of our department.  Throw in a Core Animation page flip between tabs (the code for animation in Cocoa Touch is really quite impressive) and you have something that looks decent (I think) and is fairly functional.  On a slightly side note, I kept the animation to a quarter of a second, that way it looks flashy but doesn’t slow down work flow, thats important to me. I’ve likely disabled every animation OS X has to offer on my computers after all..

I’ll likely write a follow up discussing my experience with some of the other UI widgets at a later time, but I wanna touch briefly on the spinning selector as seen in my Tab Bar screen shot. The iPhone’s user experience is superior to any other touch phone. (Android, Pre, Storm, I’m looking at you guys) I was very reluctant to use a touch screen interface because they usually annoy me long after the cool factor wears off. Apple has gone to great lengths to design the user interface of their own apps to work really well with fingers. The spinning selector is a great example of that. On the desktop, we normally select a choice of one from many in a drop down box. This works great, but is a tad annoying on something like an Android phone. The spinning selector is more of a wheel you spin with your finger that has very intuitive acceleration and deceleration such that its very easy to use. Because Apple makes it so easy to deploy these widgets in your own applications, you are very unlikely to see kludgy desktop-esque UI on the iPhone, making the user experience of 3rd party apps all the more familiar and better. That and they theoretically could stop you from publishing apps that don’t conform to the user interface guidelines, though in practice they pretty much only ban apps for their own dirty anti-competitive purposes…

*Design is an art, and UI design is at the forefront of that these days. Just look at all Apple products. You may not like their design (lord knows I’ve stripped OSX so bare its just a tiny bar on the right, no desktop and the Finder process isn’t running most of the time), but its still intuitive and attractive. In the end Apple is a design company. A PC is just a PC until its in a sleek, durable unibody aluminum case, then its a Mac. BSD is just a server operating system until its got an attractive, intuitive user interface, then its OS X.

Of Nick and the APNS…

So on Sunday I got the inspiration for my second iPhone app, fmNotify. (the first was a simple multi-tab webkit integration for a friends website that made use of some clever code to hide the tab and status bars when rotated as well as the shake gesture to go back on the current page)

fmNotify will be (ok I’m being a tad presumptuous but I have faith :>) our internal notification service for emergency alerts. It utilizes Apple’s fantastic push notification service (APNS, APN or APS depending where you read it) and some clever UI to streamline alert handling. Basically alerts and phone registration is handled by PHP code running on a server(s, easily redundant using mySQL replication) inside our network, stored in an SQL database. This allows for  pretty extensible triggering of alerts, everything from Nagios, email via procmail, and our own internally developed software.

The real thing I wanted to talk about is how impressed I am in the APNS bits of the SDK. iPhone SDK 3.x is really where the iPhone hit its stride, and the push SDK is a big part of that. (Prior to 3.x it was a pretty disappointing device IMO and more than a fancy toy for teenagers than anything workable.) OS 3.x makes the device a powerful device for any industry. (Though MobileMail.app is still so woefully inferior to the Blackberry)

BUT I DIGRESS. Working with APNS is a coders dream. When your app is setup with Apple for push support, you get a cert that can be used to connect to the APNS cloud with. APNS requires a connection via TLS or SSL, which of course can be done easily with libopenssl in C or in this case PHP. From there all you need to do is send json blobs that contain: the device id of the handset, the alert text you want to display, the badge number to show on the app (if desired) and the sound to play (if desired). Beyond that you can include whatever other custom data you want, within 256bytes. This may seem like a rather limited amount of data to work with, but its really just to trigger your app to connect to you own servers, which can then pull down whatever data you want.

So while your app isn’t running and a notification comes in, a popup will occur with vibration/sound if desired, and a link to automatically launch your app.  While it is running an event is triggered within the app delegate and you can handle it however you want. Pretty awesome. Throw that all together with a nice GUI and you have a really streamlined alert / alert handling work flow!

So the app itself is pretty simple. Just a basic UI for seeing alerts / alert history, and then panels for dealing with common alerts.  The backend is basic PHP / mySQL / simple JSON / openssl integration to handle registration (including the device id and desired alert sound) for each phone, and directing of alerts to whoever is oncall. I really look forward to future projects using APNS, considering this took less than a day to throw together, the sky is the limit!

Recent Photos

Red List’s Species of the Day