Fixing virtualenv after installing Mountain Lion

Filed under: Python | 11 Comments

After installing Mac OS X Mountain Lion you may find that your Python virtualenv setup has broken. I saw a traceback ending in “IOError: [Errno 2] No such file or directory: ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/__init__.py’”

Another error was being produced by virtualenvwrapper when trying to use the workon command: “ImportError: No module named virtualenvwrapper.hook_loader”

Fixing my virtualenv setup was pretty simple:

  1. Installed the XCode 4.4 Command Line Tools.
  2. Re-installed pip: sudo easy_install pip
  3. Re-installed virtualenv and virtualenvwrapper: sudo pip install virtualenv virtualenvwrapper

No other changes were needed and everything was running smoothly.

iOS web app icon sizes

Filed under: Apple | No Comments »

I keep looking up the resources sizes for iOS web apps (for when users save to their home screen). This is complicated by the sizes changing from time to time, so there is a lot of misinformation. Here is what’s current and what works:

Home screen icon Startup image
iPhone 3Gs / iPod Touch 57 x 57 320 x 480
iPhone 4/4s / iPod Touch 114 x 114 640 x 960
iPad / iPad 2 72 x 72 768 x 1004 (portrait) 1024 x 748 (landscape)
New iPad 144 x 144 1536 x 2008 (portrait) 2048 x 1496 (landscape)

Read more

Spy “security” cameras at the 2012 RNC in Tampa

Filed under: Personal | 6 Comments

I live in downtown Tampa and the 2012 Republican National Convention is taking place here this August. The city has seen a lot of public works project in advance, mostly beautification , but also some infrastructure. Good infrastructure like improved cell networks (LTE here is fast), but also bad infrastructure like a mesh network of spy cameras (or CCTV if you’re working for the man). I have seen the installation happen and it started by mounting antennas all over the downtown area. Seeing workers isn’t unusual here, but each of these installations was conspicuous because of a Tampa Police Department car parked by the cherry picker. Very strange to need a cop to watch someone mount an antenna, let alone dozens of antennas.

It’s a Saturday today and I was out for a walk and saw the familiar seen of someone in a cherry picker and a TPD cruiser looking over. This particular corner had an antenna installed weeks before (and I had taken pictures then too, curious about the specifics of the antennas), so I figured the camera portion was getting added today. I watched for about 15 seconds and noticed that the worker at the top was looking back at me. Strange, but there’s not much to distract yourself with up there so I didn’t think much of it. Then I took out my phone and snapped a picture. This set the worker off, he started yelling at me and then yelling “he took a picture, go get him!” to the cop. It’s a hot day and the deputy was inside his car, so I assume it took a bit for him to respond because I continued walking and was not interrupted. During my walk I made sure to upload the photo just in case I got in contact with an officer who had a less than perfect legal mind.

I grabbed a drink and then on my walk back decided to get another look, this time from across a fenced and barricaded street from another unrelated beautification project. He caught on quickly and yelled again, saying that I was a “piece of trash” and then yelling to the cop who was now out and about. The worker’s perch let him give updates to the cop, but again I was able to walk away without being interrupted.

I want to know what’s going on. We all know there will be spy cameras in downtown Tampa because of the RNC. We all have eyes and can see where they are. The antennas are large and noticeable, even an untrained eye can spot them. This was a public street and there was no way to know that photography was prohibited, even though the law there is dubious at best (I was in public, surrounded by people and taking a picture of a light pole which will remain fully visible for years).

When citizens complain about spy cameras, the response is frequently if you’re not doing anything to hide, you have nothing to fear. Or that they will just be used to solve crimes. It’s not very encouraging that they are already suppressing freedoms during the installation of these private eyes in the sky. The city has given millions of dollars to Aware Digital for apparent goons to install cameras that invade all of our privacy. Even St Petersburg has paid hundreds of thousands of dollars for CCTV during the RNC even though they aren’t hosting it. Governments use things like this as an excuse to get the toys they could never justify previously. The RNC is in and out in a week, we’re stuck with big brother for ever.

When they began installing the equipment, I took these photos. I didn’t know they would come in handy later.

Finally, since they apparently have something to hide, here’s a little bit about what cameras are being installe. The main contract is to Aware Digital, a creepy sounding Miami based company with nearly no web presence (coming soon, @2006) and Orwellian employment practices. They’re wireless and run on a custom built wireless mesh network. Officers can access the live video from mobile devices, ensuring future citizens will have to walk faster than I did. The contract is for about 60 cameras, which should cover a large amount of downtown. Their contract stated it needed to be up by July 1, which would explain why they were working today (June 30). Exact specifications of the cameras are hard to pin down, with people saying different things. City council types love to think they have classified intelligence and both boast and understate. Aware Digital spoke a little more about the system they had for Superbowl XLIV in Miami. That was two and a half years ago, so we’re likely a lot more sophisticated but they had HD pan/tilt/zoom cameras with 10x optical zoom. Not too shabby.

Update: It’s Monday and I was walking by the county courthouse and saw the familiar scene of a squad car and cherry picker. Low and behold it was the same Aware Digital goon. Unbelievably, out of the mass of people at lunch time around the busy courthouse he spotted me before I took a photo. I then snapped a picture as he yelled to a cop, “I knew it, there he is!”. What is going on?

Update 2: I have started a Google Map to track the locations of all these CCTV cameras. If you have spotted a camera that isn’t on the map, please get in touch.

Update 3: I got bored and made this data into a mobile friendly web app for use around Downtown during the convention: RNCCTV.

Make Django keep templates in memory

By default Django renders templates from disk on each request, which means if you edit a template file the changes will be reflected instantly on the site. That’s intuitive and all, but since code is kept in memory and thus code changes are not reflected until server processes are restarted, it’s easy to get yourself out of sync. I recently deployed a code/template change that depended on each other (the existing templates were incompatible with the new code) and between the time Mercurial synced files and the Apache processes were restarted I received dozens of emails about 500 errors. It was only a couple of seconds and I could not have done it any faster, but at the end of the day seeing dozens of errors is unacceptable.

Enter, django.template.loaders.cached.Loader. It’s a template loader introduced in Django 1.2 that keeps template files in memory. I’m not sure how I missed this until now. Using the cached loader will increase your memory footprint a bit, but it will keep them in sync with the code so all your changes deploy at the same time. If you have a lot of templates the memory footprint may be more significant, but it was very minor in my case.

To use it you wrap django.template.loaders.cached.Loader with the other template loaders you want it to cache. Since I wasn’t doing anything unusual I was able to get away with it wrapping the default loaders like so in settings.py:

TEMPLATE_LOADERS = (
    ('django.template.loaders.cached.Loader', (
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    )),
)

With that one change I can now deploy code and template changes and have them reflect at the same time. I am not sure why this isn’t the default, having your code update separately from your templates is illogical. Keeping it all in sync seems like common sense.

This change can be somewhat annoying while using the development web server since it automatically reloads when you change code but not when you change templates. To get around this you can either set TEMPLATE_LOADERS differently based on the value of DEBUG or override TEMPLATE_LOADERS in your local settings file(s) (assuming you have one). I’m overriding and it works fine.

KitchenAid mixer bowl weight

Filed under: Food | No Comments »

This is more for me in the future, but it’s public just in case anyone else has the same question. I have a KitchenAid Artisan Series 5-Quart Mixer (it’s great, I’ve had mine since 2007) and often bake with a digital scale. On multiple occasions I have wanted to subtract the weight of the mixing bowl, but only deciding this after adding things to it and forgetting to notate its starting weight or taring the scale. It’s a pain to figure this out after the fact and I had previously managed to not write down its weight. So for me and whoever else, here it is:

The weight of KitchenAid’s standard 5-quart mixing bowl is 793 grams (28 ounces)

Rain barrel fed by AC drain

Filed under: Food | 2 Comments

I have a rooftop garden in downtown Tampa and thanks to the lack of an outside spigot have to manually transport water from inside. Well had to, now there’s a rain barrel that is fed by the AC unit. Being in humid Florida and for cooling a couple thousand square feet, the unit puts out a lot of water per day (at least five gallons) and was previously emptying onto the roof and simply going down the drain.

I searched Amazon for a rain barrel and got a model from Algreen. After it was delivered I went to Home Depot and bought 3/8″ tubing and a 3/8″ hose barb splicer to connect the existing tubing and my extension. The rain barrel I bought (like almost all) is meant to tap into a gutter system, but has spaces to drill holes for tubing to connect multiple barrels together and/or for diversion when the barrel is full. I drilled a 3/8″ hole in one of these and inserted the extended AC drain tube and drilled out the other to divert into the drain. The photo is after the first portion, the hose shown is coming from the AC that is on the building’s roof. The building has 10′ ceilings and about a 4′ crawl space above that, but there’s a half height portion where the door out to the deck is and that’s what the barrel is on. It’s convenient in that the water is coming from basically a story above the barrel and the barrel is feeding a garden about a story below–gravity is easy to harness.

It almost immediately started to fill with water and so far is providing more water than I need for the garden (time to get new plants!). It has not filled completely yet so I haven’t had time to perfect the overflow. For now it’s just a hose out and into a drain.

This is a great way to use a rain barrel for when you don’t have a gutter system in place or don’t want to use water that has been exposed to your roof. For the most part we have a flat commercial roof without gutters, not to mention all the tar and associated materials that roofs contain. This clean water was previously being thrown away. I’ll have to figure something out in the winter when the AC is not running, but for now it has the added benefit that it generates the most water on the hottest days which is exactly when the garden needs the most water. It’s a simple hack and took remarkably little time. The barrel itself even shipped overnight with Amazon Prime so the most time consuming process was probably hunting around Home Depot.

How a Hacker News comment turned into a large Red Cross donation

Since 2004 I have provided a mobile optimized version of the Drudge Report. I was a bit early on the mobile curve and back in 2004 browsers weren’t nearly as sophisticated (or data access as fast), so it was a huge time saver. Even today having one column makes things a ton faster to read, so it has continued to draw an audience.

After some slowdowns on my server I noticed a very large amount of iPhone users (north of 100,000 unique monthly) using the site, which I thought strange because on my other sites mobile usage is pretty evenly split across lines according to market share. There were no referrers, so I had no further insight into where the traffic was coming from. I updated it to use memcached which helped reduce load on my server and then didn’t put a whole lot of thought into it other than fixing it when Matt would change his formatting a bit and a user would email me letting me know (I rarely if ever use it myself).

Flash forward to this week when in the comments of a post on Hacker News I mentioned this mysteriously popular web service and measure2xcut1x piped in saying they have an iPhone app for the Drudge Report that uses my URL. It all clicked–that explains iOS traffic dwarfing all other mobile OS’s and the lack of referrers. I quickly got the app name and downloaded both the free and paid ($.99 at the time of download) versions to confirm. Sure enough, the app is a webkit view around my site with either iAds or the $.99 purchase price. All the while I’m funding the millions of hits monthly that the site receives. I was happy to provide free hosting/reformatting as a sort of public service, but not happy that someone else was profiting off it.

I emailed the app’s listed developer, James Leung of Smartest Apple and asked to talk. After some back and forth (and disagreements) I ended up shutting the app down by changing the URL of the service, 301 redirecting anyone not on an iPhone and providing a note for iPhone users telling them of the situation. Drudge’s humorous siren graphic was also used, which made it pretty apparent something was wrong. This didn’t endear me to James much (or his superiors who control the money), but since I knew an update to the app to cut me out was coming ASAP and I had limited time with leverage.

I then had an idea, instead of sending me the money it could instead be donated to charity. With the current earthquake/tsunami/nuclear situation in Japan this seemed like a perfect idea and while I could find many ways to waste the money, the Red Cross could actually put it to good use. James wrote back right away saying he was in for his (small) cut of the revenue, but would have to get back to me for the bulk of it from his company. He wrote back again quickly saying that his employers would donate $5,000 if I would immediately return the functionality of my site so the app continued to work (negative reviews were pouring in). Almost directly afterwards I got another reply saying a matching $5,000 donation would also be made by the parent company. $10,000 to the Red Cross for Japan relief isn’t something to sneeze at, so I returned full functionality and thanked them for their generous donation. This morning he posted a video on YouTube of the first $5,000 donation while the matching donation is still in progress (at the end it says on behalf of 715 Franklin, which is the shared office I’m a part of in Tampa).

Considering how my first thoughts of what to do were incredibly immature (goatse?), I’m very happy of how this turned out.

tl;dr a couple days after a Hacker News comment I was able to help secure $10,000 for the Red Cross. The Smartest Apple and James deserve credit for turning around a bad situation into a big win for people in need.

List of content farms

Filed under: Web/Tech | 170 Comments

Now that Google has an official extension to block domains from search engine results, I thought it would be handy to list the largest and most prevalent content farms. Google’s Personal Blocklist works well, but doesn’t let you access a shared block list so it’s up to you to have a good list. It also makes you add sites from Google search result pages, so you’ll have to search for these domains and use the new block links that get injected by the extension. It’s a few more hoops to jump through than I’d like, but well worth it for less spammy SERPs going forward.

Update: Google has now made this an official feature of their web search, so there’s no longer a Chrome extension required. It’s a bit more of a hassle to block sites with, but having cross browser support is a big win (I was already bugging out seeing spam results in my mobile searches).

Update on March 23rd 2013: Google has removed the Blocked Sites feature and is suggesting everyone use the extension. The list below should still be a good starting place.

List of content farms and general spammy user generated content sites:

Note: The links go to a Google search for the associated domain, which lets you easily add it to your block list.

Further note: while it should go without saying, the below list of content farms is entirely of my own opinion. If you disagree, don’t block them (and feel free to comment and tell me why).

I’ll keep this list updated as I go. Please leave a comment if you see any I missed.

Using Google Analytics with jQuery Mobile

Filed under: Web/Tech | 46 Comments

I upgraded Crossword Tracker to use jQuery Mobile at the end of November and while it has proven popular, I had a sneaking suspicion my Google Analytics reports were off. The Pages/Visit statistic was quite low (very close to 1 in fact). It turns out that jQuery Mobile requires a little extra effort to execute Javascript on every page load. I broke up the Analytics code into two pieces and now every page view is being tracked.

In the head (which is executed only on the first page load) I load the required Javascript file from Google, using the async loader which means it won’t block page loading:

<script type="text/javascript">
    var _gaq = _gaq || [];
    
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
</script>

Originally I had the whole snippet from Google there and it counted just one view, no matter how many pages the user actually viewed. That’s because it’s not actually loading the whole other page, but requesting it with AJAX and then replacing parts of the page with new content. The trick to getting all page views counted is splitting up the part that tracks the page view. Here’s what I tucked in before the closing body tag:

$('[data-role=page]').live('pageshow', function (event, ui) {
    try {
        _gaq.push(['_setAccount', 'YOUR_GA_ID']);
        
        hash = location.hash;
        
        if (hash) {
            _gaq.push(['_trackPageview', hash.substr(1)]);
        } else {
            _gaq.push(['_trackPageview']);
        }
    } catch(err) {

    }

});

The pageshow event is triggered by jQuery Mobile on every page load (including the first), so we’re now calling the _trackPageview() method on every load. Handy. After just a day and a half’s worth of use, you can tell what a difference it made:

Google Analytics with jQuery Mobile showing average pages per visit

This all may change before jQuery Mobile hits 1.0, but for now I’m safely on the bleeding edge and have the analytics to back it up.

Update: jQuery Mobile falls back to using hashes to designate pages and that doesn’t get picked up by GA so / and /#/contact would both appear to be a hit on the homepage. You can easily get around this by checking for the hash and then sending the portion after the # symbol. I have updated the code above to account for this as well as moving to the asynchronous loader which makes a decent difference over 3G.

Update 2: I’m no longer using jQuery Mobile on Crossword Tracker because the way it works conflicts with Google Adsense. Mobile traffic has been steadily increasing and now makes up close to 50% of Crossword Tracker’s traffic.

How to stop dnssearch.rr.com

Filed under: Web/Tech | 1 Comment

A while back Brighthouse (who markets their cable modem service under the Road Runner brand) decided to drum up some revenue by redirecting unresolved DNS requests to a search results page loaded with a bunch of ads. This means if you make a typo instead of an error you get a search page that looks like a lot of the scammy domain parking pages that fuel the domain squatting industry. The search results are powered by Yahoo, which these days means Bing. The PPC ads take up most of the focus area of the page and are disguised to look like organic search results. tl;dr scammy

There’s supposed to be a way to opt-out, but at some point in time it broke. I had opted out a while back, so was surprised to see this page again. I checked the setting and sure enough I was still opted out. It’s pretty dick to hijack DNS resolving and then lie about opting out your users who have gone out of their way to do so.

Getting rid of it for real is simple, stop using your ISP for DNS. If Brighthouse or Time Warner can’t be trusted to honor their own opt-out preferences, don’t bother giving them the chance. I switched to Google’s Public DNS as it’s fast and completely ad-free like DNS should be. OpenDNS is popular, but by default does a similar redirect (though they honor your opt-out).