This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Tries to detect when mongo is up but super slow (ex: IO issue) | |
THRESHOLD = 20_000 # ms | |
def test_mongo tries: 5 | |
out = `echo -e "db.isMaster()\ndb.getReplicationInfo()" | mongo mongodb://localhost/?socketTimeoutMS=#{THRESHOLD} 2>&1` | |
res = $? | |
if res != 0 && !out['Connection refused'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Provides a system wide file lock to ensure no more | |
# than X process is running at the same time. | |
# Example: | |
# | |
# process_semaphore!({ | |
# prefix: "/tmp/my_process", | |
# limit: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this in place of `time_tag` | |
# Ex: <%= local_time_tag user.created_at %> | |
def local_time_tag time, opts = {} | |
opts[:data] = (opts[:data] || {}).merge format: 'local' | |
opts[:title] ||= time | |
time_tag(time, opts) + content_tag(:script, raw(<<-JAVASCRIPT)) | |
var nodes = document.querySelectorAll('time[data-format=local]'); | |
if (nodes.length > 0) { | |
var elem = nodes[nodes.length - 1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rewrite precompile tasks to do it locally | |
Rake::Task["deploy:compile_assets"].clear | |
task :compile_assets => [:set_rails_env] do | |
# invoke 'deploy:assets:precompile' | |
invoke 'deploy:assets:precompile_local' | |
invoke 'deploy:assets:backup_manifest' | |
end | |
namespace :assets do | |
task :precompile_local do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Ruby shows you the largest objects in your git repo's pack file & offers you to remove them automatically | |
# Based on http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/ by Antony Stubbs | |
# Use this to fetch all branches locally first: | |
# for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do | |
# git branch --track ${branch##*/} $branch | |
# done |
NewerOlder