Skip to content

Instantly share code, notes, and snippets.

View rafb43's full-sized avatar

Rafael Bandeira rafb43

View GitHub Profile
@rafb43
rafb43 / save_baby_pandas.md
Last active August 29, 2015 14:00
Ruby devs have no love for Baby Pandas :-(

Save Baby Pandas

Check how many pandas your project has killed already: $ grep -ro inject app lib | wc -l

And please, pretty please, save a panda, use #reduce.

@rafb43
rafb43 / installation.md
Created April 21, 2014 20:19
Migrating PG to MySQL with MySQLWorkbench

Install iodbc /usr fix for Mac, third link

http://www.iodbc.org/dataspace/iodbc/wiki/iODBC/Downloads#Mac_OS_X

Now you build psqlODBC

curl http://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-09.03.0210.tar.gz -o psqlodbc-09.03.0210.tar.gz
tar -xzf psqlodbc-09.03.0210.tar.gz
cd psqlodbc-09.03.0210.tar.gz

./configure --with-iodbc=/usr/local/iODBC/ --enable-pthreads --without-libpq

@rafb43
rafb43 / redis_throttle.lua
Last active April 19, 2017 21:02
Shared throttling mechanism with Redis
-- KEYS[1] namespace/key
-- ARGV[1] current timestamp
-- ARGV[2] max uses per second
local t = tonumber(redis.call("get", KEYS[1] .. ":t")) or 0
local c = tonumber(redis.call("get", KEYS[1] .. ":c")) or 0
local current = tonumber(ARGV[1])
local max = tonumber(ARGV[2])
if current - t >= 1 then
redis.call("mset", KEYS[1] .. ":t", current, KEYS[1] .. ":c", 1)
return {current, 1, 1}
@rafb43
rafb43 / recipe.md
Last active August 29, 2015 14:06
FakeWeb -> WebMock transition
  • body file path: %s/\(body\: \)\(File.\+\)\(Rails\.root\), \([^)]\+\))/\1\3.join(\4/g
  • headers top-level: %s/\(content_type\:[^,)]\+\)/headers: { \1 }/g
  • bundle exec rspec `git status --porcelain | sed -e "s/ M /.\//" | grep "spec\.rb"`
@rafb43
rafb43 / probe.rb
Last active August 29, 2015 14:07
Probe into all instance method calls for a given class
# will look into all method call in instances of given class
module Probe
def self.instances(klass, opts = {})
methods = if opts.is_a?(Array)
opts
else
methods_list(klass, opts)
end
methods.uniq.each do |m|
- http://www.creativitypost.com/create/banish_excuses_and_boost_your_mood_to_feel_more_creative
A good mood is the best way to boost creativity, and here are some tips on how to get to a good mood
@rafb43
rafb43 / analysis.markdown
Created November 28, 2014 18:01
Uniqush MySQL driver
  • DatabaseConfig.Engine should control which engine is initialized for pushDatabaseOpts, and not be validated inside the engine driver as it currently is
  • why should the db wrapper (pushDatabaseOpts) control locks when each engine has different lock mechanisms and requirements that may or may not allow things to be written and read at the same time. Shouldn't that go into the engine driver?
@rafb43
rafb43 / shuffle_resque_queue.rb
Created June 10, 2015 21:58
Shuffle resque queue
redis = Redis.current
key = "resque:queue:bulk"
total = redis.llen(key)
batch = []
total.times do |i|
entry = redis.lpop(key)
batch << entry
if batch.size == 1000
puts "re-inserting batch..."
@rafb43
rafb43 / gist:cb2f3c76d412fa0814d9
Created July 10, 2015 19:43
Share counter client-side
https://github.com/ollieglass/share-counter/blob/master/lib/share-counter.rb
https://urls.api.twitter.com/1/urls/count.json?url=http://www.getmdl.io/&callback=foo
https://api.facebook.com/method/fql.query?format=json&query=select%20share_count%20from%20link_stat%20where%20url=%22http://www.getmdl.io/%22&callback=foo
https://www.linkedin.com/countserv/count/share?url=http://www.getmdl.io/&callback=foo
https://gist.github.com/jonathanmoore/2640302#google-plus
https://gist.github.com/michielvaneerd/5989839