Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Stasch mat3u

View GitHub Profile
@mat3u
mat3u / restore.sql
Created Mar 21, 2014
Restore database script
View restore.sql
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
@mat3u
mat3u / taskExtract.ps1
Last active Aug 29, 2015
Extracts TODOs and FIXMEs from C# code
View taskExtract.ps1
param(
[ValidateScript({Test-Path $_ -PathType 'Container'})]
[string]$path
)
Add-Type -AssemblyName System.Web
$files = ls -R -Path $path -Filter *.cs
$tasks = @()
View gist:612352a76fb4829682c4
// 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
View unzip3.fs
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 / kMeans.Tests.fs
Last active Aug 29, 2015
k-means in F#
View kMeans.Tests.fs
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]
View gist:b3f785998d244df0fff7
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 =
View gol.fs
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)
View gol.fsx
//***
//*X*
//***
let vicinity (cx, cy) =
seq {
for x in -1..1 do
for y in -1..1 do
yield (cx + x, cy + y)
@mat3u
mat3u / TronAI.fs
Last active Aug 29, 2015
Engine for TronAI game - bots playing TRON
View TronAI.fs
type Direction = | North | East | South | West
type Position = int * int
type Size = int * int
type Player = int
type World = { Taken : Position list; Heads : (Player * Position) list }
type Bot = Player -> Position -> World -> Direction
let skipLast list =
// TODO: Ultra inefficient
View Disjoint.cs
using System.Collections.Generic;
using System.Linq;
namespace MergeLinks
{
public class Disjoint<T>
{
private readonly Dictionary<int, HashSet<T>> _groups;
private int _lastGroupKey = 0;