Skip to content

Instantly share code, notes, and snippets.

class Lesson < ActiveRecord::Base
belongs_to :period
validates_presence_of :period_id
end
class Period < ActiveRecord::Base
has_many :lessons, :dependent=>:delete_all
validates_associated :lessons
end
MiniTest::Unit::IntegrationTestCase.class_variable_get(:@@inheritors).each do |klass|
klass.module_eval do
alias_method :setup_with_no_hook, :setup
def setup
Capybara.current_driver = :selenium_chrome
setup_with_no_hook
end
alias_method :teardown_with_no_hook, :teardown
def teardown
@enriclluelles
enriclluelles / sass.rb
Created November 11, 2011 13:51
Stop Sass::Plugin from double compiling stuff
if Rails.configuration.try(:sass)
Rails.application.config.middleware.delete(Sass::Plugin::Rack)
Rails.configuration.sass.tap do |config|
config.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
config.preferred_syntax = :sass
end
end
Views = {
render: function (name, locals) {
var tmpl = $("[name=" + name + "]").html();
var locals = locals || {};
return require("jade.js").compile(tmpl)(locals);
},
replace: function (sel, name, locals) {
return sel.html(this.render(name, locals));
}
Uploads.setup = function (options) {
var defaults = {
runtimes: 'html5, flash, html4',
url: '/',
browse_button : 'pickfiles',
container : 'container',
max_file_size : '10mb',
filters : [
{title : "Image files", extensions : "jpg,jpeg,gif,png"}
],
@enriclluelles
enriclluelles / adding_accommodation.rb
Created November 30, 2011 17:54
Spinach step to test file upload with plupload and the js driver
When 'I add some pictures' do
path = File.expand_path(File.join(Rails.root, 'test', 'fixtures', 'dummy_image.png'))
find("input[type=file]").set(path)
page.execute_script("App.Uploads.uploader.start()")
end
#!/usr/bin/env ruby
require 'csv'
require 'json'
if ARGV.size != 2
puts 'Usage: csv_to_json input_file.csv output_file.json'
puts 'This script uses the first line of the csv file as the keys for the JSON properties of the objects'
exit(1)
end
$sprite-height: 0px;
@each $state in ordered, contacted, certified, in_transport_to_dealer, client_available, client_delivered{
.#{$state}{
background-position:left $sprite-height;
$sprite-height: $sprite-height - 100;
}
}
window.$ = new class Dollar
class Wrapper
#Utility function that returns the classes of the current object, except name
allClassesExceptOne = (name, elem) ->
(cl for cl in elem.className.split(" ") when cl isnt name and cl isnt "")
constructor: (elem) ->
elem extends Wrapper.prototype
return elem
require 'eventmachine'
require 'em-http'
require 'fiber'
def async_fetch(url)
f = Fiber.current
http = EventMachine::HttpRequest.new(url).get
http.callback { f.resume(http) }
return Fiber.yield
end