Skip to content

Instantly share code, notes, and snippets.

@erynofwales
erynofwales / countdown.coffee
Created Feb 14, 2016
Hubot script for countdowns
View countdown.coffee
# Description:
# Countdown timer. Starts at the specified number and counts down to 0.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
@erynofwales
erynofwales / AlmostEquatable.swift
Created Nov 7, 2015
An AlmostEquatable protocol for Swift floating point types
View AlmostEquatable.swift
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 Nov 2, 2015
Structs with subscript() setter don't actually set
View gist:9e132cfaaacd9f2c5ffe
//
// 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 Oct 24, 2015
Error on line 23, pointing to the size() call: Cannot convert type 'Int' to expected argument type 'Int'
View Matrix.swift
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 Aug 8, 2014
Matrix multiplication in C++
View matrix.cc
#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>
View keybase.md

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 Jan 1, 2016
Python seems to invoke Complex's __init__ with the string '3', but complex's (the Python built-in class) __init__ with the string '3#'
View ipython
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 Sep 29, 2012
Generate a list of CoreFoundation, etc. classes
View gist:3803218
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 Apr 14, 2012
Small class to convert XML data to a dictionary
View xmldict.py
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 Dec 2, 2011
Quick setup of the root logger for Python's logging module
View gist:1424249
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)
You can’t perform that action at this time.