Skip to content

Instantly share code, notes, and snippets.

Verifying that +rk is my openname (Bitcoin username). https://onename.io/rk
@ryanking
ryanking / cantTouchThis.rb
Created December 6, 2013 01:03
I just stumbled on this bit of ruby code from a long time ago. Matt Knox and I were trying to solve the question of "can you selectively prevent monkey-patching in ruby?" I think this is the best we could do at the time.
# Ever get tired of people messing with your ruby classes?
# now you can put the hammer down and stop them. Just
# include this module and no one will be able to modify the
# class implementation or any instance implementations.
module Stop
module CantTouchThis
def self.included(mod)
c197493644ea54b514965e448ac60fab
@ryanking
ryanking / gist:954555
Created May 4, 2011 00:55
Selectively stop classes from being modified in ruby.
# Ever get tired of people messing with your ruby classes?
# now you can put the hammer down and stop them. Just
# include this module and no one will be able to modify the
# class implementation or any instance implementations.
module Stop
module CantTouchThis
def self.included(mod)
module Stop
module CantTouchThis
def self.included(mod)
%w[instance_variable_get instance_variable_set].each do |m|
send(:protected, m)
end
eigenclass = class << mod; self; end
%w[const_set class_variable_get class_variable_set public_class_method attr attr_reader attr_writer].each do |m|
module MockSnowflake
TWEPOCH = 1142974214000
WORKERIDBITS = 5
DATACENTERIDBITS = 5
MAXWORKERID = -1 ^ (-1 << WORKERIDBITS)
SEQUENCEBITS = 12
WORKERIDSHIFT = SEQUENCEBITS
DATACENTERIDSHIFT = SEQUENCEBITS + WORKERIDBITS
TIMESTAMPLEFTSHIFT = SEQUENCEBITS + WORKERIDBITS + DATACENTERIDBITS
["batch_mutate",
CassandraThrift::Cassandra::Batch_mutate_args,
{:consistency_level=>1,
:mutation_map=>
{"test_get_super_sub_keys_with_count_after_remove"=>
{"StatusRelationships"=>
[<CassandraThrift::Mutation column_or_supercolumn:<CassandraThrift::ColumnOrSuperColumn super_column:<CassandraThrift::SuperColumn name:"user_timelines", columns:[<CassandraThrift::Column name:"\023\201@\000N\377\021\263\216\2351P\3706\220Y", value:"Item 1", timestamp:1270765433751692>, <CassandraThrift::Column name:"\223\201@\000\266h\021\262\214\343i\260U\367kx", value:"Item 0", timestamp:1270765433751692>, <CassandraThrift::Column name:"\023\201@\000\200,\021\264\237\003\323$\217\223S\240", value:"Item 2", timestamp:1270765433751692>]>>>]}},
:keyspace=>"Twitter"}]
["remove",
CassandraThrift::Cassandra::Remove_args,
diff --git a/lib/cassandra_object/identity/natural_key_factory.rb b/lib/cassandra_object/identity/natural_key_factory.rb
index 69dec5b..91859ee 100644
--- a/lib/cassandra_object/identity/natural_key_factory.rb
+++ b/lib/cassandra_object/identity/natural_key_factory.rb
@@ -35,7 +35,7 @@ module CassandraObject
end
def next_key(object)
- NaturalKey.new(attributes.map { |a| object[a.to_s] }.join(separator))
+ NaturalKey.new(attributes.map { |a| object.attributes[a.to_s] }.join(separator))
DEBUG - batch_insert
DEBUG - insertBlocking writing key 2783412020 to 366568@[127.0.0.1:7000]
DEBUG - Applying RowMutation(table='Twitter', key='2783412020', modifications=[ColumnFamily(Statuses [created_at:false:32@1248290653252056, favorited:false:7@1248290653252056, id:false:12@1248290653252056, in_reply_to_screen_name:false:8@1248290653252056, in_reply_to_status_id:false:12@1248290653252056, in_reply_to_user_id:false:10@1248290653252056, source:false:51@1248290653252056, text:false:138@1248290653252056, truncated:false:7@1248290653252056])])
DEBUG - RowMutation(table='Twitter', key='2783412020', modifications=[ColumnFamily(Statuses [created_at:false:32@1248290653252056, favorited:false:7@1248290653252056, id:false:12@1248290653252056, in_reply_to_screen_name:false:8@1248290653252056, in_reply_to_status_id:false:12@1248290653252056, in_reply_to_user_id:false:10@1248290653252056, source:false:51@1248290653252056, text:false:138@1248290653252056, truncated:false:7@1248290653252056])]) applied. Sending respo
@ryanking
ryanking / gist:69111
Created February 23, 2009 19:08
trace the system calls for a set of processes
strace -cp `ps ax | grep [h]ttpd | awk '{ print $1 }' | tr '\n' ',' | sed 's/,/ -p /g'` -f