Skip to content

Instantly share code, notes, and snippets.

View Aeramor's full-sized avatar

Randy Bares Aeramor

View GitHub Profile
@Aeramor
Aeramor / remove_duplicate_resque_jobs.rb
Last active January 3, 2023 21:46
Remove Duplicate resque jobs - ActiveJob
key = 'queue:default'
if Resque.redis.exists(key)
members = Resque.redis.lrange(key, 0, -1)
duplicate_members = members.group_by { |e| JSON.parse(e)["args"][0].except("job_id").to_s }.select { |k, v| v.size > 1 }.map{ |a| a[1].drop(1) }.flatten
duplicate_members.each do |duplicate_member|
Resque.redis.lrem(key, -1, duplicate_member)
end
end
@Aeramor
Aeramor / gist:b3695d065ca25f7c0299
Created February 18, 2015 05:35
OSX Terminal Get IP
/sbin/ifconfig en0 | grep 'inet ' | cut -d: -f2 | awk '{ print $2}'
@Aeramor
Aeramor / gist:8607769
Created January 24, 2014 22:10
Ruby change keys of a hash with a hash map.
ages = { "Bruce" => 32, "Clark" => 28 }
mappings = {"Bruce" => "Bruce Wayne", "Clark" => "Clark Kent"}
Hash[ages.map {|k, v| [mappings[k], v] }]
@Aeramor
Aeramor / shelltricks
Created September 16, 2013 08:09
Shell stdout and stderr fancy tricks
Redirect stdout and stderr to a variable (so you can handle an error without printing to the console)
ERROR_MSG=$(redis-cli PING 2>&1)
Redirect only stdout to a variable
ERROR_MSG=$(redis-cli PING)
Redirect a whole block of commands to not print
{
ERROR=$(redis-cli PING)
} >/dev/null 2>&1
function iOSversion() {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
}
}
@Aeramor
Aeramor / heroku load schema
Last active December 21, 2015 18:29
Load schema directly for heroku (to ignore migrations)
heroku run "bundle exec rake db:schema:dump && cat db/schema.rb"
heroku run rake db:schema:load
@Aeramor
Aeramor / retroactively gitignore
Created July 29, 2013 19:31
Remove any files from the repo that are in the gitignore, even after the fact. Just copy paste the whole thing into terminal/commandline (in the correct directory) and it will un-track the files (but leave them intact locally).Then use git status to verify nothing important was removed.
(GIT_INDEX_FILE=some-non-existent-file \
git ls-files --exclude-standard --others --directory --ignored -z) |
xargs -0 git rm --cached -r --ignore-unmatch --