Skip to content

Instantly share code, notes, and snippets.

View entry-point
#!/usr/bin/env python3
import argparse as ap
import contextlib as cl
import os
import pathlib
import shlex
import sys
import tarfile
import urllib.request as ur
View compile
#!/bin/bash -e
set -o pipefail
BUILDPACK_HOME=$(cd "$(dirname "$0")" && cd .. && pwd)
STEPS="$BUILDPACK_HOME/steps"
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
View java.c
/*
* Loads a class, convert the '.' to '/'.
*/
static jclass
LoadClass(JNIEnv *env, char *name)
{
char *buf = MemAlloc(strlen(name) + 1);
char *s = buf, *t = name, c;
jclass cls;
jlong start, end;
View gist:4a354fca9fd6bb030587
commit f3d6bcc227f14770b3d72f094f5b00f3939a6d8f
Author: Owen Jacobson <owen.jacobson@grimoire.ca>
Date: Mon Apr 13 23:36:41 2015 -0400
Add a magic linebreak to build.gradle.
Removing this line break causes Gradle to believe that the `publications`
section is being applied _after_ the Bintray plugin accesses the publications.
As this is illegal, it fails the build:
View gist:10430925
. /usr/local/git/contrib/completion/git-completion.bash
. /usr/local/git/contrib/completion/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
ps1_status() {
if [ $? -ne 0 ]; then
echo ":("
else
echo ":)"
View gist:9628394

Why We No Longer Write Init Scripts

In early 2014, we started switching our in-house services from System V startup (the standard service startup mechanism on RHEL up to RHEL 6) to supervisord, and ceased writing new SysV init scripts. The technical rationale is a bit involved; the end result simplifies development and improves parity between production and development environments, while also being easier to manage and deploy. To explain how this works, let's back up a step and talk about classic Unix daemonization.

Unix Daemons the Old Way, and Why SysV Init Sucks

The classic Unix daemonization system has each daemon (service) started by a dedicated command, which sets up the daemon as a child of PID 1, and then exits. You can see this in practice: run nginx and note that NginX starts in the background, and then returns control of the terminal to your shell. To make this happen, the startup program has to do a very complicated series of system calls. From the systemd documentation:

  1. Close all o
View Fail.java
package com.example.jersey2;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.springframework.stereotype.Component;
View gist:7991889
#!/bin/bash -e
## usage: mvn-debug <target...>
## or: SUSPEND=y mvn-debug <target...>
## or: DEBUG_PORT=2000 mvn-debug <target>
SUSPEND="${SUSPEND:-n}"
DEBUG_PORT="${DEBUG_PORT:-8000}"
export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=${DEBUG_PORT},server=y,suspend=${SUSPEND} ${MAVEN_OPTS}"
View gist:6878082
function screenToSvg(svg, x, y) {
var point = svg.createSVGPoint();
point.x = x;
point.y = y;
var screenMatrix = svg.getScreenCTM();
var svgMatrix = screenMatrix.inverse();
return point.matrixTransform(svgMatrix);
}
View gist:6516067
class my_app {
$checkout = "/vagrant"
$virtualenv = "/home/vagrant/env"
python::virtualenv { $virtualenv:
ensure => present,
owner => "vagrant",
version => "system",
}