Skip to content

Instantly share code, notes, and snippets.

View jdowner's full-sized avatar

Joshua Downer jdowner

View GitHub Profile
@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 / 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: $*"
"""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 / 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')
@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 / password_store.py
Last active August 29, 2015 14:14
Password retrieval from password-store or a custom store.
import collections
import os
import subprocess
class Entry(collections.namedtuple('Entry', 'username, password, url')):
"""
An Entry object represents an entry in the password store.
"""
def __new__(cls, username, password, url=None):
"""Create a new Entry object
@jdowner
jdowner / blocks.py
Created February 2, 2015 12:28
Iterator to return a sequence of blocks from an iterable
def blocks(iterable, n):
"""Create a generator that returns blocks of values
This generator yields lists of values from the iterable that contain 'n'
elements (except, possible, for the last block if the length of the iterable
is not divisible by 'n').
Arguments:
iterable: an interable object like a list or generator
n: a positive integer
@jdowner
jdowner / sqlite2yaml.py
Last active November 14, 2023 13:23
Print a sqlite database file as YAML
#!/usr/bin/env python2
import argparse
import sys
import sqlalchemy
import yaml
def sqlite2yaml(filename):
@jdowner
jdowner / input.py
Last active September 9, 2022 15:33
asyncio timed input
#!/usr/bin/env python3
"""
The MIT License (MIT)
Copyright (c) 2016 Joshua Downer
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
@jdowner
jdowner / reqpro.py
Created April 28, 2016 10:58
requests-provides mechanism
import functools
import weakref
class Property(object):
instances = weakref.WeakValueDictionary()
def __new__(cls, name):
if name in Property.instances:
return Property.instances[name]