Skip to content

Instantly share code, notes, and snippets.

View dtanham's full-sized avatar

Dan Tanham dtanham

View GitHub Profile
@dtanham
dtanham / param_substitution.js
Created April 21, 2013 17:41
Very simple parameter subsitution in JS. Arguments are string containing parameter placeholders and a corresponding object of keys and values. Depends on jQ.
// Return s, with parameters substituted as in key-values of object params
function subsituteParams(s, params) {
$.each(params, function(k,v) {
s = s.replace(k,v);
});
return s;
}
import parsedatetime.parsedatetime as pdt
def datetimeFromString( s ):
c = pdt.Calendar()
result, what = c.parse( s )
dt = None
# what was returned (see http://code-bear.com/code/parsedatetime/docs/)
@dtanham
dtanham / flush-iptables.sh
Created January 27, 2014 12:43
Remove firewall rules from default Debian build
#!/bin/sh
# This file will reset the firewall to allow everything.
#
# Set the default policy
#
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
#
# Set the default policy for the NAT table
@dtanham
dtanham / mail.py
Created April 26, 2014 17:54
Python SMTP mailer class for HTML and plain text email
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
class Mailer:
def __init__(self, **kwargs):
mandatory_args = ["username","password","server","port"]
for x in mandatory_args:
@dtanham
dtanham / Install_Pillow.sh
Created May 6, 2014 20:36
Installing Pillow on OS X
source venv/bin/activate # Remove if not using a virtualenv
export CFLAGS=-Qunused-arguments # /headbashing
pip install Pillow # Install with pip
python -c "import PIL" # Verify it worked
@dtanham
dtanham / lastday.py
Created May 6, 2014 20:39
Last day of month (30, 31, 28, 29)
"""Calculates the end date for any given datetime object"""
import calendar
def last_day(year, month):
return calendar.monthrange(year, month)[1]
@dtanham
dtanham / sign_python.sh
Created May 10, 2014 10:18
Self-signing python to prevent OS X application firewall popping up
# Thanks to: http://darklaunch.com/2014/02/02/fix-do-you-want-the-application-python-to-accept-incoming-network-connections
. venv/bin/activate
codesign -s "Personae Dev Cert" -f $(which python)
@dtanham
dtanham / persistent_tcpdump.sh
Last active August 29, 2015 14:06
Tcpdump restart
#!/bin/sh
#
# Startup script for persistent tcpdump
#
PCAP=/data/tcpdump/tcpdump.pcap
SIZE=100
COUNT=20
PIDFILE=/var/run/tcpdump
@dtanham
dtanham / twohundred.py
Created September 26, 2014 23:49
200 OK Server
import BaseHTTPServer
import SocketServer
import socket
import threading
import functools
import contextlib
code, content = 200, "Ok"
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
@dtanham
dtanham / https-only.js
Created March 2, 2015 20:41
JS Redirect to HTTPS
if (window.location.href.indexOf("https://") != 0 && window.location.href.indexOf("http://localhost") == -1) {
window.location.href = window.location.href.replace("http://", "https://");
}