Suppose you’re writing an application that stores and compares street addresses. Depending on how you obtain those addresses, you may need to standardize them.
- Standardizing the addresses makes them easier to compare.
- Standardizing the address can have the side effect of validating the address.
- Standardizing an address also makes it more likely that you can send a physical piece of mail to the address and have it actually arrive.
This article explores one way to solve that problem. I’ll be showing examples of Ruby and Python, but the same general approach works for other languages.
A few months ago, I switched from GNU Emacs, which I’ve used for more than 20 years, to Sublime Text 2. After years of using Emacs, there are a few things I miss in Sublime Text 2. Fortunately, Sublime Text 2 has a rich Python API, and it supports plugins; so, it’s relatively easy to add features I miss.
Like all decent modern programming editors, Sublime Text 2 supports syntax
highlighting. But, for various reasons, it can’t always guess which syntax
applies to a file. For example, lately, I find myself editing a lot of Sass
files. Sublime Text 2 always brings Sass files (i.e., files ending in
up as plain text files, with no syntax highlighting. I wanted a way to tell
Sublime that all files ending in
.scss should be assigned the “Ruby Sass”
syntax, by default.
In other words, I wanted the equivalent of this Emacs Lisp capability:
Octopress does a good job of generating a blog that scales nicely for large computer screens and smaller devices (such as my iPad). However, it’s possible to thwart Octopress’s best intentions, as I inadvertently managed to do.
I occasionally post cartoons to my blog, and the images tend to be large enough that they flow outside the boundaries of the blog’s text area, which looks like crap. My first attempt at solving the problem was to use CSS to set a minimum size for the text region. That solution, however, ruins the blog layout for smaller devices, such as a tablet.
There’s a straightforward solution to this problem, though.
The general idea is to display a smaller version of the image in the text area; when a reader clicks on that image (or taps it, on the iPad), the full size image appears in a modal popup. Many sites use this approach, of course, including Facebook and Google+. Its popularity is part of its appeal.
This solution can be implemented in a simple plugin, making it easy to drop into individual blog articles.
One of the features I need to rebuild for Octopress was the ability to generate a table of contents (like the one for this article), for some of the larger articles.
This article describes how I accomplished that goal.
I’ve been using Unix shells for so long that I tend to get locked into a particular way of doing things. I first started using Unix in 1985, so I’ve used a lot of shells, among them the original Bourne Shell; the Korn Shell; the C shell (and its fork, Tcsh); and, of course, Bash.
Every so often, it makes sense to shake up the status quo. To that end, and based on some recommendations, I recently switched from Bash to Zsh. While reading the Zsh documentation, I found that it supports recursive globbing. (Actually, Zsh’s globbing features are even more powerful, but discussing all its globby goodness is beyond the scope of this article.)
Anyone who’s used Ant in the Java world is familiar with recursive globs.
With this feature enabled in Zsh (which is the default), you can remove all
files ending in
.log in all directories in and beneath the current working
directory with one simple command:
It was bad enough when GoDaddy CEO Bob Parsons killed an elephant. Many people decided to walk away from GoDaddy then, in protest. I did not transfer my domains at that time, preferring to wait until they expired, to conserve my cash flow. Plus, I will admit, I am not a fan of PETA. I don’t like PETA’s radical stance, and I have heard and read more than enough from Ingrid Newkirk and Dan Mathews. PETA’s response to Parsons’ elephant hunt was to organize a boycott of GoDaddy, and I dislike PETA enough that I have a knee- jerk, irrational reaction against participating in anything they sanction.
That said, however, Parsons’ explanation of his elephant hunt smacks of spin. His grand safari, and his politician-like response to the outcry, planted the seed of discontent.
GoDaddy’s most recent actions have caused that seed to sprout.
GoDaddy is on that list. GoDaddy supports SOPA.
SOPA is a very bad piece of legislation for the Internet. To understand precisely how bad it is, read some of the following articles:
- MythBuster Adam Savage: SOPA Could Destroy the Internet as We Know It (Popular Mechanics)
- All About SOPA, the Bill That Wants to Cripple Your Internet Very Soon (lifehacker)
- Stop the Internet Blacklist Legislation (Electronic Frontier Foundation)
- Google, Facebook, Zynga oppose new SOPA copyright bill (CNet)
- Please Take the No Go Daddy Pledge (Lauren Weinstein)
GoDaddy’s support for SOPA was the last straw for me. Today, I initiated the transfer of all domains under my control (both personal and business), from GoDaddy to another registrar. Like so many others on the Internet, I’m voting with my wallet.
GoDaddy will no longer get any of my business.
Update, December 23, 2011 GoDaddy has reversed course. In a flurry of disingenuous backpedaling, Warren Adelman, GoDaddy’s CEO, said:
Fighting online piracy is of the utmost importance, which is why Go Daddy has been working to help craft revisions to this legislation—but we can clearly do better. It’s very important that all Internet stakeholders work together on this. Getting it right is worth the wait. Go Daddy will support it when and if the Internet community supports it.
As Gizmodo’s Casey Chan put it, “If a sleazeball company like GoDaddy can ditch SOPA because of pressure from the Internet, you bet other companies currently supporting SOPA will cave too. Let yourself be heard and let’s freaking kill this bill.”
However, while I’m delighted that GoDaddy is responding to the pressure, I don’t trust that this reversal is anything more than panic and politics. I doubt that they have really realized the error of their ways. As Lauren Weinstein puts it:
Do not be fooled. Make no mistake about their motives. They’re not suddenly against the censorship principles of SOPA: “Go Daddy will support it when and if the Internet community supports it.” There is no indication whatsoever that they have had a fundamental change of heart.
I’m still not giving that sleazeball company any more of my money. My domains are on their way to another registrar.
About 15 years ago, I wrote a network server that could talk to a Visa point of sale (POS) box. The POS box was a modem-like device that connected to an RS-232 port. POS-aware software could use the box to send credit card transactions to a bank, for processing.
We needed a network server that could accept credit card transactions from a NetWare client and route them through the POS box, handling all the timeouts, retries, and errors that might occur. Since no such software existed, my job was to write it. Over the course of a month or so, that’s what I did. Written in C++, the code ran on Solaris and UnixWare. The plan was to deploy it on UnixWare, which could handle IPX and SPX, the network protocols underneath NetWare.
I tested the hell out of that thing, until it was bulletproof–or, so I thought. It was so bulletproof, in fact, that it basically never crashed. Eventually, it kind of got lost in the machine room. It was running on a PC, under UnixWare. The operating system was pretty stable, as was my server. At some point, someone took the monitor away, for some other purpose, so the machine ran headless. Over time, it gradually got shoved behind some other machines.
It ran that way for a few years, never crashing. The server room was wired to a backup generator, in case of power failure, so the machine just stayed up, and people apparently started taking the Visa network service for granted. During that interval, I left the company. A year or so after I left, a friend sent me an email, informing me that the Visa POS server had finally crashed.
Worse: No one could find the machine.
It had run so well, for so long, that it was buried, sans monitor, somewhere in the machine room.
Ultimately, they did locate it. It had crashed because of one Achilles’ heel I’d inadvertently left in the code: I had forgotten to roll the log files. It took several years, but eventually the log files grew too big and filled the disk. At that point, the whole thing came crashing down.
On the one hand, I was proud to have written a piece of software that ran so well that its users and administrators simply forgot the machine even existed. On the other hand, lest I become too arrogant, that same piece of software ultimately crashed, and caused a minor panic, because of one small defect.
There’s a nice, neat lesson in there somewhere.
git config --get remote.origin.url
or, if you want all of them:
git remote -v
If you put the command in a shell script called
git-url, you can simply
invoke it like this:
svn info | grep -i url
hg paths default
bzr info 2>&1 |grep 'parent branch'
Shell scripts or aliases (e.g.,
are useful finger-savers for these commands.
A stack? In bash?
For reasons I won’t go into here, I needed a simple stack implementation. In bash.
Now, stack implementations aren’t difficult, and bash does have arrays. But bash does not have classes or objects, and I wanted a general-purpose solution, not a quick-and-dirty, one-use hack.