Monday, December 08, 2008

tufuhash 0.0.1 available

TufuHash is posted on github. TofuHash is a case-insensitive hash plus string/symbol indifferent access version of Ruby's Hash. It is implemented as a subclass of Hash. The behavior is easily modifiable by creating a different TofuKey. So you could have it perform key lookups anyway you want!

The current release 0.0.1 hasn't been used in many places. So if you find defects, send them to me. I'll get it fixed asap. So far I've create a bunch of unit tests to verify TofuHash behavior. These unit tests include modified versions of Ruby's Hash unit tests, sourcecode examples from the ri documentation of Hash, plus some of my own tests.

So far I've avoided monkey patching Hash. So there is a known issue where Hash doesn't always know how to handle TofuHash. For example, you can't compare Hash to TofuHash(myHash == myTofuHash), but the reverse is possible (myTofuHash == myHash).

The easiest way to create and populate a TofuHash is to use Hash's [ ] syntax as shown here:

require 'tofuhash'
h = TofuHash[ :aSymbol => "symbol", "MixedCaseString" => "string", 11 => "number" ]
puts h["asymbol"] #=> "symbol"
puts h[:mixedCaseString] #=> "string"
puts h[11] #=> "number"

color-block 0.2.0 released

Several weeks ago I made color-block available on github. This is a small library to colorize ruby output. Specifically I wanted to colorize my rake output. In some rake tasks, I didn't have access to the details of the task. So I couldn't add color to each string. Instead color-block allows me to colorize an entire block of code.

Several friends have tested color-block on Windows, Linux and Apple Mac.

require 'color-block'
include ColorBlock

color( :blue ) { "everything in this block is blue!" }

color( :white, :blue ) do
puts "now everything is white on blue!"
color( :green, :black ) { "nesting is supported" }
end

color( :white, :black, :bold ) { "third parameter to specify :bold or :dim" }

Monday, August 18, 2008

TechMixer University 2008

Here is the presentation from TechMixer University 2008. The topic is "Getting Started With Ruby" which is designed to teach an introduction of Ruby. Along the way, we will see some interesting Ruby features: dynamic programming, mixins, dependency injection (e.g. how Ruby doesn't require a DI framework). The slide set contains a couple of bonus slides covering Databases, Builder, Hpricot, RSS::Maker.



or view it here on Google Docs

Wednesday, July 23, 2008

Rake Quick Reference

I've created a Rake Quick Reference available on pastie.org.

Update : 7/28/2008 paste #242691 - reworked task generation section; added command-line tip
Update : 7/24/2008 paste #240284 - added details on namespace.
Release: 7/23/2008 paste #239387 - original release.

9/30/2013:  StuartEllis.eu has a great rake tutorial at: http://www.stuartellis.eu/articles/rake/

Wednesday, July 16, 2008

Hudson (build and continuous integration tool)

If you haven't seen Hudson (https://hudson.dev.java.net/), you should give it a look. I was introduced to it by Clay McCoy at Rubyham. After playing with it, I decided to switch from CruiseControl.Net to Hudson. The switch didn't take long. In all, I spent < 3 hours total to make the swtich (most was learning time). The setup was fast (~10min). Conversion from CC.Net wasn't hard. I'm very happy with the features of Hudson and it's plugins.

Monday, June 16, 2008

How to call Rake from CruiseControl.Net

CruiseControl.Net is a great Continuous Integration tool. It is easier to setup than CruiseControl (java). Plus it makes more sense to use CC.Net if you work at a .Net shop.

To script the Continuous Integration process, I first investigated using MSBuild. At this time, I found MSBuild to work well for building Visual Studio projects. But MSBuild wasn't mature enough to accomplish much else. NAnt is a more mature alternative to MSBuild, which I've used on some projects. NAnt is fairly powerful (even better in my opinion than the original Ant). However, there is one problem with both these tools: XML is not a programming language.

Rake is a programming language. Rake is actually Ruby, with some additional stuff to give it the powers of Make. Rake also makes sense in a .Net shop because 1) Ruby can call .Net objects using the Ruby/.Net Bridge. 2) John Lam is currently porting Ruby to run directly on the .Net DLR.

So how do you get CruiseControl.Net to call Rake? The best solution would be to create a CC.Net plugin to call Rake. But if your like me, time is limited. So an easy kludge will suffice. The kludge is this: 1) CC.Net calls either MSBuild or NAnt, which is already built in. 2) MSBuild or NAnt executes Rake via an Exec task.

(You may be wondering why not use CC.Net exec task. The short answer, I couldn't get CC.Net exec task to call Rake. I'm not sure why. It just didn't work well.)

First - CC.Net calls MSBuild or NAnt. This is very simple. In the CC.Net config file you add a task...

   <tasks>
<nant buildFile="nant.xml" />
</tasks>



or

   <tasks>
<msbuild projectFile="msbuild.xml" />
</tasks>


Then you have NAnt or MSBuild call Rake. Here are the nant.xml and msbuild.xml files:

<?xml version="1.0"?>
<project name="Rake Runner" default="RakeBuild" basedir=".">
<target name="RakeBuild">
<exec program="c:\ruby\bin\rake.bat" />
</target>
</project>



<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="RakeBuild">
<Target Name="RakeBuild">
<Exec Command="rake" />
</Target>
</Project>



Notice that each just calls the RakeBuild target, which is the default target.

Rake will then run the default target (you could specify a Rake task in the scripts above). Here is an example Rake script which displays all the environment variables:


task :default => [:test]

task :test do
ENV.each {|k,v| puts "#{k}=#{v}" }
end



CC.Net captures the output a little different for MSBuild vs NAnt. MSBuild's output is append to the end of the build log. Which results in a long build log. NAnt's output is captured to a different page "NAnt Output". However, NAnt prepends each line with "[exec]".

Sunday, May 11, 2008

Twitter fun

Last Friday I attend the IPSA meeting on Social Media. That got me interested in two products: Twitter and ooVoo.

I've now got a Twitter account using the nickname neversleep360. For which I got curious about the reach of Twitter. So I wrote a quick ruby script to search out Friends and Friends of Friends, then score everything they were following based on the number of Friends/FriendsX2 following. This should point out nicks of common interest. Also, I found several interesting nicks sitting out in the wings.

I've posted everything on my wiki at Twitter Friends of Friends. One interesting result is the number of links to BarackObama. Personally I'm not a fan of BarackObama; but it is interesting to see him score highly among this circle of friends on Twitter.

Tuesday, February 19, 2008

Unexpected Hash Behavior With String Keys

I was looking for a way to create a case-insensitive Hash class. One suggestion was to use NormalizedHash (http://pastie.caboo.se/154304), and override methods on the String keys. This doesn't work as expected.

I found that Hash makes a duplicate of the String key. This unfortunately removes any methods added in the singleton class. (surprise!)

Here is the code to demonstrate this behavior: http://pastie.caboo.se/154595

----

Shortly after writing the above post, I came across a little footnote in Hash#[]= which says... "(a String passed as a key will be duplicated and frozen)"

I learn something new every day. (I wish this information was given in the class description instead of the method description where it is easly missed.)