Skip to content

Instantly share code, notes, and snippets.

View benknoble's full-sized avatar
💚
reproductive rights are human rights

D. Ben Knoble benknoble

💚
reproductive rights are human rights
View GitHub Profile
import argparse
from mock import Mock
m = Mock()
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
query_group = subparsers.add_parser('query')
add_group = subparsers.add_parser('add')
@jboner
jboner / latency.txt
Last active July 6, 2024 06:48
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active July 4, 2024 17:31
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@funrep
funrep / lisp.sml
Created June 3, 2014 17:42
Unfinished (but working) lisp interpreter in SML.
(* simple lisp interpreter *)
type sym = string
datatype exp = Sym of sym
| List of exp list
| Num of int
| Str of string
| Bool of bool
| Lam of (sym list) * ((sym * exp) list) * exp
@lnznt
lnznt / chcc.bashrc
Created November 30, 2014 00:45
[bash function] change environment variable CC/CXX (.bashrc)
function chcc {
case "$1" in
--unset) unset CC ; unset CXX ;;
clang) export CC=clang ; export CXX=clang++ ;;
gcc) export CC=gcc ; export CXX=g++ ;;
distcc) export CC=distcc ; export CXX=distcc ;;
llvm-gcc) export CC=llvm-gcc ; export CXX=llvm-g++- ;;
llvm-gcc-4.8) export CC=llvm-gcc-4.8 ; export CXX=llvm-g++-4.8 ;;
arm) export CC=arm-linux-gnueabi-gcc ; export CXX=arm-linux-gnueabi-g++ ;;
@romainl
romainl / _rnb.md
Last active August 12, 2021 21:56
RNB, a Vim colorscheme template
@AndrewRadev
AndrewRadev / dsf.vim
Last active November 5, 2018 05:01
Delete surrounding function call
" Delete surrounding function call
" Relies on surround.vim
"
" function_call(cursor_here) => dsf => cursor_here
"
" Try `dsf` with more complicated structures:
"
" nested(function_call(cursor_here))
" nested(cursor_here(chewy_center))
" One::Two.new([cursor_here])
@benknoble
benknoble / LinkedListImplTest.java
Last active February 13, 2017 20:02
Comp 410 Spring 2017 Test cases
package LinkedListA0;
import static org.junit.Assert.*;
import org.junit.Test;
public class LinkedListImplTest {
@Test
public void clearEasy() {
@chrisleee
chrisleee / BSTTest.java
Last active February 21, 2017 01:10
COMP 410 Assignment 2 BST Tests
package BST_A2;
import static org.junit.Assert.*;
import org.junit.Test;
public class BSTTest {
@Test
public void testFindMin() {
@PeterRincker
PeterRincker / SortGroup.vim
Last active March 17, 2024 04:51
Sort groups of lines in vim
" :[range]SortGroup[!] [n|f|o|b|x] /{pattern}/
" e.g. :SortGroup /^header/
" e.g. :SortGroup n /^header/
" See :h :sort for details
function! s:sort_by_header(bang, pat) range
let pat = a:pat
let opts = ""
if pat =~ '^\s*[nfxbo]\s'
let opts = matchstr(pat, '^\s*\zs[nfxbo]')