Skip to content

Instantly share code, notes, and snippets.

@rduplain
rduplain / slides.md
Last active February 7, 2019 15:40
Use Werkzeug's web-based interactive debugger with Tornado.

Interactive Debugging in any Python Web Project

Ron DuPlain - PyOhio 2013

Turn this:

@rduplain
rduplain / gist:4980944
Created February 18, 2013 21:31
SysV Init script for supervisord, running as a production user 'garcon'. Run supervisorctl as 'garcon'.
#! /bin/sh
# /etc/init.d/supervisord
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: process supervisor
### END INIT INFO
@rduplain
rduplain / gist:4946399
Last active December 13, 2015 17:18
Prevent stop/restart of postgresql on Debian/Ubuntu. Do so carefully while watching updates, and restart manually.
#!/bin/sh
# /usr/sbin/policy-rc.d
# Do not stop/restart postgresql. --rduplain 2013-02-13
# http://askubuntu.com/a/254307/113086
if [ "$1" = "postgresql" ]; then
# Forbid stop/restart, or any init action for that matter.
# 101 - action forbidden by policy
exit 101
fi
@rduplain
rduplain / get.py
Last active October 13, 2015 01:47
Build a road-trip curated mp3 directory of a podcast. Our car plays .mp3 files from CD & USB,
"Build a road-trip curated mp3 directory of a podcast."
# Developed against feedparser v5.1.2 and BeautifulSoup v3.2.1.
# pip install feedparser BeautifulSoup
import datetime
import re
import time
import urllib
@rduplain
rduplain / xscreensaver-watch.sh
Created October 8, 2012 15:02
Watch xscreensaver lock/unlock events and act on them.
#!/bin/sh
# Watch xscreensaver and react to status changes.
#
# Replaced my previous perl-based recipe with this:
# http://semicomplete.googlecode.com/svn/tools/xscreensaver-watch.sh
#
# Include somewhere in X session startup with:
#
# xscreensaver-watch &
@rduplain
rduplain / gist:3701086
Created September 11, 2012 19:11
Hook for git commits to print top-line character count of commit message.
#!/bin/bash
# Hook for git commits to print top-line character count of commit message.
# Useful for calls to `git commit -m '...'` keeping to 50 char convention.
#
# Place into a file called .git/hooks/commit-msg on a repository.
# Be sure to set executable mode: chmod a+x .git/hooks/commit-msg
count_plus_newline=`head -1 $1 | wc -m | awk '{ print $1 }'`
let count=$count_plus_newline-1
echo "Top line character count: $count"
@rduplain
rduplain / README.md
Created August 30, 2012 16:07
Flask-Script: demo passing in configuration file.

This demonstrates that you can configure a Flask application through Flask-Script, without having to create a Flask instance or deal with circular dependencies. Note that Flask-Script's Manager accepts a factory function in place of a Flask app object.

Running:

python manage.py runserver

gives "Hello, world!" on http://localhost:5000/, while running:

python manage.py runserver -c development.cfg
@rduplain
rduplain / editor.py
Last active October 21, 2018 19:32
Wrap sed in Python to provide ed-style line editing in a simple function call.
"Wrapper to provide ed-style line editing."
# Ron DuPlain <ron.duplain@gmail.com>
from subprocess import Popen, PIPE
def edit(text, command):
r"""Edit given text using ed-style line editing, using system's sed command.
Examples:
@rduplain
rduplain / build_clone_script.py
Created July 15, 2012 15:30
Backup GitHub with dumb scripts.
"A dumb script builder to clone scraped GitHub repo listings."
# 1. Scrape <ul id="repo_listing" class="repo_list"> into listing.html
# 2. python build_clone_script.py | sort -u > clone.sh
# 3. time sh clone.sh
from __future__ import print_function
import lxml.html
@rduplain
rduplain / commitments.rst
Created June 23, 2012 21:14
A commitment spec, a data model in structured text for injestion. Collaboration with mattd.

Life Area

Commitment 1

Program