Skip to content

Instantly share code, notes, and snippets.

View goldsborough's full-sized avatar
🔨
Fixing things

Peter Goldsborough goldsborough

🔨
Fixing things
View GitHub Profile
@goldsborough
goldsborough / hashtable.cpp
Created July 31, 2016 16:26
Quick and dirty separately-chained Hashtable.
#include <functional>
#include <iostream>
#include <stdexcept>
#include <string>
template <typename Key, typename Value>
class HashTable {
public:
using size_t = unsigned long;
using HashFunction = std::function<size_t(const Key&)>;
@goldsborough
goldsborough / queue.cpp
Created July 31, 2016 16:26
Quick and dirty queues
#include <cassert>
#include <iostream>
template <typename T>
class ListQueue {
public:
using size_t = unsigned long;
ListQueue() : _head(nullptr), _tail(nullptr), _size(0) {
}
@goldsborough
goldsborough / stack.cpp
Created July 31, 2016 16:26
Quick and dirty stack
#include <cassert>
#include <iostream>
template <typename T>
class ArrayStack {
public:
using size_t = unsigned long;
static constexpr size_t MINIMUM_CAPACITY = 8;
static constexpr size_t GROWTH_FACTOR = 2;
@goldsborough
goldsborough / binomial-heap.cpp
Created August 3, 2016 21:11
A binomial heap in C++
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <functional>
#include <iostream>
#include <unordered_map>
#include <vector>
template <typename T>
class BinomialHeap {
@goldsborough
goldsborough / .zshrc
Created August 31, 2016 17:05
My ZSH config
# Path to your oh-my-zsh installation.
export ZSH=/Users/goldsborough/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="agnoster"
# Uncomment the following line to use case-sensitive completion.
@goldsborough
goldsborough / fun.scss
Created September 6, 2016 13:44
Fun with SCSS
@mixin media-query($type) {
@if $type == phone {
@media only screen and (min-width: 320px) {
@content;
}
} @else if $type == tablet {
@media only screen and (min-width: 768px) {
@content;
}
} @else {
@goldsborough
goldsborough / quicksort.scss
Last active September 6, 2016 19:24
Quicksort in CSS (SASS)
@function swap($list, $first, $second) {
@if ($first == $second) {
@return $list;
}
$temp: nth($list, $first);
$list: set-nth($list, $first, nth($list, $second));
$list: set-nth($list, $second, $temp);
@return $list;
}
@goldsborough
goldsborough / benchmark.py
Created October 2, 2016 17:18
A benchmarking decorator that can handle recursive functions
def benchmark(function):
"""
Registers a function for benchmarking.
Args:
function (func): The function to benchmark.
Returns:
A new function with benchmarking functionality.
"""
@goldsborough
goldsborough / enable_timeit.py
Last active May 10, 2017 00:39
A benchmarking decorator for easy use of timeit
def enable_timeit(number=1000, repeat=1):
"""
Adds a `timeit` member function to the decorated function.
This function allows for configuration of how `timeit` will be executed for
the decorated function. Note that ultimately, `timeit.repeat()` will be
called, not `timeit.timeit()`.
Args:
number (int): How often `timeit` should execute the function.
@goldsborough
goldsborough / heap.go
Created October 23, 2016 19:00
A heap in Go
package heap
type Heap struct {
data []int
compare func(int, int) bool
}
func New() *Heap {
return &Heap{
data: []int{-1},