Skip to content

Instantly share code, notes, and snippets.

@kuzux
kuzux / anal_mp4.c
Last active February 17, 2024 14:18
Getting a bunch of properties about the video out of an mp4 file
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <assert.h>
@kuzux
kuzux / build.sh
Last active November 19, 2023 12:47
accessing the osx clipboard via c++
set -ex
clang -x objective-c -c osx.m -o osx.o
g++ -std=c++17 -c main.cpp -o main.o
g++ main.o osx.o -framework AppKit -o cliptest
@kuzux
kuzux / noheaders.c
Created November 14, 2023 19:16
osx raw syscall on arm
#define STDOUT 1
#define SYS_WRITE 4
int strlen(const char* str) {
int len = 0;
for(const char* cur = str; *cur; ++cur) ++len;
return len;
}
int write(int fd, const char* buf, int count) {
@kuzux
kuzux / bolzano.apl
Created December 29, 2013 18:54
minimizing a polynomial function using bolzano's method. in 3 lines. of APL. i hope nobody will be forced to read that.
deriv ← {((⍴⍵) - 1)↑⍵ × ((⌽⍳⍴ ⍵) - 1)}
apply ← {+/ ((⍴⍵) ⍴ ⍺ * ((⌽⍳⍴ ⍵) - 1)) × ⍵ }
minimize ← {(2⊃⍵-⊃⍵)≤epsilon: (+/⍵÷2) ⋄ ((+/⍵÷2) apply (deriv ⍺)<0): ⍺∇((+/⍵÷2) , 2⊃⍵) ⋄ ⍺∇(⊃⍵ , (+/⍵÷2))) }
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct {
uint8_t* buf;
time_since_last_read = 0
burst_length = const
max_buflen = 2000
recvTag()
loop while serial not available - waiting for an answer
header = serial read
return 0xFFFF if header != 0xA0
len = serial read
tag = 0
#include "Arduino.h"
class LedMatrix {
int _rows[8];
int _cols[8];
public:
LedMatrix(int rows[], int cols[]) {
for(int i=0; i<8; i++) {
_rows[i] = rows[i];
@kuzux
kuzux / LedMatrix.h
Last active December 23, 2021 11:50
#ifndef LEDMATRIX_H
#define LEDMATRIX_H
#include "Arduino.h"
class LedMatrix {
int _rows[8];
int _cols[8];
public:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Text.Read ( reads )
import System.IO ( FilePath
, readFile
)
import System.Directory ( doesFileExist )
import Control.Monad ( forever )
import Control.Concurrent ( MVar
@kuzux
kuzux / anal_annexb.c
Created July 1, 2021 19:08
anal_annexb.c
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
FILE* fp;
size_t N;
uint8_t* buf;