Skip to content

Instantly share code, notes, and snippets.

# Compile both coffee and js, co-mingled in the same directory
compile '/js/*' do
case item[:extension]
when 'coffee'
filter :coffee
when 'js'
# Nothing
end
end
# Pathname/File require alternative?
require File.instance_eval {
expand_path(join(dirname(__FILE__), '..', 'bin', path))
}
require 'pp'
require 'rack/mount'
$LOAD_PATH.unshift("../sas-backend")
require 'app'
class DefaultPage < Rack::Directory
def call(env)
path = env['PATH_INFO']
if path =~ /\/$/ || !(path =~ /\..+$/)
# # Don't waste time testing your scripts!
# file_cache('results') { expensive_computation }
# file_cache('data') { data_from_the_internet }
def file_cache(key)
key = key.gsub(/\W/, '-')
base = File.dirname(__FILE__) + "/../../tmp/cache"
FileUtils.mkdir_p(base)
path = "#{base}/#{key}"
if File.exists?(path)
result = File.open(path) {|f| Marshal.load(f) }
@xaviershay
xaviershay / dm-postgres-adapter.rb
Created September 26, 2010 15:08
This is a sample patch for three dm gems - data_objects, do_postgres, and dm-postgres-adapter. It is not ready to be applied, since it is currently unspecced and untested. The purpose of this patch is to solicit feedback as to the architecture, to ensure
require 'dm-transactions/adapters/dm-do-adapter'
module DataMapper
class Transaction
module PostgresAdapter
include DataObjectsAdapter
# Produces a fresh transaction primitive for this Adapter. Fake nested
# transactions by using save points.
# Need a method that works regardless of whether active_support/core_ext is loaded or not
def today
(Time.respond_to?(:zone) && Time.zone) ?
Time.zone.today :
Date.today
end
describe 'timezone support' do
before :all do

Moral questions for veganism

Hypothetically, you are a vegan with an iPhone.

Your choice to become a vegan was because you determined it to be morally correct.

Your moral evaluation is based primarily on two considerations

  • That factory farming is harming the environment
  • That treating animals inhumanely is, well, inhumane
@xaviershay
xaviershay / gist:668930
Created November 9, 2010 10:12
DataMapper identity map test
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://localhost/test') # createdb test
class Container
include DataMapper::Resource
property :id, Serial
module DataMapper
module Model::Relationship
# By default, when validating a model, any child models will not be
# checked for validation. This means that the following situation can
# occur:
#
# user = User.new(:author => Author.new)
# user.valid? # => false
# user.author.valid? # => false
#
# Trying to replicate http://datamapper.lighthouseapp.com/projects/20609-datamapper/tickets/470-memcaching-can-t-marshal-dm-objects#ticket-470-19
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-timestamps'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://localhost/test') # createdb test
class TestDm