Skip to content

Instantly share code, notes, and snippets.

class ThreadThing
def initialize
@threads = []
@mutex = Mutex.new
@shutdown = false
trap('INT') { shutdown }
trap('TERM') { shutdown }
end
using NUnit.Framework;
using metrics.Stats;
namespace metrics.Tests.Stats
{
[TestFixture]
public class ExponentiallyDecayingSampleTests
{
[Test]
public void HoldsRequestedNumberOfSamples()
@slumos
slumos / l.sh
Created March 18, 2013 17:04
Magical DWIM show the thing
function l {
if [[ ! -t 0 ]]; then
# stdin is not connected to a tty
pager -
elif [[ $# -eq 1 && -f "$1" ]]; then
# single argument names a file
pager "$1"
else
ls -CFL $*
fi
typeset -U path
typeset -U manpath
function addpath {
[[ -d "$1" ]] && path=("$1" $path)
[[ -d "${1:h}/sbin" ]] && path=("${1:h}/sbin" $path)
for d in "${1:h}"/{man,share/man}; do
[[ -d "$d" ]] && manpath=("$d" $manpath)
done
}
public static string[] Columns(this IDataReader reader)
{
return Enumberable.Range(0, reader.FieldCount).Select(reader.GetName).ToArray();
}
//...
var columns = reader.Columns();
@slumos
slumos / client.rb
Created March 28, 2014 20:00
Why prefer ActiveRecord `attribute=`
User.create(username: 'jdoe', name: 'John Doe')
User.find_by_name('John Doe')
@slumos
slumos / osx-flush-dns.sh
Last active January 27, 2018 16:34
flush dns cache for different versions of OSX.
#! /bin/sh
# super-simplified version of flushDNSCache from Tunnelblick
osx_version=$(/usr/bin/sw_vers | awk '/ProductVersion:/ {print $2}')
echo "OSX: ${osx_version}"
case "${osx_version}" in
10.9.*|10.11.*)
sudo /usr/bin/dscacheutil -flushcache
sudo /usr/bin/pkill -HUP mDNSResponder
#!/bin/sh
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until script has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Set the colours you can use
black='\033[0;30m'
@slumos
slumos / init.lua
Created November 26, 2014 00:41
~/.mjolnir/init.lua
local app = require "mjolnir.application"
local hotkey = require "mjolnir.hotkey"
local window = require "mjolnir.window"
local fnutils = require "mjolnir.fnutils"
local geom = require "mjolnir.geometry"
local screen = require "mjolnir.screen"
local alert = require "mjolnir.alert"
local MOD = {"cmd", "ctrl"}
# Initialize to use Indexer object idx. Also precomputes some
# things that can be computed with a single traversal of the
# document directory.
def initialize(idx)
@idx = idx
@m = 0.0
@c = Hash.new(0.0)
@idx.each_document do |doc|
@m += 1
@c[cat(doc.name)] += 1