Force download of fasta files and aln files with Apache
By kenglish
If you are serving fasta files or alignment files on your server, you may want to force users to download them instead of previewing them in the browser. My application would return the fasta files as Content-Type text/plain. I wanted to force it to application/x-fasta and force download. This is accomplished rather easily in Apache with the following directive:
<FilesMatch "\.(?i:fasta)$"> ForceType application/x-fasta Header set Content-Disposition attachment </FilesMatch> <FilesMatch "\.(?i:aln)$"> ForceType application/x-aln Header set Content-Disposition attachment </FilesMatch>
You will have to enable the apache module “mod_header” for this to work.
Example Bash script to rename directories
By kenglish
This script will rename directories based on a pattern. My goal was to rename my directories so the album year would be in [] and not (). For example, we would move /home/Music/ACDC/Back in Black (1980) to /home/Music/ACDC/Back in Black [1980]. The downside is you have to enter the pattern twice, once for bash and once for sed.
#!/bin/bash find /home/kenglish/Music -type d | while read DIR; do if [[ "$DIR" =~ \([0-9]{4}\)$ ]]; then NEW_DIR=`echo $DIR | sed 's/(\([0-9][0-9][0-9][0-9]\))$/[\1]/'` echo "$DIR --> $NEW_DIR" ` mv "$DIR" "$NEW_DIR" ` fi done
Bash script to copy files in order to my Coby mp305
By kenglish
I’m one of those people that refuses to get an IPOD. I think they are too expensive and they don’t play nice with Linux.
Last Christmas, I bought myself the 4GB Coby mp305 because it has more capacity than the Sandisk Sansa m200. The interface is crap compared to the Sansa m200. It doesn’t read the mp3 ID3tags at all. The navigation tree is simply the directory structure.
The major flaw is that it does not always sort files in the directory in the correct order. I finally figured out that it sorts files by the order that they were put on the device. However, for some reason in linux if you do “cp -R”, it doesn’t put them on in the proper order.
Here’s my script to put files on the device, it’s call coby_copy.sh:
#!/bin/bash if [ !-d $1 ]; then echo "Source Directory does not exists" exit fi if [ !-d $2 ]; then echo "Target Directory does not exists" exit fi echo "arg1 = $1 arg2 = $2" IFS=`echo -en "\n\b"` for FILENAME in `find $1 -type f -iname "*mp3" -print | sort | sed 's/^\.\///'` do DIR=`dirname $FILENAME` mkdir -p $2/$DIR echo $FILENAME cp $FILENAME "$2/$DIR" done
To run it:
coby_copy.sh "Harry Potter and Leopard-Walk-Up-to-Dragon" "/mnt/disk/Audio Books"
Install ruby gem libxml-ruby on Ubuntu 9.04 (Jaunty)
By kenglish
Quick note on how to install the libxml-ruby gem on Ubuntu:
sudo apt-get install libxml2 libxml2-dev sudo gem install libxml-ruby
Setup for CAC card on Linux Ubuntu 9.04 in Firefox
By kenglish
Install CoolKey
sudo apt-get install coolkey -y
Install PCSC Tools:
sudo apt-get install libpcsclite1 pcsc-tools pcscd -y
Install dod-configuration-1.0.2.xpi into firefox by downloading it to a local directory and then doing “File|Open”. You have to get this from https://software.forge.mil which you can only get to with your CAC. Yes, I know. This makes a lot of sense. I got it from a co-worker.
Plugin your CAC card reader and insert your CAC. The green light should come on. Next, you will to set up the CAC in Firefox.
Open Firefox, goto Edit | Preferences | Advanced | Security Devices.
Click Load.
Enter the following:
Module Name : CAC Module
Module filename : /usr/lib/pkcs11/libcoolkeypk11.so

The CAC should appear in your list of security devices now. Click “Log in” to test it. It should look something like this:

Click “Log In” and enter your pin to test it.
Try to bring up https://software.forge.mil. Firefox will complain about the cert so just add an exception for it.
You should be all good. Let me know how this works out.
NOTE: I’m using Firefox 3.5
Bedazzle Your Bash Prompt with Git Info (for Ubuntu 9.04)
By kenglish
This is in response to the railstip.org post about how to Bedazzle Your Bash Prompt with Git Info. If you do this in Ubuntu, it will screw up your gnome-terminal title.
This is how add the git branch to your prompt in Ubuntu 9.04. Edit /home/kenglish/.bashrc. Find the lines with PS1. Replace them with this:
function parse_git_branch { ref=$(git symbolic-ref HEAD 2> /dev/null) || return echo "("${ref#refs/heads/}")" } if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] $(parse_git_branch) \$ ' #PS1="\w \$(parse_git_branch)\$ " else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w $(parse_git_branch)\$ ' fi
Facebook plugin for Pidgin
By kenglish
Today, I installed the Facebook Plugin for Pidgin. Pretty basic, just downloaded the .deb file and double clicked on it.
One caveat was that I had the Pidgin MusicTracker plugin enabled and this caused Pidgin to crash when I set up my Facebook account. The MusicTracker can be disabled for selected acocunts and it must be disabled for Facebook. The solution was to disable MusicTracker, setup the facebook account and go back re-enable MusicTracker and disabling it for Facebook.

Using gitk
By kenglish
Just installed gitk. Very nice…. Here’s how to install it on Ubuntu:
apt-get install gitk
Awesome git resources:
I hope this post has been helpful.
Is Mac better than Linux?
By kenglish
I’ve been using Linux as my primary desktop since 2002. I love it. Last night I was at the for new Hawaii Linux Users Group. One guy asked, “So, I’m a developer. I have a Mac, I have eclipse, I have a terminal, etc. What is the compelling reason for me to switch to Linux?” None of the Linux geeks could really answer him. My only argument is cost. I got my Dell with Ubuntu pre-installed for about $900. I think a comparable Mac would cost around $1500.
I’ve never used a Mac so I don’t know what I am missing. I’m sure they work great all the time like the unbiased Mac enthusiasts tell me.
I have no original content to add to this debate but I did come across this interesting post that I thought was worth sharing. Enjoy:
5 Things Linux does better than Mac OS X
For the record, I travel in many circles and quite often people find out that I’m a software developer and they ask me questions like “How come I can’t get on the internet at home?”, “Do you writing code in 1′s and 0′s all day?” and “What kind of computer should I buy?” I always tell people they are better off spending the extra money getting a Mac. I do this because I wouldn’t wish Windows on anyone…
Mail Relay/Transport Setup
By admin
I had to set up a relay with sendmail, because i'll never remember, here's what I did:
Synopsis: Server1 is running postfix. It needs to send all it's mail out through Server2 which is running sendmail is and the main mail server for the domain (eg mydomain.com)
HOWTO:
1) Set up sendmail on Server2 to relay for server1:
a) vi /etc/mail/relay-domains
b) add (where 10.0.6.5 is the ip of Server1):
10.0.6.5 RELAY
c) do these 2 commands to make it stick:
sudo makemap hash /etc/mail/access.db < /etc/mail/access
sudo /etc/init.d/sendmail restart
2) Set up postfix on server1 to use a transport. This means it sends it's mail out through server2.
a) add this line to /etc/postfix/main.cnf
transport_maps = hash:/etc/postfix/transport
b) create /etc/postfix/transport and this line to it (where 10.0.6.101 is the ip of the relay server, server1):
* smtp:10.0.6.101
c) execute these command for it to take effect:
sudo postmap /etc/postfix/transport”
sudo /etc/init.d/postfix restart
d) One last thing to do, since Server2 is sendint e-mail from mydomain.com, gotta make server 1 do that too (otherwise it may send from myhost.mydomain.com), edit /etc/mailname and change the value to mydomain.com. This one took a while for me to find!
3) Test it out. I created a stupid php script to test if from the command line, to save me typing in the future here it is:
$ cat t.php
$to = 'kevin@kenglish77.com';
$subject = 'Test e-mail ' . date('c');
$body = 'HI FORM PHP ' . date('c');
mail( $to, $subject, $body );
?>



January 14th, 2010