Skip to content

Instantly share code, notes, and snippets.

View justinwyer's full-sized avatar

Justin Wyer justinwyer

  • Johannesburg, South Africa
View GitHub Profile
@justinwyer
justinwyer / A200.hs
Created December 9, 2022 12:12
advent of code 2022 day 2
module A200 where
import Data.List.Split (splitOn)
data Symbol = Rock | Paper | Scissors
data Strategy = Win | Lose | Draw
data Match = Match { opponent :: Symbol, player :: Symbol }
strategy :: Symbol -> Strategy -> Match
strategy o s = Match o (case s of
Win -> case o of

[Know about it][Understanding][Clear understanding]

NOVICE

CONCEPTS

  • xxx Immutable Data
  • xxx Second-Order Functions
  • xxx Constructing & Destructuring
  • xxx Function Composition
  • xxx First-Class Functions & Lambdas
diff --git a/spec/unit/pluginmanager_spec.rb b/spec/unit/pluginmanager_spec.rb
index be531c8..d99fba0 100755
--- a/spec/unit/pluginmanager_spec.rb
+++ b/spec/unit/pluginmanager_spec.rb
@@ -6,7 +6,7 @@ module MCollective
describe PluginManager do
before do
class MCollective::Foo; end
-
+ @config = mock
from psycopg2 import connect
from Levenshtein import *
conn = connect("dbname=education user=Jwyer host=localhost")
id_look_up = {}
candidates = []
cursor = conn.cursor()
cursor.execute("select id, name from school")
for row in cursor.fetchall():
import codecs
import requests
import multiprocessing
def process_url(page):
print page
url = "http://www.southafricaschools.co.za/schools2?page=%ld&tid=13&tid_1=All&tid_2=All&title=" % (page)
r = requests.get(url)
out = codecs.open('eastern-cape/page-%ld' % (page), 'w', 'utf-8')
out.write(r.text)
@justinwyer
justinwyer / DeckTest.m
Created February 10, 2013 19:49
Example of mocking.
- (void)testShouldKnowCardsCanBeAddedToDeck {
Deck *deck = [Deck new];
Card *card = [[Card alloc] initWithContents:@"Test Card"];
id cardsMock = [OCMockObject mockForClass:[NSMutableArray class]];
[[cardsMock expect] addObject:card];
deck.cards = cardsMock;
[deck addCard:card atTop:NO];
@justinwyer
justinwyer / Card.m
Created February 10, 2013 18:47
Refactored match method
- (int)match:(NSArray *)cards {
return [cards containsObject:self];
}
@justinwyer
justinwyer / gist:4750573
Created February 10, 2013 18:44
Card equals tests and evolving implementations
// FIRST TEST
- (void)testShouldKnowCardsWithSameContentsAreEqual {
Card *card = [[Card alloc] initWithContents:@"Test Card"];
Card *equalCard = [[Card alloc] initWithContents:@"Test Card"];
STAssertEqualObjects(card, equalCard, @"Cards with the same content should be equal");
}
// RED isEqual is not yet overriden
// GREEN returns YES
- (BOOL)isEqual:(id)other {
@justinwyer
justinwyer / Card.m
Created February 10, 2013 18:18
Implementation for TDD
@implementation Card {
}
- (int)match:(NSArray *)cards {
int score = 0;
for (Card *card in cards) {
if ([card.contents isEqualToString:self.contents]) {
score = 1;
break;
}
}
@implementation CardTest
- (void)testShouldKnowCardCannotMatchEmptyCardList {
Card *card = [Card new];
NSArray *otherCards = [NSArray new];
STAssertEquals(0, [card match:otherCards], @"Should not match empty card list.");
}
- (void)testShouldMatchCardWhenCardListContainsCardWithSameContent {
Card *card = [[Card alloc] initWithContents:@"Test Card"];
Card *matchingCard = [[Card alloc] initWithContents:@"Test Card"];