Friday, June 26, 2009
Thursday, June 4, 2009
How to optionally load gems
module Kernel
def desire(library)
require library
return true
rescue LoadError
STDERR.puts "warning: #{library} gem desired but not found."
return false
end
end
And here's how I optionally include the metric_fu gem.
desire 'metric_fu'If a user has the gem installed, rake -T will show the tasks.
jasonn:~/sources/my_files [master] $ rake -T (in ~/sources/my_files) rake metrics:all [...] jasonn:~/sources/my_files [master] $If the user does not have the gem installed, rake -T will show a simple warning and continue.
jasonn:~/sources/my_files [master] $ rake -T (in ~/sources/my_files) warning: metric_fu gem desired but not found. [...] jasonn:~/sources/my_files [master] $I don't remember where I first heard the desire idea, but it works pretty well.
Wednesday, June 3, 2009
Recover files from git after deletion is committed
git diff --diff-filter=D --name-only HEAD@{'7 days ago'} | \
grep -v ^doc | perl -ne 'chomp;
print "git show e2ae03f14ce81a3e24ec6cbe2e73767f4c6fed1b -- $_ > $_\n";' | sh
This restored all the files I deleted that did not start with doc.
These files show up as diff files, so you may have to remove the "- " at the beginning of the lines and commit messages. But hey, it's better than not having the files you need.
Friday, April 24, 2009
RDoc preview in Textmate
Create /usr/bin/rdoc2html:
#!/usr/bin/env ruby -rrdoc/markup/simple_markup -rrdoc/markup/simple_markup/to_html input = ARGF ? ARGF.read : STDIN.read print SM::SimpleMarkup.new.convert(input, SM::ToHtml.new)Make the file executable:
sudo chmod +x /usr/bin/rdoc2htmlIn textmate, hit Cntrl-Option-Command-P. In the bottom left corner, click Show options. Click the Pipe text through checkbox and enter "/usr/bin/rdoc2html" in the text box.
Tuesday, April 21, 2009
GitHub set author/committer
More specifically, the author field was the two members of the pair and the committer name was the workstation they were working on.
Example:
After playing around with it for a while, I figured out how to do it. Within a git project clone, run the following commands.
1) git config user.name = 'Workstation Perlwizard'
2) git config user.email = 'devs2@perlwizard.org'
3) export GIT_AUTHOR_NAME='Bob Smith and Betty Jones'
4) export GIT_AUTHOR_EMAIL='devs@perlwizard.org'
Both of the email addresses need to be addresses Github doesn't know about (i.e. not used to sign up for an account).
I could see using this while pairing with someone so you both get name credit for your commits.
Labels: git, github, pair programming
Saturday, September 20, 2008
Making TextMate recognize .html.erb files
You can fix this by editing the Ruby on Rails language bundle.
In TextMate, select Bundles -> Bundle Editor -> Edit Languages.
This will open a new Bundle Editor Window. Click the arrow next to Ruby on Rails and highlight HTML (Rails). In the code that appears on the right, change the following
fileTypes = ( 'rhtml');to
fileTypes = ('rhtml', 'html.erb');
Click the red X in the upper left corner to close the Bundle Editor Window.Close any existing .html.erb files, when you open them again, they will have ruby syntax highlighting.
Labels: ruby, ruby on rails, textmate
Sunday, September 14, 2008
Adding an alias to the Tcsh Shell
11:32:07 /Users/jasonn $ vi ~/.tcshrcAdd a line of text of the format "alias YYY 'ZZZ'" where YYY is the command you want to type in, and ZZZ is the command you want to be run. Examples:
# Show long listing alias ll 'ls -al' # Use VI Improved instead of Vi alias vi 'vim' # Change into your web directory alias web 'cd /usr/local/apache/vhosts/jasonnoble.org/htdocs'This alias ability allows you to type less at your shell prompt. If you find yourself typing the same long command line over and over, try adding an alias to your shell that will save you some time.


