Skip to content

Instantly share code, notes, and snippets.

View bantic's full-sized avatar
💭
Status!

Cory Forsyth bantic

💭
Status!
View GitHub Profile
/*
* This is the Towers of Hanoi example from the prolog tutorial [1]
* converted into Scala, using implicits to unfold the algorithm at
* compile-time.
*
* [1] http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_3.html
*/
object TowersOfHanoi {
import scala.reflect.Manifest
#!/usr/bin/ruby
require 'net/smtp'
PRINT_RESULTS = false # Print results to screen?
EMAIL_RESULTS = true # email the results?
pool = %w{[email protected] [email protected] [email protected]}
avail = pool.dup
@bantic
bantic / config.ru
Created March 11, 2010 02:21
An app for Teleku to tell you how many days old you are. See: http://www.teleku.com/extensions/42
require 'rubygems'
require 'sinatra'
require 'phone.rb'
set :environment, :production
root_dir = File.dirname(__FILE__)
set :root, root_dir
FileUtils.mkdir_p 'log' unless File.exists?('log')
log = File.new("log/sinatra.log", "a")
module God
module Conditions
class FileTouched < PollCondition
attr_accessor :path
def initialize
super
self.path = nil
end
[~]$ ruby test_state_machine_callbacks.rb
TestActiveRecord: starting to do_a. done a already? false
TestActiveRecord: starting to do_a. done a already? true
TestActiveRecord: done with do_a
TestActiveRecord: done with do_a
Caught error: 'SQLite3::SQLException: PRIMARY KEY must be unique: INSERT INTO "test_active_records" ("id", "state") VALUES(1, 'done_with_b')'
TestMongoMapper: starting to do_a. done a already? false
TestMongoMapper: starting to do_a. done a already? true
TestMongoMapper: done with do_a
TestMongoMapper: done with do_a
diff --git a/test/unit/integrations/active_record_test.rb b/test/unit/integrations/active_record_test.rb
index 639f1f0..d90c7a7 100644
--- a/test/unit/integrations/active_record_test.rb
+++ b/test/unit/integrations/active_record_test.rb
@@ -1749,6 +1749,34 @@ module ActiveRecordTest
else
$stderr.puts 'Skipping ActiveRecord Scope tests. `gem install active_record` >= v2.1.0 and try again.'
end
+
+ class MachineWithBeforeCreateCallbackTest < BaseTestCase
module Appname
class Application < Rails::Application
# ...lots of stuff...
config.middleware.use Rack::Auth::Basic, "My Realm", &(Proc.new {|user,pass| [user,pass] == ["foo","bar"]})
end
end
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
#
# To use:
# rails project_name -m http://gist.github.com/gists/219223.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
module AgeValidationTest
require 'date'
def self.valid_age_string(age_string)
d, m, y = age_string[0,2].to_i, age_string[2,2].to_i, age_string[4,2].to_i
Date.valid_civil?(y, m, d) && y.between?(11,89)
end
def self.random_age_string
age_string = ""
6.times { age_string << rand(10).to_s }
age_string
@bantic
bantic / gist:778918
Created January 14, 2011 00:31
nodeclient.js
var http = require('http');
var connection_count = 0;
var client_id = 0;
function createClient() {
client_id++;
var _client_id = client_id;
var google = http.createClient(8080, '184.72.131.24');
var request = google.request('GET', '/', {'host': '184.72.131.24'});