Skip to content

Instantly share code, notes, and snippets.

View gist:11dc4427be513f4ce6c6fb1408ddb62d
let RunProcess (startInfo : ProcessStartInfo) =
let bufferOutput = new StringBuilder()
let bufferError = new StringBuilder()
let dataHandler handler = DataReceivedEventHandler(fun sender args -> try handler args.Data with _ -> ())
let append (sb: StringBuilder) txt = sb.Append(txt + "\n") |> ignore
let consume (sb: StringBuilder) = sb.ToString() |>! (fun _ -> sb.Clear() |> ignore)
let outputHandler = append bufferOutput |> dataHandler
let errorHandler = append bufferError |> dataHandler
startInfo.RedirectStandardInput <- true
startInfo.RedirectStandardOutput <- true
@rmunn
rmunn / build-sh
Created Feb 24, 2018
Bash completion file for FAKE build scripts (build.fsx)
View build-sh
# bash completion for FAKE build.sh scripts
# Assumes that your FAKE build script is named build.fsx
# Put this file in /etc/bash_completion.d/ and start a new terminal to activate it
_build_sh()
{
local cur base dir
cur="${COMP_WORDS[COMP_CWORD]}"
base="${COMP_WORDS[0]}"
dir=$(dirname "${base}")
@rmunn
rmunn / mono-stacktrace-from-corrupted-paket-executible.txt
Created Jul 21, 2017
Stack trace after a corrupted paket.exe file (truncated download) causes Mono to segfault
View mono-stacktrace-from-corrupted-paket-executible.txt
Stacktrace:
at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Diagnostics.FileVersionInfo.GetVersionInfo_internal (System.Diagnostics.FileVersionInfo,string) [0x0000c] in <2b0d86369d72459baed0cee98a8e578a>:0
at System.Diagnostics.FileVersionInfo.GetVersionInfo (string) [0x00019] in <2b0d86369d72459baed0cee98a8e578a>:0
at Paket.Bootstrapper.PaketRunner.SetBootstrapperArgument (string,System.Collections.Generic.IEnumerable`1<string>) [0x00000] in <807696f396d948598fb055e78b9c00e9>:0
at Paket.Bootstrapper.PaketRunner.Run (string,System.Collections.Generic.IEnumerable`1<string>) [0x00000] in <807696f396d948598fb055e78b9c00e9>:0
at Paket.Bootstrapper.Program.OnSuccessfulDownload (Paket.Bootstrapper.BootstrapperOptions) [0x0003c] in <807696f396d948598fb055e78b9c00e9>:0
at Paket.Bootstrapper.Program/<>c__DisplayClass0_0.<Main>b__0 () [0x00000] in <807696f396d948598fb055e78b9c00e9>:0
at Paket.Bootstrapper.Program.StartPaketBootstrapping (Paket.Bootstrapper.DownloadStrategies.IDownloadSt
@rmunn
rmunn / bitcount.fs
Created Jul 20, 2017
Bitcount (aka popcount) implementation in F#, for 32 and 64-bit ints
View bitcount.fs
let bitcount (n : int) =
let count2 = n - ((n >>> 1) &&& 0x55555555)
let count4 = (count2 &&& 0x33333333) + ((count2 >>> 2) &&& 0x33333333)
let count8 = (count4 + (count4 >>> 4)) &&& 0x0f0f0f0f
(count8 * 0x01010101) >>> 24
let bitcount64 (n : int64) =
let count2 = n - ((n >>> 1) &&& 0x5555555555555555L)
let count4 = (count2 &&& 0x3333333333333333L) + ((count2 >>> 2) &&& 0x3333333333333333L)
let count8 = (count4 + (count4 >>> 4)) &&& 0x0f0f0f0f0f0f0f0fL
View correct-fsharp-snippets.txt
First snippet:
let rec fib = seq {
yield! [0; 1]
yield! fib
|> Seq.pairwise
|> Seq.map (fun (prev, next) -> prev + next)
}
@rmunn
rmunn / git-prompt-howto.md
Created Mar 9, 2016
How to get a nice Bash prompt that includes your current Git branch
View git-prompt-howto.md

Edit your .bashrc as follows. Before the "case $TERM" statement that sets color_prompt, add the following:

# GNOME Terminal is broken re: $TERM settings
if [ "$COLORTERM" = "gnome-terminal" -a "$TERM" = "xterm" ]; then
    TERM="xterm-256color"
fi

Now edit that "case $TERM" statement to look like this:

@rmunn
rmunn / OutlandsMonoLeadership.o8d
Created Jan 15, 2016
Example OCTGN-format deck with notes in it (for the Lord of the Rings card game by Fantasy Flight Games)
View OutlandsMonoLeadership.o8d
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<deck game="a21af4e8-be4b-4cda-a6b6-534f9717391f" sleeveid="0">
<section name="Hero" shared="False">
<card qty="1" id="85699571-9cc3-4ccc-98b0-0e1664893ef5">Hirluin the Fair</card>
<card qty="1" id="bf2cb5a8-2ec6-4366-89f6-7e3010686a85">Balin</card>
<card qty="1" id="51223bd0-ffd1-11df-a976-0801200c9002">Théodred</card>
</section>
<section name="Ally" shared="False">
<card qty="3" id="4cb4741d-c9d8-4d62-ab4f-50fa80c59fbb">Anfalas Herdsman</card>
<card qty="3" id="1c149f93-9e3b-42fa-878c-80b29563a283">Ethir Swordsman</card>
@rmunn
rmunn / fizzbuzz.clj
Created Nov 17, 2014
FizzBuzz with transformation functions
View fizzbuzz.clj
;; FizzBuzz with transformation functions
(defn reduce'
"Alternate reduce with reordered params, so -> can be used easily."
[val f coll]
(reduce f val coll))
(def fizz (constantly "fizz"))
(def buzz (constantly "buzz"))
(def fb (constantly "fizzbuzz"))
@rmunn
rmunn / gist:1714107
Created Feb 1, 2012
Error messages from Quickfixsigns interaction with Fugitive
View gist:1714107
Quickfixsigns PlaceSign: Invalid lnum: {'lnum': 0, 'bufnr': 2, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'Added the sweet quickfixsigns plugin (+/- by lines)'}
Quickfixsigns PlaceSign: Invalid lnum: {'lnum': 0, 'bufnr': 3, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'Added C-d for page down mapping and better explanation'}
Quickfixsigns PlaceSign: Invalid lnum: {'lnum': 0, 'bufnr': 4, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'Fixes neocomplcache undefined variable'}
Quickfixsigns PlaceSign: Invalid lnum: {'lnum': 0, 'bufnr': 5, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'Command-T / ctrlp size tweak for performance'}
Quickfixsigns PlaceSign: Invalid lnum: {'lnum': 0, 'bufnr': 6, 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'One more neocachecompl tweak'}
Quickfixsigns PlaceSign: Invalid lnum: {'lnum': 0, 'bufnr': 7, 'col': 0, 'valid': 1,