Skip to content

Instantly share code, notes, and snippets.

@mattsnyder
mattsnyder / warrior_8.rb
Created March 6, 2014 02:21
Ruby Warrior Level 8 (kills captive)(works on 9 too)
class Strategy
def initialize(warrior, player)
@warrior = warrior
@player = player
end
def run
false
end
@mattsnyder
mattsnyder / warrior_7.rb
Created March 6, 2014 02:08
Ruby WarriorLevel 7
class Strategy
def initialize(warrior, player)
@warrior = warrior
@player = player
end
def run
false
end
@mattsnyder
mattsnyder / warrior_6.rb
Created March 6, 2014 01:56
Ruby Warrior Level 6
class Strategy
def initialize(warrior, player)
@warrior = warrior
@player = player
end
def remember(memo)
player.remember memo
end
@mattsnyder
mattsnyder / bash_profile.sh
Created December 26, 2013 14:56
Configure Bash prompt to perform Git command completion and show Git repo info
# Symlink the completion and prompt scripts from your Git install to your home directory
# Then add the following to your .bash_profile
source ~/git-completion.bash
source ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export PS1='\033[00;36m\]\W\[\033[01;37m\]$(__git_ps1)\[\033[01;36m\] \$\[\033[00m\] '
@mattsnyder
mattsnyder / null_object.rb
Created September 23, 2013 20:43
NullObject based on Avdi Grimm's Confident Code talk. http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/
class NullObject
def initialize
@origin = caller.first ### SETS ORIGIN FOR INSPECT INFO
end
def method_missing(*args, &block)
self
end
def nil?; true; end
@mattsnyder
mattsnyder / fuey.yml
Created August 23, 2013 11:57
Example fuey client configuration (v0.4.2)
---
title: "My app server"
logfile: /var/log/fuey.log
notifications:
-
- "run.trace"
- "Fuey::Log"
traces:
VPN_UP:
- Ping:
@mattsnyder
mattsnyder / sentry_example_controller.rb
Created June 26, 2013 14:56
Example of using sentry as guard clause/routing for Rails controllers
class PersonsController
extend ::Sentry
def show
# do stuff
end
sentry_for :show, :expect => [:person], :if_not => :handle_person_not_found
def subscribe
# do stuff
@mattsnyder
mattsnyder / currency_example.rb
Created June 11, 2013 12:28
Examples of configuring currency for different locales and leveraging Rails ActionView::Helpers to format currency.
include ActionView::Helpers # If you want to test from a Rails console
number_to_currency(12.34, :locale => :en) # => "$12.34"
number_to_currency(12.34, :locale => :ja) # => "12円"
number_to_currency(12.34, :locale => 'en-GB') # => "£12.34"
set -g default-terminal "xterm-256color" # More colors
set-option -g xterm-keys on # Work more nicely with odd key combos (emacs)
set -g base-index 1 # Tabs start at '1', not '0'
set -s escape-time 0 # Faster activation
# Bind <C-q> to leader
# Make sure to update status-right to include your leader!
unbind C-b
set -g prefix C-q
bind-key q send-prefix
@mattsnyder
mattsnyder / application_controller.rb
Created June 4, 2013 13:04
In an attempt to clarify what the controller makes available to views instead of guessing, identify them with #expose
#Include this method in your application_controller.rb
def self.expose(*variable_names)
variable_names.each do |variable_name|
define_method((variable_name.to_s+"=").to_sym) do |value|
@exposed ||= Hash.new
@exposed[variable_name]= value
end
private (variable_name.to_s+"=").to_sym
define_method(variable_name) do