Monthly Archives: February 2012

My horrible experience at FedEx Kinko’s

I needed to have something printed, filled out, scanned, and email’d (a horrible workflow yet needed by many companies). I’m currently out of town and at my sisters place, which doesn’t have a scanner nor a printer (hey neither do I). The town she lives in doesn’t have any public libraries or a kinko’s, but the neighboring town 20 minutes away does. So, I loaded up the document I would need onto a USB drive and packed a laptop (just in case) and headed on out.

When I got there, there was two sets of computer areas. The first contained their machines, and the second contained open areas for laptops. All I needed to do was print a PDF from a thumb drive so I hopped on their computers. When you sign in, you are asked what the purpose of needing the computer is. I clicked the obvious print station option. After about 5 minutes, the computer program had loaded the next screen. These things charge by the minute, and I was surprised how long it took to load their application.

Turns out, their print option is only good for designing things using their crappy software and then printing them out. They do not allow access to Explorer or any tools which can read a USB drive. I got annoyed by this, logged out, got my credit card back, and headed over to the area for laptops.

These little booths have three things in them. A credit card reader, an ethernet cord, and a USB cord. Shit. That means I’m probably going to have to do something with a binary they provide. I login, plug in the cords, and insert my credit card. Surely enough, the USB cord appears on the desktop as a CD-ROM device with a bunch of binaries for OS X and Windows. Well, there’s no way in hell I’m going to install their crappy software on my main OS, so I boot up windows in a Virtual Machine, configure the tool to send the ethernet and USB connection directly to Windows.

I installed their software, and of course a bunch of printers are attached to the OS now. I then pop in my USB drive into the remaining USB port on my MBP and open the files. Oh yeah, this whole time a timer is running in the corner of Windows, showing the steadily increasing charges.

My copy of Windows didn’t come with a PDF reader. Still not sure why any modern OS wouldn’t ship with one of these; OS X does, every decent flavor of Linux does, but M$ apparently doesn’t want to ship one. So I had to download a copy of that (their internet is crazy slow btw, which helps increase costs). Finally, I was able to print to their printer. I get a little window telling me it’s going to cost about three bucks to print the five black and white pages, and I hit OK. I grabbed the printouts, wrote down my answers, and was ready for the next step.

The don’t have scanners available on the floor, you have to go to the people behind the counters and ask them to do it. So, I handed them my five sheets of paper, and was told it costs 90 cents per page to scan them. Ridiculous I thought, but I’ve come this far. A few minutes later and they were scanned. Now, it was time to put the PDF onto my thumb drive. I handed them my drive (which is a tiny thing, it’s one of those open metal ones which doesn’t have the shield over the connection).

The lady behind the counter proceeds to plug it in the wrong direction on every port of the computer, not understanding the Windows error that there was a surge on the USB port. She may or may not have burned up a few ports in the process. I then yell back to her than she needs to plug it in the other way, and she proceeds. But, she gets an error message that the device isn’t formatted. She starts to click the options to format the device before a co-worker runs up to her and tells her not to do it. The device is 16 GB, FAT32, so I’m not sure what the problem was, probably some goofy XP compatibility issue.

So, she tells me the drive doesn’t work. I tell her that she can just email the files to me. At this point her and two co-workers look at me like I’m an idiot, and say, “Oh no no no, we don’t email here”. Okay, I ask if they have a USB drive floating around that they could copy the files to and I could just copy to my laptop while I’m here. “Oh no, we don’t have USB drives here. But, you can buy one. They’re on sale and a good deal too, 8GB for $20!” At this point I look at them like they’re stupid.

I fish around my bag and was able to find an old drive that was only 1GB, and hand that to them. They were able to copy the files over this time and hand me the drive. Now it’s time to pay the bill. I hand them my card, they run it, and I go to sign on their little digital screen. Now, most of these screens have a little bounding box around the screen, and when you sign outside of the box, it is un-spoken-ly understood that yeah, those pixels were lost, so what. But, this device felt the need to display a popup warning every time it happened, which needed to be confirmed.

In conclusion, I couldn’t believe how crappy my experience at FedEx Kinko’s was. I understand the need to cater to a dumb user by using binary installers, but maybe have a secondary option for us geeks to simply print to a network printer. If binary files are ever needed, your solution is incorrect. And, why didn’t they have any USB drives available? They’re business model is centered around making more money, not keeping people happy.

Moving Content to a new Domain and Keeping SEO

I recently killed my personal blog domain, nucleocide.net, and transferred some of the existing articles over to this domain. One thing I wanted to make sure happened is anyone hitting any of the articles I had on the old site would be redirected to the appropriate article on the new site. Also, anyone hitting any other URL on the old site should be redirected to the homepage of the new site.

I was able to get this working by setting up an .htaccess and using mod_rewrite with Apache. This file is run before any files on the server are accessed, and tells the server what to do with the request before it would serve up the normal file.

Here’s a truncated example of the file I had used:

RewriteEngine on

RewriteRule (notepad-tidy-for-xml/?) http://www.thomashunter.name/blog/notepad-tidy-for-xml/ [R=301,L]
RewriteRule (contact/?) http://www.thomashunter.name/contact/ [R=301,L]
RewriteRule (.*) http://www.thomashunter.name/ [R=301,L]

A 301 redirect is a permanent redirect, use it for a permanent change. If you want to temporarily redirect users, use a 302 redirect instead.

Hiding Files and Folders in OS X Finder

OS X, being a unix based OS, will hide files and folders whose name begin with a period. However, the Finder utility (and dialogs which use the OS features like save dialogs) also support meta information for hiding files (similar to Windows). This is useful if you want to hide a folder but you don’t want to have the name change. OS X 10.7 recently started doing this with the Library folder in your home directory.

Hide Files in Finder

To enable this feature, you’ll need to open up Terminal (Applications | Utilities | Terminal) and type the following command:

chflags hidden

Then, you can drag and drop a file onto the terminal window (which will put the files path after the command). Then press enter and the file will disappear. If you want to make a file visible, you can do the same process but using a different command, although it may be harder to find out where the folders are hidden.

chflags nohidden

Easy, huh? I use it to hide useless folders left around by applications originating from the Microsoft world which love to clutter the users Documents directory. E.g. Microsoft Office and a bunch of Steam games.

Also, you can press Cmd + Shift + G in Finder to open a directory you know of which is hidden. This is useful if you wanted to, say, hide files on your computer from other people which use the same account.

Open Hidden Directory in Finder

Open Source AJAX Game Engine

Today I’ve open sourced the game engine to an old game I started work on and abandoned in 2006.

Open Source AJAX Game Engine on GitHub

It’s a horrible, failed experiment, using polling and sloppy JavaScript, some horrible PHP 4x syntax, and un-optimized MySQL. It was one of the first apps/games I ever built. I learned a lot of lessons with that project, most notably that PHP and MySQL were the wrong technologies to use for such a project.

I do plan on building a Cobalt Calibur 3 one day.

Tracking Backbone.js “Page Views” with Mixpanel

At the startup I was working with recently, I was tasked with getting the different “Page Views” in Backbone.js to be sent to Mixpanel as different page views. Backbone doesn’t use normal page views, since it’s a Single Page Application framework. Page view events are only triggered by the Mixpanel javascript library during a page view.

After talking with the Mixpanel customer support, I found out I can track an event called mp_page_view, which is the event Mixpanel treats internally as a page view. It has one attribute, and that is mp_page, which is the URL to the page being viewed. This is relative to the root of your site. Unfortunately, if you use the # symbol, Mixpanel ignores the hit, so it has to be removed. This means that from within the Mixpanel screens, you can’t click a link to go to the equivalent page in your app. But, this isn’t really to big of a deal.

Backbone, since it uses the hashchange API, is really easy to integrate with. The following code works assuming you are using jQuery as your Backbone selector engine (I’m not sure if it works with Zepto). Just throw this code somewhere in your JavaScript, make sure it comes after jQuery, Backbone, and Mixpanel code has been instantiated.

$(window).bind('hashchange', function(){
    mpq.track("mp_page_view", {'mp_page':window.location.href.replace(/#/, '')});
});

And there you have it! Let me know in the comments below if this doesn’t work for you or if you try it with Zepto.

The Shark Fin Conjecture

This is what happened to my traffic thanks to a recent post which hit the Hacker News frontpage:

Shark Fin Conjecture

It’s a pretty familiar shape, isn’t it? I propose we all start to call the temporary large boost in traffic gained from hitting the front page of news sites a shark fin. They are usually created from the massive amount of traffic gained from the first day the article is popular, along with some residual traffic from the article being up part of the second day. If you’re lucky and can keep users moving around your website, you should see an overall increase in traffic after the fame is over with (which, as you can see, I had none).

Why Node.js is awesome: A short history of web applications

Warning: This is somewhat of a rant and I have no numbers to back up my claims.

In the beginning, there was a 1:1 mapping between URL’s and the filesystem from which they returned files. These files were heterogeneous, being both binary image files and text html files. Dynamic code was kept in cgi-bin directories and not usually mixed with everything else. Each HTTP request spawned a new web server process, it retrieved a file, and died. And it was good.

Then, the SEO people came. They wanted cleaner URLs. And, MVC frameworks came. And they happened to provide clean URLs. And before you knew it, a URL no longer pointed directly to a file in your filesystem. And it was okay.

Then, we started doing more of the application development on the client side. Suddenly the client was smart, and only needed to grab small bits of XML or JSON or HTML data from the server, and would process it into the DOM somehow. And it was okay.

You see, most web apps use a traditional web server designed for this nearly antiquated model of making occasional HTTP requests which grab a single file from the file system and return it. This is usually not a good thing.

In an attempt to make our new, pretty URLs and MVC frameworks work with the old servers (read as Apache), we start to use funny files which awkwardly make the old server work with our new way of doing things. Thus the .htaccess / mod_rewrite combination was born.

The way it works with Apache is if a file is requested, the directory the site is anchored to is checked for a .htaccess file. And the parent. And the grandparent. And so on until you hit the root. This is done for every single request. Now, this file, if it contains mod_rewrite directives, will explain a regular expression for matching the URL to a particular file. This was the ultimate of hacks to make Apache work with modern web applications.

Now, not all situations are this bad. With Apache, one can disable the .htaccess files, keep it all in httpd.conf. With lighttpd, you can define these rules in the master pseudo json syntax lighttpd.conf file (which resides in memory).

These are all awkward solutions for modern web application development. Why do we even need a web server anyway? All it does is take a request from a browser, figure out what file to grab or code to run, and return the result.

This is where Node.js got it right from the start. Why would someone need to keep the web server separate from the application code and keep a heterogeneous file system / url schema? Did you know that your cookies (up to 4k worth) are sent back to the server with every single request to the same domain, even for these images which don’t care about them?

With a Node.js app, the server is built right into your code. If you are using something like Express, the code to handle this is really simple, and probably isn’t any more complex than what your MVC framework is doing now:

var app = express.createServer();
app.get('/', function(req, res){
    res.send('Hello World'); });
app.listen(3000);

You’ll probably want to bind your app to a certain (sub)domain, and server your static files from a different (sub)domain (e.g. Content Delivery Networks) and use a super simple ‘web server’ for the CDN.

Once you do this, the huge overhead of keeping a bunch of Apache processes in memory goes away. Your site can handle a lot more traffic. Since inter-process communication and filesystem reads are decreased dramatically, your application is a lot more efficient and you’ll need less servers to scale.

Getting the PHP MongoDB driver installed with MAMP on OS X

There is a summary at the end of this post to skip all of my debugging. Scroll to the end to skip all of this rambling.

I was trying to get MongoDB support working in the PHP provided by MAMP Pro. I issued the PECL command to get it installed and was greeted with the following error:

tlhunter@macbook:/Volumes/Server $ sudo pecl install mongo
downloading mongo-1.2.7.tgz ...
Starting to download mongo-1.2.7.tgz (84,677 bytes)
....................done: 84,677 bytes
36 source files, building
running: phpize
grep: /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend_modules.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
... Output Truncated
/private/tmp/pear/install/mongo/php_mongo.h:564: error: declaration for parameter ‘default_host’ but no such parameter
/private/tmp/pear/install/mongo/php_mongo.h:563: error: declaration for parameter ‘allow_persistent’ but no such parameter
/private/tmp/pear/install/mongo/php_mongo.h:562: error: declaration for parameter ‘auto_reconnect’ but no such parameter
/private/tmp/pear/install/mongo/php_mongo.c:344: error: expected ‘{’ at end of input
lipo: can't figure out the architecture type of: /var/tmp//ccbF5uEi.out
make: *** [php_mongo.lo] Error 1
ERROR: `make' failed

It turns out MAMP doesn’t ship with a bunch of the PHP sources (makes sense, most people don’t need them and it makes the download a lot bigger). To get the PHP sources required to build MongoDB using PECL, you can visit the MAMP Download Page, scroll down to Source Code, and download the components file (in this case it was named MAMP_components_2.0.2.zip). You can also grab it from their SourceForge page.

Once you get that file you can decompress it to a temporary directory. It is full of a ton of archives. You’ll want to find the PHP archive for the version you’re using (I’m using 5.3.6). Extract this archive. You’ll want to move the files from this archive to the right directory, as specified in the error message. So, you’ll want to navigate to the following directory:

/Applications/MAMP/bin/php/php5.3.6

And then make a folder in there called includes and a folder in there called php. Then, move the files from the php archive into this folder.

Unfortunately, shit still don’t work. Issuing the PECL command again issues these errors now:

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/libtool --mode=compile cc -I./util -I. -I/private/tmp/pear/install/mongo -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/include -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/main -I/private/tmp/pear/install/mongo -I/Applications/MAMP/bin/php/php5.3.6/include/php -I/Applications/MAMP/bin/php/php5.3.6/include/php/main -I/Applications/MAMP/bin/php/php5.3.6/include/php/TSRM -I/Applications/MAMP/bin/php/php5.3.6/include/php/Zend -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext/date/lib -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/util -I/private/tmp/pear/install/mongo/util -DHAVE_CONFIG_H -g -O2 -arch i386 -arch x86_64 -mmacosx-version-min=10.5 -c /private/tmp/pear/install/mongo/php_mongo.c -o php_mongo.lo
mkdir .libs
 cc -I./util -I. -I/private/tmp/pear/install/mongo -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/include -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/main -I/private/tmp/pear/install/mongo -I/Applications/MAMP/bin/php/php5.3.6/include/php -I/Applications/MAMP/bin/php/php5.3.6/include/php/main -I/Applications/MAMP/bin/php/php5.3.6/include/php/TSRM -I/Applications/MAMP/bin/php/php5.3.6/include/php/Zend -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext/date/lib -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/util -I/private/tmp/pear/install/mongo/util -DHAVE_CONFIG_H -g -O2 -arch i386 -arch x86_64 -mmacosx-version-min=10.5 -c /private/tmp/pear/install/mongo/php_mongo.c -fno-common -DPIC -o .libs/php_mongo.o
In file included from /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h:34,
 from /private/tmp/pear/install/mongo/php_mongo.c:22:
/Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend.h:51:26: error: zend_config.h: No such file or directory
In file included from /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend_alloc.h:27,
 from /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend.h:237,
 from /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h:34,
 from /private/tmp/pear/install/mongo/php_mongo.c:22:
/Applications/MAMP/bin/php/php5.3.6/include/php/Zend/../TSRM/TSRM.h:20:26: error: tsrm_config.h: No such file or directory
In file included from /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend.h:237,
 from /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h:34,
 from /private/tmp/pear/install/mongo/php_mongo.c:22:

It is at this point that we curse the antiquated make system and the dependency hell developers put us though. These errors appear to have something to do with libtool or tsrm or zend or who knows what the hell is going on.

If you know how to fix these issues, please leave a comment below and let me know what you did!

I got annoyed and started looking into pure PHP drivers for MongoDB. These libraries don’t require a binary to work and will work with any platform. They aren’t written in C, so they are theoretically slower, but since MongoDB uses such a simple interface, I doubt this will make the application much slower.

BLAST! It turns out those aren’t actually pure PHP drivers, they depend on the binary still. This angers the humble PHP developer. So, we get annoyed some more and look for the mongo.so binary and download it, and copy it into the extensions folder used by MAMP:

/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626

We also add mongo.so to the list of extensions in our PHP.ini file:

/Library/Application Support/appsolute/MAMP PRO/conf/php.ini:~539

And then we reboot. Only to find out that nothing happened. Turns out MAMP deletes and rebuilds this file each time it restarts. A quick google search reveals the PHP file it uses before being rebuild is located here, so we edit that one:

/Applications/MAMP/bin/php/php5.3.6/conf/php.ini:~541

We do a reset of the server and… Still nothing works. A google search reveals the best way to edit the php.ini file is to go to File > Edit Template > PHP > PHP 5.3.6 php.ini. So we edit that file and add the mongo.so line near the list of extensions (line 541). Then, we restart the server and OH MY GOD IT WORKED!

tl;dr

That was a lot of hoops to jump through to get this working. Here’s the condensed version:

  • Download and extract the mongo.so pre-compiled binary PHP extension
  • Move file to /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/
  • MAMP Pro > File > Edit Template > PHP > PHP 5.3.6 php.ini | Line 541 add extension=mongo.so
  • Restart MAMP Services

My Recent Development Stack: OS X Tools

I made the switch to OS X about half a year ago now, and I must admit I’m going to find it rather hard to go back to using Windows or Linux on the desktop. The interface is way more user friendly, the OS is rock solid, and I find myself far more efficient than the days I was using an alternative desktop OS.

Now, I still need a Windows-based desktop computer for running video games, and I’ll never turn my back on a Linux-based web server, but for a development/general purpose machine, OS X wins hands down.

This post contains a listing of several tools I use and love every day for development. I’ve donated to all but one of them (GitX doesn’t  have a way to donate) and look forward to continuing updates.

Sequel Pro

For years I was a big user of phpMyAdmin, it had served my every need. However, I started to move further away from shared hosts (which usually provide PMA) and more into cloud/VPS solutions, and installing and maintaining PMA on every server was a bit of a chore. Also, the skins for the tool are horrible, the only good skin having been long outdated.

Sequel Pro is a native OS X MySQL client, it is snappy and has all of the useful tools one needs in a MySQL client (e.g. indexes, relationships, table editing, etc.). The interface makes sense and is very easy to use. You can open different connections in different tabs as well. The only thing I wish it could also do is SQLite and Postgres administration, otherwise it’s the one MySQL app you’ll ever need.

Sequel Pro Screenshot Native OS X MySQL Client

MacVim

Having hopped between IDE’s for years, trying all of those bulky Java based apps on varying different operating systems, I finally came to the conclusion that I need something a little lighter. That’s what makes VIM awesome, it only requires a handful of megabytes to get it running, and it has the snappiest interface you will ever use. Text movement and editing, once you get used to the keys, is nothing short of amazing.

MacVim is the defacto VIM client for OS X. Using some configuration settings I was even able to bind to the OS X swipe left/right inputs for controlling my buffers. With some keyboard wizardry, my Caps Lock key is now an escape key; without this using VIM is a bit of a chore. If you’d like to check out my VIM settings, you can do so via my MacVim Github repo.

MacVIM Screenshot

Jason

Jason is a sexy JSON editor native to OS X. For the last project I was working on, I was building a Single Page App which talked to a RESTful JSON API. When doing this communication I often needed to visualize the data being passed to me from the server for debugging purposes. That’s where Jason came in. Jason has a lot of cool features, such has hitting Cmd+V to paste a JSON document into a new Jason window, which makes JSON management a breeze.

Jason OS X JSON screenshot

GitX

GitX is a nice GUI tool for visually representing Git history. It’s not perfect (as you can see from this chaotic screenshot below) but it has been the best tool I’ve used so far. As far as doing standard Git stuff, nothing beats the command line. But, for visualizing history and quickly moving through commits, GitX is awesome. Unfortunately, there hasn’t been any updates in some time.

GitX Screenshot OS X Git Client

 Scroll to top