Skip to content

Instantly share code, notes, and snippets.

@wulab
wulab / hpcalc.md
Last active December 31, 2022 16:00

HP Calculator S/N Decoder

Pre-1996 models only. The format of their serial numbers is:

YYWWCNNNNN

where:

  • YY is the year number
  • WW is the week number
@wulab
wulab / piano.py
Created October 1, 2022 05:41 — forked from av1d/piano.py
Simple 1 octave piano in Python with live input
import numpy as np
import simpleaudio as sa
import os, sys, termios, time, tty
# Key mapping:
# W E T I U
# A S D F G H J K
#
# Which translates to:
# C#D# F#G#A#
@wulab
wulab / lisp.lua
Created September 29, 2022 17:51 — forked from polymeris/lisp.lua
Toy Lisp interpreter in Lua / LPEG
local lpeg = require'lpeg'
local P, R, S = lpeg.P, lpeg.R, lpeg.S --patterns
local C, Ct = lpeg.C, lpeg.Ct --capture
local V = lpeg.V --variable
local parser = P {
'program', -- initial rule
program = Ct(V'sexpr' ^ 0),
wspace = S' \n\r\t' ^ 0,
atom = V'boolean' + V'integer' + V'string' + V'symbol',
@wulab
wulab / Student Grading.R
Last active May 10, 2022 20:07
Student grading without if/else or for loop
grade <- function(score) {
levels <- c("F", "D", "C", "B", "A")
return( levels[(score>80)+(score>60)+(score>40)+(score>20)+(score>0)] )
}
sum({*range(3, 1000, 3), *range(5, 1000, 5)})
import types
the_empty_stream = ()
def cons(x, y):
return (x, y)
def cons_stream(x, y):
assert isinstance(y, types.LambdaType)
return cons(x, y)
def divide(n, d):
while True:
yield n // d
n = (n % d) * 10
def next_n(n, g):
return [next(g) for _ in range(n)]
def input(number):
pi = divide(355, 113)
class ElasticsearchAT56 < Formula
desc "Distributed search & analytics engine"
homepage "https://www.elastic.co/products/elasticsearch"
url "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.16.tar.gz"
sha256 "6b035a59337d571ab70cea72cc55225c027ad142fbb07fd8984e54261657c77f"
bottle :unneeded
keg_only :versioned_formula
(load "rand.scm")
(load "monte-carlo.scm")
(define (make-dice sides)
(lambda () (+ (modulo (rand) sides) 1)))
;; rolling a 7 and activating the robber
(define (catan-robber-activation)
(let ((d1 (make-dice 6))
(d2 (make-dice 6)))
;; Representing dense polynomials
(define (make-dense* var term-list)
(cons var term-list))
(define var car)
(define term-list cdr)
(define (make-term-list term-list min-order)
(if (>= (order term-list) min-order)