development

Command-line tip: replace a word in all files in a directory

Wed, Jun 26, 2013 - 11:37pm -- Isaac Sukin

I need to use this command every once in awhile and I always forget how to do it off the top of my head.

grep -lr --exclude-dir=".git" -e "oldword" . | xargs sed -i '' -e 's/oldword/newword/g'

If you're on Windows you'll need unix command-line tools installed. The easiest way to do that is with Gow.

Here's what each piece does:

"I want to learn programming. How should I start?"

Wed, Aug 22, 2012 - 10:21am -- Isaac Sukin

This is a slightly edited response I recently wrote to someone who asked how to learn skills that would be useful at a hackathon. It's my usual response when someone asks how to get started programming.

You should start by approaching the problem from a different perspective. You should be thinking "I want to build X. Now what do I need to learn to build that?" not "I want to learn to build stuff. What can I learn?"

Big Screens Matter Too

Fri, May 11, 2012 - 1:05am -- Isaac Sukin

I have a problem with mobile-first design.

I spend a lot of time every day sitting in front of three 1920x1080 screens. That's 6,220,800 pixels to play with, and web developers are not using them well. Take Twitter.com, for example: the Tweet column is 496 pixels wide. That's 26% of the width of just one of my screens for all of the content on the site that I'm supposed to read and engage with. When I'm sitting 3 feet away, the text is small, and it's a small target for my mouse (I've sped up the cursor so I can efficiently pan across screens).

TODO: Make code prettier

Sat, Jan 7, 2012 - 5:38pm -- Isaac Sukin

I'm writing a game in JavaScript for fun (I'm almost done, it'll be out within a few days). I've written dozens of games in traditional desktop languages, and I've written a lot of JavaScript designed to make user interfaces prettier, and I've even written some useful JS tools -- but this is the first time I've written a full application in JS complete with complex hierarchical entities. That is to say that I've never had to care much about the fact that JS more or less supports OO architectures before. I could have made this an opportunity to learn about OOP in JS, but I didn't. Instead I wrote the game basically without using (custom) objects at all, resulting in some redundancy and confusion. I did this because it was fast and easy and I already knew how to do it. The code's a mess, but so what? It works. It's good enough. I had fun, and I'm about to ship.

But I have this little note at the top of main.js:

Java Validated FileChooser

Fri, Nov 4, 2011 - 7:55am -- Isaac Sukin

I happened to be working on a Java project recently where I needed to let the user save files through the GUI. The Swing toolkit has a nice JFileChooser class that lets you show a file save dialog so that the user can choose the directory and name of the file to save. However, not all filenames are valid, and Java doesn't validate them for you by default. If you try to save a file with an invalid name, Java will throw an error, and this is often considered the only way to know if the filename is valid. That's bad practice though since you should never rely on an exception being thrown as a condition of your program running correctly; by definition, exceptions are unreliable and sometimes unpredictable. Additionally if your file saves successfully then you have to immediately delete it (because you were only saving it to test the filename) and that's messy. So I wrote a ValidatedFileChooser class that checks various criteria to make sure that filenames are valid before attempting to save the file, and alerts the user if one of the criteria fails. The class is below, and I'm releasing it to the public domain.

Pages

Subscribe to RSS - development