Skip to content

Instantly share code, notes, and snippets.

View ssboisen's full-sized avatar

Simon Stender Boisen ssboisen

View GitHub Profile
@ssboisen
ssboisen / huffman.example.fs
Created October 14, 2012 19:02
Huffman coding in F#
let ct = createCodeTree "abcdefghijklmnopqrstuvxyz "
let encoded = fastEncode ct ("simon says fsharp rocks" |> List.ofSeq)
let decoded = decode ct encoded
printfn "%A" encoded
printfn "%A" decoded
git branch -r --merged | where { $_ -match ' origin/(?<branch>ssb.+)' } | % { git push origin {:}$matches['branch'] }
#!/bin/sh
changedPackageFiles=$(git diff --cached --name-only | grep -i packages.config)
grepedCommitMessage=$(grep -i 'Update Packages' $1)
if [ -n "$changedPackageFiles" -a -z "$grepedCommitMessage" ]
then
echo "Aborting commit."
echo "Your changing the following packages.config files but you did not confirm this action:"
echo "$changedPackageFiles"
@ssboisen
ssboisen / gist:3780381
Created September 25, 2012 07:05
ssh tunneling
ssh -L 12345:internal-remote-server:8081 -N username@publicfacing-remote-server
@ssboisen
ssboisen / gist:3049158
Created July 4, 2012 19:31
ReplaceElementAt alternatives
let ReplaceElementAt index element sequence =
let beforeIndex = sequence |> Seq.take index
let atIndex = element |> Seq.singleton
let afterIndex = sequence |> Seq.skip (index + 1)
Seq.append beforeIndex <| Seq.append atIndex afterIndex
let ReplaceElementAt index element sequence =
let beforeIndex = sequence |> Seq.take index
let afterIndex = sequence |> Seq.skip (index + 1)
seq { yield! beforeIndex; yield element; yield! afterIndex }
$psgit = @{
'tb' = "git branch -r --no-color |
where { `$_ -match ' (?<fb>origin/(?<b>#1.+))' } |
% { git branch --set-upstream `$matches['b'] `$matches['fb'] }";
}
Set-Alias git Wrap-Git
function Wrap-Git {
if (-not $psgit.ContainsKey($args[0])) {
@ssboisen
ssboisen / gist:3002299
Created June 27, 2012 07:55
Unfold in C# .
public sealed class Option<T> : IEquatable<Option<T>>
{
private readonly T m_Value;
private static readonly Option<T> g_None = new Option<T>();
private Option() { }
private Option(T value)
{
m_Value = value;
}
public static void ShouldBeStructurallyEqualTo<T, U>(this IEnumerable<T> actual, IEnumerable<U> expected)
{
var actualList = actual.ToList();
var expectedList = expected.ToList();
actualList.Should().HaveCount(expectedList.Count());
bool isArrayOfValueType = typeof (T).IsArray && typeof (T).GetElementType().IsValueType;
foreach (var pair in actualList.Zip(expectedList, Tuple.Create))
{
if (isArrayOfValueType)
let fibs = Seq.unfold( fun (a,b) -> Some( a + b, (b, a + b) ) ) (1,1)
let result = fibs |> Seq.takeWhile ( fun x -> x <= 4000000)
|> Seq.sumBy ( fun x -> if x % 2 = 0 then x else 0)
@ssboisen
ssboisen / project_euler_p1.fsx
Created February 6, 2012 08:22
Project Euler Problems
{1..999} |> Seq.sumBy (fun n -> if n % 3 = 0 || n % 5 = 0 then n else 0)