Skip to content

Instantly share code, notes, and snippets.

View keithnorm's full-sized avatar

Keith Norman keithnorm

View GitHub Profile
@keithnorm
keithnorm / UICollectionView+ScrollViewAnimateable.swift
Created May 25, 2016 14:45
enable animating a scroll view's contentOffset property with custom easing
//
// UICollectionView+ScrollViewAnimateable.swift
// persimmon
//
// Created by Keith Norman on 5/24/16.
// Copyright © 2016 Good Eggs. All rights reserved.
//
/// Based on https://github.com/plancalculus/MOScrollView. This allows animating contentOffset with a timing function. It's not possible to animate contentOffset via a CAAnimation. It is possible to animate bounds but then scrollview delegate methods don't get called which may be an issue if the animation exposes new cells in a table view or collection view and you expect those cells to render when the scroll into view.
@keithnorm
keithnorm / observable.swift
Created February 5, 2015 00:49
observable pattern pseudo code in swift
class ViewController {
var observable<[String]>
public var viewModel: ViewModel? {
didSet {
self.observable = Observable(viewModel?.someProperty)
self.observable.bind { [unowned self] (someProperty) in
if let dataSource = self.dataSource {
dataSource.someProperty = someProperty
}
@keithnorm
keithnorm / delegator.coffee
Created December 31, 2014 17:21
A JavaScript implementation of the Rails delegate class method (kind of)
class Delegator
@delegate: []
constructor: ->
for delegate in @constructor.delegate
target = delegate[delegate.length - 1].to
for attribute in delegate when not attribute.to
property = {}
if /\(\)$/.test attribute
@keithnorm
keithnorm / UILabel+StyleExtensions.h
Last active August 29, 2015 14:05
A category to allow setting dynamic type via Classy
#import <UIKit/UIKit.h>
@interface UILabel (StyleExtensions)
@property (nonatomic, strong) NSString *fontTextStyle;
@end
@keithnorm
keithnorm / kway-mergesort.c
Created March 28, 2014 16:06
k-way merge on 2D array of sorted arrays using bottom up mergesort
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void merge(int **a, int start, int end, int sz) {
int *a1 = a[start];
int *a2 = a[end];
int res[sz];
int i = 0;
int j = 0;
import math
import itertools
def length(x, y):
dx = x[0] - y[0]
dy = x[1] - y[1]
return math.sqrt(dx*dx + dy*dy)
def solve_tsp_dynamic(points):
#calc all lengths
@keithnorm
keithnorm / heap.js
Created August 11, 2013 01:21
Implementing a heap in Javascript as part of the Stanford Algorithms course on Coursera
// a heap is good at finding min in O(log n) time
// it supports the following methods:
// - insert
// - getMin
// - deleteMin
// it gets initialized with an array
// it stores its data internally as an array, but we visualize it as a binary tree
// 4
// / \
// 5 6
diff --git a/public/js/client.js b/public/js/client.js
index feb581f..95bcd9b 100644
--- a/public/js/client.js
+++ b/public/js/client.js
@@ -8,6 +8,7 @@ var stream;
var room_count = 0;
var pc = new webkitRTCPeerConnection(configuration);
var connected = false;
+var shouldInitConnection = false;
var mediaConstraints = {
$target = 15.05
$items = [2.25, 2.75, 3.35, 3.55, 4.20, 5.80].select{|item| item <= $target}
def main(arr)
(1..arr.length).each do |n|
# this finds all combinations of subarrays http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-combination
# given something like [1, 2, 3, 4]
# each iteration of this loop contains something like
# [[1], [2], [3], [4]]
# [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
{
education = (
{
school = {
id = 110086219021467;
name = Harvey;
};
type = "High School";
year = {
id = 143018465715205;