Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sh1boot
sh1boot / githead.sh
Created March 7, 2025 05:47
Function to get current git hash without external tools.
function githead() {
local commondir ref hash _
local gitdir="${1:a}"
until [[ -e "$gitdir/.git" ]]; do
local updir="${gitdir%/*}"
[[ "$updir" == "$gitdir" ]] && return 1
gitdir="$updir"
done
gitdir="$gitdir/.git"
[[ -f "$gitdir" ]] && read _ gitdir < "$gitdir"
@sh1boot
sh1boot / adler32.cc
Created March 19, 2024 16:43
adler32 generic SIMD calculation method
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#define VECLEN 16
#define ADLER_MOD 65521
typedef uint8_t vuint8_t __attribute__((ext_vector_type(VECLEN)));
from scipy.fftpack import fft
from matplotlib import pyplot
N = 65536
f_s = 48000
f_c = 1000
prng_lfsr = 0x32B71700
prng_tap = 0xb874
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
uint8_t Y(uint8_t r, uint8_t g, uint8_t b) { return ((r * 66 + g * 129 + b * 25 + 128) >> 8) + 16; }
uint8_t U(uint8_t r, uint8_t g, uint8_t b) { return ((r * -38 + g * -74 + b * 112 + 128) >> 8) + 128; }
uint8_t V(uint8_t r, uint8_t g, uint8_t b) { return ((r * 112 + g * -94 + b * -18 + 128) >> 8) + 128; }
uint32_t ref(uint8_t const* p) {
uint8_t lr = p[0], lg = p[1], lb = p[2], rr = p[3], rg = p[4], rb = p[5];
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
void split(uint8_t* r, uint8_t* g, uint8_t* b, uint16_t rgb16) {
*r = (((rgb16 >> 11) & 0x1f) * 255 + 15) / 31;
*g = (((rgb16 >> 5) & 0x3f) * 255 + 31) / 63;
*b = (((rgb16 >> 0) & 0x1f) * 255 + 15) / 31;
}
@sh1boot
sh1boot / fngen.c
Created June 8, 2016 17:09
odd output
#include <stdio.h>
#include <math.h>
int main(void) {
long double x = 0.0;
long double phi = 0.61803398874989484820458683436563811772030917980576286213544862L;
long double t = 1.0;
for (;;) {
int n = 0;
#include <stdint.h>
class Foo {
uint64_t& data;
uint64_t* const pdata;
public:
Foo(uint64_t& d) : data(d), pdata(&d) { }
inline uint64_t get(void) { return data; }
inline uint64_t pget(void) { return *pdata; }
@sh1boot
sh1boot / gist:5732738
Last active December 18, 2015 05:29
experimental table-based divide operation
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define TABBITS 8
#if 0
extern uint32_t divfn(uint16_t i, uint16_t j);
#else