Skip to content

Instantly share code, notes, and snippets.

@miklund
miklund / permutations
Created September 15, 2012 12:55
Function to permute a list into permutations with fixed length
// wide depth lft rgt
// depth: the length of result lists
// lft: the left list (default [])
// rgt: the right list (default items we want to permute)
//
// example: wide 2 [] [1; 2; 3]
// -> [[1; 2]; [1; 3]; [2; 1]; [2; 3]; [3; 2]; [3; 1]]
let rec wide depth lft = function
| [] -> []
| hd :: tl -> (deep hd (depth, (lft @ tl))) @ (wide depth (hd :: lft) tl)
@miklund
miklund / gist:3838023
Created October 5, 2012 04:07
FAKE ExecProcess build target example
let fslex = @"packages\FSPowerPack.Community.2.1.3.1\Tools\fslex.exe"
let parserDir = @".\LiteMedia.Dsl\"
// FsParse
Target "FsYacc" (fun _ ->
let result =
ExecProcess (fun info ->
info.FileName <- fsyacc
info.Arguments <- parserDir + "parser.fsy --module Parser"
) (System.TimeSpan.FromMinutes 1.)
@miklund
miklund / pe32.fs
Created October 18, 2012 03:55
F# solution to Project Euler 31
module PE31
let solution n =
let filter_less_than n = List.filter (fun c -> c <= n)
let rec _solution values = function
| 200 -> 1 // success
| n when n > 200 -> 0
| n -> List.sum (List.map (fun coin -> _solution (values |> filter_less_than coin) (n + coin)) values)
_solution [200; 100; 50; 20; 10; 5; 2; 1] n
@miklund
miklund / CacheArg.cs
Last active February 20, 2019 19:43
A simple cache interceptor using Castle.DynamicProxy2.
namespace LiteMedia.Cache
{
public static class CacheArg<T>
{
public static readonly T Any = default(T);
}
}
@miklund
miklund / TestClass1.cs
Created September 19, 2013 06:54
MEF Open Generics problem in unit test project. 1. This works if run in a console exe project 2. Does not work if you run through nunit-console(-x86).exe 3. Does not work if run through Resharper 4. Works! if run through Visual Studio test runner (!) Could someone smarter than me figure this out? Need to reference System.ComponentModel.Compositi…
namespace Test
{
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using NUnit.Framework;
[Export]
public class Class0
{

Keybase proof

I hereby claim:

  • I am miklund on github.
  • I am mikaellundin (https://keybase.io/mikaellundin) on keybase.
  • I have a public key whose fingerprint is 1C4F AD00 2906 BD13 EA40 2BD2 8520 5442 15D9 FD5E

To claim this, I am signing this object:

// Brains game implementation in javascript
// new Brains(el)
// initialize Brains on a preferably empty div
function Brains (el) {
// --- START: Board ---
var Board = function (boardEl) {
var board = [[]];
var width = 0;
@miklund
miklund / 2015-12-12 backup-database-in-a-rails-docker-setup
Last active December 14, 2015 07:37
2015-12-12 Backup database in a rails docker setup
# Backup database in a rails docker setup
# http://blog.mikaellundin.name/2015/12/12/backup-database-in-a-rails-docker-setup.html
@miklund
miklund / 2015-12-11-deploying-legacy-rails-application-on-raspberry-pi-2-with-docker
Created December 15, 2015 19:23
2015-12-11 Deploying legacy Rails application on Raspberry Pi 2 with Docker
# Deploying legacy Rails application on Raspberry Pi 2 with Docker
# Mikael Lundin
# http://blog.mikaellundin.name/2015/12/11/deploying-legacy-rails-application-on-raspberry-pi-2-with-docker.html
@miklund
miklund / 2015-06-04 property-based-testing-with-fsharp.html
Created December 15, 2015 19:50
2015-06-04 Property-Based Testing with F#
# Property-Based Testing with F#
# Author: Mikael Lundin
# Link: http://blog.mikaellundin.name/2015/06/04/property-based-testing-with-fsharp.html