Skip to content

Instantly share code, notes, and snippets.

@rduplain
rduplain / isatty.py
Created Jun 3, 2014
Is stdin a tty? Use this to determine whether to provide prompt or just read stdin for input.
View isatty.py
import sys
if sys.stdin.isatty():
print('you are a tty')
else:
print('you are not a tty')
@rduplain
rduplain / gist:e637ac9205d7df82dff4
Last active Aug 29, 2015
python: method delegation and copy-able threading.Lock
View gist:e637ac9205d7df82dff4
from threading import Lock
def build_delegating_method(delegate_name, method_name):
def delegating_method(self, *a, **kw):
delegate = getattr(self, delegate_name)
method = getattr(delegate, method_name)
return method(*a, **kw)
doc_format = "Calls self.{}.{}."
delegating_method.__name__ = method_name
@rduplain
rduplain / receipt.py
Created Aug 12, 2014
Simple project to print text to Epson receipt.
View receipt.py
# Print text to serial Epson printer. Escape codes are Epson ESC/POS.
#
# pip install pyserial jeni # Developed on Python 3.4.
import struct
import serial
from jeni import annotate, partial
from jeni import Injector
@rduplain
rduplain / wait.py
Last active Aug 29, 2015
Avoid race conditions by waiting for 200 OK on a URL.
View wait.py
import datetime as dt
import time
import requests # pip install requests
def get_ok(url):
"GET url and raise an exception if not 200 OK."
r = requests.get(url)
r.raise_for_status()
@rduplain
rduplain / Vagrantfile
Last active Aug 29, 2015
Simple Ubuntu LTS vagrant.
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.hostname = "scratch1"
config.vm.box = "ubuntu/trusty64" # vagrantcloud, use vagrant 1.5+
# config.vm.box_url = "http://domain.com/path/to/above.box"
@rduplain
rduplain / start_ventrilo.bat
Last active Aug 29, 2015
Wait, then launch Ventrilo, in order to include in autostart programs.
View start_ventrilo.bat
@echo off
title Waiting to Launch Ventrilo
rem Delayed launch ventrilo, since it does not as executable in Startup.
rem Sleep for 60s using a dummy ping.
ping 127.0.0.1 -n 60 > nul
start "Ventrilo" "C:\Program Files\Ventrilo\Ventrilo.exe" -cHOST:PORT:PASSWORD
@rduplain
rduplain / supervisord_minimal.conf
Created Sep 2, 2010
Configuration examples for supervisord, a process control system for projects.
View supervisord_minimal.conf
[supervisord]
nodaemon=true
[supervisorctl]
serverurl=unix://supervisor.sock
[unix_http_server]
file=supervisor.sock
[rpcinterface:supervisor]
@rduplain
rduplain / fancontrol-init.sh
Created Oct 5, 2010
SysV init script for fancontrol to keep deskside servers quiet (USE WITH CAUTION).
View fancontrol-init.sh
#! /bin/sh
# Save as /etc/init.d/fancontrol
# update-rc.d fancontrol defaults 90 10
#
# Based on /etc/init.d/skeleton
# Tested on a Supermicro 1U box running Ubuntu 10.04 x86_64.
### BEGIN INIT INFO
# Provides: fancontrol
# Required-Start:
# Required-Stop:
@rduplain
rduplain / .bootstrap.md
Created Oct 5, 2010
Instructions and configuration to get started with gitolite git hosting.
View .bootstrap.md

Git Hosting

  • GitHub.com provides great public repository hosting.
  • vanilla git over ssh works for simple project structures.
  • gitosis works well where you'd like to use ssh pubkeys without shell access.
  • gitolite works well where you'd like gitosis to have finer access control.

How I setup our gitolite server

@rduplain
rduplain / mirror-github
Created Feb 1, 2011
Mirror a GitHub project to a local filesystem.
View mirror-github
#!/bin/bash
# usage: mirror-github <account_name> <project_name>
git clone --mirror git@github.com:${1}/${2}.git