Skip to content

Instantly share code, notes, and snippets.

View cadwallion's full-sized avatar
⚒️
Building all the things

Andrew Nordman cadwallion

⚒️
Building all the things
View GitHub Profile
@cadwallion
cadwallion / gist:1522260
Created December 26, 2011 23:04
What is this I don't even...
def prepare_vars #:nodoc:
h = eval(%q{instance_variables.map {|var| "#{var.gsub("@",":")} => #{eval(var+'.inspect')}"}.join(", ").chomp(", ")})
return eval("{#{h}}")
end
@cadwallion
cadwallion / gist:1528233
Created December 28, 2011 14:58
Really, ActiveShipping? REALLY?
>> hash = { 'password' => 'pass*123', 'login' => 'testperson', 'key' => '1234567890' }
=> {"key"=>"1234567890", "login"=>"testperson", "password"=>"pass*123"}
>> ActiveMerchant::Shipping::UPS.new(hash) ArgumentError: Missing required parameter: key
from /Users/cadwallion/.rvm/gems/ruby-1.8.7-p352@gatorade_direct/gems/active_shipping-0.9.13/lib/active_merchant/common/requires_parameters.rb:11:in `requires!'
>> hash = { :password => 'pass*123', :login => 'testperson', :key => '1234567890' }
=> {:login=>"testperson", :key=>"1234567890", :password=>"pass*123"}
>> ActiveMerchant::Shipping::UPS.new(hash) => #<ActiveMerchant::Shipping::UPS:0x103d6b9c0 @last_request=nil, @options={:login=>"testperson", :key=>"1234567890", :password=>"pass*123"}, @test_mode=nil>
>>
@cadwallion
cadwallion / cad.zsh-theme
Created December 30, 2011 16:55
Using branch coloration to indicate dirty/clean in oh-my-zsh
PROMPT='%{$fg_bold[red]%}%m%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
RPROMPT='%{$reset_color%} %{$fg[yellow]%}$(todo_prompt) %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="(%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[blue]%})%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}"
@cadwallion
cadwallion / gist:1796129
Created February 11, 2012 04:22
Proper Conventions according to Cad
using System;
class NamedWelcome {
static void Main(string[] args) {
string name;
if (args.Length == 0) {
Console.WriteLine("What is your name: ");
name = Console.ReadLine();
} else {
name = args[0];
@cadwallion
cadwallion / Address.cs
Created February 11, 2012 15:01
C# AddressBook
using System;
class Address {
public string name;
public string address;
public Address(string name, string address) {
this.name = name;
this.address = address;
}
@cadwallion
cadwallion / gist:1803169
Created February 11, 2012 17:50
Tests pregenned by VS2010
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace TestProject1
{
/// <summary>
///This is a test class for AddressBookTest and is intended
///to contain all AddressBookTest Unit Tests
@cadwallion
cadwallion / output.rb
Created February 12, 2012 20:16
Namespace derivation problem
# EXPECTED OUTPUT
a = Foo::Bar.new
b = AnotherFoo::AnotherBar.new
a.thing # => [1,2,3,4]
b.thing # => [5,6,7,8]
@cadwallion
cadwallion / gist:1877106
Created February 21, 2012 15:49
Bracket API Improvements
# BEFORE
INFO  Rendered app/api/tournaments/bracket.json.jbuilder (3651.1ms)
INFO  Completed 200 OK in 3792ms (Views: 3551.0ms | ActiveRecord: 123.4ms)
# AFTER
INFO  Rendered app/api/tournaments/bracket.json.jbuilder (465.3ms)
INFO  Completed 200 OK in 593ms (Views: 360.9ms | ActiveRecord: 126.2ms)
module Namespace
class Address < ActiveRecord::Base
include Namespace::AddressMethods
end
end
===
module Namespace
class MailingAddress < ActiveRecord::Base
@cadwallion
cadwallion / gist:1951475
Created March 1, 2012 17:12
FuckLogger - when breakpoints aren't good enough
class FuckLogger
class << self
attr_reader :count
attr_accessor :logger
def fuck
add
log "FUCK#{count}"
end