Skip to content

Instantly share code, notes, and snippets.

@banthar
banthar / gist:2355847
Created April 11, 2012 00:09
dcpu vm
#include <stdbool.h>
#include <stdint.h>
struct dcpu {
uint16_t ram[0x10000];
uint16_t reg[8];
uint16_t pc;
uint16_t sp;
uint16_t o;
@banthar
banthar / gist:1866512
Created February 19, 2012 23:38
gdb backtrace
gcc -g -lgmp -o rho rho.c
gdb ./rho
run 10
bt
@banthar
banthar / aux.c
Created January 30, 2012 17:06
windows forbidden file name
// aux.c
@banthar
banthar / curses_test.c
Created December 5, 2011 00:04
curses demo
#include <stdio.h>
#include <curses.h>
int main(int argc, char*argv[])
{
initscr();
printw("curses - press any key");
getch();
endwin();
@banthar
banthar / stack_trace.c
Created November 7, 2011 01:41
stacktrace with libunwind and elfutils
// stack_trace.c
//
// gcc stack_trace.c -ldw -lunwind -g -o stack_trace
#define UNW_LOCAL_ONLY
#include <elfutils/libdwfl.h>
#include <libunwind.h>
#include <stdio.h>
num: 1 2 3 4
val: 1 1 0 0
limit: 5
.file "test.cpp"
.globl cosine
.bss
.align 32
.type cosine, @object
.size cosine, 67108864
cosine:
.zero 67108864
.globl sine
.align 32
.file "test2.cpp"
.section .text._ZSt3cosf,"axG",@progbits,_ZSt3cosf,comdat
.weak _ZSt3cosf
.type _ZSt3cosf, @function
_ZSt3cosf:
.LFB22:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
enum Type
{
Void;
Primitive(name:String);
Pointer(to:Type);
Function(args:Array<NamedType>,ret:Type);
}
class NamedType
@banthar
banthar / lazy_read.c
Created January 28, 2011 12:24
lazy read
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
{