Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Benjamin Bolte codekansas

🏠
Working from home
View GitHub Profile
@codekansas
codekansas / parse_webtime.py
Created Dec 3, 2020
Script to parse the Webtime Tracker CSV file and plot it
View parse_webtime.py
#!/usr/bin/env python
import argparse
from datetime import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
View bookend.scad
// Total dimensions.
height = 120;
width = 40;
padding = 10;
module col(h, sph=false) {
difference() {
cube([width, width, h]);
if (sph)
translate([width / 2, width / 2, h])
View combination_lock_riddle.scad
/*
A combination for a lock has 3 wheels, X, Y, and Z, each of which
can be set to eight different positions. The lock is broken and when
any two wheels of the lock are in the correct position, the lock
will open. Thus, anyone can open the lock after 64 tries (let A and
B run through all possible permutations). However, the safe can be
opened in fewer tries! What is the minimum number of tries that can
be guaranteed to open the lock?
*/
View two_students_riddle.py
#!/usr/bin/env python3
"""Problem statement:
There is a teacher and 2 students in a classroom. The students are A and B.
The teacher thinks of 2 positive integers and tells the sum of those numbers
to student A without student B hearing it. Then tells their product to student
B without student A hearing it. After this, the teacher asks the 2 students
what was the 2 numbers.
First student A says: I don't know.
View dishwasher-chopstick-holder.scad
thickness = 3;
padding = 1;
slat_size = 3;
short_length = 46.36;
long_length = 61.76;
height = 51.76;
first_indent = 15.92;
second_indent = 29.97;
View laptop-stand.scad
// Parametric OpenSCAD design for a laptop stand.
// Laptop dimensions.
lwid = 304.1;
lhei = 212.4;
ldep = 15;
// Stand long dimensions.
slen = 200;
sswid = 60;
@codekansas
codekansas / bert_pytorch.py
Created Nov 1, 2018
Implementation of the transformer block used by BERT
View bert_pytorch.py
#!/usr/bin/env python3
"""Implementation of the transformer block used by BERT.
I saw an excellent implementation of the complete BERT model here:
https://github.com/codertimo/BERT-pytorch
I re-wrote a simplified version of the transformer block below. This was mainly
for my own understanding (so that I could get a grasp of the dimensions and
how the whole attention mechanism works), but I tried to document it pretty
thoroughly so that other people can understand it without having to go too far
@codekansas
codekansas / binarized_nn_inference.cpp
Created Nov 1, 2017
Efficient binarized neural network inference
View binarized_nn_inference.cpp
/* Binarized neural network inference example.
This shows a simple C++ program for doing inference on
binarized neural networks. To do this efficiently, the code
below makes use of the "bitset" class, which uses the "popcnt"
instruction to count the number of 1's that show up in the
matrix product, in constant time. This means that a matrix
multiplication between a (A, B) and (B, C) matrix takes
O(A * C) time; in other words, each value in the output matrix
is computed in constant time.
*/
@codekansas
codekansas / factors.scm
Created Sep 18, 2017
Program for finding all the factors of a number in Scheme.
View factors.scm
; Finds all factors of a number in O(sqrt n) time.
(define (factors n)
(define (@factors n i a)
(cond ((= (modulo n i) 0) (@factors (quotient n i) i (cons i a)))
((>= (* i i) n) (if (= 1 n) a (cons n a)))
(else (@factors n (+ i 1) a))))
(@factors n 2 `()))
; Multiples all the elements in a list.
(define (mult l)
View adv_domain_transfer.py
#!/usr/bin/env python
"""The training script for the DANN model."""
from __future__ import division
from __future__ import print_function
import csv
import os
import itertools
import sys