Skip to content

Instantly share code, notes, and snippets.

@xaviershay
xaviershay / app.rb
Created November 24, 2011 19:14
Simple rack app with routing. Is this possible with http_router?
require 'rack/request'
require 'rack/response'
class App
attr_accessor :provider
# This constructor DI is not possible in Sinatra(?), since the framework
# creates the new instance for you.
def initialize(provider)
@provider = provider
@xaviershay
xaviershay / vegan-month.md
Created November 19, 2011 17:45
Vegan Month Curriculum

Vegan Month Logo

Back in Melbourne circa 2010/11, Jodie, Jared and I used to run a [monthly vegan mentoring group][vegan-month]. I have gone back through the mailing lists and collected much of the curriculum and information from the program into this single document, so that I can distribute it more widely. The program was designed not just to get you through the first month nutritionally, but to expose you to a variety of foods and ideas that may be new to you. It emphasises that veganism is a shift sideways, not a sacrifice.

@xaviershay
xaviershay / db.rake
Created November 4, 2011 19:22
db:structure:load for Rails 3.1
# Adapter from http://pivotallabs.com/users/jdean/blog/articles/1707-using-mysql-foreign-keys-procedures-and-triggers-with-rails
namespace :db do
namespace :structure do |schema|
schema[:dump].abandon
desc "OVERWRITTEN - shell out to mysqldump"
task :dump => :environment do
cmd = "mysqldump #{mysql_options} -d --routines --triggers --skip-comments > db/development_structure.sql"
system cmd
File.open("#{Rails.root}/db/#{Rails.env}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
end
Volunteer role available: TECHNOLOGY TEAM: Project Manager
Description:
Working with the BZE technology team in Melbourne, this role involves managing the tasks for the various technology volunteers. We are currently rolling out a new website and CRM database. As our team grows, we now need someone to help manage tasks and to ensure volunteer time and skills are being utilized as efficiently as possible.
This role is a great opportunity to apply your management skills to a very important role that will see the deployment of the next generation of core tools used by BZE to research and communicate, helping to keep BZE one step ahead in climate change action!
Requirements: A basic understanding of project management and working with coders. You will understand the difference between a CRM and MYSQL.
@xaviershay
xaviershay / ocr.main
Created August 7, 2011 06:34
OCR with Clojure. See the blog post at rhnh.net.
(ns ocr.main
(:use [clojure.string :only (split trim)])
(:use [clojure.contrib.duck-streams :only (write-lines read-lines)])
(:use [clojure.contrib.shell-out :only (sh)])
(:use [clojure.contrib.math :only (sqrt)]))
; Input handling
(defn read-text-image-line [line]
(if (= "white" (last (split line #"[,:\s]+"))) "0" "1"))
@xaviershay
xaviershay / application_controller.rb
Created July 12, 2011 02:21
Helpers outside your view
class ApplicationController
# Provide access to helper methods from outside controllers and views,
# such as in Presenter objects. Rails provides ActionController::Base.helpers,
# but this does not include any of our application helpers.
def self.all_helpers
@all_helpers_proxy ||= begin
# Start with just the rails helpers. This is the same method used
# by ActionController::Base.helpers
proxy = ActionView::Base.new.extend(_helpers)
@xaviershay
xaviershay / ruby_interface.rb
Created June 5, 2011 06:55
Playing around with ruby mocking, interfaces and communication.
# In ruby you can mock everything, but get no indication when you forget to change underlying methods.
# In Java, this would be picked up by the compiler.
# This makes mocking in ruby more fragile.
# What if you were only allowed to mock methods on an "interface"? In the simple case
# this is just a class, but could be a module for re-use.
require 'minitest/unit'
require 'minitest/mock'
require 'minitest/autorun'
@xaviershay
xaviershay / acceptance_runner.rb
Created June 4, 2011 05:04
Parallel tests with unified SimpleCov coverage
require 'parallel'
class AcceptanceRunner < MiniTest::Unit
def initialize(opts = {})
super()
@opts = opts
end
def _run_suites_in_parallel(suites, type)
@xaviershay
xaviershay / require-performance-fix-r31758.patch
Created May 27, 2011 23:53
Patch to make ruby require much faster than it used to be.
diff --git a/.gitignore b/.gitignore
index 57557c9..7955376 100644
--- a/.gitignore
+++ b/.gitignore
@@ -129,3 +129,4 @@ y.tab.c
# /win32/
/win32/*.ico
+ext/win32ole/.document
diff --git a/array.c b/array.c
@xaviershay
xaviershay / query_trace_logger.rb
Created May 27, 2011 04:18
Ghetto query tracing for DataMapper. Put it in an initializer.
class QueryTraceLogger
def initialize(logger)
@logger = logger
end
def method_missing(method_name, *args)
if method_name == :debug
if args.first =~ /SQL/
Rails.logger.debug ""
Rails.backtrace_cleaner.clean(caller).each do |line|