Skip to content

Instantly share code, notes, and snippets.

@jbodah
jbodah / prompt for input
Created June 19, 2015 17:39
prompt for input
TerminalNotifier.notify("Awaiting input for deploy: #{filter}")
print 'Continue with deploy? (y/n): '
res = $stdin.gets.strip
raise unless res == 'y'
# Hide input
print "Please enter password for #{user}: "
password = STDIN.noecho(&:gets).chomp
@jbodah
jbodah / color to term
Created June 17, 2015 17:47
printing color to teminal
# see http://ascii-table.com/ansi-escape-sequences.php
def alert(str)
puts "\e[36;1m***** #{str}\e[0m"
end
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
@jbodah
jbodah / yard cron
Created June 4, 2015 16:49
yard cron
# cron
* * * * * ~/yard/restart_server > ~/yard/restart_server.log 2>&1
# restart_servers
#! /usr/bin/env bash
echo 'Killing yard server...'
ps aux | grep 'yard server' | grep -v 'grep' | awk '{ print $2 }' | xargs kill
echo 'Pulling new code...'
cd /home/vagrant/yard && git pull
echo 'Starting yard server...'
@jbodah
jbodah / clean
Created June 1, 2015 14:26
clean branches2
git fetch --all -p; git branch -vv | grep ": gone]" | awk '{ print $1 }' | xargs -n 1 git branch -d
@jbodah
jbodah / nginx unicorn example
Last active August 29, 2015 14:21
nginx unicorn example
# /etc/nginx/sites-enabled/default.conf
upstream unicorn_server {
# Path to Unicorn SOCK file, as defined previously
server unix:/home/vagrant/buildo/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
@jbodah
jbodah / assert_performance.rb
Created April 9, 2015 18:37
assert_performance
require 'minitest/autorun'
class Minitest::Test
def assert_performance(current_performance)
self.assertions += 1 # increase Minitest assertion counter
benchmark_name, current_average, current_stddev = *current_performance
past_average, past_stddev = load_benchmark(benchmark_name)
save_benchmark(benchmark_name, current_average, current_stddev)
@jbodah
jbodah / performance_benchmark.rb
Created April 9, 2015 18:31
performance benchmark
require 'benchmark'
def performance_benchmark(name, &block)
# 31 runs, we'll discard the first result
(0..30).each do |i|
# force GC in parent process to make sure we reclaim
# any memory taken by forking in previous run
GC.start
# fork to isolate our run
@jbodah
jbodah / measurer.rb
Last active August 29, 2015 14:18
measurer
# Measures runtime, memory usage,
# of GC calls
class Measurer
require "json"
require "benchmark"
def self.measure(opts = {}, &block)
use_gc = opts.has_key?(:use_gc) ? opts[:use_gc] : true
if use_gc
# collect memory allocated during library loading
@jbodah
jbodah / gist:e6629c92630c909d7be3
Created December 31, 2014 16:46
working with gems and ctrlp
:CtrlP .
:CtrlP ~/.rbenv