Skip to content

Instantly share code, notes, and snippets.

@dchiji
dchiji / jit-bf.c
Created May 27, 2009 09:57
JIT Brainfuck
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DEBUG
#ifdef DEBUG
unsigned char *mem;
int mem_size;
#endif
@dchiji
dchiji / skipgraph.erl
Created June 18, 2009 14:26
Skip Graph in Erlang
-module(sg).
-export([start/0, start/1, get_node/0, find_/1, put_/2, get_/1, get_/2]).
-define(error(X), (begin io:format("*** ERROR ~p ~p ~p~n", [?MODULE, ?LINE, X]) end)).
-define(debug(X), (begin io:format("*** DEBUG ~p ~p ~p~n", [?MODULE, ?LINE, X]) end)).
start() -> register(node_loop, spawn(fun() -> node_loop(boot(dummy_node(), 0, 0)) end)).
start(Init) ->
Pid = rpc:call(Init, sg, get_node, []),
register(node_loop, spawn(fun() -> node_loop(Pid) end)).
#include <stdarg.h>
void cps(int a, int b, ...)
{
void *p;
void *m;
va_list ap;
va_start(ap, b);
p = va_arg(ap, void *);
-module(heron).
-export([heron/3]).
heron(A, B, C) ->
S = (A + B + C) / 2,
math:sqrt(S * (S - A) * (S - B) * (S - C)).
-module(euclidean).
-export([euclidean/2]).
euclidean(M, 0) -> M;
euclidean(M, N) when M rem N == 0 -> N;
euclidean(M, N) -> euclidean(N, M rem N).
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
int main()
{
int lis[MAX];
int n = 0;
int j = 0;
// name: curve.cpp
// compile: $ g++ curve.cpp `pkg-config gtkmm-2.4 --cflags --libs`
#include <cairomm/context.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm.h>
#include <iostream>
#include <pthread.h>
#include <stdio.h>
#include <time.h>
void *func(void *param_p)
{
int *p = (int *)param_p;
printf("## start: %u\n", (unsigned int)pthread_self());
for(int i = 0; i < 100000; i++) {
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <iostream>
#include <map>
#define LEVEL 128
/*
* <Skip List>
@dchiji
dchiji / Makefile
Created December 2, 2009 10:58
KVS
.SUFFIXES: .erl .beam .yrl
.erl.beam:
erlc -W +'{parse_transform, smart_exceptions}' $<
.yrl.erl:
erlc -W +'{parse_transform, smart_exceptions}' $<
ERL = erl