Skip to content

Instantly share code, notes, and snippets.

View jdowner's full-sized avatar

Joshua Downer jdowner

View GitHub Profile
@jdowner
jdowner / regex.py
Created February 2, 2015 00:52
Named regex groups
import re
class Regex(object):
"""
This is a convenience class for wrapping a regular expression, naming the
groups in the expression, and retrieving a named tuple as the result of a
match. For example,
>>> regex = Regex('filename: (\S*)', 'filename')
>>> regex.match('filename: my-file.txt')
@jdowner
jdowner / sendmail.py
Created January 23, 2015 16:54
How to send email using python
#!/usr/bin/env python
import email.mime.text
import smtplib
username = 'foo@example.com'
password = '****************'
hostname = 'outlook.office365.com'
msg = email.mime.text.MIMEText('test')
"""Disk And Execution MONitor (Daemon)
Configurable daemon behaviors:
1.) The current working directory set to the "/" directory.
2.) The current file creation mode mask set to 0.
3.) Close all open files (1024).
4.) Redirect standard I/O streams to "/dev/null".
A failed call to fork() now raises an exception.
@jdowner
jdowner / chroot-env.sh
Last active August 29, 2015 14:13
chroot
#!/bin/bash
set -o pipefail
CHROOT_PATH="${HOME}/scm/chroot"
SRC_PATH="${HOME}/scm/rift"
die() {
echo
echo "ERROR: $*"
@jdowner
jdowner / keybase.md
Created January 10, 2015 14:09
keybase.md

Keybase proof

I hereby claim:

  • I am jdowner on github.
  • I am jdowner (https://keybase.io/jdowner) on keybase.
  • I have a public key whose fingerprint is 5CBD 453C 443E 82E6 6E4D 72DE 72D0 D9D9 8165 C99D

To claim this, I am signing this object:

@jdowner
jdowner / immutable.py
Created December 12, 2014 14:19
immutable decorator
import functools
def make_immutable(obj):
"""Tries to create an immutable version of an object
Converts object into a nested structure of named tuples where possible.
Primative types (int, str, float, bool) are unchanged but lists and sets are
converted into tuples. Objects are converted into named tuples.
This is not a terribly sophisticated function and will work best with
@jdowner
jdowner / HOWTO-bitlbee+hipchat.mkd
Last active August 29, 2015 14:11 — forked from taylor/HOWTO-bitlbee+hipchat.mkd
Configuring bitlbee + hipchat

Using bitlbee with HipChat

First time on bitlbee

  • register <username>

Initial setup

@jdowner
jdowner / vim-build.sh
Last active November 13, 2018 09:32
vim-build
#!/bin/bash
PREFIX=${HOME}/usr/local
VIMRUNTIMEDIR=${PREFIX}/share/vim/vim80/
./configure --with-features=huge \
--enable-multibyte \
--enable-python3interp=yes \
--with-python3-config-dir=/usr/lib/python3.5/config \
--enable-cscope \
@jdowner
jdowner / munkres-np-subtract.py
Last active August 29, 2015 14:06
Performance testing numpy subtract verses the interpreter
#!/usr/bin/python
import contextlib
import numpy
import time
@contextlib.contextmanager
def timer():
start = time.time()
yield
@jdowner
jdowner / example.html
Last active August 29, 2015 14:05
Example of SVG event passthrough
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>svg-event-overlay</title>
<style>
.first {
fill: red;
}