Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexandru Scvortov scvalex

View GitHub Profile
View counter.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Counter</title>
<link rel="stylesheet" href="/r/screen.css" media="screen">
<meta name="description" content="An HTML5 counter">
View Makefile
all: pingcat.c
gcc -o pingcat pingcat.c
@scvalex
scvalex / Makefile
Last active Aug 29, 2015
Variable Length Arrays in C
View Makefile
all: var_len_arrays.c
gcc -O1 var_len_arrays.c -S
@scvalex
scvalex / Makefile
Last active Aug 29, 2015
Faster Fibonacci
View Makefile
run: fib
./fib
fib: fib.ml
ocamlfind ocamlopt nums.cmxa fib.ml -o fib
View mat_mult.ml
(** Run:
corebuild -pkg core_bench mat_mult.native && sleep 1 && ./mat_mult.native
*)
open Core.Std
open Core_bench.Std
module Array_mat = struct
type mat3 = float array array
type vec3 = float array
View existential.ml
(** Run:
coretop existential.ml
*)
open Core.Std
type ('a, 'b) entity = {
id : unit -> string;
step : 'b -> 'b some_entity;
to_string : unit -> string;
@scvalex
scvalex / poly_compare.ml
Created Oct 21, 2013
An example of why polymorphic compare is tricky in OCaml.
View poly_compare.ml
(** A circular doubly-linked list in OCaml. See:
https://en.wikipedia.org/wiki/Doubly_linked_list#Circular_doubly-linked_lists
*)
module Doubly_linked_list = struct
type 'a doubly_linked_node = {
data : 'a;
mutable prev : 'a doubly_linked_node;
mutable next : 'a doubly_linked_node;
}
@scvalex
scvalex / PrintfString2.hs
Last active Dec 18, 2015
Make strings behave like printf.
View PrintfString2.hs
{-# LANGUAGE OverloadedStrings, FlexibleInstances, UndecidableInstances #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-type-defaults #-}
module Main where
import Data.String ( IsString(..) )
--------------------
-- Custom printf that takes '%s' for `Show` values.
@scvalex
scvalex / PrintfString.hs
Last active Dec 18, 2015
Make strings work like printf.
View PrintfString.hs
{-# LANGUAGE OverloadedStrings, FlexibleInstances, UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
import Data.String ( IsString(..) )
import Text.Printf ( PrintfType, printf )
instance (PrintfType a) => IsString a where
fromString s = printf s
main :: IO ()
@scvalex
scvalex / prec.c
Created May 11, 2013
An example to illustrate the surprising precedence of `<<` in action.
View prec.c
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("1 << 1 + 2 = %d\n", 1 << 1 + 2);
printf("1 << 1 * 3 = %d\n", 1 << 1 * 3);
printf("1 << 1 + 1 << 1 = %d\n", 1 << 1 + 1 << 1);
return 0;
}