Archive for the ‘Coding’ Category

Who needs mice?

Thursday, April 17th, 2008

Saw this on Ongoing today, and got sucked in.

steves-MacBook:~ gnubbs$ history|awk ‘{a[$2]++} END{for(i in a){printf "%5d\t%s \n",a[i],i}}’|sort -rn|head
   92    svn
   76    cap
   58    cd
   57    ssh
   55    ls
   26    ~/rdiff
   22    exit
   13    export
   12    mate
    7    vi

"svn" allows me to make stupid mistakes without regretting them.  "cap" allows me to roll out those stupid mistakes from Subversion to my web servers.  "ssh" shows that I upgraded servers lately so was stuck doing a bunch of SysAdmin work. "rdiff" is a piece of code that I stole off the intar-webs that allows me to run diff on two pieces of code reguardless of what computer they are actually on.

Getting rid of another desktop

Sunday, March 9th, 2008

A while ago I bought myself a MacBook.  I use it as both my primary computer at home, and at work.  It sucks to have to buy a computer with my own money for work - but it was either that or continue to use an outdated PC and WinXP.

Over time, it has gotten to a point where I pretty much only use the PC to check my outlook and make sure that documents I have created on my Mac look okay in Office.  Not exactly computational heavy lifting.

The other day I had the bright idea to try and get a corporate image of WinXP working in VM Ware.  It was amazing how easy that turned out to be.  The process was amazing simple.  Use VMWare to create a new virtual machine, pop in my depoyment CD, type in my corporate username and password, and let the installer run.

Once installed, everything worked like a champ.  I use the Unity option in VMWare so that I can just interact with my windows apps like they were any other app running on my laptop.  Performance is surprising usable — just a tad slower than Windows running on my bottom of the line PC at work.

Overall, a very pleasant experience.  For anyone holding out on using a Mac because they need to run one or two applications, this is a great solution.

Site Fixed, maybe?

Saturday, February 23rd, 2008

Okay. I finally got around to getting things working on my blog. My new site uses Wordpress MU to manage my blog and a couple for friends and families — as opposed to just having a separate Wordpress installation for each person.

It took me a while to get around to fixing my mod_rewrite rules to redirect my old urls to my new urls. Hopefully it works.

RubyQuiz 136 : ID3 Tags

Tuesday, February 5th, 2008

A while back I decided to take on some of the problems from RubyQuiz.  The first one that I picked was the ID3 tags quiz.  My first attempt read in the entire mp3 to get just the last 128 bytes. 

It worked, but really rubbed me the wrong way.  I spent quite a bit of time trying to figure out how to seek to just the bit of  the file that I wanted to read in.  Unfortunately, I didn’t have much luck because I hadn’t used the more low level file IO functions.  In the end, I had to resort to the RubyQuiz solution to figure that out — but it was truly the last resort.  (So what exactly was my input…)

Here is the core of the code:

  # This is the heart of the code for reading the id3 tags.  id3 tags are stored
  #
in the last 128 bytes of the file.
  def read_id3
   
    # When writing this code, this is what caused me the most trouble. 
    #
I didn’t want to have to read in the entire mp3 to get the last 128 bytes.
    #
I knew what I was tring to accomplish, but just couldn’t nail down the .
    #  seek(offset,IO::SEEK_END) on my own.  I ended up finding
    # that code (more or less) on the ruby quiz page — not from lack of

    # searching though.
    offset = -128
    @mp3_file.seek(offset,IO::SEEK_END)
    unparsed_data = @mp3_file.read

   
    # This code is pretty straight forward, after you look at the info on how id3
    #  tags are stored.
    tag, @title, @artist, @album, @year, @comment, genre_index =
               unparsed_data.unpack(’A3A30A30A30A4A30C’)
    @year = @year.to_i
    @genre = @genres[genre_index]
   
  end

The rest of the code, genres file, test code, and a test mp3 are included in the attached zip file.  Do you use autotest?

ID3 Tags Project

How long will it take to fix my sites?

Thursday, January 24th, 2008

I recently moved from Dreamhost to Joyent.  I figured it would be a quick transition.  It should have been a quick and easy move, but somehow it has now been about a month and things are still broke.

My plan is to try and get my subdomains fixed tomorrow which will cover most of the things that are still broken.

On a side note…  I like Joyent so far.  There are a couple of things that are a bit more work than it seems they should be, but nothing unreasonable.  My main reason from changing hosts is that there are some Rails apps that I would like to get online, and Rails deployment on Dreamhost currently leaves a bit to be desired.

Record In the Sun 

If it isn’t available through an API, it doesn’t exist

Tuesday, June 26th, 2007

I am currently writing some new tools for my boss. Basically just a bunch of tools that look at data in a DB and generate pretty graphs for him. You know how bosses like graphs. He asked me to automate a bunch of reporting that is done manually right now, and that is where I am starting.

Basically these reports are running against our online schedule tracking tool for our support folks. All of the data is in a SQL db, so life is good. Looking at the data got me thinking though. If we can get the number of people we have answering the phones for everyday over the past year, what good is that? Not much. What would be valuable is if we looked at the number of people on the phones versus hold times. That is data we could use. It would allow us to pick a hold time that is acceptable and staff to support that time. That would be gaining power from our data.

Unfortunately, our call tracking software doesn’t write it’s info to a standard DB. It is only available through some custom report generating tools they wrote. That might be fine for some companies, but for us if the data isn’t available to other software you might as well not track it.

This is closely in line with a post on Productivity 501: Integration is more important than features. I couldn’t agree more. Going forward, if a piece of software does not provide some sort of API to access the data it uses to generate reports, I am not going to support buying it. As simple as that.

If it isn’t available through an API, don’t waste resources collecting it. It doesn’t actually exist.

Auto-launching my rails development environment

Tuesday, May 15th, 2007

My morning routine is pretty much always the same. My wife wakes me up, saying something about “late” that I can’t quite comprehend. I writhe about on the bed a bit trying to break free from the remaining tendrils of sleep. Finally, I look at my watch and spend a moment processing the numbers.

Shit. I have to go to work.

A 30 second shower later and I am in my car heading to the office. Luckily, Stephanie understands this process enough to get it started earlier enough for me to get to work on time. I roll into my office at the last possible moment though.

Okay. I have to get to work fast. Unlock my windows box, open my MacBook, launch Outlook on my windows box, launch iTerm on my MacBook. Have you seen the scene in office space where the main character is trying to get out of work before his boss asks him to work on the weekend? That is how I feel at about this point.

iTerm is finally up. Now, I just need to open 3 tabs and start my server, my rails console, and a tail of my development log.

Am I not a programmer? Can’t I make my Mac do all of this work for me? Of course I can.

listing for /usr/local/bin/rdev

#!/bin/zsh -f

if [[  $TERM_PROGRAM != iTerm.app ]]; then
    open -a Terminal
    return 0
fi

# First, get the directory for rails

if [[ $# == 0 ]]; then
      ThisDirectory=$PWD
elif [[ $# == 1 && -d "$1" ]]; then
      ThisDirectory=”$@”
else
      print “usage: rdev [directory]”
      return 1
fi

if [[ -e "$ThisDirectory/script/server" ]]; then
      print “Starting Rails Dev Environment”
else
      print “$ThisDirectory does not look like a rails app!”
      return 1
fi

osascript <<-eof
tell application “iTerm”
	make new terminal
	tell the front terminal
		activate current session
		launch session “Default Session”
		tell the last session
			write text “cd \”$ThisDirectory\”"
		end tell
		tell the last session
			write text “./script/server”
		end tell
	end tell
end tell
tell application “iTerm”
	make new terminal
	tell the front terminal
		activate current session
		launch session “Default Session”
		tell the last session
			write text “cd \”$ThisDirectory\”"
		end tell
		tell the last session
			write text “./script/console”
		end tell
	end tell
end tell
tell application “iTerm”
	make new terminal
	tell the front terminal
		activate current session
		launch session “Default Session”
		tell the last session
			write text “cd \”$ThisDirectory\”"
		end tell
		tell the last session
			write text “tail -f log/development.log”
		end tell
	end tell
end tell
tell application “iTerm”
	activate
end tell
eof

Now, when I get in I use Quicksilver to open an iTerm in my development directory. Then I simply type “rdev” and I am ready to roll.

This code is thanks largely to the scripts available at http://xanana.ucsc.edu/xtal/iterm_tab_customization.html

Find across multiple levels of relationships

Thursday, April 12th, 2007

I was writing some code today and I would like to be able to find all my users who work for a specific group. The relationship is that a User belongs to one or more Jobs. Each Job belongs to a Group.

user.rb
class User “jobUsers”, :association_foreign_key => “jobID”,
:foreign_key => “usrID”

def self.get_active_by_group(groupname)
find(:all,
:include => [:jobs, {:jobs =>:group}],
:conditions => ["usrDeleted = 'false' and groups.grpName=?", groupname],
:order => “usrName ASC”)
end
end

job.rb
class Job ‘jobGrpID’
end

The key to this working is in the :include parameter.  (Sorry I can never get wordpress to format code that I cut and paste correctly)

Backing up my flash drive or Floder Actions Are Awesome!

Tuesday, April 10th, 2007

Voodoo Programming — Backing up Flash Drives Automatically

Great article that gives you the code to do something very useful. Now, anytime that I plug in my thumb drive my Mac automatically makes a backup of it.

Now that I have had my Mac for a couple of days, I have to say that the combo of Folder Actions and AppleScript is a very useful thing. There will be more examples to come as I get used to AppleScript.

Continuing MacBook impressions

Thursday, April 5th, 2007
  • Macs are very, very keyboard centric.  I know that keyboard shortcuts are available in pretty much all windows programs too.  Here is why I think that I notice the difference so much — in OS X there are a lot of things in the OS that are faster using keys than the mouse.  Closing an app for example.  If I click on the red X like I am used to, only the window closes.  So, it is easier to just use cmd+q to close the app.  That, plus ctl+tab, plus quicksilver to launch apps and I am so used to keyboard shortcuts for normal things that reaching for my mouse is unappealing.  So in my apps I start looking for more.  Like cmd+p in TextMate to insert params[:id] in a rails file.
  • TextMate is worth every penny.  It is incredibly nice.
  • My MacBook is kinda easy to get to bog down.  Not a good thing, so I need to figure out why.  I am curious if 512mb of ram is just not enough.
  • STM makes very nice affordable laptop bags.  Way lighter and smaller than my old Timbuk2 bag.  Is it too small?  Time will tell.

That is all that is new.  I still really, really like my new machine.  I need to write an applescript for starting my dev environment.  I will post that once I am done because I think people might find it useful.