Skip to content

Instantly share code, notes, and snippets.

View ilyakurdyukov's full-sized avatar

Ilya Kurdyukov ilyakurdyukov

View GitHub Profile
@DavidBuchanan314
DavidBuchanan314 / tinypng.py
Created March 16, 2021 09:47
You can use imagemagic's `convert` command to easily generate the raw RGB data file
import zlib
WIDTH = 570
HEIGHT = 453
IMG_RGB = open("source.rgb", "rb")
def pack_chunk(chunktype, chunkdata):
chunk = len(chunkdata).to_bytes(4, "big")
chunk += chunktype
chunk += chunkdata
@kssreeram
kssreeram / table-driven-wc.c
Created November 12, 2020 08:17
Table-driven word-count in C
#include <stdio.h>
#include <stdlib.h>
int is_space[256];
int next_states[3 * 2];
int increments[3];
void initialize_tables(void) {
is_space[' '] = 1;
is_space['\n'] = 1;
@katef
katef / hattifatteners.awk
Created October 23, 2020 22:48
hattifatteners.awk
#!/usr/bin/awk -f
function hoop(h, w) {
printf("l 0 %d ", -h);
printf("c 0 -%u, %u -%u, %u 0 ", w, w, w, w);
printf("l 0 %d", +h);
}
function hand(x, h, o, l) {
printf("<g transform='translate(%d.5 %d)'>\n", x, h);
@DavidBuchanan314
DavidBuchanan314 / life.c
Last active August 9, 2023 23:12
Yet another reformatting of my tiny game of life implementation. Valid ANSI C with no (default) compiler warnings or UB
#define F\
for(i=l;i\
<l*4; i++)
main(){int
i,j,w=512,
n,l=w*w,o[
]={~w,-w,-
w+1,-1,1,w
-1,w,w+1},
b[l*5];F b
@DavidBuchanan314
DavidBuchanan314 / terse_aes_128.py
Last active October 11, 2020 10:41
A deliberately terse AES128 implementation in pure python. Functions taken from https://github.com/DavidBuchanan314/aes-playground, comments removed, put into a single file, and minified.
def xor_bytes(a, b):
return bytearray([ai^bi for ai, bi in zip(a, b)])
def ff_divmod(r, b, q=0):
while True:
diff = r.bit_length() - b.bit_length()
if diff < 0: break
q ^= 1 << diff
r ^= b << diff
return q, r
@DavidBuchanan314
DavidBuchanan314 / cursed_mandelbrot.c
Last active June 28, 2023 15:12
Compile-time mandelbrot in pure C. Outputs a PGM image file to stdout. Output can be seen at https://twitter.com/David3141593/status/1062468528115200001
#include <stdio.h>
#define SQ(x) (x)*(x)
#define M0(x,y) SQ(x)+SQ(y)<4?0:0xe0
#define M1(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M0(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0)):0xc0
#define M2(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M1(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0xa0
#define M3(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M2(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0x80
#define M4(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M3(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0x60
#define M5(x,y,x0,y0) (SQ(x)+SQ(y)<4)?M4(SQ(x)-SQ(y)+(x0),2*(x)*(y)+(y0),x0,y0):0x40
@XVilka
XVilka / TrueColour.md
Last active October 29, 2024 09:43
True Colour (16 million colours) support in various terminal applications and terminals

THIS GIST WAS MOVED TO TERMSTANDARD/COLORS REPOSITORY.

PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!

@fernandoaleman
fernandoaleman / rpm-digital-signature.sh
Created November 18, 2011 15:18
How to sign your custom RPM package with GPG key
# How to sign your custom RPM package with GPG key
# Step: 1
# Generate gpg key pair (public key and private key)
#
# You will be prompted with a series of questions about encryption.
# Simply select the default values presented. You will also be asked
# to create a Real Name, Email Address and Comment (comment optional).
#
# If you get the following response: