Skip to content

Instantly share code, notes, and snippets.

@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 / 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: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 / 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: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});
}