Skip to content

Instantly share code, notes, and snippets.

@briancicutti
briancicutti / gist:3035155
Created July 2, 2012 19:29
Ruby Warrior Beginner Level 4 Solution
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
else
if warrior.health < 20 && !taking_damage?(warrior)
warrior.rest!
else
warrior.walk!
end
@briancicutti
briancicutti / gist:3040507
Created July 3, 2012 15:34
Decent Exposure
BEFORE DECENT EXPOSURE
def create
@person = Person.new(params[:person])
if @person.save
...
AFTER DECENT EXPOSURE
@briancicutti
briancicutti / gist:3043510
Created July 3, 2012 21:42
example migration
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users" do |t|
t.column :login, :string, :limit => 40
t.column :name, :string, :limit => 100, :default => '', :null => true
t.column :email, :string, :limit => 100
end
def self.down
drop_table "users"
@briancicutti
briancicutti / builder.rb
Created April 4, 2013 14:50
Fun metaprogramming, blocks, and some tricks with Ruby (basically a quick replication of what builder gem does)
class Builder
def initialize
@tag_stack = []
end
def method_missing(name, *args, &blk)
print " "*@tag_stack.size
print "<#{name}" + attributes(args) + ">"
@tag_stack.push name
if block_given?
@briancicutti
briancicutti / 0_reuse_code.js
Created February 5, 2014 16:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@briancicutti
briancicutti / gerrit_spacing
Created August 21, 2014 14:07
Gerrit Example -- Spacing Standards
Feature: Some terse yet descriptive text of what is desired
Textual description of the business value of this feature
Business rules that govern the scope of the feature
Any additional information that will make the feature easier to understand
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
Given /^I am logged in/ do
Given /^I login to a ([Ss]ecure|[Cc]ontrol) account/ do |accountType|
Given /^I login to (?:a|an) ([Uu]n)?[Rr]estricted secondary account/ do |negate|
Given /^I login to a suspended account$/ do
Given /^I press the Sign In button$/ do
@briancicutti
briancicutti / voices.rb
Last active August 29, 2015 14:05
Playing with Unix Voices
FileUtils.cd('/System/Library/Speech/Voices/') do
@voices = Dir.glob("*.SpeechVoice")
end
@voices.map{|v| v.scan(/[A-Z][a-z]+/) }
@voices.reject{|v| v.include? "Compact"}