March 2007 Archives

toggle.el

| | Comments (0)

I just released toggle.el, allowing you to quickly open corresponding files via a dynamic mapping.

From the description:

This package provides the ability to quickly open a corresponding file for the current buffer by using a bi-directional mapping of regular expression pairs. You can select a mapping style from toggle-mapping-styles using the toggle-style function or set your default style via the toggle-mapping-style variable.

There are 3 different mapping styles in this version: zentest, rails, and ruby. Feel free to submit more and I'll incorporate them.

Example Mapping (ruby style):

blah.rb <-> test_blah.rb
lib/blah.rb <-> test/test_blah.rb

Get it (and other packages I'll release soon) via: http://www.emacswiki.org/cgi-bin/wiki/RyanDavis

Episode 3 of the "Stupid Thing I Wrote", figure out the worst actors on IMDB:

  1. 194 Paris Hilton (The Hillz, Bottoms Up)
  2. 183 Jim Varney (Snowboard Academy, 3 Ninjas: High Noon at Mega Mountain)
  3. 177 Hulk Hogan (Santa with Muscles, 3 Ninjas: High Noon at Mega Mountain)
  4. 174 Kal Penn (Son of the Mask, Epic Movie, Van Wilder 2: The Rise of Taj)
  5. 171 Clint Howard (Santa with Muscles, House of the Dead)
  6. 168 Jack McGee (Chairman of the Board, Cool as Ice)
  7. 164 Corey Haim (Snowboard Academy, Last Resort)
  8. 162 Deezer D (In the Mix, Cool as Ice)
  9. 159 Gary Anthony Sturgis (Daddy's Little Girls, Pride)
  10. 157 Myles Fitzgerald (SuperBabies: Baby Geniuses 2, Baby Geniuses) / Gerry Fitzgerald (SuperBabies: Baby Geniuses 2, Baby Geniuses) / Leo Fitzgerald (SuperBabies: Baby Geniuses 2, Baby Geniuses) / Will Sanderson (House of the Dead, Alone in the Dark, BloodRayne)
  11. 153 Gabrielle Union (Daddy's Little Girls, The Honeymooners)
  12. 151 Terrence Howard (Glitter, Pride)
  13. 150 Valarie Pettiford (Glitter, Stomp the Yard) / Jack Warden (Chairman of the Board, Ed) / Mickey Knox (Ghosts Can't Do It, Bolero, Ghoulies II)
  14. 142 Kevin Smith (Bottoms Up, Doogal)
  15. 138 Jürgen Prochnow (House of the Dead, Primeval)
  16. 136 Meagan Good (Stomp the Yard, You Got Served)
  17. 127 Bo Derek (Ghosts Can't Do It, Bolero)
  18. 123 Victor Wong (3 Ninjas: High Noon at Mega Mountain, Shanghai Surprise)
  19. 116 Jon Polito (The Honeymooners, Happily N'Ever After)
  20. 110 Billy Zane (Going Overboard, BloodRayne)

code after the cut.

It makes me sad that "You Got Served" is no longer the worst movie on IMDB.

Sharing gems in multiruby

| | Comments (0)

Need to use multiruby with gems? Do what I do and share them with your existing gems:

% cd ~/.multiruby/install
% rm -rf */lib/ruby/gems  
% for DIR in */lib/ruby; do
> ln -s /usr/local/lib/ruby/gems $DIR/gems
> done

Then test with something easy like:

% multiruby -rubygems -e 'require "inline"'

Remember, use this method only when you aren't testing version dependent binary gems!!

PNG is an almost-pure-ruby PNG library. It lets you write a PNG without any C libraries.

FEATURES

  • Very simple interface.
  • Outputs simple PNG files with ease.
  • Basic PNG reader as well (someday it might do compositing and the like!).
  • Almost pure ruby, does require a compiler.

SYNOPSYS

require 'png'

canvas = PNG::Canvas.new 200, 200

# Set a point to a color
canvas[100, 100] = PNG::Color::Black

# draw an anti-aliased line
canvas.line 50, 50, 100, 50, PNG::Color::Blue

png = PNG.new canvas
png.save 'blah.png'

Changes:

1.1.0 / 2007-03-26

  • 4 major enhancements:
    • Fixed and incorporated Dominik Barathon's optimizations.
    • Wrote inline methods for pngcrc and pngjoin. Now about 15x faster overall.
    • Basic PNG loading.
    • Reoriented x/y origin to bottom left. This will break things!
  • 3 minor enhancements:
    • Awesome ascii art patches from Tom Werner: Canvas#inpsect, Canvas#tos, Color#toascii.
    • Switched to Hoe.
    • PNG.pie_chart from png/pie.
  • 1 bug fix:
    • Fixed bug in PNG::Canvas#each.

Allows you to lay out HTML using ASCII art. Stolen from psykotic's code posted to reddit: http://programming.reddit.com/info/k9dx/comments

SYNOPSIS:

require 'box_layout'

page_template = <<-END
----------
|        |
----------
| |    | |
| |    | |
| |    | |
| |    | |
----------
|        |
----------
END

layout = BoxLayout.html page_template
puts "<title>cute</title>"
puts "<style>* { border: 1px solid black }</style>"
puts layout % %w[header left body right footer].map {|s| "**#{s}**" }

1.0.0 / 2007-03-24

  • 1 major enhancement
    • Birthday!

I'm running a script to gather SVN details for a graph I'd like to make. I've done this before in perforce and it takes about 5-10 minutes to run. HOURS! HOURS this has run in subversion. Compare:

Subversion:

% time svn diff -r1743:1744 https://svn.example.com/project/trunk > /dev/null
real 0m8.183s
user 0m0.179s
sys  0m0.049s

Perforce:

% time p4 describe 3037 > /dev/null
real 0m0.867s
user 0m0.039s
sys  0m0.091s

Am I doing something horribly wrong? All the doco I can find says that this is the way to get the diffs for a single revision, yet... 10x slower? Hell, CVS is faster!

ADDED:

Some have suggested that it is SSL negotiation. For that I offer the following:

% svn up
At revision 2761.
% time svn -u st -N > /dev/null    
real    0m2.681s
user    0m0.119s
sys 0m0.045s
% time svn diff -r2759:2760 https://svn.example.com/project/trunk > /dev/null
real    0m9.189s
user    0m0.187s
sys 0m0.055s

A 3x increase in time for a 20 line diff??? Nuh uh. Not SSL.

require 'rubygems'
require 'ruby2ruby'

p = proc { |x| x + 1 }
puts p.to_ruby
# => proc { |x|
#      (x + 1)
#    }

This script sifts through your iTunes DB and tells you what you really like to listen to. It told me that my mental list of my top N and my actual listening habits disagree. It also illustrates that you don't need to parse XML if it is well formed and it can be way faster than rexml and the other xml-overkill libraries.

  1. = (2306 tot, 327.33 adj): Everything! (Disc 2) by Tones On Tail
  2. = (2295 tot, 316.93 adj): Mezzanine by Massive Attack
  3. = (2026 tot, 293.42 adj): Earth Sun Moon by Love & Rockets
  4. = (1789 tot, 259.74 adj): Kakusei by DJ Krush
  5. = (1700 tot, 241.82 adj): Staring At The Sea: The Singles 1979-1985 by The Cure
  6. = (1753 tot, 240.61 adj): 100th Window by Massive Attack
  7. = (1307 tot, 224.80 adj): Nouvelle Vague by Nouvelle Vague
  8. = (1458 tot, 207.87 adj): Substance 1987 (Disc 1) by New Order
  9. = (1342 tot, 194.84 adj): Meiso by DJ Krush
  10. = (1351 tot, 192.62 adj): Express by Love & Rockets

See the code after the cut.

Hopefully this will become a series that will let me clean out my Work/misc dir, but "That Stupid Thing I Wrote The Other Day" needs to be changed because TSTIWTOD is a lame acronym. Suggestions?

I use this to populate my iPod with all my music so I don't get confused in music stores:

music = Hash.new { |h,k| h[k] = [] }

Dir.chdir File.expand_path("~/Music/iTunes/iTunes Music") do
  Dir["*"].sort.each do |artist|
    artist_name = artist.sub(/^The (.*)/, '\1, The')
    Dir.chdir artist do
      Dir["*"].sort.each do |album|
        music[artist_name] << album
      end
    end
  end
end

dir = "/Volumes/NanoSpider/Notes/"
dir = test(?d, dir) ? dir : Dir.pwd
out = $stdout
last = nil

music.sort_by { |k,v| k.downcase }.each do |artist, albums|
  letter = artist[0..0].downcase
  if last != letter and dir then
    out.close
    out = File.open("#{dir}/music-#{letter}.txt", "w")
    last = letter
  end
  out.puts "#{artist}:"
  out.puts "  #{albums.sort.join("\n  ")}"
end

out.close if dir

hoedown

| | Comments (3)
Yeeeee Haw!2
It's a hoedown!!!

Currently:

  • There are 54 authors using hoe.
  • Contributing 102 projects to the ruby community!!!
  • Hoe is used in 7.18% of all gems!

Hot damn!

2) I should note that with 50+% Texan blood, I'm legally allowed (some might say obliged) to use the phrase "Yee Haw" and its variants.

...and the 100th is:

| | Comments (2)

Matthew King for activemdb!!! YAY Matthew!!!

Other contenders were:

  • John Nunemaker with twitter.
  • Aaron Patterson with his 4th (!!) hoe'd gem, daapclient (which only missed it by about 30 minutes).

Who will be the 100th?

| | Comments (4)

Hoedown reports that we're at 99 hoe'd gems from 52 authors. We've been there since Thursday when Seattle.rb's very own Mike Mondragon published mms2r.

Who will be the 100th???

ImageScience is a clean and happy Ruby library that generates thumbnails -- and kicks the living crap out of RMagick. Oh, and it doesn't leak memory like a sieve. :) For more information including build steps, see http://seattlerb.rubyforge.org/

Changes:

1.1.1 / 2007-03-08

  • 5 minor enhancements:
    • Added error handler that raises with information about what went wrong.
    • thumbnail is now pure ruby, everything now uses resize.
    • Produces cleaner JPEG files, with a small cost to file size/speed.
    • resize now uses Catmull-Rom spline filter for better quality.
    • resize copies existing ICC Profile to thumbnail, producing better color.
    • ICC Profile NOT copied for PNG as it seems to be buggy.
  • 1 bug fix:
    • Fixed rdoc

A simplistic script which automates a limited set of rubyforge operations

  • Run 'rubyforge help' for complete usage.
  • Setup: For first time users AND upgrades to 0.4.0:
    • rubyforge setup
    • edit ~/.rubyforge/user-config.yml
    • rubyforge config
  • Don't forget to login! logging in will store a cookie in your .rubyforge directory which expires after a time. always run the login command before any operation that requires authentication, such as uploading a package.

Changes:

0.4.1 / 2007-03-08:

  • Verify that login succeeded and warn against if not (prolly should raise).
  • Print a friendly error if you have the wrong package id.
  • Handle upload error in add_release a bit better.

autotest bindings

| | Comments (0)

I should add that I keep the previous autotest code in autotest.el and the following in my setup-modes.el (I have my emacs setup broken up):

(autoload 'autotest-switch "autotest" "doco" t)
(autoload 'autotest "autotest" "doco" t)
(add-hook 'ruby-mode-hook
          '(lambda ()
             (define-key ruby-mode-map (kbd "C-c C-a") 'autotest-switch))

This allows me to use C-c C-a to toggle back and forth between autotest and ruby files. I should also have it hooked in for grep buffers and other things, but I'll leave that as an exercise for the reader. :P

autotest for emacs

| | Comments (0)

I've been using this for a while now. It works pretty well for me, but I'm sure stuff could be ironed out and made a bit smoother/cleaner. Please provide any and all suggestions/patches as you see fit. This will be incorporated and eventually released with ZenTest once it feels good.

autotest.el behind the cut.

locate and spotlight

| | Comments (0)

locate and spotlight each have their pros and cons. I like both for different reasons, but recently I caught on to using mdfind (spotlight's command-line interface) to search for file-names only. It is still a little slower than locate (but not much) but always up to date:

(defun locate-make-mdfind-command-line (search-string)
  (list "mdfind" (concat "kMDItemDisplayName=*" search-string "*")))

(defun spotlight ()
  "Search for files by name using spotlight"
  (interactive)
  (let ((locate-command "mdfind")
        (locate-make-command-line 'locate-make-mdfind-command-line))
    (call-interactively 'locate nil)))

(defun spotlight-full ()
  "Search using spotlight"
  (interactive)
  (let ((locate-command "mdfind"))
    (call-interactively 'locate nil)))

If you're feeling adventurous, keep the first defun and set locate-command and locate-make-command-line via customize. I did that for a few weeks but I like the flexibility of having both available.

Adding blogging to hoe.

| | Comments (0)

Thanks to the ever-awesome Aaron Patterson (go Seattle.rb!), hoe can now blog for you. You've got to set up a ~/.hoerc file to make it work.

--- 
publish_on_announce: true
blogs: 
- user: yourusername
  password: yourpassword
  url: http://blog.example.com/cgi-bin/mt-xmlrpc.cgi
  blog_id: 1
  extra_headers:
    mt_convert_breaks: markdown

Note that extra_headers is just that, extra. This lets me post plain text to the server and apply the markdown filter to make it pretty. Everything else is required and you'll have to consult your blog doco to see what the values should be.