Skip to content

Instantly share code, notes, and snippets.

@tonymorris
tonymorris / StringZipper.scala
Created October 20, 2012 10:47
String zipper?
sealed trait StringZipper {
// The length of the zipper.
// O(1) if there have not been any length-altering updates, O(n) otherwise.
def length: Option[Int] =
this match {
case EmptyZ => Some(0)
case OffBoundsZ => None
case StringZ(_, x, _, y) => Some(y - x)
case ListZ(l, _, r, n) => n orElse Some(l.length + 1 + r.length)
}
@travisbrown
travisbrown / fizzbuzz-faster.scala
Created November 18, 2012 23:19
FizzBuzz in the type system (faster)
import shapeless._, Nat._
trait FizzBuzz[N <: Nat] {
type R3 <: Nat
type R5 <: Nat
def ti: ToInt[N]
def prev: List[String]
def d3: R3 =:= _0
def d5: R5 =:= _0
@atifaziz
atifaziz / csboot.cmd
Created November 23, 2012 11:19
C# embedded in a bootstrapping batch script
@@@ setlocal
@@@ set cmdnet=%temp%\cmd.net& set base=%temp%\cmd.net\%~n0& set this=%~f0
@@@ if not exist "%cmdnet%" md "%cmdnet%"
@@@ fc "%cmdnet%\%~nx0" "%this%" >nul 2>&1 && if exist "%base%.exe" set same=1
@@@ if not defined same copy "%this%" "%cmdnet%" >nul
@@@ if not defined same findstr /v "^@@@" "%this%" > "%base%.cs" || exit /b 42
@@@ if not defined same for /f %%i in ('dir /b /ad /on "%windir%\Microsoft.NET\Framework\v*"') do @if exist "%windir%\Microsoft.NET\Framework\%%i\csc".exe set csc=%windir%\Microsoft.NET\Framework\%%i\csc.exe
@@@ if not defined same if not defined csc (echo C# compiler not found>&2 & exit /b 42)
@@@ if defined csc "%csc%" /nologo /d:TRACE "/out:%base%.exe" "%base%.cs" || (type "%base%.cs" & del "%base%.cmd" & exit /b 42)
@@@ "%base%.exe" %*
@markembling
markembling / LICENCE
Created December 9, 2012 13:16
Google Drive & Spreadsheets Using OAuth 2.0 Service Account Example. See http://markembling.info/2012/12/google-spreadsheet-dotnet-oauth2-service-account
Copyright (c) 2012, Mark Embling
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Mark Embling nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
@dvdsgl
dvdsgl / VolareHelloWorld.fsx
Last active December 10, 2015 06:18
Sketching an API for 'Volare', a Sintra-esque web app DSL in F#, with nods to Express and CoffeeKup.
#r "Volare.dll"
open Volare
get "/" <| fun req res ->
"Hello, world!"
get "/:name" <| fun req res ->
html <| fun _ ->
body <| fun _ ->
@t0yv0
t0yv0 / subtyping.v
Last active August 27, 2025 17:43
Demonstrating TypeScript 0.8 type system to be unsound. The subtyping relationship is defined in a way that admits the following code that results in TypeError exception being thrown.
Require Import Utf8.
Inductive subtype (a b : Set) : Set :=
| ST : (a -> b) -> subtype a b.
Infix ":>" := subtype (at level 50).
Definition st {x y} f := ST x y f.
Definition unpack {a b : Set} (st : a :> b) :=
@patrickt
patrickt / cmdargs.hs
Last active December 10, 2015 20:18
data Options = Options
{ review :: Int
, username :: Maybe String
, password :: Maybe String
, patch :: Bool
, diffRevision :: Maybe Int
, purgeCredentials :: Bool
, dryRun :: Bool
} deriving (Show, Eq)
@palladin
palladin / gist:4524544
Created January 13, 2013 15:15
Type Safe Higher-order abstract syntax via GADT encoding
type Expr<'T> =
abstract Eval : unit -> 'T
let eval (x : Expr<'T>) = x.Eval()
let lift (value : 'T) =
{ new Expr<'T> with
member self.Eval () = value
}
let tup (first : Expr<'T>) (second : Expr<'S>) =
@anderssonjohan
anderssonjohan / Install-ARRFromWeb.ps1
Created January 19, 2013 21:01
A basic PowerShell script used to push IIS 7 Application Request Routing (tl;dr; reverse proxy features for UrlRewrite) to several servers. Assumptions: - cURL is in the path on the source machine - servers are specified as objects on the pipeline with properties telling the unc path and local path to a writable network share on the server - Win…
param(
[parameter(mandatory=$true, valuefrompipeline=$true)]
$TargetHost,
[switch] $force
)
begin {
$packages = @( `
@{ Name = "rewrite.msi"; Url = "http://download.microsoft.com/download/6/7/D/67D80164-7DD0-48AF-86E3-DE7A182D6815/rewrite_2.0_rtw_x64.msi" }, `
@{ Name = "webpi.msi"; Url = "http://download.microsoft.com/download/B/0/0/B00FEF21-79DE-48B0-8731-F9CFE70CE613/WebPlatformInstaller_3_10_amd64_en-US.msi" }, `
@{ Name = "webfarm.msi"; Url = "http://download.microsoft.com/download/3/4/1/3415F3F9-5698-44FE-A072-D4AF09728390/webfarm_amd64_en-US.msi" }, `

Application specific host grouping in Riemann-dash

It is generally desirable to group all the hosts for a specific service into a single dashboard view. For example, all the web servers are in single view while all the database servers are in another view.

This is usually not an issue when you are sending custom metrics using Riemann client. However, there are cases where you are using something that you do not control how the metrics are being sent. i.e., Riemann-tools.

Since Riemann-tools scripts are application agnostic, in order for the dashboard view to group hosts, we must inject some application specific information into the tags field. Tags is a collection of arbitrary strings. In the case of Riemann-tools scripts you can pass in arbitrary strings on the command line.

riemann-health --host 127.0.0.1 --tag "prod" --tag "webserver"