Skip to content

Instantly share code, notes, and snippets.

module MockSnowflake
TWEPOCH = 1142974214000
WORKERIDBITS = 5
DATACENTERIDBITS = 5
MAXWORKERID = -1 ^ (-1 << WORKERIDBITS)
SEQUENCEBITS = 12
WORKERIDSHIFT = SEQUENCEBITS
DATACENTERIDSHIFT = SEQUENCEBITS + WORKERIDBITS
TIMESTAMPLEFTSHIFT = SEQUENCEBITS + WORKERIDBITS + DATACENTERIDBITS
@ryanking
ryanking / __init__.py
Created September 29, 2021 16:08
pytest honeycomb tracing
import os
import libhoney
# If buildevents is configured, set up a libhoney client to send spans for each test
writekey = os.environ.get('BUILDEVENT_APIKEY')
if writekey:
libhoney.init(writekey=writekey, dataset="buildevents", debug=True)
@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)

Keybase proof

I hereby claim:

  • I am ryanking on github.
  • I am ryanking (https://keybase.io/ryanking) on keybase.
  • I have a public key ASC16Ud8pxUHAgyaFq_RLrZdYdDp_Npw8K9vpL1gLmHFXQo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am ryanking on github.
  • I am ryanking (https://keybase.io/ryanking) on keybase.
  • I have a public key ASBNy_mrGeMvbuMMi84pqS9T9Rulx_X3rOfjGk9NNVrGnQo

To claim this, I am signing this object:

@ryanking
ryanking / powerball.rb
Last active January 11, 2016 02:31
powerball number generator
#!/usr/bin/env ruby
require 'colorize'
white_ball_drum = (1..69).to_a
red_ball_drum = (1..26).to_a
white_balls = []
red_ball = nil
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|
["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,