Skip to content

Instantly share code, notes, and snippets.

Paul Hendricks paulhendricks

Block or report user

Report or block paulhendricks

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View damage.py
import matplotlib.pyplot as plt
import numpy as np
# settings
n_iterations = 100000
# great sword
initiative = np.random.randint(1, 21, size=(n_iterations,)) + 2
damage = np.random.randint(1, 7, size=(2, n_iterations)).sum(axis=0) + 2
View print_list.py
spam = ['apple', 'banana', 'tofu', 'cats']
result = ', '.join(spam[:-1]) + ', and ' + spam[-1]
print(result)
View words_with_friends.py
"""
Iterates through all possible word combinations and checks if they are in the
English dictionary; if so, calculates the value for that play. Finally, prints
all solutions in descending order of value.
Setup: pip install pyenchant
Usage: python words_with_friends.py --letters "a,r,f,i,b,a,o" --values "1,1,4,4,1,4,1,1"
"""
import argparse
import enchant
View effective_modern_cmake.md

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

View effective_modern_cmake.md

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@paulhendricks
paulhendricks / latency.txt
Created May 28, 2018 — forked from understeer/latency.txt
HPC-oriented Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference/hit 1.5 ns 4 cycles
Floating-point add/mult/FMA operation 1.5 ns 4 cycles
L2 cache reference/hit 5 ns 12 ~ 17 cycles
Branch mispredict 6 ns 15 ~ 20 cycles
L3 cache hit (unshared cache line) 16 ns 42 cycles
L3 cache hit (shared line in another core) 25 ns 65 cycles
Mutex lock/unlock 25 ns
L3 cache hit (modified in another core) 29 ns 75 cycles
View mnist_cnn.py
'''Trains a simple convnet on the MNIST dataset.
Gets to 99.25% test accuracy after 12 epochs
(there is still a lot of margin for parameter tuning).
16 seconds per epoch on a GRID K520 GPU.
'''
from __future__ import print_function
import keras
from keras.datasets import mnist
View gist:058874bc03f1508eb98d9dac8e0e2ae0
#!/usr/bin/env julia
using Luxor
Drawing(500, 500, "/tmp/julia-flowers.png")
background("white")
function juliaflowers(cpos::Point, radius; petals=30, outercircleratio=0.75, innercircleratio=0.65)
# clockwise, from bottom LEFT...
points3 = ngon(cpos, radius, 3, pi/6, vertices=true)
View theano_xor.py
import numpy as np
import theano; import theano.tensor as T; import theano.tensor.nnet as nnet
X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]).reshape((4, 2))
y_train = np.array([0, 1, 1, 0])
x = T.dvector('x')
y = T.dscalar('y')
theta_0 = theano.shared(np.array(np.random.rand(3, 3), dtype=theano.config.floatX), name='theta_0')
theta_1 = theano.shared(np.array(np.random.rand(4, 1), dtype=theano.config.floatX), name='theta_1')
layer_1 = nnet.sigmoid(T.dot(theta_0.T, T.concatenate([np.array([1], dtype=theano.config.floatX), x])))
layer_2 = T.sum(nnet.sigmoid(T.dot(theta_1.T, T.concatenate([np.array([1], dtype=theano.config.floatX), layer_1]))))
View example.R
# Good - I can customize the way the file is read in
df <- read.csv("foo.csv", stringsAsFactors = FALSE)
df <- read.table("foo.txt", delimiter = "\t", stringsAsFactors = FALSE)
df <- read.table("foo.txt", delimiter = "|", stringsAsFactors = FALSE)
analyze(df)
# Bad - arguments are needed to customize how foo.csv is read in
analyze("foo.csv", stringsAsFactors = FALSE)
analyze("foo.txt", delimiter = "\t", stringsAsFactors = FALSE)
You can’t perform that action at this time.