Skip to content

Instantly share code, notes, and snippets.

class ActiveSupport::TestCase
def setup
clear_all_collections
end
def clear_all_collections
# ruby 1.9 compatability
Dir[File.join(Rails.root, 'app/models/**/*.rb')].each do |model_path|
klass = File.basename(model_path, '.rb').classify.constantize
klass.collection.remove if klass.respond_to?(:collection)
class User
include MongoMapper::Document
key :email, String
key :encrypted_password, String, :limit => 128
key :salt, String, :limit => 128
key :confirmation_token, String, :limit => 128
key :remember_token, String, :limit => 128
key :email_confirmed, Boolean, :default => false, :null => false
// ideas for the new restful-routing dsl, inspired by the rails 3 router
public class WebsiteApp : RestfulRoutingApp
{
public WebsiteApp()
{
Resource<SessionController>(() => Only.New.Create);
Namespace("admin", () =>
{
Resources<BlogsController>(() =>
{
public static class ConventionHelper
{
public static string PluralUnderscore(string name)
{
return Underscore(Inflector.Net.Inflector.Pluralize(name));
}
public static string Underscore(string name)
{
var lowered = name.ToLowerInvariant();
#!/usr/bin/env ruby
def say_hello(name)
puts "Hello #{name}"
end
%w{Gafitescu D_Roch Steven Ng n0x13 hosheng Pratik Desal r kumar Ashley Moran persiancoffee Andre Fischer}.each do |person|
say_hello(person)
end
#!/usr/bin/env ruby
def hello_loop(*names)
names.each do |name|
puts "Hello #{name}"
end
end
hello_loop("Gafitescu", "D_Roch", "Steven Ng", "n0x13", "hosheng", "Pratik Desal", "r kumar", "Ashley Moran", "persiancoffee", "Andre Fischer")
class ContactForm < Form
attr_accessor :name, :email, :message
validates_presence_of :name, :email, :message
def save
# do something
end
end
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@stevehodgkiss
stevehodgkiss / gist:806733
Created February 1, 2011 21:31
/etc/init.d/thinking_sphinx
We couldn’t find that file to show.
@stevehodgkiss
stevehodgkiss / hooks.rb
Created April 19, 2011 10:07
Automatically save and open page when a @wip scenario fails
After do |scenario|
if scenario.failed? && scenario.source_tag_names.include?("@wip")
save_and_open_page
end
end