Skip to content

Instantly share code, notes, and snippets.

@RichardKelley
RichardKelley / gist:8050626
Created December 20, 2013 05:11
This is a simple example using check++ with Google Test. The func variable holds a function that represents the property that addition of ints is commutative. When we pass that function into the check function, check generates random ints to test the property and prints statistics on success or failure.
TEST(BasicTest, CommutativityTest) {
// declare property
auto func = [](int i, int j) {
return i + j == j + i;
};
// test property
checkpp::check(checkpp::Property<int,int>{func});
}
@RichardKelley
RichardKelley / mean.R
Last active August 29, 2015 13:57
Basic Arithmetic Mean Calculation with R.
count = 10
x = seq(from=1, to=count, by=1)
# calculating the mean is easy - just use the built-in mean function.
x_mean = mean(x)
# In this easy case, we can confirm that the mean is the same whether we use R or do the math by hand.
# We're using a summation formula to figure out the sum of the numbers from 1 to count.
x_sum_analytic = (count * (count + 1))/2
@RichardKelley
RichardKelley / gist:12ae0d6dc0d13e8578f1
Created April 9, 2015 02:26
This model implements a CNN in Torch7. It will work with MNIST input data.
model = nn.Sequential()
model:add(nn.SpatialConvolution(1, 6, 5, 5))
model:add(nn.SpatialMaxPooling(2,2,2,2))
model:add(nn.SpatialConvolution(6, 16, 5,5))
model:add(nn.SpatialMaxPooling(2,2,2,2))
model:add(nn.View(16 * 5 * 5))
model:add(nn.Linear(16 * 5 * 5, 256))
model:add(nn.PReLU())
model:add(nn.Dropout(0.5))
model:add(nn.Linear(256, 10))
@RichardKelley
RichardKelley / gist:eef2df52f7fa39fe8441e08b8e64cbae
Created September 20, 2016 02:51
The beginning of a lisp interpreter, implemented in Scheme.
(define (atom? x)
(and (not (pair? x))
(not (null? x))))
(define (assoc. x y)
(cond ((equal? (caar y) x) (cadar y))
(#t (assoc. x (cdr y)))))
(define (eval. e a)
(cond
@RichardKelley
RichardKelley / gist:932201c5352786364598ce03bb696bda
Created September 26, 2016 16:03 — forked from jlongster/gist:1712455
traditional lisp macros
;; outlet code for implementing traditional macro expansion
;; macros
(define (expand form)
(cond
((variable? form) form)
((literal? form) form)
((macro? (car form))
(expand ((macro-function (car form)) form)))
@RichardKelley
RichardKelley / pytorch_xor.py
Created July 13, 2017 07:25
Using Pytorch to learn xor
import numpy as np
import torch
import torch.nn as nn
from torch.autograd import Variable
import torch.nn.functional as F
import torch.optim as optim
class XorNet(nn.Module):
def __init__(self):
super().__init__()
@RichardKelley
RichardKelley / CMakeLists.txt
Created August 2, 2017 14:13 — forked from linknum23/CMakeLists.txt
CMakeList configuration for compiling ROS and Driveworks on a Tegra (Drive PX2)
cmake_minimum_required(VERSION 3.1)
project(dw_wrapper)
set (CMAKE_CXX_STANDARD 11)
# FindDriveworks.cmake, ArchConfiguration.cmake, and LibFindMacros.cmake were needed for my setup they are taken from driveworks/samples/cmake/
# ArchConfiguration.cmake was the only file that needed small changes, remove the fatal error on line 17 and add the following lines in its place
# set(VIBRANTE TRUE)
# add_definitions(-DVIBRANTE)
# this is the path I placed the driveworks cmake files in
@RichardKelley
RichardKelley / probit.rkt
Last active October 10, 2017 04:39
Probit Function in Racket. This gives quantiles of the standard normal, which ends up being trickier to implement than you might guess. We follow the "quantile mechanics" approach of Steinbrecher and Shaw: http://www.homepages.ucl.ac.uk/~ucahwts/lgsnotes/EJAM_Quantiles.pdf.
#lang racket
(define (sum-to n term)
(letrec ((S (lambda (acc k)
(cond
[(eq? k 0) (+ (term 0) acc)]
[else (S (+ acc (term k)) (- k 1))]))))
(S 0.0 n)))
(define vs '())
@RichardKelley
RichardKelley / structhash.cpp
Created January 16, 2018 19:56
Computing the SHA-256 Hash of a C++ Structure in Memory
#include "PicoSHA2/picosha2.h"
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
struct person {
std::string name;
% A Simple LaTeX Example
% Author: Richard C Kelley
% This is a comment. A comment begins with a '%' and extends to the
% end of the line.
% We always start our LaTeX documents by specifying the document class
% we want to use. There are several document classes available that
% you could use if you wanted - article, book, report, letter,
% etc. For many purposes, though, all you need is the article