code
Upstart Notes
I think I’m going to try to keep my notes about Upstart here in the hopes that it may save some others time in the future.
Where scripts should live:
/etc/init
Failed to connect to socket:
status: Unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
Run commands as root (duhh):
sudo [start|stop|restart] SERVICE
Information regarding all the stanzas:
jQuery $.live() Equivalent in YUI 3
It’s been a while since I’ve posted and since I started at Yahoo! so I figured I’d give a little love to the new toys I’ve had the pleasure of playing with as of late. Clearly, we’re using YUI here at Yahoo! and because of that I’d had to adjust my thinking on a few goto front-end techniques that I relied on jQuery for. I hope to post more on these adjustments I’ve had to make, but we’ll see.
Aside from general patterns involving YUI loader, a major jQuery feature I realized that I had come to rely on is jQuery’s $.live() method.
Let’s say I have some markup like:
<div id="wrap">
<span id="button">Click Me!</span>
</div>
That’s being dynamically inserted into the DOM.
I got pretty used to doing something like:
$("#id").live("click", function() {
// do stuff
}
Super handy, but not exactly the best performance-wise. If you read the jQuery documentation (or even the jQuery source), you’ll soon find out that what’s going on behind the scenes is an implied event delegation to the root of the DOM. But, not to get too far off topic, there’s a lot of overhead that comes at the expense of this convenience.
YUI provides the same sort of functionality, albeit in a more explicit fashion via the Event delegate() method. I personally like the design decision that was made by the YUI team considering the performance hits that can be involved with using jQuery’s live method incorrectly, but to be completely fair, you can’t really mind the cleanliness of jQuery’s API. Anyways, you can always read the YUI 3 Event docs, but the above simply becomes:
YUI().use('node', 'node-event-delegate', function(Y) {
Y.one('#wrap').delegate('click', function(e) {
// do stuff
}, '#id');
});
I really like the cleanliness of jQuery, but sometimes, you gotta make a little lemonade outta the lemons you were given, even if they’re a little bit rounder and less yellow than the ones you’ve seen before.
There are definitely some caveats in the jQuery way of doing things as well as in YUI, but I feel like it’s a whole lot harder to screw it up in YUI.
Now, go try it yourself.
More Node.js + Comet Tomfoolery
I know there have been quite a few people out there that have messed around with node and comet already, but I figured I’d give it a go perhaps if only to familiarize myself more with the awesomeness that is node.js. I was originally inspired by this post on Ajaxian, so you’ll notice that I too am basing this off of Faye’s implementation of the Bayeux protocol for publish/subscribe. Only real difference is that in my example, messages are passed to the client via stdin.
Here’s the code: http://github.com/eculver/node_comet
I also read in a few other places where people were using fs.watchFile or node’s process.createChildProcess to create a public activity log of sorts. Maybe I’m just a nerd, but it would be kind of cool to go to a high-trafficked site and see some of the server log data (origin, user-agent, etc) in real-time. Something to that effect.
Filtering Special Characters Injected by Microsoft Word
I have been having trouble with users pasting content directly from M$ Word into admin fields, so I set out to create some sort of filter that replaces these little terds with something more HTML friendly. Here’s what I came up with, efficiency aside:
Please fork and enhance if you find more of these evil demon characters anywhere.
I guess it should also be noted that this can be called from any model save method on fields that you wish to filter.
UPDATE:
Just use SmartyPants: http://pypi.python.org/pypi/smartypants/
curl-ca-bundle Macports Checksum Woes
Just got done pulling my hair out over some pretty stupid MacPorts problems, but eventually got things working again, so I figured I would share. My problem started with trying to upgrade curl to support SSL so that I could do git over http yadda yadda yadda. Little did I know that I could have just upgraded curl in the first place, but this serves to address another point. I’ll spare all the lame details, but in essence I got to a point where I was trying to re-install git-core but curl-ca-bundle, a dependency, was failing with this:
$ sudo port install curl-ca-bundle
---> Computing dependencies for curl-ca-bundle
---> Verifying checksum(s) for curl-ca-bundle
Error: Checksum (md5) mismatch for certdata-1.58.txt
Error: Checksum (sha1) mismatch for certdata-1.58.txt
Error: Checksum (rmd160) mismatch for certdata-1.58.txt
Error: Target org.macports.checksum returned: Unable to verify file checksums
Error: Status 1 encountered during processing.
Before reporting a bug, first run the command again with the -d flag to get complete output.
After some googling around, I found the bug and saw that it had been fixed. Great, the fix is only available in trunk. Ok so I’m thinking, I’ll just pull down trunk a build and run it. Why not I like to live dangerously:
Installing MacPorts from Subversion
Nope, that didn’t work either:
$ sudo ./configure --enable-readline
...
checking for existence of /usr/lib/tclConfig.sh... loading
checking for Tcl public headers... /usr/include
checking for tclsh... /opt/local/bin//tclsh
checking for Tcl package directory... /opt/local/lib/tcl8.5
checking whether tclsh was compiled with threads... no
configure: error: tcl wasn't compiled with threads enabled
Not really getting anywhere now am I. Dammit. But after scratching my head for a few minutes, I said, wait… this is all over a few lousy checksums? C’mon…So, in looking at the actual commit from the bug, I saw that it was just an updated Portfile and lightbulbs went off. All I had to do was copy the updated Portfile to my ports tree and port should see the updated checksums:
# cd to curl-ca-bundle
cd /opt/local/var/macports/sources/rsync.macports.org/release/ports/net/curl-ca-bundle
# backup Portfile just in case, even though it's totally jank
sudo cp Portfile{,.bak}
# replace Portfile with one from trunk
sudo cp /opt/mports/trunk/dports/net/curl-ca-bundle/Portfile .
# install package that depends on curl-ca-bundle, in my case, git-core
sudo port install git-core
Seems like if I can’t install git-core, a pretty common package, then a lot of people are probably having this same problem. Hope this helps, I was at a loss for quite a while.
Beer-thirty!
Tab-Complete SSH Logins
A smart guy named Dave Hull (@davehull) shared this piece of bash magic with me a while back and I have relied on it ever since because it’s just that handy. It’s a bit of a stretch to say that typing out “ssh” every time is that annoying, but when you can tab-complete hostnames to login, pure bliss ensues. Ok, so to do this we just need one magical little bash script:
#!/bin/sh
ssh $(basename $0) $*
I usually name this “ssh-to”. Doesn’t really matter though. What matters is how you link it up. But first, make sure this is somewhere in your PATH, like ~/bin and also make sure it’s executable:
mv ssh-to ~/bin
chmod +x ~/bin/ssh-to
Last step is just symlinking to a hostname:
cd ~/bin
ln -s ssh-to some.host.com
And that’s it. You should be able to type “some.<tab>” and the hostname will be tab-completed. Super handy if you’re like me and login to the same hosts frequently.
Simple Fix for python-memcached MemcachedKeyLengthError and MemcachedKeyCharacterError
Here at work, we recently ripped out cmemcache and replaced it with the more apache+mod_wsgi friendly python-memcached, only to be innundated with a bunch of these:
MemcachedKeyCharacterError: Control characters not allowed
as well as these:
MemcachedKeyLengthError: Key length is > 250
The good news was that we knew it was definitely related to our new memcache library that Django was falling back on, but the bad news was that we didn’t want to go through all of our code and filter/hash our keys for every call to cache.get() or cache.set(). My simple solution was to write a set of overrides to the default Django memcached backend. I went ahead and gist’d it if anyone is interested:
This solution truncates and filters the keys as opposed to hashing them like some would suggest. I believe either method should work fine for the most part, hashing offering a far lesser chance of key collisions, but I was a little scared to start hashing keys after reading how it bit Reddit in the ass:
http://www.royans.net/arch/reddit-learning-from-mistakes/
This seems to work well at alleviating our python-memcached woes since our keys should be safely unique after truncating. One thing to note though, that took me for a sec (because I was referring to Django trunk) is that `set_many` and `delete_many` are added in Django 1.2, so they will not work unless using 1.2 or unless your backend already implements them. All others methods should work though.
Cheers.
Notes on PIL + virtualenv + Ubuntu
Just some quick notes on installing PIL in a virtualenv in Ubuntu:
Most forums or message boards suggest:
sudo apt-get install python-imaging
to install PIL, but that doesn’t exactly do when you’re trying to install into a virtualenv with –no-site-packages, so… you try to install from source by downloading the tarball and doing the usual:
wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
tar -xzf Imaging-1.1.7.tar.gz
cd Imaging
sudo python setup.py install
In some cases this works, but other times build will fail with this:
...
_imaging.c:3138: warning: return type defaults to ‘int’
_imaging.c: In function ‘DL_EXPORT’:
_imaging.c:3138: error: expected declaration specifiers before ‘init_imaging’
_imaging.c:3149: error: expected ‘{’ at end of input
A little known fact is that if you first install python developer tools, the build will go smoothly:
sudo apt-get install python-dev
This may install a few packages other than just python2.6-dev, but whatever. You should now be able to build and install as usual:
sudo python setup.py install
Took me some poking around, so I figured I’d share, maybe save someone some time.
Handy One-Liners
It’s been a while since I’ve posted, so I figured I’d just go with something that I found to have been pretty useful as of late. Peteris Krumins recently posted a great article about one-liners, so I figured I’d add a few of my own to that list:
- Python SMTP Server
python -m smtpd -n -c DebuggingServer localhost:1025This just starts an email consumer on your localhost on port 1025. When emails are sent to it, they are echoed to STDOUT instead of being routed. Handy when developing features that require email.
- Git Graph ‘Pretty Print’
git log --graph --abbrev-commit --pretty=oneline --decorateThis really just serves as a replacement to gitk or GitX in a (command-line) pinch.
- Remove .pyc
find . -name '*.pyc' -exec rm {} \;Does just what you’d think it does: removes all .pyc files from the current directory you are in.
These are all pretty much just great candidates for bash aliases, but I figured I’d share since I was inspired. Thanks Peteris, and if you haven’t checked out his article, do so IMMEDIATELY:
Getting Started with Rails – ERROR: could not find rails locally or in a repository
Just wanted to share this with everyone directly since I had a little bit of a delay getting Rails installed and up to date. Per the “Getting Started” docs, I tried to install rails:
sudo gem install rails
But was stopped in my tracks with this bad boy:
ERROR: could not find rails locally or in a repository
After some googling around, I fixed it by first doing:
sudo gem update --system
And then:
sudo gem install rails
Just thought I’d share that, maybe save someone some time.
Search
What I'm Doing...
- Everyone that considers themselves a Mizzou fan can... well, go fsck themselves. #checkyofilesystem 13 hrs ago
- Missouri sucks. Period. 13 hrs ago
- @aaronky seat's taken brah! You're not welcome in these parts. in reply to aaronky 15 hrs ago
- More updates...
Powered by Twitter Tools

Social Links