Skip to content

Instantly share code, notes, and snippets.

routes.rb
map.term ':term', :controller => 'conference', :action => 'index'
index.rhtml
<% form_for :term, :url => { :controller => :conference, :action => :index }, :html => {:method => :get} do |f| %>
<input type="text" name="term" id="search" size="50" />
<input type="submit" value="Submit" id="submit" />
<% end %>
@BenHall
BenHall / My First Test
Created September 28, 2009 13:52
My first gist
public static string Test()
{
return "abc";
}
@BenHall
BenHall / Mongo_Controller.rb
Created October 25, 2009 10:13
using mongomapper with ruby on rails
class HomeController < ApplicationController
def index()
post = Post.create({
:title => 'John'
})
post.save
@posts = Post.find(:all)
end
@BenHall
BenHall / Automated RubyGem Install
Created November 16, 2009 17:23
How to install RubyGems via an automated ruby script
#!c:/ruby/bin/ruby.exe
require 'rubygems'
require 'rubygems/gem_runner'
require 'rubygems/exceptions'
def install(lib)
begin
Gem::GemRunner.new.run ['install', lib]
rescue Gem::SystemExitException => e
end
@BenHall
BenHall / xunit.msbuild
Created November 22, 2009 00:42
XUnit Build
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
TaskName="CodePlex.MSBuildTasks.RegexReplace"/>
<UsingTask
AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
TaskName="CodePlex.MSBuildTasks.Unzip"/>
<UsingTask
AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
require 'net/http' => true
require 'uri'
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'), { 'files[file1.rb]' => "puts 'Hello World!'", 'files[file2.rb]' => "puts 'Gists example'"})
puts res.body
#http://gist.github.com/240755
@BenHall
BenHall / Ruby Format
Created November 22, 2009 22:45
String format in Ruby
str = "a%sb%sc%s"
str % ['_', '/', '.']
=> "a_b/c."
@BenHall
BenHall / YieldBlock.rb
Created November 27, 2009 15:20
Yield a block of code in Ruby
def x()
yeild
end
x { puts 'abc' }
s = "test 'a' and 'b' and 'c'"
arguments = s.scan /'\w+'/
=> ["'a'", "'b'", "'c'"]
targets 1,2,3,4
def targets(*targets)
@targets=[targets]
end
@targets
=> [1,2,3,4]