Skip to content

Instantly share code, notes, and snippets.

View chribben's full-sized avatar

Christian Jacobsen chribben

View GitHub Profile
@chribben
chribben / vagrantfile
Last active March 25, 2017 13:51
Vagrantfile which provisions an Ubuntu (trusty 64) with stuff needed for running .NET on it
$script = <<SCRIPT
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
sudo apt-get install -y mono-complete
sudo apt-get install -y automake libtool curl unzip
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.4.2
sudo sh autogen.sh
sudo ./configure
@chribben
chribben / QuickSort.fsx
Created September 17, 2014 21:12
Using the function pattern matching construct to bind the tuple from List.partion to ltx and gtx in a forward pipe
let rec quickSort l =
match l with
| [] -> []
| x::xs -> xs |> List.partition (fun y -> y < x) |> function (ltx,gtx) -> (quickSort ltx)@x::quickSort gtx
open System
open System.Windows.Forms
open System.Drawing
//************Number of cells and dimensions************
let cellSide = 10
let noOfCellsInOneDir = 16
let side = cellSide * noOfCellsInOneDir
let totNoOfCells = pown noOfCellsInOneDir 2
//***********Helper functions********************
let mapMatrix matrix = (List.map >> List.map) matrix
@chribben
chribben / pong.elm
Last active August 29, 2015 14:03
Pong
import Basics
import Keyboard
import Random
--MODEL
background = {width = 500.0, height = 500.0, color = black}
paddle1 = {width = background.height/30, height = background.height/7, x = 20-background.width/2, y = 0.0}
paddle2 = {paddle1 | x <- background.width/2 - 20}
ball = {side = paddle1.height/5, x = 0, y = 0, vx = 1, vy = 0.3}
--UPDATE
import Keyboard
import Window
import Graphics.Input (Input, input, button, dropDown)
import Graphics.Input.Field (Content, noContent, field, defaultStyle, Forward, Backward)
-- MODEL
data Direction = North | East | South | West
type Robot = {x:Int, y:Int, dir:Direction}
type Board = [(Int,Int)]
type Game = {robot:Robot, board:Board}
import String
import Graphics.Input (Input, input)
import Graphics.Input.Field as Field
xaxis = segment (-150,-100) (150,-100)
yaxis = segment (-150,-100) (-150,100)
content : Input Field.Content
content = input Field.noContent
field = Field.field Field.defaultStyle content.handle id "Type here!" <~ content.signal
import List
import Mouse
import Window
--MODEL
defaultBall = {x = 0, y = 0, v = toFloat 0, angle = toFloat 0}
--UPDATE
location t b = { b | x <- b.x - t * b.v * cos b.angle,
y <- b.y - t * b.v * sin b.angle }
import Mouse
import Window
-- Mouse.isDown is true whenever the left mouse button
-- is pressed down and false otherwise.
--MODEL
type Points = [(Int,Int)]
--UPDATE
@chribben
chribben / SignalForPressingRightOrLeftArrow.elm
Created August 21, 2013 08:18
SignalForPressingRightOrLeftArrow
import Keyboard
keyToBool x = if x == 0 then False else True
sfx p = lift (\p -> p.x) p
signalX = sfx Keyboard.arrows
xArrowPulse = fpsWhen 10 (keyToBool <~ signalX)
main = lift asText xArrowPulse
@chribben
chribben / MoveableAndClickableBouncingFruit.elm
Created August 18, 2013 14:54
MoveableAndClickableBouncingFruit
import Random
import Mouse
import Keyboard
data Fruit = Apple | Orange | Banana | Melon | Guava
rand = Random.range 0 4 (Mouse.clicks)
fruit n = if | n == 0 -> Apple
| n == 1 -> Orange
| n == 2 -> Banana
| n == 3 -> Melon
| otherwise -> Guava