Skip to content

Instantly share code, notes, and snippets.

View sshine's full-sized avatar
📐
180°

Simon Shine sshine

📐
180°
View GitHub Profile
@sshine
sshine / gist:1307449
Created October 23, 2011 15:02
Standard ML: Imperative vs. functional
infixr 0 $
fun f $ x = f x
val concat = List.concat
fun good_cartesian_product (xs, ys) =
concat (map (fn y => map (fn x => (x,y)) xs) ys)
fun evil_cartesian_product (xs', ys') =
let
val result = ref []
@sshine
sshine / listekomb.sml
Created October 25, 2011 14:25
Standard ML functors and list combinators
(* Først defineres en signatur for lister. Den indeholder nogle
* af de mest elementære operationer, man kan lave på lister. *)
signature LISTE =
sig
type 'a liste
val null : 'a liste -> bool
val empty : 'a liste
val cons : 'a * 'a liste -> 'a liste
val hd : 'a liste -> 'a
val tl : 'a liste -> 'a liste
@sshine
sshine / gist:1329208
Created October 31, 2011 22:17
Standard ML functor example
signature FOO =
sig
type 'a foo
val f : 'a -> 'a foo
end
signature BAR =
sig
structure Foo : FOO
val p : 'a -> bool
@sshine
sshine / MultiServer.java
Created November 15, 2011 17:25
Java: A modification of KKMultiServer
package multiserver;
import java.net.*;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class MultiServer {
protected ServerSocket serverSocket = null;
protected boolean listening = true;
@sshine
sshine / cowsay.hs
Created November 22, 2011 00:18
Cowsay (Haskell)
import Data.String.Utils
cow :: String
cow = concatMap (++ "\n") [
" \\ ^__^",
" \\ (oo)\\_______",
" (__)\\ )\\/\\",
" ||----w |",
" || ||" ]
@sshine
sshine / categories.php
Created December 15, 2011 15:00
Tree traversal in PHP
<?php
$recursive_array = array(
0 => array(
'name' => 'pets',
'category' => array(
0 => array(
'name' => 'cats',
'category' => array(
0 => array(
@sshine
sshine / gist:1540128
Created December 30, 2011 14:37
My first Scheme program!
(define (tabulate n f)
(define (helper m)
(if (= m n)
()
(cons (f m) (helper (+ m 1)))))
(helper 0))
(define (make-table x y fill)
(define table (make-vector x))
(tabulate x
@sshine
sshine / particles.py
Created March 5, 2012 17:00
2D particle simulator with objects and steady attractors
#!/usr/bin/python
import math
import random
import sys
import os
import pygame
import time
class UnpreparedParticle(Exception):
pass
@sshine
sshine / gist:3609048
Created September 3, 2012 12:36
afrunding
fun afrund n =
let
val n' = Real.trunc (n * 125.0)
val kr = Real.fromInt (n' div 100)
val ore = Real.fromInt ((n' mod 100) div 25 * 25) / 100.0
in kr + ore end
(* Mads og Christians *)
fun moms n = real(round(n * 4.0 * 1.25 ))/4.0;
@sshine
sshine / gist:3673388
Created September 8, 2012 10:47
tabs2spaces
>~:9-v
^ ,_$84v
^,,:,:,:*<