Skip to content

Instantly share code, notes, and snippets.

@toburger
toburger / prompt.ps1
Last active Mar 16, 2019 — forked from kadet1090/prompt.ps1
PowerLine like prompt for PowerShell
View prompt.ps1
$script:bg = [Console]::BackgroundColor;
$script:first = $true;
$script:last = 0;
function Write-PromptFancyEnd {
Write-Host-NoNewline -ForegroundColor $script:bg
$script:bg = [System.ConsoleColor]::Black
}
@toburger
toburger / idiomaticjsonserialiser.fs
Last active Sep 28, 2017 — forked from isaacabraham/idiomaticjsonserialiser.fs
This JSON.Net converter handles F# discriminated unions with more "idiomatic" JSON than what is generated by the current version of JSON .NET. Option types and single case DUs are transparently handled, and tuple-style properties are used rather than array notation.
View idiomaticjsonserialiser.fs
namespace Newtonsoft.Json.Converters
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open System
type IdiomaticDuConverter() =
inherit JsonConverter()
[<Literal>]
@toburger
toburger / build.fsx
Last active May 15, 2017
Use fsc 4.x to compile your code
View build.fsx
//...
let fscToolPath = findToolFolderInSubPath "fsc.exe" "packages"
let msbuildProps = [ "FscToolPath", fscToolPath ]
Target "Build" (fun _ ->
!! projectFile
|> MSBuildReleaseExt releaseDir msbuildProps "Build"
|> Log "AppBuild-Output")
View keyboard_speed_settings.reg
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
"AutoRepeatDelay"="250"
"AutoRepeatRate"="13"
"BounceTime"="0"
"DelayBeforeAcceptance"="0"
"Flags"="59"
"Last BounceKey Setting"=dword:00000000
"Last Valid Delay"=dword:00000000
View ParserLibrary.fs
(*
ParserLibrary.fsx
Final version of a parser library.
Related blog post: http://fsharpforfunandprofit.com/posts/understanding-parser-combinators-3/
*)
module ParserLibrary
View JsonParser.fs
(*
JsonParser.fsx
A JSON parser built from scratch using a combinator library.
Related blog post: http://fsharpforfunandprofit.com/posts/understanding-parser-combinators-4/
*)
module JsonParser
View maybe.js
function maybe(value) {
const isEmpty = () => value === undefined || value === null;
const nonEmpty = () => !isEmpty();
return {
map(f) { return isEmpty() ? this : maybe(f(value)) },
getOrElse(n) { return isEmpty() ? n : value },
isEmpty: isEmpty,
nonEmpty: nonEmpty
}
}
@toburger
toburger / file.php
Last active Sep 28, 2015
PHP: Computes the difference of two arrays by value, not by key (like array_diff_ukey)
View file.php
<?php
function diff($array1, $array2, $compare_func) {
return array_diff_ukey($array1, $array2, function($key1, $key2) use ($array1, $array2, $compare_func) {
if (!isset($array1[$key1])) return 1;
if (!isset($array2[$key2])) return -1;
return $compare_func($array1[$key1], $array2[$key2]);
});
}
@toburger
toburger / reflector.fsx
Last active Aug 29, 2015
Cool new F# 4.0 feature
View reflector.fsx
module Reflection =
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open System.Reflection
let private (|Name|) (info: MemberInfo) = info.Name
let private (|PropertyName|_|) = function
| PropertyGet (_, Name name, _) -> Some name
| _ -> None
View BumFitz.fsx
#r "System.Speech"
open System.Speech.Synthesis
let synt = new SpeechSynthesizer()
// synt.Rate <- 5 // schneller mochn!
let say s = synt.Speak(s: string)
[1 .. 100]
|> List.map (fun n ->
match n%3, n%5 with
You can’t perform that action at this time.