An implementation of Conway's Game of Life in 140 characters of Ruby.
Created by Simon Ernst (@sier).
>> IF = -> b { b } | |
=> #<Proc:0x007fb4e4049cc8 (lambda)> | |
>> LEFT = -> p { p[-> x { -> y { x } } ] } | |
=> #<Proc:0x007fb4e403d680 (lambda)> | |
>> RIGHT = -> p { p[-> x { -> y { y } } ] } | |
=> #<Proc:0x007fb4e4028ff0 (lambda)> | |
>> IS_EMPTY = LEFT |
An implementation of Conway's Game of Life in 140 characters of Ruby.
Created by Simon Ernst (@sier).
class ActionDispatch::Routing::Mapper | |
def draw(routes_name) | |
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb"))) | |
end | |
end | |
BCX::Application.routes.draw do | |
draw :api | |
draw :account | |
draw :session |
# SSL self signed localhost for rails start to finish, no red warnings. | |
# 1) Create your private key (any password will do, we remove it below) | |
$ openssl genrsa -des3 -out server.orig.key 2048 | |
# 2) Remove the password | |
$ openssl rsa -in server.orig.key -out server.key |
Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.
Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.
First you will need to get an OAuth Token from GitHub using your own username and "note"
# RAILS 2.3.15 | |
# | |
# Since <tag type="yaml"> was removed from rails' xml parsing, | |
# but not from its to_xml method, rails can't talk to an API | |
# generated by rails, if you have serialized attributes. | |
# This can be put in config/initializers and you should probably | |
# upgrade to rails 3 already. Ugh. | |
# Three parts: |
desc 'rolls back migrations in current branch not present in other' | |
task :rollback_branch_migrations, [:other_branch] do |t, args| | |
load "#{Dir.pwd}/Rakefile" | |
branch_migrations = BranchMigrations.new(args.other_branch) | |
puts ['Rollback the following migrations', branch_migrations, 'y,n? '] | |
next if %w[no n NO N].include?(STDIN.gets.chomp) | |
Rake::Task['environment'].invoke |
require 'bundler/setup' | |
require 'active_record' | |
include ActiveRecord::Tasks | |
db_dir = File.expand_path('../db', __FILE__) | |
config_dir = File.expand_path('../config', __FILE__) | |
DatabaseTasks.env = ENV['ENV'] || 'development' |
require "active_record" | |
namespace :db do | |
db_config = YAML::load(File.open('config/database.yml')) | |
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'}) | |
desc "Create the database" | |
task :create do | |
ActiveRecord::Base.establish_connection(db_config_admin) |
# http://redis.io/commands/rpoplpush | |
module Resque | |
def self.move_queue(source, destination) | |
r = Resque.redis | |
r.llen("queue:#{source}").times do | |
r.rpoplpush("queue:#{source}", "queue:#{destination}") | |
end | |
end | |
end |