Skip to content

Instantly share code, notes, and snippets.

@saolsen
saolsen / number-to-binary.rkt
Created August 26, 2014 16:39
number to binary
#lang racket
(define (get-spaces-inner n spaces)
(define current-space (car spaces))
(if (> current-space n)
(cdr spaces)
(get-spaces-inner n (cons (* current-space 2) spaces))))
(define (get-spaces n)
(get-spaces-inner n '(1)))
#include <stdlib.h>
int main(int nargs, char * args[])
{
void* vp = malloc(sizeof(char) * 5);
const char* ip = (char*)(vp);
free(ip);
}
@saolsen
saolsen / multicore.c
Last active June 1, 2016 20:33
sort and print a giant list
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
#define TEST_CASES 1000000
#define TEST_RUNS 30
// Channels for passing data between threads. We pack a whole cache line of ints before
@saolsen
saolsen / workq.c
Created December 2, 2015 00:35
another lock free work queue
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
#include <libkern/OSAtomic.h>
#include <unistd.h>
typedef void(*WorkFunction)(void* work_data);
@saolsen
saolsen / 2016-04-13.c
Last active June 1, 2016 20:31
circular chat buffer
#if 0
echo Compiling...
cc -Wall -g -std=c99 $0 -o 2016-04-13 && ./2016-04-13
exit
#endif
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
@saolsen
saolsen / aissac.cpp
Created August 3, 2017 21:35
python screen capture
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define LEN(e) (sizeof(e)/sizeof(e[0]))
@saolsen
saolsen / keybase.md
Created October 10, 2017 16:51
keybase.md

Keybase proof

I hereby claim:

  • I am saolsen on github.
  • I am saolsen (https://keybase.io/saolsen) on keybase.
  • I have a public key ASD9j8N4AtK0fUZlAh1XujYN4d4bSiK7GJ3_RQuP7_pj5wo

To claim this, I am signing this object:

@saolsen
saolsen / steve_lib.h
Last active March 17, 2018 23:48
steve_lib.h
// Collections and helpers for c programming.
// Version: 0.1.3
// Shoutouts to @nothings and @pervognsen who I learned / copied most of this from
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
@saolsen
saolsen / program.c
Created June 6, 2019 16:11
grow_memory in wasm from c
include <stdlib.h>
#include <stddef.h>
#include <assert.h>
#include <webassembly.h>
typedef uint8_t u8;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t i32;
@saolsen
saolsen / readme.md
Last active August 6, 2019 17:56
trying out structs in javascript

I've been thinking about trying to build something like terra but with javascript as the host language and wasm as the low level thing you metaprogram for. Could be used to just "jit" expensive functions and call them from javascript or to build a fully wasm program but metaprogram it from javascript or whatever inbetween. One of the things I think I need to get that to be nice is to be able to have a struct implementation that can be easily shared between wasm and js.