retronerd

the musings of an old programmer

The World of Python

| Comments

When I first started learning Python, I quickly became a fan of the syntax. Tuples, dictionaries and list comprehensions are some cool language features that remove a lot of boilerplate. But as I waded into existing projects I kept running into environmental concepts like eggs, easy_install, pip, virtualenv and other scaffolding that have nothing to do with the language per se, but I needed to know to do anything useful with it.

However I couldn’t find any overview of this Python ecosystem that I needed to navigate.

PyPi Cache

| Comments

The Problem

Not many things are more annoying than a build failure that is nobody’s fault:

1
2
3
4
5
6
7
8
9
10
11
12
[exec] Getting distribution for 'MarkupSafe>=0.9.2'.
[exec]
[exec] An internal error occurred due to a bug in either zc.buildout or in a
[exec] recipe being used:
[exec] Traceback (most recent call last):
[exec] File "/mnt/buildout-caches/eggs/zc.buildout-1.5.2-py2.7.egg/zc/buildout/buildout.py", line 1805, in main
...
[exec] File "/usr/lib/python2.7/socket.py", line 447, in readline
[exec] data = self._sock.recv(self._rbufsize)
[exec] timeout: timed out
 
 BUILD FAILED

The code is fine, but our build depends on a website that we don’t control!

iTunes U Rocks

| Comments

On the side I’ve just started helping out on a fun iOS project. iPhone development is one of those things that I’ve been meaning to do for literally 2 years now. Finally getting that off the ground feels good.

Being one of those people who prefers instructor-lead learning over a book any day, I was thrilled to find that Stanford offers CS 193P iPhone Application Development via iTunes U for absolutely free. They even provide the course materials for free.

While it rained on a Saturday, I was able to “attend” the first week of classes and am busy finishing my homework. But I had to take a break to give a shout out to Stanford and Apple for providing something so awesome.

Take a look around iTunes U and you’ll definitely find something that interests you. I remember checking it out when Apple first announced it, but it has grown very large since then.

Serving Up Skin Images From Magento

| Comments

While integrating a shipping solution with Magento for multiple websites, we needed a way to get a logo for the invoice for each store in a generic way. The problem is that ShipWorks only knows the store URL and has no knowledge of Magento’s skin directory. So I came up with a simple PHP script that sits in the root of the Magento install and handles all the skin sanity (that’s right) inside of Magento for me. Enjoy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
  require_once 'app/Mage.php';
  $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
  Mage::app($mageRunCode);
  $file = Mage::getDesign()->getSkinUrl('images/logo-offline.gif');

  //Header
  header('Content-Type: image/gif');
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($file));
  ob_clean();
  flush();

  //Contents
  readfile($file);
  exit;
?>

SimpleDateFormat Will Harm Your Pets

| Comments

Today while researching a production issue I found a concurrency bug when formatting a date. It really wasn’t anyone’s glaring fault, it’s mainly just an artifact of our still-in-progress transition to Spring. We have an MDB that calls an EJB that calls a Spring-created object which has an object-local variable that is a SimpleDateFormat. The problem is that by default, Spring beans are singletons. Combine that with the fact that SimpleDateFormat is not thread-safe and hilarity ensues.