Skip to content

Instantly share code, notes, and snippets.

#include <assert.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/timerfd.h>
00: 902 !..! .... ..!. mov r0, 2
01: cf0 !!.. !!!! .... mov [0xf0], r0
02: 901 !..! .... ...! mov r0, 1
03: cf1 !!.. !!!! ...! mov [0xf1], r0
04: 912 !..! ...! ..!. mov r1, 2
05: 923 !..! ..!. ..!! mov r2, 3
06: dff !!.! !!!! !!!! mov r0, [0xff]
07: a19 !.!. ...! !..! mov [r1:r9], r0
08: dff !!.! !!!! !!!! mov r0, [0xff]
09: a29 !.!. ..!. !..! mov [r2:r9], r0
# https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html
from bs4 import BeautifulSoup
soup = BeautifulSoup(open('jvms-6.html', encoding='ISO8859').read(), 'html.parser')
ops = {
div['title']: {
'words': len(div.find('div', {'class': 'literallayout'}).find_all('br')) - 1,
'opcodes': [
int(p.text.split(' ')[2])
# this builds on https://gist.github.com/acdimalev/ff75aa864e49a41231d19c921132faf1
# double-word division takes three input parameters and outputs two
# for ALU-type usage, it makes sense to re-use two of the input registers as output registers
# A : dividend high-word -> remainder
# B : dividend low-word -> quotient
# C : divisor
# long-division is accomplished by zeroing out the dividend high-word,
// modprobe snd_pcm_oss
#include <fcntl.h>
#include <linux/soundcard.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
from math import log
from random import random, randrange
sample = lambda: (randrange(1, 101), random())
q = [
(1 - y) * log(x) + y * x
for (x, y)
in (sample() for _ in range(1000))
#!/usr/bin/env python3
# interactive log-log profiling visualizer with scales I personally find useful for microprocessor-scale optimizations
# usage: ./profile <depth> <filename>
#
# "depth" is basically the height of the graph
# it controlls how many samples are stored at any given time
# legend for reading the output
from dataclasses import field
@dataclass
class InMessage:
line: str
prefix: str
command: str
params: list[str]
#!/usr/bin/env python3
import crypt, random, sys
(_, nick) = sys.argv
password = '{:016x}'.format(random.randrange(256 ** 8))
crypted = crypt.crypt(password)
passwd_entry = ':'.join([nick, crypted])
File Format
|-- 32 bits --|
+---------------+
| file magic | 0xa42d19a9
|---------------|
| record magic | see Record Magic
|---------------|
| total records | actual number of stored records