Skip to content

Instantly share code, notes, and snippets.

View mindware's full-sized avatar

Andrés mindware

View GitHub Profile
# Adding simple colorization to our outputs
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def black
colorize(30)
end
def red
redis-cli rpush "resque:queue:myqueue" '{"class":"MyModel","args":["arg1"]}'
# expects seconds, returns pretty string of how long ago event happened
def ago(seconds)
a = seconds
case a
when 0 then "just now"
when 1 then "a second ago"
when 2..59 then a.to_s+" seconds ago"
when 60..119 then "a minute ago" #120 = 2 minutes
when 120..3540 then (a/60).to_i.to_s+" minutes ago"
when 3541..7100 then "an hour ago" # 3600 = 1 hour
TERM_CHILD=1 QUEUES=* VVERBOSE=1 rake resque:work --trace
@mindware
mindware / generaten-ssh-keys-ansible-distribute-keys
Last active August 29, 2015 14:15
Ruby script to generate 4096 ssh key and display ansible commands to distribute the public key to all machines
### Ask for SENSITIVE DATA:
puts "\nLet's help you generate the RSA keys and distribute it to your machines.\n\n"
print "Enter a secret passphrase to use for the key (save it well!): "
passphrase = gets.strip
print "Enter how many iterations (500 for security + performance, 1000 > for maximum security):"
iterations = gets.strip
print "Enter the name of the remote user: "
@mindware
mindware / gist:e7e02d8f2d0ab863abd5
Created March 7, 2015 07:36
How to distort an image to create flag waving in the wind effect using html5 canvas
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>HTML Canvas Flag Wave</title>
<style type="text/css" media="screen">
body { background:#eee }
#flag { position:absolute; top:50%; left:50% }
</style>
<script type="text/javascript">
window.onload = function(){
@mindware
mindware / gist:5f9280f7327e7a31ae35
Created March 7, 2015 07:38
How to distort an image to create flag waving in the wind effect using html5 canvas with no clipping
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>HTML Canvas Flag Wave</title>
<style type="text/css" media="screen">
body { background:#eee }
#flag { position:absolute; top:50%; left:50% }
</style>
<script type="text/javascript">
window.onload = function(){
@mindware
mindware / gist:c05e249ce5e7b35eb997
Created March 7, 2015 07:40
How to distort an actual image to create flag waving in the wind effect using html5 canvas
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>HTML Canvas Flag Wave</title>
<style type="text/css" media="screen">
body { background:#eee }
#flag { position:absolute; top:50%; left:50% }
</style>
<script type="text/javascript">
var h = new Image;
@mindware
mindware / gist:260c38312b931739191b
Created March 7, 2015 07:43
Bash script to clear old SSH hosts from known_hosts and rescan them
# say you save this as clear.sh
# chmod +x clear.sh
# usage: ./clear.sh <host1> <host2> <host..n>
for var in "$@"
do
echo "Clearing $var from host file."
ssh-keygen -f "$HOME/.ssh/known_hosts" -R $var
echo "Key scanning $var"
ssh-keyscan $var >> ~/.ssh/known_hosts
done
@mindware
mindware / gist:9fbfcc94abde630aa88c
Created March 7, 2015 07:46
Distribute your SSH-keys to all your hosts using Ansible
ansible -i ~/ansible/hosts -m authorized_key -a "key='{{ lookup('file', '/home/YOURUSER/.ssh/id_rsa.pub') }}' user=YOURUSER" -u YOURUSER all -k