MetaSkills.net

A MacPort/RubyODBC Update

Posted On: July 18th, 2010 by kencollins

Quite a while ago I wrote a soup to nuts article on getting the full multi-ruby development stack installed for those using the SQL Server adapter. The base package management system used there was MacPorts. In it I described how to edit the outdated Portfile for the rb-odbc package and exclaimed how important it was to use the +utf8 variant. I was totally wrong about that part.

Tags: macports, odbc, ruby

Interactive JavaScript Console With TextMate

Posted On: July 8th, 2010 by kencollins

Last week I started reading JavaScript: The Good Parts by Douglas Crockford. It was on my list of long overdue things to do. While reading it, I wanted to be able to kick some simple JavaScript examples around. As rubyist we have it good, irb let's us fire up an interactive console anytime we want. But with JavaScript, options are limited. Sure you could install Johnson/EnvJS, Rhino or some other JavaScript engine. Maybe even load up firebug or the web inspector. But who wants to load a browser to play with JS?

The alias_method_chain of Rake - Override Rake Task

Posted On: May 25th, 2010 by kencollins

Rake is cool. It is built so that multiple tasks with the same name run in a reverse defined series. This is great, but sometimes you want to override a task with your own behavior and conditionally call the earlier task. Especially if that task is defined deep somewhere else, like in a rails gem. I have had to solve this problem before in Rake. Awhile back I hacked something up that would totally trump a predefined rake task and allow you to replace it with a new one. Lately while working on the SQL Server adapter, I had a need to method chain some core rails :db namespaced tasks. So once again I googled others work and again resorted to hacking Rake. Below is what I was left with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Rake::TaskManager.class_eval do
  def alias_task(fq_name)
    new_name = "#{fq_name}:original"
    @tasks[new_name] = @tasks.delete(fq_name)
  end
end

def alias_task(fq_name)
  Rake.application.alias_task(fq_name)
end

def override_task(*args, &block)
  name, params, deps = Rake.application.resolve_args(args.dup)
  fq_name = Rake.application.instance_variable_get(:@scope).dup.push(name).join(':')
  alias_task(fq_name)
  Rake::Task.define_task(*args, &block)
end

It's easy to use, just require it in your Rakefile. In the example below, I was able to programmatically method chain the core rails db:test:purge and only call the original if I needed to. Very cool!

1
2
3
4
5
6
7
8
9
10
11

namespace :db do
  namespace :test do
    override_task :purge => :environment do
      ...
      # To invoke the original task add ":original" to its name
      Rake::Task["db:test:purge:original"].execute
      ...
    end
  end
end

Lastly, thanks to Eugene Bolshakov, John Wood, and Mark Foster whom have tackled this rake problem before. My version above was based on their work, but correctly works with namespaces which was critical for my needs.

Tags:

Git Init XCode Projects

Posted On: February 23rd, 2010 by kencollins

Here is a little ZSH function I have been using for quickly setting up new XCode apps I call tire kickers, little play and learn apps. Being able to track your learning as you go with git.

if [[ -x `which git` ]]; then
  
	function ginit_xcode () {
	  git init
	  echo "\n\n# XCode\nbuild\n*.mode1v3\n*.mode2v3\n*.nib\n*.swp\n\
*.pbxuser\n*.perspective\n*.perspectivev3\n\n# OSX\n.DS_Store\n\n\
# TextMate\n*.tm_build_errors\n\n\n" >> .gitignore
	  git add .gitignore
	  git commit -m "Ignore Xcode stuff."
	  git add .
	  git commit -m "Initial Xcode project."
	}
  
fi

The echo lines puts out a .gitignore file that will look something like this.

# XCode
build
*.mode1v3
*.mode2v3
*.nib
*.swp
*.pbxuser
*.perspective
*.perspectivev3

# OSX
.DS_Store

# TextMate
*.tm_build_errors
Tags: git, xcode

Simple Script/Console Function

Posted On: February 6th, 2010 by kencollins

This is something simple I worked up today for my ZSH profile that let's me keep my simple sc alias and have it work with all versions of rails. If you did not know, all the script files in rails 3 are gone and the new all-in-one rails executable does all the heavy lifting. This little function even passes down all the arguments too.

sc () {
  if [ -f ./script/rails ]; then 
    rails console $argv
  else
    ./script/console $argv
  fi
}

One other thing, the way rails uses IRB is different now. I had to change my ~/.irbrc file to look like this below to get my simple prompt and history back. IMPORTANT NOTE: In order for this to work, you have to apply this 2 line patch to your save-history.rb file. Worked like a champ for me.

1
2
3
4
5
6
7
8
9
10

# IRB history patch <http://redmine.ruby-lang.org/issues/show/1556>

require 'irb/completion'
require 'irb/ext/save-history'

IRB.conf[:USE_READLINE] = true
IRB.conf[:SAVE_HISTORY] = 500
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb.hist"
IRB.conf[:PROMPT_MODE] = :SIMPLE
Tags:

Unobtrusive JS In Rails 3 With Prototype

Posted On: January 29th, 2010 by kencollins

Are you bleeding on the edge of rails 3 and need to shim up some unobtrusive JavaScript to work with your link_to code that uses a destructive :method option? I did today and here is what I did to solve it. If you are unfamiliar with the problem, and what has been happening in rails 3 with UJS, check out Piotr Solnica's blog for a good run down. Or you can check out the simple code block below.

Tags:

Quickie.js - Prototype wrapper for QuickTime

Posted On: January 24th, 2010 by kencollins

As some of you know, I am in the last steps of announcing my first iPhone application. We all know that every good iPhone application has a great marketing website with a screen cast. I myself was heavily inspired by the Tapbots Convertbot website while building my own and wanted a good way of embedding the screen cast. I think the last time I did an object/embed tag was god... around 2003 or something, seriously.