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 / download_mnist.py
Created January 8, 2019 19:26
Python script to download the MNIST dataset
from __future__ import division
from __future__ import print_function
import argparse
import gzip
import os
import sys
import urllib
try:
@goldsborough
goldsborough / database.py
Created September 3, 2014 10:07
Python Sqlite3 wrapper
###########################################################################
#
## @file database.py
#
###########################################################################
import sqlite3
###########################################################################
#
@goldsborough
goldsborough / conv.cu
Last active February 2, 2025 09:14
Convolution with cuDNN
#include <cudnn.h>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <opencv2/opencv.hpp>
#define checkCUDNN(expression) \
{ \
cudnnStatus_t status = (expression); \
if (status != CUDNN_STATUS_SUCCESS) { \
@goldsborough
goldsborough / install-gcc.sh
Last active January 1, 2025 17:14
Instructions for installing GCC >= 4.9 for PyTorch Extensions
# Instructions for installing GCC 4.9 on various platforms.
# The commands show instructions for GCC 4.9, but any higher version will also work!
# Ubuntu (https://askubuntu.com/questions/466651/how-do-i-use-the-latest-gcc-on-ubuntu/581497#581497)
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9
@goldsborough
goldsborough / postgres.py
Created September 3, 2014 10:09
Python psycopg2 wrapper
###########################################################################
#
## @file postgres.py
#
###########################################################################
import psycopg2
###########################################################################
#
@goldsborough
goldsborough / weight.cpp
Last active January 8, 2024 21:33
Weight Literals in C++
namespace Weight
{
/*
// A Unit of weight is defined by a type T to represent the
// weight, e.g. std::size_t or double (latter required for
// proper conversion between units), as well as a ratio for
// conversion between the Unit and our base unit: grams.
// The ratio defaults to a ratio of 1/1 for grams.
*/
template<typename T, typename R = std::ratio<1>>
@goldsborough
goldsborough / rnn.py
Created February 24, 2018 09:12
RNN/LSTM/GRU in NumPy
import numpy as np
np.random.seed(42)
def sigmoid(z):
return 1 / (1 + np.exp(-z))
def d_sigmoid(z):
@goldsborough
goldsborough / zip.cpp
Last active November 12, 2022 06:48
Python built-in zip() method implemented in C++
template<typename T>
class Zip
{
public:
typedef std::vector<T> container_t;
template<typename... Args>
Zip(const T& head, const Args&... args)
@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>
@goldsborough
goldsborough / dpll.py
Last active November 22, 2021 20:37
The Davis-Putnam-Logemann-Loveland (DPLL) Algorithm.
#!/usr/bin/env python3
# -- coding: utf-8 -*-
"""Module for the Davis-Putnam-Logemann-Loveland (DPLL) Algorithm."""
from __future__ import print_function
from __future__ import unicode_literals
import re
import sys