Skip to content

Instantly share code, notes, and snippets.

View CoryFoy's full-sized avatar

Cory Foy CoryFoy

View GitHub Profile
#!/usr/bin/env ruby
failures = 1
if failures.zero?
puts "0 failures!"
else
puts "Commit NOT COMMITTING! ABORT! ABORT!"
exit 1
end
var list = new List<string> { "fish", "and", "chips" };
for (int i = 0; i < list.Count; i++)
{
list.Add(list[i].ToUpper());
}
private void RetrieveMessages()
{
try
{
if (serviceUrl.Text.Length == 0)
{
if (alertHasBeenShown) { return; }
throw new DebuggingWFException("Exception occurred",
new NullReferenceException("Service URL"));
}
@CoryFoy
CoryFoy / gist:1186580
Created September 1, 2011 16:31
Skype Home Killer
using System;
using System.Runtime.InteropServices;
namespace SkypeHomeKiller
{
class Program
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
describe "Processing XML file" do
it "opens the file correctly" do
file_path = "/some/path/to.xml"
xml = "<xml>bleh</xml>"
stub_file = stub(:read).and_return(xml)
File.stub(:open).and_return(stub_file)
Parse.should_receive(:process_xml).with(xml)
Parser.process(file_path)
end
end
@CoryFoy
CoryFoy / gist:2491139
Created April 25, 2012 16:35
Rebuttal to C# Shims
//presented class (from http://www.peterprovost.org/blog/2012/04/25/visual-studio-11-fakes-part-2)
namespace ShimsDemo.SystemUnderTest
{
public class CustomerViewModel : ViewModelBase
{
private Customer customer;
private readonly ICustomerRepository repository;
public CustomerViewModel(Customer customer, ICustomerRepository repository)
@CoryFoy
CoryFoy / gist:2562415
Created April 30, 2012 20:27
This method is all over the place
# This method is all over the place.
def default_url
if @attachment_options[:default_url].respond_to?(:call)
@attachment_options[:default_url].call(@attachment)
elsif @attachment_options[:default_url].is_a?(Symbol)
@attachment.instance.send(@attachment_options[:default_url])
else
@attachment_options[:default_url]
@CoryFoy
CoryFoy / gist:3076845
Created July 9, 2012 14:20
Why is this causing a SystemStackError (stack level too deep)?
class ImportError < StandardError
attr_reader :row
def initialize(msg, row)
super(msg)
@row = row
end
def to_s
"#{self.message} (Found processing row: #{@row.inspect})"
#non SRP
def map
user = User.find(params[:id])
user.name = params[:name]
user.email = params[:email]
end
#SRP
#spec
@CoryFoy
CoryFoy / gist:4383355
Created December 26, 2012 21:46
Testing recursion in RSpec
it "calls recursively" do
MyClass.class_eval do
class << self
alias_method :mymethod_normal, :mymethod
end
end
MyClass.should_receive(:mymethod)
MyClass.mymethod_normal
end