Skip to content

Instantly share code, notes, and snippets.

@andruby
andruby / ubuntu-11.10-gems.erb
Created March 27, 2012 20:51 — forked from kashif/ubuntu-11.10-gems.erb
Chef bootstrap With rvm and ruby 1.9.3 on ubuntu 11.10
bash -c '
<% if knife_config[:bootstrap_proxy] -%>
(
cat <<'EOP'
<%= "proxy = #{knife_config[:bootstrap_proxy]}" %>
EOP
) > ~/.curlrc
<% end -%>
if [ ! -f /usr/bin/chef-client ]; then
@andruby
andruby / 1-encodings.rb
Created April 18, 2012 16:31
Ruby Encodings for ruby 1.9.3p125
# ruby -rpp -e 'pp Encoding.list.map(&:name)'
["ASCII-8BIT",
"UTF-8",
"US-ASCII",
"Big5",
"Big5-HKSCS",
"Big5-UAO",
"CP949",
"Emacs-Mule",
"EUC-JP",
@andruby
andruby / risk.rb
Created May 11, 2012 01:46
Risk Simulation: Attacker or Defender advantage?
def game(attackers = 3, defenders = 2) # returns [attacker, defender] loses
attack = (1..attackers).map { rand(6) }.sort.reverse[0..1].reverse
defense = (1..defenders).map { rand(6) }.sort
max_wins = [attackers, defenders].min
attack_wins = (1..max_wins).map { attack.pop > defense.pop }.select{ |x| x}.count
[max_wins - attack_wins, attack_wins]
end
def full_game(armies = 30)
attack = defense = armies
while [attack-1, defense].min > 0
@andruby
andruby / gist:2861712
Created June 3, 2012 03:28
Bypass Devise email reconfirmation from console
u = User.find_by_email("old@email.com")
u.email = "new@email.com"
def u.postpone_email_change?; false; end
u.save
@andruby
andruby / svn_tags_to_git.sh
Created March 15, 2013 11:28
Shell script to import svn tags to git tags. Run this after git svn clone & git svn fetch. Remove line 6 if you don't want it to push the tag to origin.
git for-each-ref refs/remotes/tags | cut -d / -f 4- |
while read ref
do
echo "creating and pushing tag: $ref"
git tag -a "$ref" -m "import svn tag $ref" "refs/remotes/tags/$ref"
git push origin tag "$ref"
done
@andruby
andruby / ubuntu-vagrant-chef-bootstrap.sh
Last active December 16, 2015 06:08
Bootstrap shell script to install ruby and chef on a clean Ubuntu 12.04 ami
# postinstall.sh for Ubuntu 12.04 base ami
# Online at: https://gist.github.com/andruby/5389159
# Usage: config.vm.provision :shell, :inline => "curl 'https://gist.github.com/andruby/5389159/raw' | sudo sh"
if hash chef-client 2>/dev/null; then
echo "Chef is already installed"
else
echo "Chef is not available on the system"
echo "Bootstrapping ruby & chef"
@andruby
andruby / config.xml
Last active December 16, 2015 10:19
SparkleShare Invite with announcements_url
<?xml version="1.0" encoding="UTF-8"?>
<sparkleshare>
<user>
<name>Andrew</name>
<email>andruby@example.com</email>
</user>
<notifications>True</notifications>
<folder>
[...]
</folder>
@andruby
andruby / User-Data
Last active December 17, 2015 07:19
Testing for EC2 cloud-init with User Data
#include
https://gist.github.com/andruby/5571940/raw/cloud-config
https://gist.github.com/andruby/5571940/raw/remote.sh
@andruby
andruby / miner_bbq.sh
Created June 7, 2013 21:33
cgminer shellscripts
#!/bin/sh
export DISPLAY=:0
export GPU_MAX_ALLOC_PERCENT=100
export GPU_USE_SYNC_OBJECTS=1
export THREAD_CONCURRENCY=7680
export INTENSITY=12
export GPU_THREADS=2
export WORKSIZE=256
export LOOKUP_GAP=2
@andruby
andruby / gist:7628903
Last active December 29, 2015 06:29
Devise routes
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update