Skip to content

Instantly share code, notes, and snippets.

@baines
baines / inso_json.h
Last active Sep 8, 2018
json tokenizer
View inso_json.h
#define _GNU_SOURCE
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
// streaming json tokenizer that operates on fixed sized memory chunks
// no dynamic memory allocation necessary
enum ij_type {
@baines
baines / asmsort.s
Created Jan 17, 2017
x86_64 linux sort program, 640 bytes
View asmsort.s
#!/bin/bash
# example: ./asmsort 3 2 1 -> prints 1 2 3
// 2>/dev/null; as -g $0 -o $0.o && ld -s $0.o -o asmsort; exit
.text
.global _start
quicksort:
dec %rsi # base case
jle qs_end
@baines
baines / quicksort.s
Last active Jan 16, 2017
x86_64 asm quicksort
View quicksort.s
#!/bin/bash
# (gdb) r
# -> SIGTRAP
# (gdb) x/12g $rax
# -> stuff is sorted
// 2>/dev/null; as -g $0 -o $0.o && ld $0.o -o $0.bin && gdb $0.bin; exit
.data
stuff: # numbers to sort
.quad 74, 3, 53, 11, 52, 94, 16, 12, 48, 88, 19, 82
@baines
baines / freetype-atlas.c
Created Jul 15, 2016
minimal freetype texture atlas example
View freetype-atlas.c
#include <stdio.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#define NUM_GLYPHS 128
struct glyph_info {
int x0, y0, x1, y1; // coords of glyph in the texture atlas
@baines
baines / xkeyexample.c
Last active Feb 21, 2019
simple xlib key example
View xkeyexample.c
#include <stdio.h>
#include <locale.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
int main(void){
setlocale(LC_ALL, "");
Display* dpy = XOpenDisplay(NULL);
@baines
baines / script.txt
Last active Apr 18, 2016 — forked from anonymous/readme.txt
Lawn-Mowing Robot [PuzzleScript Game]
View script.txt
title Lawn-Mowing Robot
author Alex Baines
homepage abaines.me.uk
again_interval 0.5
background_color #1B1825
(
debug
verbose_logging
)
========
@baines
baines / twitch-notify.sh
Last active Aug 29, 2015
Twitch.tv desktop notification bash script
View twitch-notify.sh
#!/bin/bash
# twitch-notify.sh by Alex Baines
# Desktop notifications about twitch.tv streams.
# dependencies:
# curl
# underscore-cli
# notify-send
# md5sum
@baines
baines / oggextract.cpp
Last active Aug 29, 2015
Extract OGGs from stuff
View oggextract.cpp
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unistd.h>
bool test_header(FILE* f, int magic = 2){
bool r = false;
char buf[5];
fread(buf, 1, 5, f);
@baines
baines / hls-multi-atomic.cpp
Last active Sep 14, 2016
3 C++11 threaded HLS downloader / player thingies
View hls-multi-atomic.cpp
#if 0
g++ $0 -std=c++11 -pthread -lcurl -o hls-dl
exit
#endif
#include <thread>
#include <mutex>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
You can’t perform that action at this time.