Saturday, February 13. 2010Absolute paths must dieOk guys, it's pretty simple: if you're working in a Turing-complete environment and you've got paths which start with a '/', you're doing it wrong. Very wrong! Todays offender: WSGI scripts. Here's the first line of a common WSGI script:
See a problem there? That's right, the absolute path! How could this be solved? Simple: put the WSGI script in </rant> Wednesday, February 10. 2010A Parameterized Testrunner for FlexUnitA couple of days ago, I complained about FlexUnit's Theories. Well, with a bit of encouragement from @drewbourne, I broke down and wrote a proper parameterized testrunner:
And that code will do exactly what you'd expect: run three test cases, one for each of the inputs. If one test fails, the others will still run. Helpful error messages will be provided when a test fails. The source can be downloaded from: http://gist.github.com/299871 (and it will be getting a new home when ever I get around to releasing all of my AS utilities) Look useful? Give it a try and tell me what you think – I'd love to know. Monday, February 8. 2010How Wolfram|Alpha makes me happytl;dr: learn what Alpha can do, add a keyword search for it. Remember Wolfram|Alpha? Wolfram's attempt at a computer knowledge engine that got a little bit of hype, then drifted into obscurity? Well, it has been making me pretty happy recently, and maybe it can make you happy too. Here's my trick: First, learn what it can and can't do: it won't help much with a broken xorg.conf… But if you need to convert units (especially units of storage), get information about a date, compare stock information or do anything with a mathematical equation, Alpha is incredible. (yes, there is nothing there that's unique to Alpha… But that's not the point. The point is that, once you know what it can do, you can, on the first try, get the information you need. There's no looking through Google search results (even Google's calculator takes a couple of tries (compare: alpha: 4 CAD in USD).) Second, make it really, really easy to use: add a keyword search (if you're in Safari, use Stand) so searching Alpha is just as easy as searching the rest of the Internet:
Then just start using it Friday, February 5. 2010FlexUnit's Test Theories: Don't BotherI've just been playing around with FlexUnit 4's nifty new "Test Theories"… And I have come to the conclusion that, right now, they are basically worthless. Here's why:
So, don't waste your time on Theories just yet. For now, just use a
Or, if you want to test the cartesian product of a set of data, use my handy cartesian product function:
Followup: as Alan (see comments) said, what I really want is a parameterized testrunner. So I've gone ahead and written one. See my post on a Parameterized Testrunner for FlexUnit. Friday, January 29. 2010DVCSs and Changeset NumberingOne of my big beefs with DVCSs is their version numbers. For example, take two changesets I committed today: 6899 and 02a9. Which one is more recent? How many changesets separate them? Without access to a repository, there's no way to tell… But that sort of information can be useful to have. Two of the three DVCSs I have experience with,
And, of course,
I'd like to see this taken a step further, though: I'd like the changeset hashes themselves to encode some basic information about where they live in the repository. For example, one way to do this could be using the first two bytes of the hash to store the distance from the root*, and the next two bytes to store a "repository id", which is generated once, when a repository is first cloned or initialized. So, for example, one of these changeset hashes might look like this: 0afc53bf02f1, and committing again to the same repository would produce 0bfc109dca65. Of course, this scheme doesn't guarantee anything - it's entirely possible to generate two completely different changesets with the exact same four-byte prefix… But in the general case, this sort of scheme could make it significantly easier to figure out how arbitrary changesets relate to one another. *: Doug Philips suggested this - thanks. Friday, January 22. 2010Self documenting code is a lieBe very, very wary of anyone who suggests that "self documenting" code can replace comments. Case in point: I consider myself a mediocre programmer, who is usually capable of producing mostly coherent code. Below is a hunk of the code I wrote today - keywords are blue, variables are white, comments are green:
I don't think I could take much away from that without doing a serious disservice to the poor person (probably me) who will be tasked with fixing the inevitable bugs in the above code. Sunday, January 17. 2010Django settings.py mini-tip: the `path` lambdaThere are a few things I do every time I start a new Django site, and one of those things is add my
From then on, it's drop-dead simple to create absolute paths which are relative to the root of the project (or, at least, the directory which contains settings.py). For example:
And some other places where it is useful:
Tuesday, January 12. 2010dm-crypt and confusing error messages(this is a post intended for Google - sorry for bothering you, faithful RSS readers) I've been setting up encrypted backups for my Linux machine, found that $ cryptsetup luksFormat /dev/sda3 ~/.backupKey WARNING! ======== This will overwrite data on /dev/sda3 irrevocably. Are you sure? (Type uppercase yes): YES Failed to setup dm-crypt key mapping. Check kernel for support for the aes-cbc-essiv:sha256 cipher spec and verify that /dev/sda3 contains at least 133 sectors. Failed to write to key storage. Command failed. $ Google will suggest lots of things… But none of them solved my problem. What was I doing wrong? I needed to run D'oh. Sunday, January 10. 2010Makefile for Arduino 0017I picked up an Arduino yesterday, and I was quite dismayed by how much work it took to build/flash from the command line. After some hours of Googling, though, I finally found an up-to-date Makefile, and it didn't take too much to make it "just work" with the default install of Arduino.app on the Mac. To use this Makefile, simply drop it into the project sketch directory, then run Get the Makefile from: http://gist.github.com/273821. Just a note: I haven't had much time to tinker with this system yet, so it may have some serious issues... If so, drop me a comment below. Also, leave a comment if you want me to let you know if (when?) I update this. Tuesday, December 8. 2009Using git for Backup is Asking for Paingit isn't a backup system. Neither is Mercurial, Bazaar, Subversion or even (even) CVS Version control systems, with the possible exception of SourceSafe, are great at keeping track of code. Why is that? Because they were designed to keep track of code. Unfortunately, though, the features of a good VCS are entirely different – and often exactly the opposite – of the features which make a good backup system. Take, for example, file ownership. A good VCS will, very rightly, ignore file ownership: when I check out someone else's code, I should be the owner of those file - not whatever And ownership is just one example - permissions†, creation and modification times, empty directories‡, hardlinks, xattrs, resource forks, … the list of details that a backup system must keep track of goes on and on. In fact, there are so many things a backup system can get wrong, there is a project called Backup Bouncer, designed specifically to verify that backup scripts correctly copy all the various bits of metadata tracked by the filesystem. So, please: if you value your bytes, use a real backup system, not git. †: Most VCSs only track the 'x' bit - for backup purposes, all bits, including suid bits, must be tracked. Monday, December 7. 2009Best Ever Implementation of "indexOf"!(alternate title: The "Fail Early, Fail Often" Principle in Action) I would like to award Adobe the "best ever implementation of
This beauty can be found in And the kicker? The function's documentation:
The author clearly knew that unknown methods* shouldn't be called… But instead of doing something sensible – like throwing an exception – they do something wholly nonsensical and return Next up: why implicit conversions from </rant> *: the magic PS: Instead of calling Saturday, December 5. 2009You and Your Editor: Vim normal mode commands g, : and d (3 of N)In my last post, I showed off some normal-mode data from vim-logging. In this (and the next few) posts, I'll go though my most-used commands and describe how I use them. (Don't use Vim? This post won't be too interesting… Although you may pick up something useful) gMy logs contain more than 60,000 references to the 'g' command (eight times more than ':', the next most frequently used command). This may seem surprising at first, but stick with me and let me explain: the 'g' command is something of a 'gateway' command - a prefix for a number of common actions which don't have their own single-character command (for example, gd, goto definition and g?, rot13 encode). Here is a breakdown of the 'g' suffixes I often use:
That's all the 'g' commands I can think of for now... The next version of vim-logging will log the sub-command used, so I will be able to provide better data in the future. :The colon command is fairly obvious: enter command-line mode to run commands like I'll write more about this later, when I analyze my most-used ex commands. dAh, As with
You and Your Editor: Data from vim-logging (2 of N)Remember when I blogged about vim-logging? Well, I've finally gotten around to interpreting the results. First, I will cover what I believe to be the most important thing to know about vim: the normal mode commands. Below is a chart of my 39 (why 39? I can't remember - when I created the graph, that's the number I chose) most-frequently-used normal-mode commands: Continue reading "You and Your Editor: Data from vim-logging (2 of N)" Tuesday, December 1. 2009codekills (and wolever.net) downtimeI'm sure you didn't notice, but I'll tell you about it anyway: the server that runs wolever.net and codekills.net, lazarus, died of unknown causes two weeks ago. It took two weeks to get everything fixed because it lives in Toronto and I live in Waterloo… And the first weekend I went back to pick it up… I forgot to pick it up. Right now the data has been migrated to another machine (the one you're talking to right now), and it is doubtful if lazarus will ever live again. Wednesday, October 28. 2009Splitting Audio on the MacThis is a quickie, but hopefully it'll help someone out there. I had to setup my laptop so two people could use it to talk on Skype: one audio input (the call), two outputs. First, I installed Soundflower. Second, I opened up "Audio MIDI Setup" (/Applications/Utilities/Audio MIDI Setup.app) and created an Aggregate Device (Audio -> Open Aggregate Device Editor). I checked all the output devices, and included the Soundflower device:
Third, I set the system's input and output to Soundflower:
Fourth, I opened up AU Lab (/Developer/Applications/Audio/AU Lab.app) and created a new… thing… with two outputs and one input. After hitting OK the right number of times and getting the main window up, I hit Window -> Show Studio, then selected the Aggregate device on the left. Finally, I checked both the "1" and the "2" on the left side of the "input" to send its output to both output 1 and 2. Some tinkering with the input and output streams (in the Studio) was also necessary.
Finally, in Skype, I set the audio input to the built in microphone (which was fine for me), and everything was peachy!
(Page 1 of 4, totaling 59 entries)
» next page
|
QuicksearchArchivesLinks
CategoriesSyndicate This Blog |
