Skip to content

Instantly share code, notes, and snippets.

@tpope
tpope / .inputrc
Created September 8, 2011 16:43
Basic amenities for vi readline bindings
set keymap vi-insert
Control-a: beginning-of-line
Control-b: backward-char
Control-d: delete-char
Control-e: end-of-line
Control-f: forward-char
Control-k: kill-line
Control-n: next-history
Control-p: previous-history
set keymap emacs-ctlx
@praeclarum
praeclarum / ListDiff.cs
Created November 5, 2011 14:42
Finds a diff between two IEnumerables
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace Algorithms
{
/// <summary>
/// The type of <see cref="ListDiffAction{S,D}"/>.
static readonly string[] videoCardBlacklist = {"8086:0116"};
static void DisableHwRenderingForCrapVideoCards()
{
if (!String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("MY_VIDEO_CARD_REALLY_WORKS")))
{
return;
}
int osVersion = Environment.OSVersion.Version.Major * 100 + Environment.OSVersion.Version.Minor;
if (osVersion < 601)
@rampion
rampion / RedBlackTree.hs
Created May 11, 2012 13:55
red-black trees in haskell, using GADTs and Zippers
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
module RedBlackTree where
data Zero
data Succ n
type One = Succ Zero
data Black
@mislav
mislav / easy_way.rb
Last active May 20, 2020 13:48
RESOLVE SHORT URLS before storing. Short URLs are for microblogging; you should never actually keep them around.
require 'net/http'
# WARNING do not use this; it works but is very limited
def resolve url
res = Net::HTTP.get_response URI(url)
if res.code == '301' then res['location']
else url.to_s
end
end
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Text;
using System.Threading;

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"

@praeclarum
praeclarum / Layout.cs
Created March 16, 2013 05:23
A C# syntax for NSLayoutConstraints.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using MonoTouch.UIKit;
namespace Async.iOS
{
public static class Layout
{

In no particular order, some fiction I've loved:

  1. The Last Samurai by Helen DeWitt
  2. Vox and The Fermata by Nicholson Baker
  3. The Forgotten Beasts of Eld by Patricia McKillip
  4. The Cyberiad by Stanislaw Lem
  5. Winter's Tale by Mark Helprin
  6. Invisible Cities and Cosmicomics by Italo Calvino
  7. The Scar by China Mieville (And Perdido Street Station, natch. I also liked his The City and the City and Embassytown, but more as metaphorical tools than as stories)
  8. Rosencrantz and Guildenstern are Dead and Arcadia by Tom Stoppard