Skip to content

Instantly share code, notes, and snippets.

View mat3u's full-sized avatar

Matt Stasch mat3u

View GitHub Profile
@mat3u
mat3u / gol.fs
Last active August 29, 2015 14:16
type Cell = int * int
let exists_in element =
Seq.exists ((=) element)
let vicinity (x, y) =
seq {
for px in -1..1 do
for py in -1..1 do
yield (x+px, y+py)
type Verbosity = Silent | Normal | Verbose
type Url = string
type Depth = int
let (|IsDepth|_|) str =
match System.Int32.TryParse(str) with
| (true, int) when int > 0 -> Some int
| _ -> None
let (|IsUrl|_|) url =
@mat3u
mat3u / kMeans.Tests.fs
Last active August 29, 2015 14:14
k-means in F#
module kMeans
open NUnit.Framework
let distance = (fun a b -> abs(a - b))
let avg = Seq.average
[<Test>]
let ``Should generate random subset`` () =
let data = seq [1..10]
@mat3u
mat3u / unzip3.fs
Last active August 29, 2015 14:14
let rec unzip3<'a, 'b, 'c> ((A: 'a list), (B: 'b list), (C: 'c list)) (tuples: (('a * 'b * 'c) list)) : ('a list) * ('b list) * ('c list) =
match tuples with
| (a: 'a, b: 'b, c: 'c)::tail -> unzip3 (a ++ A, b ++ B, c ++ C) tail
| [] -> (A, B, C)
let rec unzip3 (A, B, C) tuples =
match tuples with
| (a: 'a, b: 'b, c: 'c)::tail -> unzip3 (a :: A, b :: B, c :: C) tail
| [] -> (A, B, C)
@mat3u
mat3u / gist:612352a76fb4829682c4
Created January 16, 2015 12:17
Functional Friday
// Functional Friday - Introduction
// Mateusz Stasch <mstasch@future-processing.com>
// 2014.12.12
// Links:
// http://fsharp.org
// http://tryfsharp.org
// http://fsharpforfunandprofit.com
// F# is a mature, open source, cross-platform, functional-first programming language
@mat3u
mat3u / taskExtract.ps1
Last active August 29, 2015 14:02
Extracts TODOs and FIXMEs from C# code
param(
[ValidateScript({Test-Path $_ -PathType 'Container'})]
[string]$path
)
Add-Type -AssemblyName System.Web
$files = ls -R -Path $path -Filter *.cs
$tasks = @()
@mat3u
mat3u / restore.sql
Created March 21, 2014 08:38
Restore database script
CREATE procedure [dbo].[db_restore](@Dbname nvarchar(200), @File nvarchar(max))
AS
BEGIN
declare @sql nvarchar(max)
declare @rowsPath nvarchar(max)
declare @logPath nvarchar(max)
declare @dbRows nvarchar(255)
declare @dbLog nvarchar(255)
IF (SELECT COUNT(*) FROM sys.databases WHERE name = @Dbname) = 0