Tuesday, July 09, 2013

Sublime Text 2 Configuration

After many months of trying it, I am now a official Sublime Text 2 convert.  I love the flexibility of this editor and the fact that it is available on most of the platforms I use (Mac, Windows, Linux).  Maybe they could make an iOS version in the future.  I keep a Google Doc that describes how I configure Sublime Text 2 which is now shared:  My Sublime Text Configuration  Also I've have a gist that shows the keyboard shortcuts:  https://gist.github.com/4686573

Thursday, November 01, 2012

Yeoman on Windows (via Git Bash)

See Yeoman.io

If you try to install yeoman on windows (via Git Bash), it says that windows is not supported. But don't worry, all you need to do is install yeoman and its dependencies manually.

Software to install:

You will need to add this software to your GIT BASH's $PATH so that yeoman can run it from the command-line.

IMPORTANT: ONLY RUN YEOMAN COMMANDS FROM THE GIT BASH COMMAND LINE! Never run yeoman from the windows cmd prompt. Yeoman will use unix style file paths. If you run from windows cmd, yeoman will put files in the wrong folders. You have been warned!


Tuesday, October 25, 2011

NBuilder with Prototypes

I've created an extension method for NBuilder's SingleObjectBuilder. This allows setting property values based on a prototype. A typical usage would supply an anonymous object as the prototype...

            var prototypeStyle = Builder<Subject>
.CreateNew()
.Prototype(new
{
Id = 11,
Name = "prototypeStyle",
ParentName = "Dad"
})
.Build();



I like this style because the property name/value pairs are easier to see.

You can find an implementation at http://code.google.com/p/nbuilder/issues/detail?id=78

Thursday, December 16, 2010

Thursday, October 14, 2010

SpecFlow is Cucumber for .Net

I'm a big fan of Cucumber, a testing tool in Ruby. Cucumber lets you write tests in a language that business people can read (Gherkin). This really helps when working out requirements and edge cases.

These days I am working .Net for my day job. So I was happy to find SpecFlow - Pragmatic BDD for .Net. SpecFlow implements Cucumber for .Net. I've tried it a couple of times and found it works really well. One more tool for my tool box!

Saturday, January 23, 2010

IronRuby 1.0 RC1 on Rails

Tonight I put 20,000 Leagues Under the Sea (1916 silent film) in the DVD player and started playing with IronRuby while the movie ran. It didn't take long for me to get engrossed in IronRuby and now I'll need to watch the movie some other time. No loss, the sound track for the movie makes good enough background music.

I decided to try the Rails tutorial on IronRuby's site. I was pleasently surprised to find instructions for ironruby_sqlserver gem which provides ActiveRecord support. The tutorial uses SQL Express, but I had no trouble using SQL 2008 Developer instead.



Everything in the tutorial worked great. After entering a few commands and creating the Post scaffold, I had a working Rails site (2.3.5) running on WEBrick with IronRuby!

The only problem I ran into was the last step of the tutorial which runs script/console. When I ran script console, as the tutorial specified (ir script\console --irb="c:\ironruby\bin\iirb.bat") I got the following error...

IronRuby.Libraries:0:in `GetExecutable': c:\ironruby\bin\iirb.bat -r irb/comple
tion -r "C:/Users/Greg/Documents/dev/ironruby/ironrubyonrails/config/environment
" -r console_app -r console_with_helpers --simple-prompt (Errno::ENOENT)
from IronRuby.Libraries:0:in `CreateProcess'
from :0:in `exec'
from C:/ironruby/lib/ironruby/gems/1.8/gems/rails-2.3.5/lib/commands/console.rb:47

To get around the error, I found I could run the commandline that line 47 was attempting run through Ruby's exec:

iirb.bat -r irb/completion -r "config/environment" -r console_app -r console_with_helpers --simple-prompt

This launched a good iirb console with access to the Rails environment!

Overall I was very pleased with IronRuby and I'll have to spend more time with it.

Monday, October 12, 2009

TechMixer University 2009



October 13th, 2009: TechMixer University is a one-day conference in Birmingham AL. This year it had ~500 people attending. I gave the "Getting Started with Ruby" presentation to ~40 people. Almost everyone in the meeting had never seen Ruby before, so this presentation was perfect for them.

This presentation is an update from last year's presentation. The differences are: 1) shortened the Ruby language syntax details 2) Changed the Bonus Slides to "Ruby in Action" and added Cucumber, Sinatra, Rake to this section.

Thanks to all that attended. If anyone needs help getting started, please post questions to the Rubyham message board.

Wednesday, August 19, 2009

Free E-Book: O'Reilly C# 3 Pocket Reference

RedGate is running a marketing campaign where they are giving away O’Reilly’s C# 3 Pocket Reference. You can get it by following this link. The book is available by a download link at the bottom of the page. Kudos to RedGate, especially since you dont have to fill out any forms to get the book.

Thursday, July 16, 2009

IronRuby 0.6 and TofuHash

I took a quick look at IronRuby 0.6 which was release earlier this month. My first test of it was to run the TofuHash gem's unit tests.

Running in MRI (Matt's Ruby Interpreter) the result was:


Loaded suite test-tofuhash
Started
............................................................
Finished in 0.031 seconds.

60 tests, 220 assertions, 0 failures, 0 errors

.

Running in Iron Ruby the result was:


Loaded suite test-tofuhash
Started
...........................F.................F..............
Finished in 2.031315 seconds.

{stack traces for the failed cases removed to keep the output short}

60 tests, 220 assertions, 2 failures, 0 errors

.

The first thing to notice is the execution time difference 0.03 sec vs 2.03; which shows IronRuby still needs work on it's performance. These times are a good improvement over prior versions. Not show here is the start-up time. MRI was practically unnoticable, while IronRuby was noticable at ~5 seconds. The startup time is now fast enough to not be annoying.

The second noticable difference is that two tests failed under IronRuby.

The first was the #invert method. TofuHash doesn't have a custom implementation of #invert because in MRI's Hash #invert makes use of other methods in Hash. In IronRuby, it appears #invert has it's own implementation, so I'll have to give TofuHash a custom #invert to get that test to pass in IronRuby.

The second failed test was with YAML serialization and deserialization. I'll have to dig to find the root cause. Making a roundtrip from TofuHash to YAML and back, IronRuby resulted in a Hash object instead of a TofuHash. Just like the prior error, TofuHash doesn't have a custom implementation for #to_yaml, it just inherits it from Hash. I'm guessing there are differences between the implementations of Hash#to_yaml in MRI and IronRuby that work for Hash but dont work for the subclass TofuHash.

I'll probably wait until IronRuby 1.0 is released before updating TofuHash to correct these two errors. Until then, it appears TofuHash 1.0 will work in IronRuby 0.6 except for #invert and #to_yaml.

Wednesday, June 03, 2009

White - UI Testing Library (.Net)

White is an open source .Net library designed to support Unit Testing of Windows GUIs. I used it for the first time this week. The results were good enough to recommend using it again. The performance was a little slow, so I wouldn't want to have lots of tests. I prefer to avoid UI Unit Tests by separating the presentation from the logic. However, sometimes you need to unit test an interaction. For those cases, White can be useful.

I'm not going to blog an example here. The documentation for White has some examples. See Getting Started.

Wednesday, April 29, 2009

Using Cucumber Testing Framework without Rails

Most of the articles for Cucumber are given as Rails examples. While Cucumber was born for Rails testing, it isn't limited to that environment. A few simple steps will allow you to use Cucumber with any Ruby project.

This example will use Rake to run cucumber because the Cucumber::Rake::Task does a lot of work for you. It will automatically load (require) the features and steps for you.

First, you should follow Cucumber's pattern for directories:




{project home}/featuresstores all the .feature files
{project home}/features/step_definitionsstores the .rb files containing steps
{project home}/features/supportcontains the env.rb file


First create a rakefile for your project and add a Cucumber::Rake::Task as follows...



Next create the features file(s). The rake task will automatically require all the .feature files in the features directory. This example reproduces the additions.feature shown on Cucumber's homepage.



At this time, you may run "rake features" to see Cucumber runs. The results will show that 4 steps are undefined. To define the steps create features\step_definitions\addition_steps.rb. The rake task will automatically require all the step_definitions files.



This example uses a class Calculator from my project. So lets define that class under lib\calculator.rb.



This calculator isn't very exciting. It just uses a stack to remember values. The first item in the stack is the "screen". The add method will add the top two values. This is the bare minimum needed to meet the defined feature. (Normally you would define the class and fill in the details in a test-first fashion. But to keep this article short, I've posted the completed class.)

The rake features task doesn't automatically require the calculator.rb file. Also, if you noticed the addition_steps.rb makes use of rspec expectations, which isn't available by default. To require these files, create the features/support/env.rb file. The rake features task will automatically require any file under features/support



Now when you run "rake features" everything will work together. Your steps should all run and pass with green color!

Saturday, April 04, 2009

TofuHash is done!

I've released TofuHash v1.0 which supports the entire Hash interface for both Ruby 1.8.x and Ruby 1.9.1.

On Monday April 6, I'll be presenting a lightning talk on TofuHash to Rubyham. The talk will mostly cover the ruby 1.9.1 issues encountered.

Thursday, March 12, 2009

TofuHash is now a ruby gem.

I've released v0.1.0 as a ruby gem. The documentation is online at http://tofuhash.rubyforge.org/

To install it, simply use:

gem install tofuhash

Tuesday, February 03, 2009

wordle.net



I found wordle.net which can generate word clouds from text, blogs, etc. Just for fun, I created one from my blog.

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]".