Skip to content

Instantly share code, notes, and snippets.

View scvalex's full-sized avatar

Alexandru Scvorțov scvalex

View GitHub Profile
@scvalex
scvalex / counter.html
Last active December 3, 2017 10:47
counter
<!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">
@scvalex
scvalex / Makefile
Last active August 29, 2015 14:14
pingcat
all: pingcat.c
gcc -o pingcat pingcat.c
@scvalex
scvalex / Makefile
Last active August 29, 2015 14:13
Variable Length Arrays in C
all: var_len_arrays.c
gcc -O1 var_len_arrays.c -S
@scvalex
scvalex / Makefile
Last active August 29, 2015 14:12
Faster Fibonacci
run: fib
./fib
fib: fib.ml
ocamlfind ocamlopt nums.cmxa fib.ml -o fib
(** 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
(** 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 October 21, 2013 10:27
An example of why polymorphic compare is tricky in OCaml.
(** 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 December 18, 2015 21:49
Make strings behave like printf.
{-# 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 December 18, 2015 21:49
Make strings work like printf.
{-# 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 01:47
An example to illustrate the surprising precedence of `<<` in action.
#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;
}