Skip to content

Instantly share code, notes, and snippets.

View jacobo's full-sized avatar

Jacob Burkhart jacobo

  • HOVER
  • San Francisco, CA
View GitHub Profile
def load_from_cache
unless File.exists?(cache_path)
return false
end
toload = YAML.load_file(cache_path)
created = {}
models.each do |model|
toload[model.name].each do |id, attributes|
atts = {}
attributes.each do |k,v|
@jacobo
jacobo / gist:6275395
Created August 19, 2013 23:27
my pull request
From 767031e6fc1f313b29a982dc2f315596ac97bf47 Mon Sep 17 00:00:00 2001
From: Jacob Burkhart & Martin Emde <[email protected]>
Date: Mon, 19 Aug 2013 16:25:02 -0700
Subject: [PATCH] Optimize more by not using normalized_ methods
---
Rakefile | 9 ++++++---
lib/gitable/scp_uri.rb | 10 +++++-----
lib/gitable/uri.rb | 5 ++---
3 files changed, 13 insertions(+), 11 deletions(-)
@jacobo
jacobo / gist:6216165
Created August 12, 2013 23:02
for travis gem
def setup_engineyard
configure 'deploy', 'provider' => 'engineyard' do |config|
eyrc = File.expand_path(".eyrc", Dir.home)
if File.exists?(eyrc)
config['api_key'] = YAML.load_file(eyrc)["api_token"]
end
env = ask("Environment (optional): ").to_s
config['environment'] = env unless env.empty?
if agree("Run migrations on deploy? ") { |q| q.default = 'yes' }
@jacobo
jacobo / gist:6084556
Created July 25, 2013 23:02
that was fun
while true; do find . -name '*service*' | head -1 | while read filename ; do echo $filename; mv $filename ${filename/service/addon}; done; done
@jacobo
jacobo / gist:5870675
Last active December 19, 2015 00:39
There should be a button in github UI for doing this...
git remote add upstream https://github.com/resque/resque.git
git fetch upstream
git checkout master
git merge upstream/master
git push origin master
require 'rubygems'
require 'nokogiri'
str = "<select id=\"cluster_configuration_data_snapshot_id\" name=\"cluster_configuration[data_snapshot_id]\"></select>"
#This one fails
failing = Proc.new do
innards = "<option data-size=\"15\" value=\"\" volume_size=\"\">New volume</option>\n<option class=\"time\" data-html-suffix=\" (snap-f2e4f551) (Application Master) [64-bit]\" data-size=\"15\" datetime=\"2013-06-20T20:29:32+00:00\" value=\"8\" volume_id=\"14\" volume_size=\"15\" selected>\nThu Jun 20 20:29:32 2013 (snap-f2e4f551) (Application Master) [64-bit]\n</option>"
x = Nokogiri::XML::Element.new('select', Nokogiri::XML(str))
x.inner_html = innards
@jacobo
jacobo / alternate_refinements.rb
Created May 31, 2013 01:37
Yet another example of implementing something LIKE refinements directly in pure ruby. I run into the contraint of being unable to properly set 'self' in my blocks. (could be solved if I had https://bugs.ruby-lang.org/issues/8465) AND, it's very hacky because it uses caller. but I *think* this is what @Shogu generally intends the semantics of blo…
class BlockRefinement
def self.refines(*classes_refined)
@classes_refined = classes_refined
end
def self.refines_method(method_refined, &new_method)
@classes_refined.each do |class_refined|
old_method = class_refined.instance_method(method_refined)
@reverts ||= []
@jacobo
jacobo / block_refinement.rb
Last active December 17, 2015 22:19
In http://rubykaigi.org/2013/talk/S58 @Shogu describes how refinements work, but says he would rather they work with a block-like syntax. I asked why he couldn't just implement these extensions in pure ruby using the same techniques that stub and mock libraries use. The translated answer was "Because I want to refinement only to apply inside the…
class BlockRefinement
def self.refines(*classes_refined)
@classes_refined = classes_refined
end
def self.refines_method(method_refined, &new_method)
@classes_refined.each do |class_refined|
old_method = class_refined.instance_method(method_refined)
@reverts ||= []
require 'celluloid'
class Worker
include Celluloid
def work(x)
sleep 0.2; puts x*x
end
end
worker_pool = Worker.pool(size: 10)
(0..99).to_a.each{|x| worker_pool.async.work x }
sleep 2 #how do I wait the right amount of time before terminating?
@jacobo
jacobo / gist:5393037
Created April 16, 2013 03:01
re-create datamapper database in console
DataMapper.repository(@repository).adapter.extend(SQL::Mysql)
DataMapper.repository(@repository).adapter.recreate_database