Skip to content

Instantly share code, notes, and snippets.

@rduplain
rduplain / vpn
Last active Oct 10, 2021
OpenVPN rc.d script for VPN client on BSD (i.e. jail): connect to VPN, start another service once VPN is connected.
View vpn
#!/bin/sh
# PROVIDE: vpn
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# vpn: connect to VPN, start another service once VPN is connected.
#
# Uses OpenVPN and assumes the configuration does not need any authentication
# beyond the given .conf file. Consider an approach using `expect` if needed:
#
@rduplain
rduplain / rrsync-mountpoint
Created Dec 27, 2017
Ensure rrsync subdirectory is a mountpoint.
View rrsync-mountpoint
#!/bin/bash
# Simple pre-rsync check to ensure rrsync subdirectory is a mountpoint.
# That is, only allow rsyncing to a mounted drive, and fail otherwise.
#
# Drop-in replacement for rrsync in .ssh/authorized_keys.
rrsync="$HOME"/bin/rrsync
# Assume -ro always comes before the subdirectory, if provided.
if [ $# -eq 0 ]; then
@rduplain
rduplain / 21-rules-of-thumb-how-microsoft-develops-its-software.md
Last active Dec 9, 2017
"21 Rules of Thumb for Shipping Great Software on Time" by Jim McCarthy at Microsoft
View 21-rules-of-thumb-how-microsoft-develops-its-software.md

21 Rules of Thumb for Shipping Great Software on Time

Jim McCarthy, Microsoft Corporation

Shipping great software on time is a difficult but not impossible task. Elements you think would count the most count for very little. Development methodology, process, technical prowess, excellence of tools and depth of project management skills all influence the outcome of a software development project; but nothing indicates success as much as the manager's ability to focus on a few critical and conceptually simple things. These things can be expressed as rules of thumb.

I enumerate twenty-one of these rules of thumb. Pick a handful (or so), apply them, and your project will be more likely to succeed. I lump them into three groups: "Shipping," "Great Software," "On Time". Duh. I cover them in a different order, because the concepts build a bit.

On Time

@rduplain
rduplain / README.md
Last active Apr 10, 2019
Code Quarterly's 2011 Q&A with Rich Hickey, by Michael Fogus
View README.md

From the Archives: Code Quarterly's 2011 Q&A with Rich Hickey

Rich Hickey is frequently quoted as saying:

You can reach a point with Lisp where, between the conceptual simplicity, the large libraries, and the customization of macros, you are able to write only code that matters. And, once there, you are able to achieve a very high degree of focus, such as you would when playing Go, or playing a musical instrument, or meditating. And then, as with those activities, there can be a > feeling of elation that accompanies that mental state of focus.

@rduplain
rduplain / README.md
Last active Nov 29, 2016
Setting up libRETS with SWIG
View README.md

Setting up libRETS with SWIG

2016-11-29

Goal: Get a working [SWIG][SWIG] build of the latest [libRETS][libRETS].

This setup will use Ubuntu with [vagrant][vagrant], a tool for creating development environments with virtual machines on Mac, GNU/Linux, and Windows.

Initial setup:

@rduplain
rduplain / doctest-in-hylang.md
Last active Jan 26, 2016
Investigate Python's doctest with hy (hylang.org).
View doctest-in-hylang.md

Can I use [doctest][doctest] with hy (hylang.org)?

Yes, you can, with some limitations.

Writing doctests in hy

hy already supports docstrings, and simple-quoted strings can have newlines in them. Write the doctest using formatting of a Python REPL (not hy):

@rduplain
rduplain / match.hy
Last active Dec 22, 2020
Getting started with hy (hylang.org), a simple example.
View match.hy
#!/usr/bin/env hy
;; match.hy - Getting started with hy (hylang.org), a simple example.
;;
;; As executable, `chmod +x match.hy`:
;;
;; $ ./match.hy '(.*), (.*)!' 'Hello, world!'
;; ('Hello', 'world')
;;
;; Developed on hy master 14c412c (after 0.11.1) on Python 3.5.
;;
@rduplain
rduplain / build-python3.5
Last active Nov 18, 2015
Simple, throwaway script to build Python 3.5 from source on Unix systems.
View build-python3.5
#!/bin/bash
set -e
apt-get build-dep -y python-imaging matplotlib lxml python3 # Ubuntu 12.04+, adjust to your needs
cd /usr/local/src/
curl -L -O https://python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz
tar -xf Python-3.5.0.tar.xz
cd Python-3.5.0
./configure --prefix=/usr/local/python3.5
make && make install
ln -s /usr/local/python3.5/bin/python3.5 /usr/bin/python3.5
@rduplain
rduplain / calendar_summary.py
Created Oct 28, 2015
Provide simple CSV summary of calendar events in .ics file.
View calendar_summary.py
#!/usr/bin/env python3
# calendar_summary: provide simple CSV summary of calendar events in .ics file.
#
# Developed on python3.5 with:
#
# pip install click icalendar pytz
#
# Save calendar.ics from:
#
# Google Calendar: Calendar Settings > Calendar Details > Export Calendar
@rduplain
rduplain / linode-node-balancer-500-limitation.md
Last active Nov 1, 2015
Linode NodeBalancer: Passive health checks lead to many false positives.
View linode-node-balancer-500-limitation.md

Linode's NodeBalancer assumes (as of Apr 2015) that a 500 response means that the node should be removed from rotation. Naturally, exceptions happen, so this is a very serious design limitation for any application which allows its code to have uncaught exceptions. I have opened a support ticket, with discussion copied here.

Ultimately, we had to rewrite our 500 responses to a non-50x response, which is strange to our application, but at least the change was limited to an nginx config and a single line of JavaScript to handle our status code as a server error. Linode specifically advised to use a non-50x response. All we need is a configuration in the NodeBalancer to not use passive checks on 500 Internal Server Error responses. There is no such configuration.

Due to the head-scratching nature of this configuration, we used 418 I'm a teapot in place of 500 responses. In nginx:

proxy_intercept_errors on;

error_page 500 =418 /_error/internal-serve