Skip to content

Instantly share code, notes, and snippets.

View dahlbyk's full-sized avatar

Keith Dahlby dahlbyk

View GitHub Profile
let GetChainLength value =
let next x = match x % 2L with
| 0L -> x / 2L
| _ -> x * 3L + 1L
let rec chain n acc = match n with
| x when x <= 1L -> acc
| x -> chain (next x) (acc+1)
value, (chain value 1)
seq { 1L..999999L }
static void Main(string[] args)
{
var f = Fault(() => Console.WriteLine("Okay"),
() => Console.WriteLine("Fault"));
f();
Console.WriteLine();
var g = Fault(() => { throw new Exception("Oops"); },
() => Console.WriteLine("Fault"));
try
Index: branches/1.3.1/src/Core/IE.cs
===================================================================
--- branches/1.3.1/src/Core/IE.cs (revision 1091)
+++ branches/1.3.1/src/Core/IE.cs (working copy)
@@ -20,6 +20,7 @@
using System.Collections;
using System.Diagnostics;
using System.Drawing;
+using System.Net;
using System.Runtime.InteropServices;
alias.lg=log -w -C --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.dd=diff -w -C --diff-filter=ACMRTUXB
alias.fp=format-patch -w -C --diff-filter=ACMRTUXB -o c:/Dev/JP/Patches
alias.new=log -w -C --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative origin/master..
alias.up=!git svn rebase && git push . remotes/git-svn:master && git push origin master
alias.dci=!git svn dcommit && git push . remotes/git-svn:master && git push origin master
filter disableSigning() {
$proj = $_
$xml = [xml](Get-Content $proj.FullName)
$propertyGroup = $xml.Project.PropertyGroup | ? {$_.SignAssembly}
if($propertyGroup.SignAssembly -eq 'true') {
echo "Disabling Signing: $proj"
$propertyGroup.SignAssembly = 'false'
$xml.save($proj.FullName)
Push-Location $proj.DirectoryName
@dahlbyk
dahlbyk / NestedSetModel.cs
Created March 31, 2011 04:19
Nested set model
public class NestedSetModelTest
{
public class Node
{
public Node(string value, params Node[] children)
{
Value = value;
Children = children;
}
@dahlbyk
dahlbyk / gist:932601
Created April 20, 2011 20:12
Write-ChildGitStatus
function Write-ChildGitStatus($dir = '.')
{
gci $dir |
where { $_.PSIsContainer } |
foreach {
pushd $_
$s = Get-GitStatus
if($s) {
Write-Host -NoNewline $_.Name
Write-GitStatus $s
@dahlbyk
dahlbyk / .gitattributes
Created July 13, 2011 16:05
C# .gitattributes
*.cs diff=csharp
@dahlbyk
dahlbyk / gist:1102893
Created July 24, 2011 18:09
Rx Sliding Window
static IObservable<string> CheckForFraud(IObservable<string> logins)
{
return from g in logins.GroupByUntil(l => l, CheckForFraud)
from c in g.Count()
where c >= 3
select g.Key;
}
static IObservable<Unit> CheckForFraud(IGroupedObservable<string, string> g)
{
@dahlbyk
dahlbyk / Enable-AllowInteractWithDesktop
Created August 13, 2011 16:16
Set "Allow Interact with Desktop" for Windows Service
$svcName = Get-Service -DisplayName *cruise* | select -Exp Name
$svcKey = Get-Item HKLM:\SYSTEM\CurrentControlSet\Services\$svcName
# Set 9th bit, from http://www.codeproject.com/KB/install/cswindowsservicedesktop.aspx
$newType = $svcKey.GetValue('Type') -bor 0x100
Set-ItemProperty $svcKey.PSPath -Name Type -Value $newType