Skip to content

Instantly share code, notes, and snippets.

View myitcv's full-sized avatar

Paul Jolly myitcv

View GitHub Profile
@myitcv
myitcv / lval_rval_collector.rb
Created March 1, 2013 03:27
Take a string that contains colon separated lval:rval pairs, produce a hash that collects the rvals for the lvals
# Take a string that contains colon separated lval:rval pairs
# Produce a hash that collects the rvals for the lvals. E.g.
#
# "Fruit:orangeSize:largeQuantity:5Fruit:Apple"
#
# when considered with the lvals of:
#
# %w(Fruit: Size: Quantity: Fresh:)
#
# results in:
@myitcv
myitcv / a16z_portfolio.rb
Created March 1, 2013 04:19
Some interesting text processing: combines XPath and some unstructured extraction
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://a16z.com/portfolio/'))
def collect_up(string,lvals)
progress = [string]
# Result hash
result = {}
@myitcv
myitcv / broken_serialize.rb
Last active December 21, 2015 11:39
Rails 4.0.0 ActiveRecord bug for serialize attribute
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.0'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
@myitcv
myitcv / ec2_redis.conf
Last active December 22, 2015 07:08
EC2 Redis Conf (basic)
daemonize yes
pidfile /var/run/redis.pid
port 6379
timeout 0
bind 127.0.0.1
tcp-keepalive 0
loglevel notice
logfile stdout
databases 16
save 900 1
@myitcv
myitcv / zeroclipboard_patch.diff
Created November 10, 2013 10:05
Patch to ZeroClipboard v1.1.7 to support css zoom
--- zeroclipboard-rails/app/assets/javascripts/zeroclipboard/ZeroClipboard.js 2013-11-10 10:04:08.968800717 +0000
+++ zeroclipboard/ZeroClipboard.js 2013-11-10 10:04:20.840117981 +0000
@@ -20,17 +20,6 @@
}
return y;
};
- var _getZoom = function(obj) {
- var zoom = 1;
- if(RegExp(' AppleWebKit/').test(navigator.userAgent)){
- while(obj)
@myitcv
myitcv / broken.rb
Last active December 29, 2015 22:59
Differences in define_method
module V1
def self.doit(opts = {})
opts.each_pair do |k,v|
define_method(k, &v)
end
end
doit a: -> { b }
doit b: -> { 'b' }
RuntimeError: Unrecognized properties: type, serialized_name on {"type"=>"string", "serialized_name"=>"ExclusiveStartTableName"}
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/node.rb:88:in `from_hash'
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/shapes/shape.rb:107:in `from_hash'
kernel/common/enumerable.rb:293:in `inject'
kernel/common/hash.rb:342:in `each'
kernel/common/enumerable.rb:288:in `inject'
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/shapes/shape.rb:107:in `from_hash'
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/property.rb:122:in `deserialize'
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/property.rb:52:in `load_from'
/home
Rubinius::ObjectBoundsExceededError: Tuple::at_prim: index 16 out of bounds for size 16
kernel/common/hash.rb:462:in `redistribute'
kernel/common/hash.rb:193:in `__store__ ([]=)'
kernel/common/hash.rb:424:in `merge!'
kernel/common/hash.rb:330:in `each_item'
kernel/common/hash.rb:423:in `update (merge!)'
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/node.rb:38:in `properties'
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/node.rb:78:in `from_hash'
kernel/common/hash.rb:342:in `each'
/home/myitcv/.rbenv/versions/rbx-2.2.5/gems/gems/aws-sdk-core-2.0.0.rc6/vendor/seahorse/lib/seahorse/model/node.rb:75:in `from_hash'
Aws::DynamoDB::Errors::InvalidSignatureException: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
The Canonical String for this request should have been
'POST
/
content-type:application/x-amz-json-1.0
host:dynamodb.us-east-1.amazonaws.com
user-agent:aws-sdk-ruby2/2.0.0.rc6 rbx/2.1.0 x86_64-linux-gnu Seahorse/0.1.0
x-amz-content-sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a
@myitcv
myitcv / v3.rb
Last active August 29, 2015 13:56
require 'rubygems'
require 'bundler/setup'
require 'celluloid/autostart'
require 'aws-sdk-core'
Aws.config = { access_key_id: 'xxxxxxxxx', secret_access_key: 'xxxxxxxxxxxx', region: 'xxxxxxxxx' }
class SigningTest
include Celluloid