This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Thing < ActiveRecord::Base | |
state_machine :initial => :pending do | |
# when published, the thing has to be removed | |
after_transition :on => :done_publishing, :do => :destroy | |
event :publish do | |
transition :pending => :publishing, :unless => :not_ready? | |
end | |
event :done_publishing do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simply run rake jammit:package to compile your coffeescript and then package up all your assets | |
# including the newly compiled javascripts | |
namespace :jammit do | |
task :package do | |
Rake::Task["barista:brew"].invoke | |
Jammit.package! | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "openssl" | |
require "digest" | |
def aes128_cbc_encrypt(key, data, iv) | |
key = Digest::MD5.digest(key) if(key.kind_of?(String) && 16 != key.bytesize) | |
iv = Digest::MD5.digest(iv) if(iv.kind_of?(String) && 16 != iv.bytesize) | |
aes = OpenSSL::Cipher.new('AES-128-CBC') | |
aes.encrypt | |
aes.key = key | |
aes.iv = iv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Migrate from old assigns[]= to assign() | |
Dir["spec/**/*_spec.rb"].each do |file| | |
changed = File.readlines( file ).map do |line| | |
pattern = /assigns\[(:[\w\d_]+)\] = (.+)$/ | |
if line =~ pattern | |
puts "Match: #{line}" | |
puts "Assign: #{$1}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import grails.plugin.spock.IntegrationSpec | |
import java.sql.Connection | |
import javax.sql.DataSource | |
import spock.lang.* | |
class DatabaseSchemaSpec extends IntegrationSpec { | |
@Shared def dataSource | |
@Shared List<String> tableNames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'em-hiredis' | |
module EMServer | |
def post_init | |
puts "-- someone connected to the echo server!" | |
end | |
def receive_data data | |
redis = EM::Hiredis.connect | |
redis.callback do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
class Watermark < Processor | |
## | |
# A Paperclip::Processor for watermarking images with imagemagick's | |
# composite command. | |
# | |
# Place this code in lib/paperclip_processors/watermark.rb or into a Rails initializer. | |
# | |
# Example: All orginal files are resized to be at most 480 pixels in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn remove-duplicates | |
"Returns a lazy sequence of the elements of coll with duplicates removed using a predicate" | |
[coll pred] | |
(let [step (fn step [xs seen] | |
(lazy-seq | |
((fn [[f :as xs] seen] | |
(when-let [s (seq xs)] | |
(if (some #(pred f %) seen) | |
(recur (rest s) seen) | |
(cons f (step (rest s) (conj seen f)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jasmine.Fixtures.prototype.loadTemplate_ = function(template) { | |
var templateUrl = "/backbone/templates/" + template; | |
var self = this; | |
$.ajax({ | |
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded | |
cache: false, | |
dataType: 'html', | |
url: templateUrl, | |
success: function(data) { | |
$('#' + self.containerId).append(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
namespace :assets do | |
task :precompile, :roles => :web, :except => { :no_release => true } do | |
from = source.next_revision(current_revision) | |
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0 | |
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} | |
else | |
logger.info "Skipping asset pre-compilation because there were no asset changes" | |
end | |
end |