Skip to content

Instantly share code, notes, and snippets.

rvm use 1.9.2@gist-2002019
@gareth
gareth / output.txt
Created January 30, 2012 21:08
`make` output
[gareth@Gareths-MacBook-Pro src]$ make
Makefile:23: Makefile.local.mk: No such file or directory
**** No Makefile.local.mk found, copying dist.
cp Makefile.local.mk.dist Makefile.local.mk
make -s -C lib -f local.mk
Generating dependencies
CC aes.c
glibtool: compile: cc -Wall -Wextra -ggdb -std=gnu99 -Wno-pointer-sign -c aes.c -fno-common -DPIC -o .libs/aes.o
glibtool: compile: cc -Wall -Wextra -ggdb -std=gnu99 -Wno-pointer-sign -c aes.c -o aes.o >/dev/null 2>&1
CC auth.c
@gareth
gareth / Gemfile
Created January 3, 2012 05:29
BH IMPORT
source :rubygems
#!/usr/bin/env ruby
require 'logger'
$stdout.sync = true
$stdin.sync = true
path = "/usr/local/var/log/ejabberd/auth.log"
file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
file.sync = true
$logger = Logger.new(file)
$logger.level = Logger::DEBUG
@gareth
gareth / normdist.rb
Created November 9, 2011 00:43
Ruby Normdist
# Code adapted from http://bytes.com/topic/c-sharp/answers/240995-normal-distribution#post980230
module Normdist
def self.normdist x, mean, std, cumulative
if cumulative
phi_around x, mean, std
else
tmp = 1/((Math.sqrt(2*Math::PI)*std))
tmp * Math.exp(-0.5 * ((x-mean)/std ** 2))
end
end
class Project < ActiveRecord::Base
has_many :goals
end
class Goal < ActiveRecord::Base
belongs_to :project
class << self
def setup *some_fields
new.tap do |goal|
@gareth
gareth / README.md
Created August 4, 2011 22:36
FestivalsLab API access for Rails apps

Introduction

This snippet is something I put together to play around with the FestivalsLab API inside a Rails app I was building. I built it with Rails 3 on Ruby 1.9.2 but there's no reason it shouldn't work on older versions of either of those.

This could potentially be used as a bare Ruby library without Rails, but I am using a couple of useful features - Rack's query string parsing and some MIME type handling - that would have to be rewritten to do that. I'm using these features because I don't think that any URI string manipulation should happen outside of a URI library, your philosophy may be different ;)

This code should be considered a work in progress, there are no guarantees that it will work for you, or that it won't wipe your hard drive. But you can see the code, it's all pretty simple.

Installation

require 'test/unit/assertions'
include Test::Unit::Assertions
assert_equal "1.9.2", RUBY_VERSION
# A Ruby meta-programming puzzle for polite programmers.
# This puzzle was created by Matt Wynne (@mattwynne) on 2011-04-10 inspired by Jim Weirich's
# talk at the Scottish Ruby Conference 2011.
#
# The challenge is: you have a class Foo which you want to monkey-patch, but politely.
@gareth
gareth / error_steps.rb
Created February 13, 2011 17:26
Step definition to test for the presence of error messages (and display discrepancies)
Then /^I should see( only)? the following error messages?( in order)?:$/ do |only, ordered, table|
# Uses Capybara's `all` CSS selector to find error messages in Rails' default
# error messages output format
errors = all(:css, "#errorExplanation li").map { |error| [error.text] }
errors_expected = table.raw
errors_actual = only ? errors : (errors & table.raw)
unless ordered
# Cucumber cares about the order of tables, If we don't then we need to sort
# both sets of messages using the same criteria
errors_actual = errors_actual.sort
[:user, :crypted_password, :uid, :gid, :homedir, :mail_dir, :options, :quota].each do |attribute|
define_method attribute do
@attributes[attribute]
end
end