Home / Blog Menu ↓

Blog: #coding

91 posts / tag feed / about the blog / archive / tags

Some small scripts

Migrating to Day One has resurrected my efforts to scan and transcribe my older paper journals. As I’ve been doing this, I’ve run into the need for a couple small shell scripts to automate things.

On several of these journals I’m scanning the full two-page spread because the whole journal fits on the scanner platen, which means splitting the resulting image out into two (one for each page). Splitimage uses ImageMagick to do that nicely. There’s some overlap, but for a fully automated solution it’s not bad, and it saves me a lot of time cropping.

I prefer taking these split images and renaming them sequentially using something more meaningful (“journal-2009.005.jpg” rather than “IMG_0034.JPG”, for example). I used to do this with OS X’s Automator tool, and it works quite well, but I wanted a quick command-line tool to speed things up. Enter dub, a zsh script that simplifies the batch renaming process. Now I can just type:

dub journal-2009.X.jpg *.JPG

And then it’s just a matter of dumping them into Unbindery and transcribing them.


Reply via email

Alphabet app

Our toddler loves looking at letters and saying their names. A while ago we printed the alphabet out onto cardstock and have been using that with her, which is great, but I’ve also wanted to write a small web app that does the same thing — mostly for when we’re in another room, but also to make the randomization a little better. And because I can’t seem to stop writing little apps.

So this morning I threw together Alphabet:

Super simple. Click, tap, or hit a key to move to the next letter. It works on phones and tablets as well.


Reply via email

Spin

Introducing Spin, a game I threw together hastily for a little game jam I did with some friends.

Basically, you’re in a maze and have to get out before the timer runs out (ten minutes, which I display as 600 seconds because hey, I didn’t have much time) (pun not intended?). The world rotates 90° every five seconds with gravity changing as well, and the walls and obstacles hurt you if you touch them. And that’s about it. I threw most of the level together in, oh, about twenty minutes, so gameplay may end up being more frustrating than fun. But there is an exit, I promise. It may just take several rounds to find it without dying.

Technology-wise, Spin uses Box2D for the physics and THREE.js (WebGL) for rendering. I recommend playing it in Chrome, since Firefox’s WebGL wasn’t hardware accelerated (at least on my Mac) and was dog slow. (Safari works fine, but you have to enable the developer menu and then enable WebGL.)

Update: I realized this morning that it would be fairly trivial to add a first-person mode, since all I’d need to do is change the camera. So I did. It’s more boring of a game — with the gravity and world-rotation gone, it’s just maze exploration — but it’s kind of cool that WebGL makes it easy to do both kinds. The README has more info on how to activate the first-person mode.


Reply via email

Ordinals and degrees on OS X

For a while now I’ve used option-0 on OS X to type a degree symbol, primarily for tweets about how blasted cold this winter has been. But I’ve accidentally transgressed. That symbol (º) is not in fact a degree symbol, though it sure looks a lot like one. It’s actually an ordinal indicator. Sayonara to my typographic street cred…

To get the real degree symbol (°), type option-shift-8 instead. Now if only I could go back and edit all those tweets… (I blame iOS, where holding down the 0 key does in fact get you a degree symbol.)


Reply via email

Botswana 2.0

Two years ago my friend Chad and I released Botswana, a browser-based arena game with programmable bots written in JavaScript.

But the original was kind of boring. So we tweaked the game mechanics a bit and made a number of other modifications (multiple bots per team, extensible rulesets, etc.). And now we present Botswana 2.0, a culmination of rampant nerdiness.

The thing that interests me most about the game now is the customizable rulesets. For example, it took all of ten minutes to change the game so it’s played on a series of conveyor belts that move the bots up and down:

It likewise took less than half an hour to make the bots orbit the Death Star instead:

Since the drawing code is part of the ruleset, it’s fairly easy to get a radically different look:

Switching between the rulesets is just a matter of changing the URL in the ruleset box and starting a new tournament.

Anyway, as before, the release is on GitHub, with a README that explains how to write bots and customize rulesets and stuff.


Reply via email

Slow localhost in Chrome

For a while now I’ve been doing most of my web coding locally on my laptop, creating virtual .local hosts in Apache (like unbindery.local) and aliasing them to localhost in /etc/hosts. That was all well and good, but in Chrome there would always be a two or three second delay when first hitting a page on one of these local vhosts. Subsequent page views would be fast, but if I waited more than a minute or two, it would be slow again.

I finally googled around and just found that the problem is the .local — it’s used by Bonjour on the Mac, causing conflicts that Chrome doesn’t quite know how to resolve quickly. (Safari does, though.)

So, all you have to do is change the name of the vhost to something else — from unbindery.local to unbindery.dev, for example. Works like a charm, and my goodness, I can’t believe I waited this long to fix it.

Update: Turns out this is also the reason my terminal tabs would take two or three seconds to come up. It’s really fast now. Alleluia.


Reply via email

Unix date magic

The Unix date command has a cool feature I didn’t know about (hat tip to Dave C. for his comment about it on Dr. Drang’s blog). Turns out you can add multiple -v options to adjust dates — for example, to get the date of last Friday:

$ date -v -fri
Fri Sep 21 ... 2012

Or next Thursday:

$ date -v +thu
Thu Sep 27 ... 2012

Or the next Tuesday after two weeks from today:

$ date -v +2w -v +tue
Tue Oct 2 ... 2012

Or thirty seconds from now:

$ date -v +30S

Or five hours ago:

$ date -v -5H

Or ten years, a month, and three days from now (and no, I have no idea why you’d use something like that):

$ date -v +10y -v +1m -v +3d
Thu Oct 27 ... 2022

And so on.


Reply via email

Vim-fu

Vim has a steep learning curve, but it’s worth it. Here’s a cheat sheet of sorts showing some of the more useful commands (I put it together for a presentation at work):

There’s still a lot more to Vim, of course. And by a lot I mean a huge, massive mountain of things. Our goal here was to introduce some of the basics of Vim and provide a foundation for learning more. :help is your friend.


Reply via email

Goodbye, PHP

Yesterday I came across an article on PHP’s bad design practices that woke me up a little. I started using Python a couple years ago on some projects and I’ve loved it. Pure delight. It’s not a perfect language, but it feels so good to me. Coding is more fun and things just come together. It’s uncanny.

I don’t know why I’ve put up with using PHP all this while. My sole reason for writing apps like Bookkeeper, Donne, and Unbindery in PHP instead of Python was that it’s easier for people to deploy PHP on shared hosting, but I don’t think that’s as much of an issue these days.

So, FYI, I’ll be using Python instead of PHP for coding projects going forward.


Reply via email

Bookkeeper

About a month ago I was thinking about how I want to read more long, hard books — specifically The Brothers Karamazov. Back in college I plowed through Don Quixote in a week for my Comp Lit class (and I still think that’s slightly insane), and I read lots of other long books as well, all because I had a deadline.

Enter Bookkeeper. My coworker Chad and I have been working on it for the past couple weeks and it’s finally ready for an initial release. And we’re super excited.

What Bookkeeper is

It’s a reading goal tracker. You give it a book, the number of pages in the book, a start date, and a deadline, along with which days you’d like to read (since sometimes you’ll want to take weekends off or what have you), and Bookkeeper will tell you how many pages per day you have to read to hit your goal. If you miss a day, or if you read ahead, it’ll adjust that number (the red line on the chart).

Where to get it

Right now it’s just available on Github (it’s a PHP/MySQL app), and there are installation instructions in the README. It uses Google Accounts for authentication.

I’m not planning to host a public instance of it, at least not right now, but if anyone wants to do that, let me know so I can forward people to it. And of course anyone is welcome to fork the code and do whatever they want with it.

How to use it

You add books, then whenever you read, you update the page number (in the upper right). And that’s about it. The list of tabs on the left shows you your current books; the All Books tab will let you also see books you’ve finished and books you’ve hidden (for when you temporarily put a book on the back burner).

On the Account page (the link’s at the lower right) you can export your book/entry data as JSON. We figured it’d be nice to have some easy way to get your data out. (And the link doesn’t change, so you could set up a cronjob to curl the JSON weekly or something if you really want regular backups.)

The future

As we make Bookkeeper more social going forward, we’re thinking it’d be cool to build book recommendations based at least partly on reading curves. Looking at my Well of Ascension reading curve up there, you can see that it starts to go up quickly and it’s ahead of the curve, which pretty much means I really got into the book and must have liked it. That’s not a surefire method for determining which books are good and which aren’t, but we’re interested in seeing what kinds of recommendations we can get from reading data like this.

More screenshots


Reply via email