Skip to content

Instantly share code, notes, and snippets.

@erynofwales
erynofwales / countdown.coffee
Created February 14, 2016 19:09
Hubot script for countdowns
# Description:
# Countdown timer. Starts at the specified number and counts down to 0.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
@erynofwales
erynofwales / AlmostEquatable.swift
Created November 7, 2015 07:14
An AlmostEquatable protocol for Swift floating point types
import Foundation
public protocol AlmostEquatable {
@warn_unused_result
func ==~(lhs: Self, rhs: Self) -> Bool
}
public protocol EquatableWithinEpsilon: Strideable {
static var Epsilon: Self.Stride { get }
}
@erynofwales
erynofwales / gist:9e132cfaaacd9f2c5ffe
Created November 2, 2015 02:36
Structs with subscript() setter don't actually set
//
// Matrices.swift
// Game
//
// Created by Eryn Wells on 2015-10-24.
// Copyright © 2015 Eryn Wells. All rights reserved.
//
/** A square matrix. */
public protocol Matrix {
@erynofwales
erynofwales / Matrix.swift
Created October 24, 2015 16:40
Error on line 23, pointing to the size() call: Cannot convert type 'Int' to expected argument type 'Int'
protocol Matrix {
typealias ElementType
static func dimensions() -> (rows: Int, cols: Int)
static func size() -> Int
init()
subscript(row: Int, col: Int) -> ElementType { get set }
}
@erynofwales
erynofwales / matrix.cc
Created August 8, 2014 17:44
Matrix multiplication in C++
#include <cstdio>
template<unsigned int N, unsigned int M>
struct Matrix
{
static const unsigned int sRows = N;
static const unsigned int sCols = M;
template <unsigned int P>
Matrix<N, P>

Keybase proof

I hereby claim:

  • I am erynofwales on github.
  • I am erynofwales (https://keybase.io/erynofwales) on keybase.
  • I have a public key whose fingerprint is 7BDF 859E 4100 1C15 1A9F 0B11 FF6C 66F5 E56D 0154

To claim this, I am signing this object:

@erynofwales
erynofwales / ipython
Last active January 1, 2016 01:29
Python seems to invoke Complex's __init__ with the string '3', but complex's (the Python built-in class) __init__ with the string '3#'
In [3]: number.Complex('3')
> /Users/eryn/Code/sibilant/sibilant/number.py(51)__init__()
-> exact = exact is not None
(Pdb) c
Out[3]: (3+0j)
In [4]: number.Complex('3#')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-4dce8b9d03a9> in <module>()
@erynofwales
erynofwales / gist:3803218
Created September 29, 2012 04:54
Generate a list of CoreFoundation, etc. classes
find -E /System/Library/Frameworks/{Foundation,Cocoa,QuartzCore}.framework \
-iregex '.*/(ns|ca).+\.h$' \
-exec awk '/@interface.+:/ {
cls = $2;
if (cls ~ /:$/) {
cls = substr(cls, 1, length(cls)-1)
}
print cls;
}' {} \;
@erynofwales
erynofwales / xmldict.py
Created April 14, 2012 02:59
Small class to convert XML data to a dictionary
from io import StringIO
from xml.etree.ElementTree import ElementTree, Element, parse, ParseError
class XMLDict(dict):
'''A dictionary-like object to represent XML data.'''
def __init__(self, xml=None):
'''Expects a string containing XML data.'''
try:
self.populate(parse(StringIO(unicode(xml))).getroot())
@erynofwales
erynofwales / gist:1424249
Created December 2, 2011 18:17
Quick setup of the root logger for Python's logging module
loghandler = logging.StreamHandler(sys.stdout)
loghandler.setFormatter(logging.Formatter(
fmt='%(asctime)s:%(name)s:%(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'))
rootlog = logging.getLogger()
rootlog.addHandler(loghandler)
rootlog.setLevel(logging.DEBUG)