Skip to content

Instantly share code, notes, and snippets.

View kig's full-sized avatar

Ilmari Heikkinen kig

View GitHub Profile
@kig
kig / gist:34505
Created December 10, 2008 22:06
tree.hs
-- tree.hs
module Main where
import Graphics.Rendering.Cairo
import Canvas
import System.Random
main = do
gen <- getStdGen
let ns = randoms gen :: [Double]
canvas (draw ns) 600 600
@kig
kig / gist:35282
Created December 12, 2008 21:45
simpleclock.fs -- F# version of the C# SimpleClock
(*
Compile by doing
fscp10.exe -r Mono.Cairo.dll -I /usr/lib/mono/gtk-sharp-2.0/ -r gtk-sharp.dll \
-r gdk-sharp.dll -r glib-sharp.dll simpleclock.fs
*)
open System
open Gtk
open Cairo
let withDo g f v cr = f v cr; g cr
open Prelude
type 'a accum = Acc of 'a | Done of 'a
let optMap f x = match x with None -> None | Some y -> Some (f y)
let string_of_char c = String.make 1 c
let (^.) s c = s ^ string_of_char c
module Stream =
#include <math.h>
#include <pango/pangocairo.h>
#define FONT "Sans"
static void
draw_text (cairo_t *cr)
{
PangoLayout *layout;
type ('a, 'b) types =
| Int of int
| Float of float
| String of string
| Option of 'a option
| Array of 'a array
| List of 'a list
| Function of ('a -> 'b)
module type GENERATOR =
@kig
kig / gist:45095
Created January 9, 2009 12:13
my_qsort.c
#include <stdio.h>
#include <string.h>
#include <alloca.h>
#include <sys/types.h>
#include <stdlib.h>
#include <pthread.h>
typedef int (*comparer)(const void *, const void *);
#define THREAD_THRESHOLD 8192
@kig
kig / mem_bm.c
Created January 9, 2009 19:14
small memory access benchmark
#include <stdio.h>
#include <stdlib.h>
#define TEST_SIZE 10000000
long arr[TEST_SIZE];
void usage (char *name)
{
printf("USAGE: %s [forward|reverse|both]", name);
let base_default_alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let base ?(alphabet=base_default_alphabet) n i =
let rec aux a n sg i l =
if i == 0
then
let l = if l = [] && n > 0 then [a.[0]] else l in
let len = List.length l + if sg < 0 then 1 else 0 in
let s = String.create len in
if sg < 0 then s.[0] <- '-';
let () = ignore (List.fold_right (fun i c -> s.[c-1] <- i; c-1) l len) in
type 'a range_atom =
RChar of 'a
| RRange of 'a * 'a
and 'a range = 'a range_atom list
type 'a regex_atom =
Sub of 'a regex
| Or of 'a regex * 'a regex
| Char of 'a
| Opt of 'a regex_atom
#let fac_loop n =
# let s = ref 1 in
# for i=2 to n do s := !s * i done;
# !s
camlFoo__fac_loop_58:
.L104:
movq %rax, %rsi
movq $3, %rax
movq $5, %rbx