Skip to content

Instantly share code, notes, and snippets.

@lemon32767
lemon32767 / rotater.py
Last active July 31, 2021 09:31
gui program to rotate touchscreen for lenovo ideapad flex 5 14ARE05
#!/bin/python
import tkinter as tk
import subprocess as sp
import os
rot = ["normal", "left", "inverted", "right"]
trans = ["1 0 0 0 1 0 0 0 1", "0 -1 1 1 0 0 0 0 1", "-1 0 1 0 -1 1 0 0 1", "0 1 0 -1 0 1 0 0 1"]
devs = ["Wacom HID 5215 Finger touch", "Wacom HID 5215 Pen stylus", "Wacom HID 5215 Pen eraser"]
@lemon32767
lemon32767 / prng16.c
Last active March 8, 2021 10:09
16-bit seed PRNG. period=65534. uniform-ish looking distribution https://i.imgur.com/kKI5W2s.png
typedef unsigned short u16;
u16 random_u16(void) {
static u16 s;
s ^= s << 8;
s = ((s & 0xFF) << 1) ^ ((s << 8) | (s >> 8));
s = 38607*s + 35335;
s = (s >> 1) ^ (-(~s & 1) & 0x9E74) ^ 0x7E00;
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#from matplotlib.animation import FuncAnimation
import numpy as np
import sys
rng = list(map(float, sys.stdin.readlines()))
period = len(rng)
#print(rng)
#!/bin/env python3
import sys, string
def str_findp(start, s, pred):
for i in range(start,len(s)):
if pred(s[i]):
return i
return None
#takes a list of lines as template for the ascii art; and a list of tokens (for example, words) to replace it with
@lemon32767
lemon32767 / bitreg.zig
Last active August 25, 2020 21:56
zig bitreg type
const std = @import("std");
const assert = std.debug.assert;
const trait = std.meta.trait;
//example:
// BitReg(u32, .{
// .{.first_4_bits, 0, 4},
// .{.next_7_bits, 4, 7},
// })
pub fn BitReg(comptime T: type, comptime fields: anytype) type {
const check_or = struct {
#!/bin/env python
import subprocess, json, re, shutil, os
srcurl = "https://ziglang.org/download/index.json"
tmppath = "/tmp/zig-master.tar.xz"
print(" > downloading index...")
src = subprocess.check_output(["curl", "-L", srcurl])
@lemon32767
lemon32767 / mmacrofmt.py
Last active May 6, 2020 09:25
format C multiline macros
#!/bin/python
"""
usage: mmacrofmt.py [tabsize] < infile > outfile
formats something like:
#define X(a) \
whatever \
missing a backslash
//some comment
hmm\
@lemon32767
lemon32767 / fix32.cc
Last active April 28, 2020 14:10
16:16 fixed point
#include <stdint.h>
#include <cstdio>
#include <iostream>
#include <cmath>
typedef struct fix32 {
int32_t n;
static const int32_t FACTOR = (1<<16);
//constructor
@lemon32767
lemon32767 / vd.c
Last active April 4, 2020 11:02
scanline based rendering with SDL2
#include <SDL2/SDL.h>
#include<math.h>
enum {FALSE ,TRUE};
enum {W=600,H=400};
int _SCROLLX = 0;
int _SCROLLY = 0;
SDL_Surface* screen;
@lemon32767
lemon32767 / neocpkg
Last active December 22, 2019 17:19
neocities pkg archival tool
#!/bin/python
import sys, os, subprocess, re
if len(sys.argv) < 2:
print("""\
usage: neocpkg <command> [neocities website name | website/pkg]
commands:
init\t create a repo here