I have a bash script that calls a java application. Originally this script and java app were only run on a linux machine. Then for a couple good reasons I needed to run it in windows under cygwin. I already had java installed under windows, so I needed to get the bash script running under cygwin to run the java app. The problem is that java is expecting a windows classpath (e.g. c:\path\to\whatever;d:\another\path) as opposed to a POSIX/cygwin classpath (e.g. /cygdrive/c/path/to/whatever:/cygdrive/d/another/path). In addition to the path seperaters and the direction of the slash is the complication of converting symbolic links.
After some digging and testing here is what I came up with. I’m sure there are numerous other (possibly simpler) ways of getting this done, but this works just fine. Admittedly not a common problem, but hopefully useful to someone.
# save the old splitting char
SaveIFS=$IFS
# set the splitting char to linux split
IFS=":"
# split the classpath
declare -a SPLITPATH=($CLASSPATH)
# restore IFS
IFS=$SaveIFS
# iterate through the path elements
for (( i = 0 ; i < ${#SPLITPATH[@]} ; i++ ))
do
# get rid of symbolic links
new_single=`readlink -f "${SPLITPATH[i]}"`
# convert from cygwin paths to windows paths
new_single=`cygpath -w "$new_single"`
# append to the new path
new_path=$new_path";"$new_single
done
export CLASSPATH=$new_path
A project I’m currently working on has me repeatedly looking at csv text files. When the columns line up well I can simply cat or less the data on a linux command line. But when the data does not line up I have to eyeball it and try and figure out what value goes to what column. Very frustrating. A quick search on google did not return anything that would give me a quick and dirty command-line csv text viewer that would align the columns. So I threw one together in PHP. Hope this helps someone out there.
<?php
// A quick dirty CSV viewer
$USAGE = "USAGE: csvfilename [ column_width ]";
if ($argc < 2) {
echo $USAGE . "\n";
exit(1);
}
$csvFilename = $argv[1];
$colWidth = ($argc == 3) ? $argv[2] - 1 : 5;
$lines = file($csvFilename);
foreach($lines as $line) {
$cols = explode(",", $line);
$newCols = array();
foreach($cols as $col) {
$col = trim($col);
if (strlen($col) > $colWidth) {
// trim the column
$col = substr( $col, 0, $colWidth);
}
if (strlen($col) < $colWidth) {
// pad the col
$col = str_pad($col, $colWidth, " ", STR_PAD_LEFT);
}
$newCols[] = $col;
}
echo implode($newCols, ", ") . "\n";
}
?>

My new music collection maintenance recommendation is GimmeSomeTune . For what it does it works very well. GimmeSomeTune runs in the background and monitors the music currently playing in iTunes. When a new track is played it can check to if the track has lyrics and/or artwork associated to it in iTunes. If it does not it can automatically pull down lyrics and artwork and add it to the track. In the case of artwork it appears to apply whatever it finds to all tracks of the album that playing track is part of. I’m not sure where its getting artwork or lyrics, but it works pretty well on more popular stuff, while (not surprisingly) it is less accurate on more obscure stuff. The artwork and lyrics are typically of pretty good quality. Added bonus is that it is “donationware” (i.e. free to use, donate what you wish).
It can do other things like integrate with LastFM, and act as a mini controller for iTunes, but while those functions seem to work ok, the thing that makes GimmeSomeTune special is the automatic lyric and coverart updating.
Only problems I’ve encountered are that the current version does not have a function that allows you to scan and update a bunch of tracks at once. There are a couple ways around this. I will likely write an applescript that plays the first couple seconds of all tracks that I want automatically updated, that should give GimmeSomeTune the opportunity to update what it can. The second (more troubling) problem is that for anything that GimmeSomeTune gets wrong, it will consistently get it wrong. So if it uses the wrong coverart or lyrics for a track, and you go in and remove the bad info, the next time you play that track GimmeSomeTune will again add the same incorrect info (unless presumably the source that it is getting its information from with better metadata). The only way around this seems to be using a placeholder for artwork or lyrics so GimmeSomeTune will leave the track alone.
Anyways, I’m still on the lookout for something better, so let me know if you know of anything.
Here’s a simple example that uses the for command in bash to echo a list of strings
for a in 1 2 3; do echo $a; done ;
Note that the semicolons can be carriage returns instead. In fact it seems that everything prior to the first semi-colon can appear on the same line, and do can appear on the first line or by itself on the second line or on the same line as the first command in the list of commands to execute (in the case of the example that is echo).
The best ripping/encoding software for OSX is and has been for a very long time (in my opinion) Max. It supports both CDParanoia for ripping and numerous encoding formats including MP3, FLAC, OGG and a bunch more. It even does transcoding.
There are 3 types of ripping/encoding configuration settings that are important to me (and should be to you) when ripping CDs; the rip settings, the encode settings and the output metadata settings. When ripping I want the highest quality rip I can get. For that I configure Max to use cdparanoia set to Full paranoia mode. For encoding I want both mp3 files and FLAC files. MP3 files are the most portable, while FLAC files are lossless and have the highest possible quality. Max allows you to encode to multiple formats simultaneously, so for encoding CDs I enable and configure both. I use the default FLAC settings. For MP3 I use the Transparent setting, which produces the highest quality VBR (variable bit rate) MP3 files appropriate for the audio.
If there is any weakness to Max it is in the management of metadata. Since Max is concerned with ripping and encoding its not too much of a negative that metadata management is lacking, but it is something of an inconvenience. Max attempts to pulls tag information (artist, album, track title, ets…) from MusicBrainz, which in my experience has maybe a 70% hit rate. Even if it pulls the correct information it does not automatically pull album art. Max does allow you to pull art from Amazon, but if the tag information does not match with Amazon, or if no tag information is available from MusicBrainz then you’ll have to manually correct your tags before querying Amazon. I’d estimate that getting a valid hit in MusicBrainz and having the tags match with Amazon for album are is about 50% for me. For the other 50% you can manually enter all the album info prior to ripping and Max will place the metadata into the encoded music files. That’s too much of a hassle for me, so instead I just enter the artist and album name. For compilations I just enter the album name. Later I use an app like mp3tag (sadly only available on PC) to correct tags and get album art in bulk.
In addition to tags you should make sure that the filename convention works for you. I like having a folder full of artist names and in each folder have all music tracks with a naming convention of:
ALBUMNAME-TRACKNUMBER-TRACKTITLE
If the album is a compilation it will be placed into a top level folder named Various Artists.
The only thing to add is that on PC the best I’ve seen (and I’ve used it extensively as well) is Exact Audio Copy (EAC).
Lets say that you have a deep, wide directory structure with a ton of files of various types. How do you go about extracting all the files with a given filename, while maintaining the folder structure that the files were in? And for added fun lets say you want to tar the resulting list of files.
> find . -name ‘FILENAME’ -exec tar –append -vf ~/TAR_FILE.tar {} \;
I have to do this every 6 months or so and always have to look it up. So this is as much a note for me as it is for anyone else reading this.
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘monty’@'localhost’ IDENTIFIED BY ’some_pass’ WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘monty’@'%’ IDENTIFIED BY ’some_pass’ WITH GRANT OPTION;
(note: I’m sure I originally copied this from somewhere)
I have a couple USB drives that I want to automatically mount on my Ubuntu system. Problem is that since they are USB their device names change, so using the name in fstab doesn’t always work. So… UUID is the way to go. So… here’s the line I added to my fstab…
UUID=95edbea6-3793-438d-a09a-a609f88e257c /mnt/extra1 ext3 rw,auto,user 0 0
To get the UUID use this on the command line…
>sudo vol_id -u device_name
Got this info from here
Here’s something that I’ve needed to do on occasion. Mostly to give additional IPs for ssh tunneling. I’ve used this mostly on my MacBook, but I’m sure it works in any linux based environment.
sudo ifconfig lo0 add 127.0.10.10
I’ve pulled this down many times from many places on the web. This time around I grabbed it from Extra Pepperoni.
You’re supposed to be able to do this already. But unless I’m losing my mind, it looks like the implementation for random desktop background images does not work the same as random screensaver images. Specifically the random screensaver image selection recursively looks through the folder you select as the image source, while the desktop background image selection does not.
I don’t really care why they did this, but here is a simple work around (inspired by this article at devchix). Open up a terminal and do the following.
- Create a folder that will be the desktop background image location:
> mkdir ~/desktop_image_folder
- Then run the following command, which will create symbolic links in the new folder, to all the images in the folder that stores your images you want to use:
> find ~/Pictures/IMAGES -exec ln -s ‘{}’ ~/desktop_image_folder \;
- In the system preferences select the new folder as the location for your background images.
That’s pretty much it. There are a couple catches. If you have a large enough image collection, you will likely have filename collisions, in which case the latter files will not be linked into the folder. Second, if you add new files to the original image folder(s) you will need to rerun the command.