Archive for the ‘Projects’ Category

UTF-8 Converter

Thursday, February 24th, 2011


The other day at work, I needed to batch convert about one or two hundred files formatted in MACROMAN format to UTF-8. Well, it turns out there is a command line utility to do just this called iconv. I was very pleased when I found that because it was going to save me a lot of time. Then I ran it and got confused. It turns out that iconv does convert text format, but it doesn’t write it back out to a file, it just spits the results back into the terminal window. Mildly frustrated, I decided to take matters into my own hands and write a script that would take the output and put it back into a file with the same name. These are the results:

#!/bin/bash

for f in $1/* ; do
o=`basename $f`
if file $f | grep Unicode ; then
cp $f $2
else
iconv -f MACROMAN -t UTF-8 $f >$2/$o
fi
done

I went further and added options,  a debug mode, verbose mode, and the like, and even a man page! The syntax is:

# roman_to_utf8 [options] <input> <output>

The input and output can be either directories or individual files.

#!/bin/bash

usage() {
echo Usage: $0 "[-v | --verbose] [-d | --debug] [-e | --encoding <encoding>] <input> <output>"
exit 1
}

VERBOSE=false
ENCODING=MACROMAN
DEBUG=false

while true; do
case $1 in
-v | --verbose) VERBOSE=true;;
-d | --debug) DEBUG=true;;
-*) echo "Bad option $1"; usage;;
*) break;;
esac
shift
done

SOURCE="$1"
DESTINATION="$2"

if [ $DEBUG = true ]; then
echo VERBOSE = $VERBOSE
echo SOURCE = $SOURCE
echo DESTINATION = "$DESTINATION"
echo ENCODING = "$ENCODING"
exit
fi

if [ "x$SOURCE" = x -o "x$DESTINATION" = x ]; then
usage;
fi

convert() {
INPUT="$1"
OUTPUT="$2"
FILENAME=`basename "$INPUT"`
if file "$INPUT" | grep Unicode ; then
cp "$INPUT" "$OUTPUT"
$VERBOSE && echo "Successfully copied $FILENAME"
else
iconv -s -f $ENCODING -t UTF-8 "$INPUT" >"$OUTPUT/$FILENAME"
$VERBOSE && echo "Successfully converted $FILENAME"
fi
}

if [ -d "$SOURCE" ]; then
for INPUT in "$SOURCE"/* ; do
convert "$INPUT" "$DESTINATION"
done
else
convert "$SOURCE" "$DESTINATION"
fi

exit

Please excuse the poor tabbing due to wordpress. In any case, it worked and saved me a ton of time. All you need to do is copy this script into a file and make it executable. Enjoy!

Chromium for Mac

Saturday, February 19th, 2011

So, I’ve stated how I feel about web browsers. Very few are devoid fatal flaws that bug me to the point of being unable to use them. To that end, I decided to take matters into my own hands by downloading and compiling my own version of Chromium.

As previously stated, Chromium has proven to be an excellent browser. It is minimal, functional, fast, expandable. The only issue I could find with it was it’s lack of conformity with the rest of Mac OS X in terms of handling selections in the location bar. The developers of Chromium decided to follow the convention of single click selects all in the location bar, following the cue of Internet Explorer. This however is contrary to the functionality of similar text fields in pretty much every other place in the Mac OS, including that of Safari. This incongruity was beyond my ability to cope, rendering the browser useless to me.

I pleaded my case, along with many others, at the Chromium developer forums, however they said it was a non-issue, and marked the bug as “WontFix.” So, I decided to make my own version with this deliberate behavior remedied. So I downloaded the source. 6.4 GB later I located the 6 offending lines of code, spent 1.5 hours making a cool Mac-themed icon, and spent 2.5 hours compiling on all 8 processors. The outcome? Success! Now, I will offer this for download, and as long as it continues to be usable and a good browser, Chromium  may very well replace FireFox for the first time in 10 years as my browser of choice.

Faux MacPro for less Dough

Saturday, July 24th, 2010

The last non-work-related project in which I partook was the building of a Mac to be used as my media server. As much as I would have loved to drop some money on a new MacPro, I am afraid that it would be impractical due to the limitation in hard disk locations as well as the exorbitant cost. Ergo, I made a “MacFaux”

The fake mac is pretty simple these days. Sites like OS X 86 Project & Empire EFI give you information you need on what type of hardware to buy, and software to install. Below is the list of items I acquired for this project.

The Case

I wanted this computer to match my normal computer, a MacPro. I looked around on eBay, and couldn’t find anything too well priced in the broken/stripped MacPros. I did however find an ample supply of reasonably priced Power Macintosh G5s. I thought that this would provide a good counterpart to the MacPro, and as an added bonus, had more room on the interior due to the lack of a second optical drive. The tricky part was getting the new motherboard to mount in the G5 case. I accomplished this by taking a piece of sheet metal and drilled holes that match the case as well as the motherboard.

Part Model Price
Case Power Mac G5 $100.00
Sub Total: $100.00

The Internals

Using the OS X 86 Project as a resource, I got some mac-compatible hardware. It seems that the Gigabyte motherboards are some of the more compatible motherboards out there. Also, I used a PATA DVD drive first since I had it as a spare, however I found that there were less issues using a new SATA DVD Burner I purchased mid-way through the project.

Using this diagram, I enabled the power button, as well as the USB port on the front of the machine by soldering the default harness to some generic PC connectors that go to the motherboard.

Part Model Price
Motherboard Gigabyte EP45T USB3P $139.99
Processor Intel BX80571E5300 (Dual Core 2.6 Ghz) $66.99
Video Card NVidia 9500 GT $69.99
Ram Crucial 2GB DDR2 400 MHz $50.99
HDD Western Digital 500GB Freebie
DVD Burner Samsung SATA DVD Burner 22x 19.99
Fans 2x 6″ Freebie
Power Supply Cooler Master RS750-ACAAE3-US 79.99
Sub Total: $426.94

EFI-X

After getting the computer together, and trying to get a stable install of 10.5 (Leopard), I finally resorted to buying the EFI-X module. All it is is a USB dongle with the appropriate drivers required for booting OS X. It is a little expensive, but after weeks of mucking around with the competition, I felt it was worth the cost.

Part Model Price
EFI-X Module EFI-X v1.01 99.99
Sub Total: $99.99

RAID

I wanted a RAID 5 setup for this server, and unfortunately Mac OS does not provide a native software solution, so I got a RAID card from High Point. To mount the hard disks, I needed some sort of HDD rack. Not being able to find one that was suitable, I designed one that can hold 8 HDDs and cut it out on a waterjet. After a couple of bends with a sheet metal break, it was ready to go! I got just 4 drives to start off with, but will expand to either 8 drives, 2TB drives, or both depending on my need as time goes on. Unfortunately, since this project began, hard drive prices have gone down considerably!

Part Model Price
RAID Card Rocket RAID 2313 140.99
Hard Drive Rack - $15.30 for the metal
$10 for cutting out
Hard Drives WD 1TB $72.00 (x4)
SATA/Power Extenders - $3.00 (x4)
Sub Total: $466.29

The Final Result

Once all was said and done, I got my server all up and running. It may not be as elegant on the inside as a brand new MacPro, however the final cost of a thousand dollars isn’t too shabby (Considering that a new MacPro is $2000 or more dollars!) Having used the final product for a few months now, I am very pleased with the results. It has been stable and fast. Live updating has been working great as well!

Part Model Price
Case Power Mac G5 $100.00
Internals MotherBoard, CPU, Etc. $426.94
RAID Intel BX80571E5300 $466.29
EFI-X EFIX v1.01 $99.99
Total (with tax): $1043.22

Plus, if you aren’t interested in the RAID setup, you can make the the MacFaux for a mere $630!