Skip to content

Instantly share code, notes, and snippets.

@a1k0n
a1k0n / donut.c
Created October 23, 2023 04:03
donut shift and add only
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#define debug(...)
//#define debug printf
// torus radii and distance from camera
@a1k0n
a1k0n / gist:bca59b3b87cb947808eae7ca7a03f49a
Created May 13, 2022 23:43 — forked from dangerous/gist:98b2b158b5625f837b8bdce43a965b3f
First 10000 reddit users sourced from karmalb
1. kn0thing
2. spez
3. third
4. fifth
5. fourth
6. agentorange
7. chickenlittle
8. erzengel
9. fizzypop
10. madmax2
// the donut code with fixed-point arithmetic; no sines, cosines, square roots, or anything.
// a1k0n 2020
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define R(mul,shift,x,y) \
_=x; \
x -= mul*y>>shift; \
// read a sample sent to the YM3014B
// it's a 13.3 floating point format, 3 MSBs are exponent,
// 13 LSBs are mantissa, except only 10 of the mantissa bits are used
uint16_t ym3014b_read16(void) {
uint16_t data = 0;
uint8_t last_port_state = GPIOC_PDIR;
@a1k0n
a1k0n / 0.bin
Created January 16, 2017 05:56
IBM 5150 diagnostics cassette dump
00000000 a5 6c 64 63 61 73 73 20 20 80 4c 05 60 00 1e 08 |.ldcass .L.`...|
00000010 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |................|
00000020 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |................|
*
00000100 ff ff ff fe fa fb ef df 28 01 2f 1f ff ff ff ff |........(./.....|
00000110 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00000200
@a1k0n
a1k0n / cleardir.pl
Created March 15, 2016 22:46
clear a directory with a large number of files
use Time::HiRes qw(time);
opendir $d, ".";
$| = 1;
$n = 0;
$t0 = time;
while ($f = readdir $d) {
unlink $f;
$n++;
@a1k0n
a1k0n / ylogo.c
Created October 22, 2015 01:02
Expanded version of the code featured in http://www.a1k0n.net/2011/06/26/obfuscated-c-yahoo-logo.html
#include <math.h>
#include <stdio.h>
#include <unistd.h>
// Each character encodes an angle of a plane we are checking
const char plane_angles[] = "O:85!fI,wfO8!yZfO8!f*hXK3&fO;:O;#hP;\"i[";
// and these encode an offset from the origin s.t. (x, y) dot (cos(a), sin(a)) < offset
const char plane_offsets[] = "<[\\]O=IKNAL;KNRbF8EbGEROQ@BSXXtG!#t3!^";
// this table encodes the offsets within the above tables of each polygon

Keybase proof

I hereby claim:

  • I am a1k0n on github.
  • I am a1k0n (https://keybase.io/a1k0n) on keybase.
  • I have a public key whose fingerprint is 54C6 0ED3 608C E889 0913 6C06 D257 0C60 21DB 3514

To claim this, I am signing this object:

import sys
import math
from collections import defaultdict
# ideally, we need to minimize the state changes
# so we need to track the transitions
s = sys.stdin.read()
rle = []
freq = defaultdict(int)
@a1k0n
a1k0n / gist:9554723
Created March 14, 2014 19:14
gnuradio build failure
Linking CXX shared library libgnuradio-core.dylib
cd /tmp/gnuradio-y2zG/gnuradio-3.6.5.1/build/gnuradio-core/src/lib && /usr/local/Cellar/cmake/2.8.12.2/bin/cmake -E cmake_link_script CMakeFiles/gnuradio-core.dir/link.txt --verbose=1
/usr/local/bin/g++-4.2 -dynamiclib -Wl,-headerpad_max_install_names -compatibility_version 3.6.5 -o libgnuradio-core.3.6.5.1.dylib -install_name /tmp/gnuradio-y2zG/gnuradio-3.6.5.1/build/gnuradio-core/src/lib/libgnuradio-core.3.6.5.1.dylib CMakeFiles/gnuradio-core.dir/missing/bug_work_around_8.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_basic_block.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_flowgraph.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_flat_flowgraph.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_block.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_block_detail.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_block_executor.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_block_registry.cc.o CMakeFiles/gnuradio-core.dir/runtime/gr_hier_block2.cc.o CMakeFiles/gnuradio-core.dir