Skip to content

Instantly share code, notes, and snippets.

View dch's full-sized avatar
🛋️

Dave Cottlehuber dch

🛋️
View GitHub Profile
;;; File: emacs-indent-erlang
;;; adapted from http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html
;; this has to be set to the real path on your system
(add-to-list 'load-path "~/.emacs.d/elpa/erlang-20131025.6")
(load-library "erlang")
;; comment out the call to untabify if you want the mixed tabs and spaces
(defun emacs-indent-function ()
@dch
dch / prealloc_bin.S
Created February 18, 2014 15:49 — forked from nox/prealloc_bin.S
{module, prealloc_bin}. %% version = 0
{exports, [{module_info,0},{module_info,1},{new,1}]}.
{attributes, []}.
{labels, 7}.
{function, new, 1, 2}.
@dch
dch / build_otp.sh
Created February 20, 2014 18:20 — forked from gburd/build_otp.sh
#!/usr/bin/env bash
# Note: erlang depends on ncurses, openssl at a minimum
usage ()
{
echo "usage: $0 <release> <type>"
echo " release: R14B01|R14B02|R14B03|R14B04|R15B|R15B01|R15B02|R15B03|R16B|R16B01|R16B02"
echo " type: normal, opt, gcov, gprof, debug, valgrind, or lcnt"
APPDIRS := $(wildcard apps/*)
## Example hack to filter one out:
## APPDIRS := $(filter-out apps/fooapp, $(APPDIRS))
define PROXY_TARGET
$(1):
$(foreach appdir,$(APPDIRS),$(MAKE) -C $(appdir) $(1) ;)
endef
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=${GHBU_ORG-"<CHANGE-ME>"} # the GitHub organization whose repos will be backed up
# (if you're backing up a user's repos instead, this should be your GitHub username)
GHBU_UNAME=${GHBU_UNAME-"<CHANGE-ME>"} # the username of a GitHub account (to use with the GitHub API)
GHBU_PASSWD=${GHBU_PASSWD-"<CHANGE-ME>"} # the password for that account
GHBU_GITHOST=${GHBU_GITHOST-"github.com"} # the GitHub hostname (see comments)
GHBU_PRUNE_OLD=${GHBU_PRUNE_OLD-true} # when `true`, old backups will be deleted

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"

{module, mpegts_alloc}. %% version = 0
{exports, [{module_info,0},{module_info,1},{new,1}]}.
{attributes, []}.
{labels, 7}.
{function, new, 1, 2}.

I was able to install FreeBSD on GCE in a very direct way, without the hurdles of Qemu, gcutil, and the FreeBSD installer. All are great tools, but I think my apporach is somewhat more suitable for GCE, or at least much simpler. Much of this is well-known practice for installing manually, with some fluff for managing it as a disk image, as well as the few odd networking requirements of GCE (MTU and netmask).

My basic approach is to:

  • Use my FreeBSD machine at home to build a self-hosting "rescue" disk image for GCE.
  • Start a temporary Linux machine in GCE from a provided image.
  • Copy my image from home to a raw block device.
  • Start a FreeBSD machine in GCE using that block device as the root.
@dch
dch / reflect.py
Created May 28, 2014 06:58 — forked from huyng/reflect.py
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
(ns your.namespace
(:require [riemann.transport :as rtransport]
[riemann.transport.udp :as rudp]
[interval-metrics.core :as metrics]
[clojure.tools.logging :as log])
(:import (java.nio ByteBuffer ByteOrder)
(org.jboss.netty.buffer ChannelBufferInputStream)
(org.jboss.netty.handler.codec.oneone OneToOneDecoder)
(org.jboss.netty.handler.execution ExecutionHandler
MemoryAwareThreadPoolExecutor)))