Code

Google Ad Injection

2024-11-24 Google ad injection

This post is getting updates - I’m trying to collect ad samples and investigate with a site owner so I can give away js that site owners can use to detect and block the ads. Please help!

MiscPodcast

2017-08-27 PHP podcast project

I have some random episodes of podcasts laying around waiting to get listened to from podcasts I don’t (yet) care to subscribe to. Maybe they had an interesting guest or topic, or came recommended. These downloads will lay around on my computer for months because they’re not in my podcasting app, so they’re not really in my listening queue.

Hard Lessons

2016-09-28 email handmade.network

Having worked on email-related code before, I have been morbidly fascinated by one of the founders of handmade.network writing an email client. Handmade Network is trying to reinvigorate programming by emphasizing small teams and from-scratch performant code. It’s a great way to write small, self-contained projects (games, libraries, utilities) that can be done, but fell out of favor two decades ago for complex user-facing software.

When maintaining a legacy Rails apps, drink every time...

2016-06-29 Rails humor

  • …the code gives up on basic indentation
  • …you find a database access more than four layers deep from the controller/job
  • …you find an untouched test, view, or migration file from ‘rails generate’
  • …there’s an explicit require to monkeypatch an autoloaded file of the same name
  • …you realize a fix is sabotaged by nil
  • …you find another model layer
  • …you find code that never worked
  • …a database schema is justified by legacy code that was decommissioned more than a year ago
  • …the only way to prevent a future bug is a sternly worded comment
  • …code only works because an invalid model was passed to it
  • …someone reverts part of your cleanups
  • …you find an implicit, ad-hoc state machine
  • …after the second time you find a totalizing js framework (ember, angular, backbone, etc.
  • …you find a directory under spec/test/feature the test runner skips
  • …a dev misapplied DRY so they could play with metaprogramming
  • …a random script is far better written than the app’s core feature (fortress of solitude)
  • …a dev justifies a bug in untested code by incorrectly claiming static typing wouldn’t catch it
  • …you find an abandoned selenium test suite for functionality with no other tests
  • …you hear “I know you’re cleaning things up, but ______ is not worth your time”
  • …code deliberately bypasses validations (“why do we even have that lever”)
  • …you reify a core app concept for the first time
  • …you find another repo that still doesn’t bring the app over 50 KLOC
  • …you track a bug to a commit whose entire log message is “squashed”
  • …even Rails’s support for database constraints would’ve caught the bug
  • …a bug exists in local dev but not in prod
  • …a module mixed into only one model depends on another module only mixed into that model
  • …you find a new technique for passing data to javascript
  • …Rails core is invoked to win an argument (via 355E3B)
  • …the last test was added two pivots ago

Should multiple Rails Apps and APIs share a database?

2016-03-05 ActiveRecord Rails

Having two (or more) Rails apps/APIs talk to the same database is a bad idea I’ve seen a few times in the last few years at larger/older clients. While it is a nice project for a consultant like me to undo (long but not risky = good profitability), you’re better off not doing it in the first place.

Recursive Sum

2016-02-13 Ruby recursion

In #ruby on Freenode, platzhirsch asked about how to total an array of Transactions when the Transactions may have parents. The two obvious approaches have pitfalls when there are a lot of Transactions, and he said he expects to have 23 million that may be deeply nested. Here’s his sample code:

Battery Longevity

2015-11-16 batteries systemd

I switched to a Lenovo X1 Carbon (3rd gen) in January, and one of the delights of a new laptop was a new laptop battery. I chuckle when I get a stern notification that my battery is running low: it’s fallen to 20% charge! And it can only last for another... two hours and ten minutes. Well, I’m not in a big hurry to find a plug when I see that.

Replacing Ack with Ag

2015-10-19 ack ag searching vim

I used grep to search code for a bit over a decade. I switched to ack to get more quicker searches without the distractions of svn/git metadata and other non-code files. After a very nice five years of ack, I’ve switched to ag. I’ve been recommending it to other devs for a year or two (it’s faster than ack with a couple really nice features like obeying .gitignore configs), but only took the time to switch this week.

POP3 and SMTP via SSH Tunnels

2015-10-05 email privacy ssh tunnel

I use Fetchmail to retrieve my email. I have an account that still doesn’t support SSL, but at least I also have an SSH account that on the same network. Here’s the fetchmailrc config to optionally tear down, then build and use an SSH tunnel:

Finished Libraries

2015-09-07 TeX version numbers

When I evaluate a software library, I typically look first at how recently it’s had a release. Is it being updated, or has it been abandoned? There’s an assumption, here.

Against Tedium

2015-07-27

As a web dev, I often feel like a ridiculous percentage of my day is spent converting between FooBar and foo_bar in the Ruby server code, foo-bar in the CSS class, fooBar in the JavaScript, and Foo Bar in the documentation. There’s so damn much repetitive plumbing.

Sizing Up My Queue

2015-06-29 Ruby media podcasts yak shave

I have a folder named “queue” that I download podcasts, videos, and books to. It occurred to me that it hasn’t been empty for years. That’s OK, the world is a very interesting place, and I care that I produce things, not just consume them.

What Comes After MVC

2015-04-23 RailsConf presentation

Rails apps start out quickly and beautifully, but after a year features are a struggle, tests are slow, developers are grinding, and stakeholders are unhappy. “Skinny controllers and fat models” hasn’t worked, and “use service objects!” is awfully vague.

Dual-Booting Arch Linux on Lenovo X1 Carbon 3rd gen

2015-01-26 Arch Linux Lenovo Linux Windows Windows 8.1 X1 Carbon configuration hardware yak shave

I decided to replace my mid-2011 Macbook Air 3,2 with a non-Apple machine, but every laptop I looked at was unsuitable. Most were overpriced, with a big and clunky design. The Lenovo X1 Carbon was promising, but the 2nd generation had a keyboard that was just too weird (and the function keys changing modes means you can't touch-type them anymore). Standard qwerty is bad, but it's the devil I know.

That was a year ago. In January 2015 Lenovo released a third generation of the X1 Carbon with some slightly improved specs and a normal keyboard, so I picked one up. I decided to switch from Ubuntu because I've felt out-of-touch with how it works under the covers and I've been curious about Arch Linux. This post is my notes on setting that up.

2016-04-07: A year and three weeks after I started using this laptop (I know precisely because that put the laptop juuuust out of warranty), without warning or accident, the display stopped working. Lenovo's expensive repair service estimated 6 businesses days for repair but the repair took over 5 weeks. If you might purchase a Lenovo laptop (perhaps the recent X1 Carbon 4th gen), I suggest you consider whether randomly losing hundreds of dollars and access to your laptop for 5 weeks would inconvenience you. 2016-05-16: ...and by "5 weeks" I mean "9 weeks". When Lenovo sent my laptop back with a new motherboard, it was one model down with slower processor, half the RAM, etc. It took another several weeks of dealing with their incompetent bureaucracy before they replaced it. 2016-12-18: Well, shit, the display on the replacement has started flickering.

Isolating Polymorphism

2015-01-13 Ruby encapsulation inheritance

I’m reading [Code Complete, 2nd ed]{href”http:=”” www.cc2e.com=”” “=””} and it’s been like catching up with an old friend. I remember reading the first edition at my first tech job fifteen years ago. At the time a lot of it went by me, but rereading I can see a lot of things I had to learn on my own.

Type-Checking Interface in Ruby

2014-08-27 POODR Ruby boundaries experiment interfaces

One of my favorite parts in Sandi Metz’s excellent Practical Object Oriented Design in Ruby is when she describes how to enforce lightweight interfaces so that multiple objects can play a role reliably. And I thought: how I can I enforce this in a much-more heavy-handed and annoying way?

Distributed ID Generation and Bit Packing

2014-04-14 Chibrary bit packing bit twiddling concurrency design stemwinder

There are two ways for programs to collaborate: they can communicate their shared state or they can partition the work so they don’t need to know each other’s state. As I’ve been rehabbing the code for my mailing list archive Chibrary I ran into this issue, and the design constraints made for an interesting puzzle. I need to generate unique IDs in multiple programs at once, and they need to be short enough to fit in URLs. 2025-05-13: Don’t use this post. I was (re)inventing the wheel and it wasn’t worth saving the bits. Use Snowflake or TypeIDs or one of many other existing solutions that have since been invented by people with more experience.

Extracting Immutable Objects

2013-12-05 ListLibrary.net Ruby design design patterns email mailing lists object orientation

In the last few weeks I’ve been rehabilitating some of the first object-oriented code I wrote in the hopes of bringing my mailing list archive back online. Lately I’ve been refactoring some of the earliest, core code: the Message class. It manages the individual emails in the system and, because I didn’t understand how to extract functionality, had turned into something of a God Class.

Dropbox and Git Play Well Together

2011-02-15 Dropbox git how to version control

Chrys Wu asked me my thoughts about how to have easy access to a software project she’s working on so that she can conveniently access them from the several computers she uses regularly. Not all of them can be set up as development machines, so a standard version control system can’t be used alone.

XML Crash Course

2010-12-17 Star Trek XML html

A non-nerdy friend of mine (yes, they exist, moving on) changed jobs at her company last week and had a question:

Spreadsheet Errors

2010-11-14 bugs spreadsheets

Last week the magazine The Nation hurried to correct a story that they had suffered the worst drop in advertising of any weekly magazine. Their loss was actually in the middle of the pack, but the story was written from a spreadsheet that overstated their advertising for last year, giving them the appearance of a step decline.

Globalton

2010-08-26 design patterns

It’s Steve Yegge’s fault that I was rethinking the singleton pattern. I read his Singleton Considered Stupid post in early 2008 with the rest of the proggit before it devolved into a memetic garbage patch. Yegge’s rant ends with a note about design patterns that curled up in my hindbrain and has been whispering to me since:

Hackers and Gamers

2010-05-05

I’ve been meaning to mention for a while that I’ve been contributing to the tumblelog Hackers and Gamers to share interesting links at the intersection of business, code, and gaming.

JavaScript: The Good Parts

2009-06-09 Douglas Crockford JavaScript book review

In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders. The best nature of JavaScript is so effectively hidden that for many years the prevailing opinion of JS was that it was an unsightly, incompetent toy. p2

Developer Day Notes

2009-05-30 IRC

I’m attending Developer Day DC and taking notes. They’re fairly rough and sort of only cover the things that catch my attention, but here they are in the hopes that other people find them useful:

Inauguration

2009-01-22

Through some luck I ended up with a ticket to the Blue Standing Area (mid-south Capitol lawn) of the Inauguration, and through even more luck I was able to get through security to see it. I had a bit of hike to get to that point:

Rails Forum Roundup

2009-01-15

I’ve got a Rails project in the works that needs a forum to live alongside it, so I went looking for an existing Rails forum to adopt and customize.

Washington Post Update

2009-01-14 Django Washington Post politics work

It’s been a long time since I’ve written about what I’ve been up to at the Washington Post, so let me run down the apps I’ve worked on since September 2007 in roughly linear order. Lots of these apps link different places, so if you don’t see projects.washingtonpost.com at the start of the URL, you’ve probably wandered off something I directly worked on.

Developers Need IRC

2009-01-11 IRC

If you’re a developer who doesn’t use IRC, you’re not being as productive as you could be. I was thinking about this when I read a blog post on how IRC can be a nice low-interruption news source. It can be handy for that, but the real value in IRC is other developers.

Now Do You Know It Works?

2008-11-11 reliability testing verification

You’re writing code to store a file on Amazon S3. It’s a popular, powerful, widely-used and highly-reliable service, and you know the Amazon S3 API pretty well. So you write a function that takes a file and a key name (filename), then calls the HTTP PUT to store the data. Do you know it works?

RailsRumbling

2008-10-16 Rails RailsRumble crunch experiment web

I’m participating in RailsRumble this weekend, from 8 PM Friday to 8 PM Sunday. The goal is to build a web application in Ruby on Rails in 48 hours, and I welcome the change of pace of a small project. It’ll be a fun weekend crunch to build it, and I hope it will be a long-term resource for the development community.

256-Color XTerms in Ubuntu

2008-10-05 256 colors Ubuntu screen terminals vim xterm yak shave

It’s not commonly used, but most Linux terminals can support 256 colors. It’s also a bit of a pain in the ass to set up if it doesn’t Just Work out of the box. Having spent a while today tinkering and searching and cursing and testing and trading mail/IM with folks who understand the eldritch depths of terminals better than I, I thought I’d write up my findings for anyone else who’d like spiffy colors.

Rails URL Params as Types

2008-08-26 Rails URLs strings typing

Yesterday I (belatedly) took my friend Nola Stowe’s advice and picked up a book she tech-reviewed, The Rails Way by Obie Fernandez. It’s been a great read so far (about 85 pages in), and I just realized that routing is largely about type conversion.

Harkins's Law of Enterprise Software

2008-06-08

Bram’s Law cleverly explains why a lot of common software sucks. I was just chatting in #startups and coined my own law to lay alongside it. I think I finally understand why all the gigantic content management systems and “Enterprise solutions” I’ve seen are so terribly bad.

Getting Git

2008-06-03 DVCS PeepCode VCS git source control

I’ve been curious about git for a few weeks. I’ve heard friends recommend it, a lot of big projects (Linux kernel, Xorg, Rails) have switched to it, and I hadn’t yet learned a distributed version control system. I’ve bounced off the blog posts I’ve come across, they weren’t well-organized or assumed some basic familiarity I didn’t have. The man pages were also kind of intimidating.

Turning Wordpress Categories Into Tags

2008-04-17 MySQL SQL WordPress automation insert into select

I recently updated this Wordpress install from 2.2.something to 2.5 and noticed that it now supports tags instead of just categories. I had been using categories as tags, but I’d rather built-in tags than fake it anymore. I didn’t want to manually retag a couple hundred posts with ~200 tags, so I wrote some SQL to do it for me. If you’re in the same boat

Pipe Viewer

2008-03-06 bash console pipes

Today I found a really nice program for long-running console commands: pv, aka “Pipe Viewer”. If you’ve ever strung together a long command with pipes, run it, questioned why it’s taking so long, maybe open another terminal to run top... pv is the answer to that question.

My Four-Year Patch

2007-12-18

I’d actually forgotten it and had to scratch my head a bit when I got the message my ticket was closed. In August of 2003 I submitted a patch to Fluxbox to allow users to hold Alt and middle-click to push a window to the bottom of the stack. The source to Fluxbox has changed so much I can’t even find the section of code that the patch was written for, so I suspect that my ticket was closed when a developer swept through old tickets and recognized this as done.

An Academic Inconvenience of Python

2007-11-08 Python

Sometimes Python’s roots in academia bug me. Lots of functions have a computer science feel instead of a software development feel. Here’s an example I just ran into: I wanted to fit as many sentences as possible from a long text into 255 characters. So I wrote:

Keep Ruby Gems in Your Home Directory

2007-11-05 Ruby RubyGems gems install shared hosting

I like keeping my Ruby Gems in my home directory. I don’t have to type sudo in front of every gem command, it’s easier to remember the path to them when I want to read their source, and I don’t have to worry about a sysadmin on a shared host updating a gem before I test it. Here’s how to make those benefits yours:

Fixtures in Ruby Unit Tests

2007-07-12 Ruby fixtures testing tests unit tests

I’m writing some Ruby scripts that sort and store lots of small files. After a day or two of hacking I had the basic code working, ran through a few thousand files, and a malformed file blew up the sorter. That was OK, the sorter was intentionally naive and lacking in error handling; I wanted it to hack it together and try out a few approaches before committing to serious development.

Good Timing

2007-07-02 Hostway RegistryPro design sleep work

This morning, at about 4:30 AM, I awoke and just knew the Right Way to rebuild RegistryPro to be completely reliable, even more compact, and provide meaningful reporting. It would take less than two weeks of coding time and the pitfalls are well-demarcated and avoidable. It would be really great if I’d thought of it two years ago when I still worked there. Thanks, brain.

Epson Perfection V100 in Ubuntu

2007-02-18 Epson GIMP Linux Ubuntu hardware sane scanner scanning shell v100

Epson v100 I just bought an Epson Perfection V100 scanner and wanted to post about how I got it working in Ubuntu for anyone else who noticed it doesn’t Just Work. The drivers are binary-only, so you have to dick around a little to get them installed -- the SANE folks have said they’d integrate them if they were open source, but most hardware companies fail to provide source and doom their hardware to early obsolescence. Tangent aside, here’s how to get your scanner working:

Seeing Subversion Diffs for Commit Messages

2007-02-14 Subversion commit diff scripting

When I go to check code into a Subversion repository, I like to review a diff of my changes. I can confirm I’m committing the right files, make sure I didn’t leave in any debugging statements, and take one last chance to ponder the code. Usually this means doing an svn diff in another window or shelling out of vim to run it. This is a bit awkward, so it’s easy to forget the step. That’s backwards, it should be easier to do things right than slack.

Capistrano Task to Load Production Data

2007-02-07

I was working on a migration that had a decent chance of messing up my database and wanted assurance it would work with production data, not just my fixtures.

GET and POST variable hashes in Ruby on Rails

2007-01-08 Rails

In Rails, you access GET, POST, and routing variables through the params hash. This works almost all the time, except when you duplicate a variable name: routing overwrites GET overwrites POST.

Making Valid XHTML Easier

2006-11-14 Rails Ruby xhtml

I’m working on a Rails site in my Copious Free Time and I wanted to share a little way that Ruby made my life easier. I’m making my pages valid XHTML 1.0 Transitional because it makes life easier to find bugs and it just feels good to know I’m meeting the spec.

Tidy Stylesheets in Rails

2006-10-27 Rails Ruby css design maintainability

It’s very easy for a site’s CSS to grow a single giant, brittle stylesheet. It becomes impossible to change anything because of bizarre interactions between elements, unexpected interactions, and simply because it’s just too big for anyone to understand. Much of programming is managing complexity, and I’ll share a nice technique in that vein.

Triple-boot Filesystem Layout

2006-07-27 Linux OS X XP

I’ve got a MacBook on the way that I plan to triple-boot and I’m trying to figure out how to lay out the filesystems. I plan on using Linux primarily as I’m a developer. XP has a lousy command line environment* and OS X has a lousy GUI, but I’d like to keep them around for browser testing.

Rails Day 2006

2006-06-17 Rails web

I’m sort of participating in Rails Day 2006. I say “sorta” because I’m trying to build an app in one day but I’m not actually in the competition.

Ripping Unicode

2006-06-15 Python design graphics

some unicode glyphs I love shoving around large amounts of data. Unicode is an industry standard for encoding data in most every written script there’s ever been. It has over 97,000 characters. A while ago I read about a guy who made his own Unicode poster and I realized I had an opportunity for a fun project. I think Unicode is an invaluable and beautiful project, and this is my tribute to it.

Developing With Evil

2006-06-15 PHP Perl design humor web

[allaryin]{style=”color: red”}: whee... [allaryin]{style=”color: red”}: i’ve been given a job to put a simple email address subscription form on a site [Harkins]{style=”color: blue”}: sounds pretty easy [allaryin]{style=”color: red”}: and... as far as i can tell, the server has neither php nor perl :P [allaryin]{style=”color: red”}: i’m running out of options :P [Harkins]{style=”color: blue”}: cgi, baby [allaryin]{style=”color: red”}: for db access?
[Harkins]{style=”color: blue”}: Or change the target of the form to a server you control running PHP/perl that saves the data and redirects back to the other server. [allaryin]{style=”color: red”}: yeah...
[allaryin]{style=”color: red”}: but i really don’t want to commit any of our server resources to their site :P [BSDCat]{style=”color: green”}: I think a ‘simplicity’ fairy just lost its wings [Harkins]{style=”color: blue”}: Or make the form GET and write a cron job to scrape access.log. [allaryin]{style=”color: red”}: ... [allaryin]{style=”color: red”}: wow. [Harkins]{style=”color: blue”}: Yes, I’m evil. [allaryin]{style=”color: red”}: it’s beautiful really [Harkins]{style=”color: blue”}: bwa [allaryin]{style=”color: red”}: but yes, evil

Django And The Disappearing Template Tags

2006-05-25 Django

If you are defining custom template tags, don’t put them in a file named log.py. You’ll be able to {% load log %} fine in your template, but you won’t be able to use your tags. No, this isn’t documented anywhere.

Know a Good Linux Feed Reader?

2006-05-19 Linux feeds web

Could anyone recommend a good feed reader for Linux? I need to be able to organize my ~160 feeds in folders, read an entire feed or set of feeds without having to click incessantly, and get already-read items out of the way.

Lambda at Work

2006-03-27 Python

Lambda Finally, several years after learning lambda expressions, I got a chance to use one at work a few days ago. As long as I’m putting a notch in my nerd belt, I’d like to write about what lambda is and how it can be useful.

Python Flyweights

2006-03-20 Python

When I wrote Equality for Python, my example didn't mention how the Card objects could actually be a terrific waste of memory. A commenter named versimilidude (great handle!) beat me to this post, briefly describing the Flyweight Pattern. Luckily he didn't provide example code, so I still get to publish this post.

Equality for Python

2006-03-03 Python

Image A few days ago in #chipy, the chat room for the Chicago Python Users Group, we had a chat about how Python determines equality. It's a pretty neat and extensible technique, so I'm going to walk through how I recently used it for playing cards.

Versioning: The Next Big Thing

2006-02-28 Django databases math web

In the web development world, anyways. So, in the grand scheme of things, maybe not a huge deal to anyone else. Versioning is going to be one of the biggest problems and opportunities there is in web development, and it's going to take us at least five years to get it right.