Skip to content

Instantly share code, notes, and snippets.

@xaviershay
xaviershay / Goals
Created December 19, 2009 09:12
Goals for 2010
by the end of 2010 I will...
- on the cards
✘ fail, or rejected
✔ complete
physically:
✘ Lead an indoor grade 20+ sport climb [can almost onsite some 19s top rope, still need to learn to lead]
✔ Lead a multi-pitch trad climb [didn't learn how to use gear]
✘ 5 minute plank [going well, less than 90s away]
# Monkey patch in CTRL-C support for rspec from
# http://github.com/dchelimsky/rspec/commit/029f77c5063894cf52af05335b8e1c278411978b
# until it gets released
module Spec
module Example
module ExampleMethods
def execute(run_options, instance_variables) # :nodoc:
run_options.reporter.example_started(@_proxy)
set_instance_variables_from_hash(instance_variables)
require 'rubygems'
require 'hpricot'
require 'fastercsv'
doc = Hpricot::XML(File.read(ARGV[0]))
csv = FasterCSV.generate do |csv|
(doc/:Trackpoint).each do |x|
next unless x.at('HeartRateBpm') && x.at('Position')
csv << [
# In Rspec, gives you:
# before(:all_transactional) {}
#
# Uses nested transactions to correctly rollback :all before blocks
# You *may* need to reload some instance variables in a separate before(:each) block
# All a bit of a hack, but really handy
module RspecRailsTransactions
def before_all_transactional_parts # :nodoc:
@before_all_transactional_parts ||= []
end
module ActiveRecord
class Base
def atomic &block
transaction {
lock!
yield
}
end
end
end
Title:
Your database is your friend
Description:
Learn how going against rails conventions and using your database can make your
life easier. A practical tutorial on data integrity and design.
Type:
3 hour tutorial
# DM Extensions
# Use for roll your own optimistic locking, without using a dedicated lock_version column
def update_with_conditions(attributes, conditions)
properties = attributes.inject({}) do |a, (key, value)|
a.update(property_by_name(key) => value)
end
updated_count = repository.adapter.update(properties, all(conditions))
# Add pessmistic locking support. Make sure you're inside a transaction.
# resource = MyResource.get(24)
# resource.lock! # write lock (FOR UPDATE)
#
# TODO:
# resource = MyResource.get_with_lock!(:write, 24)
# resource = MyResource.get_with_lock!(:read, 24)
# MyResource.all(:lock => :write)
module DataMapper
# Hacks to get nested transactions in Postgres
# Not extensively tested, more a proof of concept
#
# It re-opens the existing Transaction class to add a check for whether
# we need a nested transaction or not, and adds a new NestedTransaction
# transaction primitive that issues savepoint commands rather than begin/commit.
module DataMapper
module Resource
def transaction(&block)
Royal Melbourne Hospital - Vegan Menu
Dinner:
- Cucumber + Cheese sandwich
- Orange Juice
Dinner (2nd try):
- Tomato/cucumber/carrot salad
- Potato + corn + mayonnaise coleslaw
- Jelly (gelatine)