Skip to content

Instantly share code, notes, and snippets.

View x0bandeira's full-sized avatar

Rafael Bandeira x0bandeira

View GitHub Profile
@x0bandeira
x0bandeira / 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"`
@x0bandeira
x0bandeira / 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}
@x0bandeira
x0bandeira / 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

@x0bandeira
x0bandeira / 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.

........ ........
........ ........
........ how . big ........
........ ........
........ ----- ----- ........
........ I . |____ ........
........ I | ........
........ ----- ----- ........
........ ........
........ the conclusion...? ........
entries.each do |e|
begin
do_stuff(e)
rescue => error
$redis.lpush("failed_strip", e.id) # will create the list and/or append the value
end
# counting
puts "failed: " + $redis.llen("failed_strip")
# http://redis.io/commands/rpoplpush
module Resque
def self.move_queue(source, destination)
r = Resque.redis
r.llen("queue:#{source}").times do
r.rpoplpush("queue:#{source}", "queue:#{destination}")
end
end
end