Instantly share code, notes, and snippets.

View conv_matrix.py
import numpy as np
green_matrix = np.array(
[
[1, 1, 1, 0, 0],
[0, 1, 1, 1, 0],
[0, 0, 1, 1, 1],
[0, 0, 1, 1, 0],
[0, 1, 1, 0, 0],
]
View add-to-shell.sh
ZONE="us-west2-b"
INSTANCE_NAME="fastai-class-fall-2018"
function fastai_ssh() {
gcloud compute ssh \
--zone=$ZONE \
jupyter@$INSTANCE_NAME \
-- -L 8080:localhost:8080
}
View easy-gnu.sh
export IMAGE_FAMILY="pytorch-1-0-cu92-experimental" # or "pytorch-1-0-cpu-experimental" for non-GPU instances
export ZONE="us-west2-b" # budget: "us-west1-b"
export INSTANCE_NAME="my-fastai-instance"
export INSTANCE_TYPE="n1-highmem-8" # budget: "n1-highmem-4"
# budget: 'type=nvidia-tesla-k80,count=1'
gcloud compute instances create $INSTANCE_NAME \
--zone=$ZONE \
--image-family=$IMAGE_FAMILY \
--image-project=deeplearning-platform-release \
View lifetime.c
struct e {
int a;
void *b;
};
// IRC said this was fine, equivalent to a memcpy (also use memcpy_s)
void init(struct e *example) { *example = ((struct e){.a = 0, .b = NULL}); }
View Makefile
CC := clang
CFLAGS := -Wall -ggdb
src = $(wildcard *.c)
obj = $(src:.c=.o)
LDFLAGS = -fsanitize=address
myprog: $(obj)
$(CC) -o $@ $^ $(LDFLAGS)
View keys.js
class T {
[() => {}]() {
return 10;
}
}
class T_ {
[() => {}] = () => ({});
}
View cheatsheet.matlab
% Matlab cheat sheet
% Author: Steven Van Vaerenbergh
% Last version: https://gist.github.com/steven2358/7578242
%% SYSTEM
% seed a random generator
seed = 1;
rng('default');
View 1-easy.js
// Create a Promise that resolves after ms time
var timer = function(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};
// Repeatedly generate a number starting
// from 0 after a random amount of time
var source = async function*() {
View async-gen.js
async function* handle() {
let i = 0;
while (true) {
yield i++;
}
}
const sleep = () => new Promise(r => setTimeout(() => r(undefined), 1000));
async function main() {
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