Skip to content

Instantly share code, notes, and snippets.

View mikecmpbll's full-sized avatar
🎯
Focusing

Mike Campbell mikecmpbll

🎯
Focusing
  • Skipton, North Yorkshire
View GitHub Profile
# proof that rsystemm2 (http://rsystemm2.tumblr.com/) is bullshit
# designed to earn referral money from ladbrokes.
#
# this actually uses a 50% win chance, compared to roulettes 48.6%
# so it should be _more_ profitable than the "system"
# sample output in 2nd file.
def roulette_system
history = []
predicted = nil
@mikecmpbll
mikecmpbll / totp
Last active October 29, 2015 14:23 — forked from jurisgalang/totp
Ruby implementation of the Time-Based One-Time Password (TOTP) Algorithm described at http://tools.ietf.org/html/rfc6238
[jgalang@rashomon:~/Code/skunkworks/2fa]
∴ ruby totp_demo.rb
Time(sec) Time (UTC format) Value of T(Hex) TOTP Mode OK
------------------------------------------------------------------------------------------
59 1970-01-01 00:00:59 0000000000000001 94287082 SHA1 ✔
59 1970-01-01 00:00:59 0000000000000001 46119246 SHA256 ✔
59 1970-01-01 00:00:59 0000000000000001 90693936 SHA512 ✔
1111111109 2005-03-18 01:58:29 00000000023523EC 07081804 SHA1 ✔
1111111109 2005-03-18 01:58:29 00000000023523EC 68084774 SHA256 ✔
@mikecmpbll
mikecmpbll / _form.html.haml
Created October 27, 2015 16:45
trying to embed erb inside yml locale file
.form-actions
- if params[:action] == "new"
= button_tag type: "submit", class: "btn btn-success btn-cons",
id: "submit" do
= fa_icon "check"
%span  Create
= link_to courses_path, class: "btn btn-danger btn-cons" do
= fa_icon "close"
%span  Cancel
def multi_tenantify(tenant, with_database = true)
connection_info = if use_tenant_specific_db_conf?
_tenants_name_value.with_indifferent_access[tenant].clone
else
@config.clone
end
if with_database
database_name = Apartment.tenant_name_transform(tenant) # to replace environmentify?
connection_info[:database] = database_name
<tr class="foo"></tr>
<tr class="foo"></tr>
<tr></tr>
<tr class="bar"></tr>
@mikecmpbll
mikecmpbll / hack.rb
Created July 21, 2015 09:45
Yes ActiveRecord, you will bow to me.
scope = RealModel.where(name: 'foo')
threads = []
dbs.each do |db|
threads << Thread.new do
dynamic_class_name = "TempModel#{Thread.current.object_id}"
dynamic_class = Object.const_set(dynamic_class_name, Class.new(query_model))
begin
con = retrieve_connection(db, resolver)
dynamic_class.establish_connection(con)
local_scope = dynamic_class.all.merge(scope)
a = [1,2]
Benchmark.ips do |x|
x.report("reduce") { a.reduce(:*) }
x.report("other") { a[0] * a[1] }
x.compare!
end
Calculating -------------------------------------
reduce 56.411k i/100ms
class SC
def self.set_var(val)
@var = val
end
def superclass_instance_get_var
puts self.class.instance_variable_get("@var")
end
def self.superclass_class_get_var
module TestConcern
extend ActiveSupport::Concern
module ClassMethods
def foobar(a,b,c)
puts "doin sum cool shiz in hurr liek: #{a}, #{b} and #{c}"
end
end
end
du | awk '{ if ($1>1000*1024) { print $0 } }'
# prints out a whole bunch of directories bigger than 1000mb
du --max-depth=3 | awk '{ if ($1>1000*1024) { print $0 } }'
# just hangs with no output (i waited 5 mins) whereas ..
du --max-depth=3
# immediately outputs directories which i can see are bigger than 1000mb