I wrote a little utility to turn something like this
this=that, something_else="something else entirely"
Into the much easier to read
this = that, something_else = "something else entirely"
I use it in conjunction with my clipboard utility so I can just copy, run, paste. I mostly use this when I'm working with ColdFusion, so it also works for those pesky cfsets.
Usage: (After copying your target text to your clipboard)
ruby clipboard_format_set.rb
PS: I'd love to set some of my scripts up as Eclipse shortcuts so I've been toying with the idea of writing an Eclipse plug-in to act as a proxy. I realize you can set up and run "External Tools", but I have yet to see a way to bind a key. I'd like the plug-in to take care of the "pasting" to save me that extra ctrl-v. Maybe this would make a good New Years Project?
Tags: Add new tag, clipboard utility, coldfusion, eclipse, ruby, tools
I just finished up my first pass on Conway's Game of Life with the Ruby version of Gosu while watching season 2 of Dexter. It's ripe for refactor and I still have some work to do to make it worth running, but yeah, first pass.
To run it, you just need to run init.rb
ruby init.rb
Tags: game of life, gosu, ruby
I wrote this little script to copy the filenames of a directory into the clipboard a while back and forgot to post about it. I've been particularly surprised about how often it's come in handy for this or that.
require 'clipboard' c = Clipboard.new list = '' if ARGV.size == 0 path = "." else path = ARGV[0] end Dir.foreach(path) { |file| if(file.length > 2) list << file << "\n" end } c.set_data list
To use it, simply call run the script with the directory you want copied to your clipboard as an argument!
Tags: clipboard utility, ruby, tools
I made a few small updates to Target Practice tonight. The biggest addition was sound although I made a few other little tweaks under the proverbial hood.
I had originally wanted to pack it up and release it as a single executable file but I was having some issues which I'll post about once I figure out what the heck I'm doing.
Speaking of lazing, there are a few things I'd like to do differently in Target Practice. Most notably I'd like to abstract out out the media to some manager or another, and also my target manager class has grown rather bloated which I take to be a good indicator that it's doing more than it should. I don't care enough about this program to fix either of these issues, but hopefully I've learned from these mistakes!
Tags: game programming, gosu, ruby
Half-Life is the game of choice at work, and sadly I'm terrible at it. I thought I'd try to write a little game using gosu to try and help me improve my accuracy. I just reached a good stopping point and I thought I'd share.
It's really simple, the idea is to shoot little 20 x 20 "targets" (I'm artistically challenged) before they expire. Missing or letting 10 targets expire will end the game. Next version will include sound, improved visuals and maybe even a couple other fun features if your lucky.
The code is a bit over-engineered but I plan on incorporating parts into some "core extensions" that I'm working on that will hopefully make it a lot easier for me to bang stuff like this out. Finally, as I doubt anyone will ever download this, I didn't bother to pack it up so you'll have to have Ruby and gosu installed in order to enjoy it.
PS: I've been a Photoshop user for many years, but I used GIMP to make these images and I didn't even hate it!
Tags: game programming, gosu, ruby

During a brief period in elementary school drawing these things was quite the cool thing to do. I've been messing around with the GD2 module a bit lately and I thought it'd be fun and easy to write a little script to generate one.
It was.
The drawing algorithm
@nodes.times do |i| adjustment = i * @node_size pen.move_to adjustment, 0 pen.line_to 0, @size - adjustment end
Example Usage:
#takes in the output image size and the number of nodes c = Curve.new 180, 30 c.draw c.export "test.gif"
*Note: If your output size doesn't divide evenly by the number of nodes then the image will actually reduce the size of the output image.
I wanted to demo an ad rotator the other day at work and I wanted to load up a bunch of images of various sizes to make it look legit. It would have taken forever to do it ad by ad, so I wrote a little ruby script to automatically resize all the images in a directory. Then I used my directory listing utility to copy the files into my clipboard. Pasted into the database from there!
(Requires GD2)
Usage:
r = Resizer.new input_path, output_path, width, height r.crop_files
Tags: clipboard utility, gd2, ruby, tools
I was tinkering a bit while watching the tube tonight and I thought it might be fun to make a simple JavaScript tile puzzle. Might look terrible in other browsers.
First step was to write a little ruby script (using the GD Graphics Library) to read in a file and cut it up into individual tiles. (Photoshop is for wussies)
if __file__ = $0 #pass the image name, tile size through the command line t = Tile_Cropper.new ARGV[0], ARGV[1].to_i t.crop_tiles end
Then I used a slightly modified method I read about in Ben Nadel's blog to scramble the tiles.
<cffunction name="ShuffleArray" output="no"> <cfargument name="tiles" required="yes"/> <cfset var random = StructNew()/> <cfset var i = ""/> <cfloop from="0" to="#arguments.tiles - 1#" index="i"> <cfset random[i] = RandRange( 1111, 9999 ) /> </cfloop> <cfreturn ArrayToList(StructSort(random, "numeric"))> </cffunction>
A little bit of CSS magic:
#puzzle { width: 500px; margin: 0px; padding: 0px; } .piece { list-style: none; display: inline; margin: 0px; padding: 0px; } img { border: 1px solid gray; }
And finally I used scriptaculous and prototype for the obnoxious drag-and-drop sorting. Not that I'm complaining. the Sortable methods weren't intended to be used for something like this.
function init() { Sortable.create('puzzle'); }
Complete the puzzle to find out what I was watching!. Here, I'll give you a hint. It's Dexter.
Tags: coldfusion, css, gd2, javascript, prototype, ruby, scriptaculous
Here's another little utility I put together. It uses my clipboard utility to copy and format xml data stored in the clipboard. Just copy, run the script and paste!
It comes in handy.
I got (and ever so slightly modified) the xml formatting code from DZone.
Tags: clipboard utility, ruby, tools
I've been following the Stack Overflow podcast for a little while and I've been itching to come up with a question to ask on the site. Well, today I was working on a little ruby formating script (more on this later) and I wanted to replace all the spaces in a string that were NOT located between quotes.
I asked my question on the site and a few hours later I had some really great working solutions!
Click the link for solutions and definitely check out http://stackoverflow.com!