Skip to content

Instantly share code, notes, and snippets.

View hadrianw's full-sized avatar

Hadrian Węgrzynowski hadrianw

View GitHub Profile
@hadrianw
hadrianw / prace.c
Last active January 24, 2016 01:06
Process Race - wait for a child process to finish, kill the rest.
/*
Compile with:
$ gcc prace.c -o prace -std=c99 -pedantic -Wall -Wextra
Example usage in shell script:
$ ((sleep 4; echo foo)& (sleep 2; echo bar)& exec ./prace)
bar
$
*/
@hadrianw
hadrianw / Makefile
Created March 13, 2017 14:11
Seven line Makefile for a directory full of single file basic programs.
all:
make $$(for i in *.c; do echo $${i%.c}; done)
.c: Makefile
gcc -std=c99 -pedantic -Wall -Wextra $< -o $@
.PHONY: all
@hadrianw
hadrianw / Makefile
Created March 13, 2017 14:06
Two line Makefile for a directory full of single file basic programs. Usage: make binary-name
.c: Makefile
gcc -std=c99 -pedantic -Wall -Wextra $< -o $@
@hadrianw
hadrianw / resize-allow.js
Created April 12, 2017 14:59
Bookrmarklet to add or modify meta viewport to allow resizing on mobile.
var d=document;
var q=d.querySelector.bind(d);
var c='width=device-width,initial-scale=1';
var v=q('meta[name=viewport]');
if(v){
v.content=c
}else{
v=d.createElement('meta');
v.name='viewport';
v.content=c;

Keybase proof

I hereby claim:

  • I am hadrianw on github.
  • I am hawski (https://keybase.io/hawski) on keybase.
  • I have a public key ASB7SqEkozW7v4jD75NZ4Mzrfz_OAY2jwl2v0SQkcI47TQo

To claim this, I am signing this object:

@hadrianw
hadrianw / blocks.c
Last active April 21, 2018 20:43
Blocks data structure for text editor.
#define _XOPEN_SOURCE
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@hadrianw
hadrianw / count.c
Created April 25, 2018 19:54
Atomic append test.
#if 0
set -e; [ "$0" -nt "$0.bin" ] &&
gcc -Wall -Wextra -pedantic -std=c99 "$0" -o "$0.bin"
exec "$0.bin" "$@"
#endif
#include <stdio.h>
#include <stdlib.h>
#define LEN(x) (sizeof(x)/sizeof((x)[0]))
@hadrianw
hadrianw / index.c
Last active May 31, 2018 21:59
Dumb benchmark for VPS performance measurment.
#include <ftw.h>
#include <stdio.h>
#include <sqlite3.h>
#define INSERT_QUERY "INSERT INTO index VALUES (?, ?)",
static sqlite3 *db;
static sqlite3_stmt *insert_stmt;
static int step(const char *path, const struct stat *sb, int flag, struct FTW *ftwbuf)
@hadrianw
hadrianw / gdb-strace.sh
Last active June 14, 2018 12:10
strace with backtrace thanks to gdb
#!/bin/sh
cmd=$1
shift
# FIXME: it would be good for every argument to be wrapped in quotes
echo run $@ | gdb "$cmd" -x strace.gdb &> gdb-strace-log
@hadrianw
hadrianw / Rantfile.md
Last active July 5, 2018 10:36
I don't enjoy this software.

Rantfile

Google Maps

Problem:

  1. Click on some place that has a website.
  2. Middle-click on the apparent link to open it in a new tab - nothing happens.

Solution: