Skip to content

Instantly share code, notes, and snippets.

@rduplain
rduplain / haproxy-servers.cfg
Last active Jun 16, 2021
Rewrite haproxy configuration and reload service.
View haproxy-servers.cfg
# Edit this file then run `update-haproxy haproxy-servers.cfg`.
# Alternatively, use a shell pipeline to build server list `... | update-haproxy`.
server demo1 127.0.0.1:8001 check cookie demo1 weight 100
server demo2 127.0.0.1:8002 check cookie demo2 weight 100
server demo3 127.0.0.1:8003 check cookie demo3 weight 0
server demo4 127.0.0.1:8004 check cookie demo3 weight 0
@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 / 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 / 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 / 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 / README.md
Last active Jan 28, 2020
Demo of the Python `code` module, for interaction and DSLs.
View README.md

import code

This is a demonstration of the Python [code][1] module, which allows for an interactive interpreter to be embedded into a Python program.

code.interact(banner=None, readfunc=None, local=None)

Convenience function to run a read-eval-print loop. This creates a new instance of [InteractiveConsole][2] and sets readfunc to be used as the

@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 / 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 / simple_vertigo.py
Created Oct 29, 2013
Simple examples to get started with the vertigo package.
View simple_vertigo.py
import vertigo
class EmptyGraphNode(vertigo.GraphNode):
@property
def value(self):
return None
def key_iter(self):
return ()
@rduplain
rduplain / gist:6886040
Created Oct 8, 2013
Cronic - A cure for Cron's chronic email problem - by Chuck Houpt - http://habilis.net/cronic/
View gist:6886040
#!/bin/bash
# Cronic v2 - cron job report wrapper
# Copyright 2007 Chuck Houpt. No rights reserved, whatsoever.
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
set -eu
OUT=/tmp/cronic.out.$$
ERR=/tmp/cronic.err.$$