Skip to content

Instantly share code, notes, and snippets.

@piquan
piquan / macro-closure-demo.lisp
Last active October 2, 2021 02:10
Demonstration of using a closure over a macro
;; Closed-over macro demo
;;
;; To answer a question, yes, you can close over macro definitions.
;; There's lots of ways to do that!
;;
;; The key is to remember that macros are "code-rewriting" functions.
;; When code is compiled, each time the macro is used, the macro
;; definition runs. Whatever it returns is what gets compiled.
;; Here's some examples.
@piquan
piquan / nickmid.c
Created August 18, 2018 23:03
Quick and dirty MIDI note reader
// Useful link:
// http://www.personal.kent.edu/~sbirch/Music_Production/MP-II/MIDI/an_introduction_to_midi_contents.htm
#include <assert.h>
#include <err.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@piquan
piquan / gauss_prime_test.py
Last active June 19, 2018 02:41
Produce images to test whether the Gaussian primes have a visibly-obvious pattern
#! /usr/bin/env python3
import base64
import gzip
import math
import random
import sys
import time
# This requires Pillow, a fork of PIL. Please uninstall PIL if you have
@piquan
piquan / Dockerfile
Created May 20, 2018 21:34
Bootstrap problem during cwebbin build
FROM debian:stretch-slim
RUN apt-get update && apt-get install -y texlive-binaries build-essential
# Note that ADD will automatically extract tarballs.
ADD cwebbin-22p.tar.gz /tmp/
ADD cweb-3.64c.tar.gz /tmp/cwebbin-cwebbin-22p/
ADD cwebbin.diff /tmp/cwebbin-cwebbin-22p/
WORKDIR /tmp/cwebbin-cwebbin-22p/
RUN patch -p1 < cwebbin.diff
/* HTTP GET Example using plain POSIX sockets
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
@piquan
piquan / sweep.ino
Created July 26, 2017 04:13
A circuit where I accidentally had two modulation sources, and made for an interesting frequency pattern.
// Today I learned that if you are sloppy with your parts bin
// organization, and mean to grab a piezo speaker and instead grab a
// piezo buzzer with a built-in oscillator, you get an interesting
// spectrum from a frequency sweep. The sum-and-difference signals
// and their harmonics make neat patterns in a spectrogram!
//
// This originally was supposed to use a piezo speaker, so the
// amplifier below is based around that. However, I grabbed the wrong
// part; I grabbed a buzzer with an internal 2 kHz oscillator, similar
// to Adafruit's part 1536. (1536 is 5v tolerant, but I meant to grab
@piquan
piquan / ca.py
Created May 17, 2017 07:01
Simple program to look at elementary cellular automata
#! ./venv/bin/python3
# Q to quit
# R to randomize
# S to make a simple initial state
# + or - to change rule number by 1 (watch the title bar)
# Digits to enter the rule number; you may need to prefix it with some 0s.
# Space to pause / resume
import random
@piquan
piquan / cuda_mod64.ptx
Last active March 25, 2017 05:56
CUDA compile of 64-bit *c = a % b; on compute capability 3.7
//--------------------- .text._Z4testmmPm --------------------------
.section .text._Z4testmmPm,"ax",@progbits
.sectioninfo @"SHI_REGISTERS=14"
.align 64
.global _Z4testmmPm
.type _Z4testmmPm,@function
.size _Z4testmmPm,(.L_28 - _Z4testmmPm)
.other _Z4testmmPm,@"STO_CUDA_ENTRY STV_DEFAULT"
_Z4testmmPm:
.text._Z4testmmPm: