My most significant tech purchase of the last five years

With a title like that, you might think I’m about to talk about some expensive fancy gadget or high-powered laptop or something. That would be wrong. No, the device I’m talking about has turned out to be worth a great deal to me, but it hardly cost me anything to purchase.

I like thrift stores. I’ve haunted them for about 25 years, from the time I was a teenager, all the way through graduate school, and even now 10 years into a career as a professor. I just can’t help popping into Goodwill or Salvation Army to see what bargains there might be.

Almost a year ago, I found an old desktop computer at the Goodwill in Scott, Louisiana. Actually it wasn’t even that old, probably about four or five years old, but it was one of those cheap computers by eMachines that they used to sell at Wal-Mart. It had 512 MB of ram, a 160 GB hard drive, and an AMD 64 processor. It cost me $7.99. I brought it home, wiped the Win XP installation off of the drive, and installed some flavor of GNU/Linux, probably Crunchbang, but I don’t really remember now. I intended to use it as a backup desktop machine for the day when our Apple eMac would finally bite the dust (still chugging along now after more than seven years).

$7.99 emachines box from Goodwill

$7.99 emachines box from Goodwill

It would have served fine for that purpose, but a few things happened right around that time that gave the machine a new destiny. First, my boss was cleaning out his house and gave me his old router, a Linksys WRT54GS. I had been looking for an extra router for quite awhile because I wanted to try flashing it with open-source firmware to turn it into a wireless bridge, partly as a fun nerdy project, but also to provide ethernet network access to remote parts of our house. I successfully loaded DD-WRT firmware onto the router, and set it up as a wireless bridge in our detached office, which meant that I could plug the eMachines computer into the router and have internet access in the office. This was important, because this cheap computer was too noisy to keep in the main house.

The second thing that happened was that Statusnet 1.0 was released, and not too long after that, they upgraded the most prominent instance of Statusnet, identi.ca, to the new version. There immediately followed some serious problems with identi.ca, resulting in days of downtime for the service. This was a problem because identi.ca was my lifeline, my connection with all of the other free software nerds of my acquaintance. After a week or two of very spotty service from identi.ca, droves of users abandoned identi.ca in favor of Google+, but a bunch of users began to set up their own private instances of the Statusnet microblogging platform and connecting with one another in this decentralized way, rather than relying on a single giant instance (identi.ca).

This is where the eMachines computer comes in. I had already set up a private Statusnet instance at school to use with my students, so I knew how to do it, but I did not have a server at home. I decided to turn the eMachines box into a webserver so I could host my own instance of Statusnet at home and stay in touch with the other nerds even when identi.ca was down. It did not take too long for me to decide also to host my main web site (this very site in fact) on the server as well. I already had a web site elsewhere but it was old, outdated, and composed almost entirely of static HTML. I wanted something more modern, so I got a new domain name, and experimented with content management systems, and eventually decided to go with WordPress. Once I had the basic LAMP setup in place for web apps like Statusnet and WordPress, I found it was very easy to install others like Moodle, owncloud, and roundcube mail.

Now back to the title of this post. The reason this piece of junk eMachines computer is the most significant tech purchase of the last five years for me is that no other purchase has given me the opportunity to learn so much. By fiddling around with an $8.00 computer, I have learned about Apache, mySQL, content management systems, cron jobs, backup scripts, nameservers, SSL certificates, and the list goes on. I have gotten tons of experience administering a web server in an environment where nothing really critical is riding on it, and as such have felt free to try things out and and have learned many lessons that I’ll remember if I ever end up in a situation where I manage mission-critical servers. I feel almost as though I have retrained myself for an alternate career for nothing more than eight bucks and many hours of fun.

Since getting the eMachines box (which now hosts my Moodle and Piwigo instances), I have expanded the “Goodwill Cluster” to include three more routers (all hacked to run DD-WRT firmware, none costing more than $6.00), a Dell Dimension 2300 ($3.99, hosting my ownCloud and Friendica instances), and my most recent and favorite of all, a sweet little Mac Mini, which is now my main web server residing inside the house because it is so quiet.

Mac Mini

$4.99 Mac Mini from Goodwill

It has been very satisfying, empowering even, to find all of these castoff machines and pull them together into my own little cluster, hosting my own web site, keeping control of my data, learning something new every day about servers and network administration. Oh, and a little bonus: my wife approves of this hobby because it costs so little and because she knows how much I am learning from it. Thrift clusters FTW!

Posted in Tech | Tagged , , , , | Comments Off

Statusnet Database Spring Cleaning

After my Statusnet instance has been running for nearly 200 days I have accumulated more than 150,000 notices in the database. I decided to clean house a bit today. To delete all notices from a certain date backwards I ran this command:

DELETE FROM `notice` WHERE `created` <= '2012-2-29 19:04:11';

This deleted more than 60,000 notices. Now I just need to figure out how to script this where it'll run on the first of every month or something.

Posted in Uncategorized | Tagged | Comments Off

Updated “stick” script for quick & easy scp to different remote servers

I posted earlier about using a script to cut down on typing when using the scp command. I’ve since added a conditional statement to allow for different target machines. There’s a main server used as default, and others chosen by nicknames I’ve assigned to them and called from the script as the 2nd command-line argument.


#!/bin/bash

# retrieve filename from first argument
FILENAME=$(basename "$1")

# set default address
address="target.hostname.com:/target/dir/"

# if there's no 2nd argument, use the default server
if [ -z "$2" ] ; then
    server="larry"
    port="1234"
# server with same domain name that uses different ssh port
# so ssh requests using that port are sent to that server
elif [ "$2" == "curly" ] ; then
    server="curly"
    port="2345"
# server on different domain, have to specify
# different address, maybe username as well
elif [ "$2" == "mo" ] ; then
    server="mo"
    port="22"
    address="user@other.hostname.com:/target/dir"
else
    echo "" &> /dev/null
fi

echo "Transferring $FILENAME to $server"
scp -oPort=$port $FILENAME $address

Follow this format for as many servers as you want, then use the script name as the command, the filename as 1st argument and server nickname as 2nd argument. This will put the foobar.zip file on the server I named “curly.”


stick foobar.zip curly

If I don’t supply a server name, it just uses the one I’ve designated as default, which is “larry.”


stick foobar.zip

Posted in Uncategorized | Comments Off

USB-powered laptop cooler

Today at Goodwill I found a laptop cooler for $1.99 and bought it even though it didn’t have its power supply. When I got it home I opened it up to see if it might be possible to connect a USB cable to it to act as a power source. I had already made USB-powered fans before from old PSU fans and case fans, so it seemed probable. After poking a few times with the bare ends of a usb cable I found that it would be pretty easy. The tiny circuit board inside the cooler was clearly marked with + and – in appropriate places, and when I touched red to + and black to – the fans spun to life. So, I soldered the usb cable appropriately, plugged the other end into my laptop and started enjoying usb-powered laptop cooling. Since then I’ve put the cooler under my WRT310N router, which is notorious for overheating. This was a fun and easy hack. The hardest part was figuring out that the thing was held together by 8 screws hidden beneath the long rubber thingies “integrated rubberized fastener concealment strips” (thanks @nybill!) on top.

Posted in Tech | Tagged | Comments Off

Quicker Secure Copy to server (scp)

Once upon a time I wrote a tiny script that I totally forgot about until finding it just now. This is meant to ease the use of scp to a remote machine. It takes a filename as argument and puts it on your server.


#!/bin/bash

# retrieve filename from first argument
FILENAME=$(basename "$1")
scp -oPort=1234 $FILENAME server.address.com:/target/dir/

I save the script with name “stick” and run command like this:

stick foobar.foo

I’m prompted for my RSA key passphrase and the file is copied over. So much easier than typing out that whole scp command every time. I wish I’d remembered this sooner.

Posted in Uncategorized | Tagged | Comments Off

Multiply a letter times a number: How I calculated quality points with sed & awk

One tricky bit in my script to parse the transcript of our students was calculating quality points. After some manipulation of the raw transcript file I end up with data in csv format like this:

#Course identifier, course description, letter grade, credit hours earned
MUS 370,Music History I,B,3

I need a 5th field “quality points” that is grade point value of field 3 multiplied by credit hours in field 4.

Briefly my solution is this: substitute grade letter with corresponding number, perform the multiplication and substitute the letter back in. I accomplish this with a series of pipes. I found I needed strategic placement of a space before the letter grade to avoid false matches when subbing letters back in for numbers. I do this with awk (note the " ," before $3).

echo "MUS 370,Music History I,B,3" | awk -F, '{ print $1 "," $2 " ," $3 "," $4 }'

Output:
MUS 370,Music History I ,B,3

Pipe that through the next bit to find the letter grades and replace them with corresponding numbers. The B gets 3 points. In my script I do this for A,B,C,D in succession (An F gets no quality points so I don’t have to deal with Fs).

sed -e 's/ ,B,/ ,3,/'

Output:
MUS 370,Music History I ,3,3

With the number in place, run it through awk again to add the extra
field for quality points. Use awk’s multiplication capability to do it.

awk -F, '{ print $1 " " $2 "," $3 "," $4 "," ($3 * $4) }'

Output:
MUS 370 Music History I ,3,3,9

Now the quality points are in place. The last step is to put the letter grades back by matching only numbers preceded by a space and a comma: " ,3", otherwise I found that it could match numbers in other fields or maybe course description depending on what course it is. Again, I do this in succession for numbers 1,2,3,4 in the script but only for 3 in this example. While I’m at it, I remove the space I had put in there at the beginning of the process:

sed -e 's/ ,3,/,B,/1'

output:
MUS 370 Music History I,B,3,9

Done!

So here’s the whole command:

echo "MUS 370,Music History I,B,3" | awk -F, '{ print $1 "," $2 " ," $3 "," $4 }' | sed -e 's/ ,B,/ ,3,/' | awk -F, '{ print $1 " " $2 "," $3 "," $4 "," ($3 * $4) }' | sed -e 's/ ,3,/,B,/1'

Posted in Uncategorized | Tagged | Comments Off

I’ll make it fit

I just got finished doing one of my more clever kludgy hacks on a script. The input file is a student transcript, and I wanted only to find lines that did NOT end with a tab character followed by passing grade (A-D or S for “satisfactory”) and append those lines to the ones before them. With sed it’s easy enough to find the lines that DO end with \t and a grade:

sed -e '/\t[A-D,S]$/'

What I needed, though, was to find the ones that did not have grades on them, and append those lines to the previous lines that did have grades.

The best clue I could find as to how to accomplish this was on a page of sed one-liners. This page had one example where it found every line that began with an equals sign = and appended that line to the one before it. I probably spent an hour or more trying to make this command work the way I wanted it to, searching for lines that did not contain a pattern and then applying the action to them. Finally I got the brilliant idea to use the example on the sed one-liners page exactly as it was. If it wanted equals signs, fine, I’ll put them there. This command puts an equals sign at the beginning of every line except the ones matching the specified pattern:
sed -e '/\t[A-D,S]/!s/^/=/'
Now that I have all of the lines I want preceded by the = sign, it’s easy to use the replacement command I found to append those lines to the ones before them and at the same time replace the equals sign with a tab. 
sed -e :a -e '$!N;s/\n=/\t/;ta' -e 'P;D'
There must be a way to do this without the extra step, but for now I am very happy to have found a hacky workaround. :)

Posted in Uncategorized | Tagged | Comments Off

Linux command to remove all Mac OSX shadow files at once

For reasons unknown to me, Mac OSX creates shadow files of every file under certain circumstances, I think having to do with FAT-formatted usb drives or something. Anyway I had thousands of them scattered around my system after copying files back and forth for a few years. They are mostly things like ._01 Some musicfile.mp3. After much experimentation and a little searching I found the command to remove all of them at once.


find . -type f -name "._*" -exec rm -f {} \;

It’s a good idea to run this without the “-exec rm -f {} \;” command first so you can see what it’s finding and make sure it’s the stuff you want to delete.

Posted in Uncategorized | Tagged | Comments Off

Fun Scripts for “Cowsay”

I discovered that there are lots of options for ASCII animals to choose from with the “cowsay” program in Linux. After trying several out manually I got tired of all the typing and wrote a script to cycle through them automatically. Much easier. Here it is:

#!/bin/bash

cowfiles=$(locate *.cow)

for cowfile in $cowfilesdo
  cowsay -f $cowfile "howdy"
  sleep 1
  clear
done


After seeing all the cowsay files I wanted to find a way to choose randomly among them to speak messages. This was trickier. The hardest part was using a variable in the context of either awk or cut. I finally figured it out though. If you want to use this to get your local weather conditions, just change the location info in the elinks -dump command.


#!/bin/bash

# there are 46 cowfiles, this picks random number from 1 to 46
whichcow=$(echo `eval `NUMBER=$[($RANDOM % 46) + 1]`` | awk -F"=" '{ print $2}')

# find cowfiles with full paths
cowfiles=$(locate *.cow)

# use randomly generated number from above to pick a cowfile
somecow=`echo $cowfiles | cut -d " " -f $whichcow`

# weather stuff
CURRENT=`elinks -dump \
"http://www.accuweather.com/us/la/lafayette/70503/city-weather-forecast.aspx" \
| grep -A 2 Currently | grep [00-99] `

# extract temp from weather stuff
TEMP=$(echo $CURRENT | awk -F " " '{print $(NF)}')

message="Right now the temperature is $TEMP"

# make it speak!
cowsay -f $somecow "$message"

Posted in Uncategorized | Tagged | Leave a comment

How to Run heybuddy on Windows

Install Deps:

  1. python
  2. pygtk
    choose the all-in-one installer for python 2.6.6, Which has Cairo and
    the other dependency that I can’t remember.

  • Be sure to install as admin
  • You’ll probably need to adjust the environment variable “PATH” to
    include python. If you are not sure how to do that, it may help to
    watch this video

Heybuddy

Get heybuddy code, unpack it
and put the heybuddy directory wherever it suits you.

Go into the heybuddy source directory and rename “heybuddy.py” to
“heybuddy.pyw” so that it will run without a windows command
prompt. Double-click to launch.

If you want to get cheeky with it like I do it, you can open up the
heybuddy.py file in a text editor and change the variable “app_name”
to “heybuddy on Winderz” and this is the client people will see in
your timeline.

Posted in Tech | Leave a comment