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 / BTree.java
Created December 17, 2015 01:33
A B-tree.
import java.util.*;
public class BTree<Key extends Comparable>
{
public BTree(int degree)
{
if (degree <= 0)
{
throw new IllegalArgumentException("Degree must be greater 0!");
}
@goldsborough
goldsborough / best.cpp
Created December 19, 2015 15:44
C++ Template functions to find the best (e.g. max/min) of something.
template<typename Iterator, typename Value>
struct Position
{
Position(const Iterator& iterator_, const Value& value_)
: iterator(iterator_)
, value(value_)
{ }
Iterator iterator;
@goldsborough
goldsborough / utility.cpp
Created December 20, 2015 23:08
Current collection of generic utility functions for one of my projects.
#ifndef UTILITY_HPP
#define UTILITY_HPP
#include "global.hpp"
#include <algorithm>
#include <chrono>
#include <cmath>
#include <ctime>
#include <iterator>
@goldsborough
goldsborough / graph-exists.cpp
Last active January 9, 2016 21:01
Havel-Hakimi algorithm to determine if a graph with the given list of degree is possible.
bool graph_exists(std::vector<int> degrees)
{
auto remaining = degrees.size();
for (auto i = degrees.begin(), end = degrees.end(); i != end; ++i)
{
std::sort(i, end, std::greater<int>());
if (*i == 0) return true;
@goldsborough
goldsborough / client.cpp
Created April 5, 2016 23:32
A TCP/IP example implementation
#include <iostream>
#include <netdb.h>
#include <netinet/in.h>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
@goldsborough
goldsborough / gauss.py
Created May 11, 2016 12:13
Gauss Algorithm
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import re
import sys
import numpy as np
@goldsborough
goldsborough / hashtable.c
Created May 26, 2016 20:49
HashTable in C
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "hashtable.h"
#include <stdio.h>
@goldsborough
goldsborough / assignment3.c
Created June 14, 2016 20:04
Working IPv6 Neighbor Discovery
#include <arpa/inet.h>
#include <asm/byteorder.h>
#include <assert.h>
#include <errno.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
#include <netinet/icmp6.h>
#include <netinet/ip6.h>
#include <stdio.h>
#include <stdlib.h>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
def pca(X, cutoff=2):
"""
Performs principal components analysis on a data-set.
@goldsborough
goldsborough / hash_functions.py
Last active July 31, 2016 19:05
Some popular hash function implementations in Python.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import random
WORD_SIZE = 32
WORD_MAX = 1 << 32
WORD_MASK = WORD_MAX - 1