Skip to content

Instantly share code, notes, and snippets.

@erikprice
erikprice / depth_first.py
Created March 23, 2022 00:22
Illustration of depth-first search for Hack.Diversity Learning Labs 2022-03-22
#!/usr/bin/env python
class Node:
def __init__(self, value=None, children=None):
self.value = value
self.children = children or []
self.visited = False
def make_graph():
graph = {}
@erikprice
erikprice / breadth_first.py
Created March 23, 2022 00:22
Illustration of breadth-first search for Hack.Diversity Learning Labs 2022-03-22
#!/usr/bin/env python
class Node:
def __init__(self, value=None, children=None):
self.value = value
self.children = children or []
self.visited = False
def make_graph():
graph = {}
(use 'clojure.core.async)
(def output (atom []))
(defn producer [ctrl k]
(go (loop [i 0]
(when-let [c (<! ctrl)]
(>! c [k i])
(>! ctrl c)
(recur (inc i))))))

Keybase proof

I hereby claim:

  • I am erikprice on github.
  • I am erik_price (https://keybase.io/erik_price) on keybase.
  • I have a public key whose fingerprint is 12E5 0EFF CEA1 BD87 DE0A E362 7DF0 A230 7331 5642

To claim this, I am signing this object:

@erikprice
erikprice / gist:9360897
Created March 5, 2014 03:58
Graham Scan in Haskell
grahamScan :: [Point] -> [Point]
grahamScan pts
| length pts < 3 = error "Not a polygon"
| otherwise = reverse $ scan rest (b:[a])
where (a:b:rest) = pts
scan [] acc = acc
scan pts acc = case d of
TurnsRight _ _ _ -> scan ps (c:a:stack)
_ -> scan ps (c:b:a:stack)
where (c:ps) = sortBy sortByYThenX pts
//
// CPPViewController.m
// Catalog Playlist Playback
//
// Created by Robert Crooks on 10/2/13.
// Copyright (c) 2013 Brightcove. All rights reserved.
//
#import "CPPViewController.h"
//
// CPPViewController.h
// Catalog Playlist Playback
//
// Created by Robert Crooks on 10/9/13.
// Copyright (c) 2013 Brightcove. All rights reserved.
//
#import <UIKit/UIKit.h>
//
// CPUViewController.h
// Cue Point Usage
//
// Created by Robert Crooks on 11/14/13.
// Copyright (c) 2013 Robert Crooks. All rights reserved.
//
#import <UIKit/UIKit.h>
// import the SDK master header
//
// CPUViewController.m
// Cue Point Usage
//
// Created by Robert Crooks on 11/14/13.
// Copyright (c) 2013 Robert Crooks. All rights reserved.
//
#import "CPUViewController.h"
// import the SDK master header and RAC EXTScope header
@erikprice
erikprice / DisposeSignalUpstreamOfMerge.m
Created November 17, 2013 19:28
Test to verify that in a RACSignal subscription chain, the completed event on a signal downstream of a `+merge:` invokes the disposable of an upstream signal. (ReactiveCocoa)
it(@"should propagate disposal to signals upstream of a +merge: to which it is subscribed when it completes", ^{
__block BOOL disposed1 = NO;
__block BOOL disposed2 = NO;
RACSignal *upstream1 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> _) {
return [RACDisposable disposableWithBlock:^{
disposed1 = YES;
}];
}];
RACSignal *upstream2 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> _) {
return [RACDisposable disposableWithBlock:^{