Skip to content

Instantly share code, notes, and snippets.

View dtanham's full-sized avatar

Dan Tanham dtanham

View GitHub Profile
@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 / random_string.py
Created October 22, 2017 17:47
Generate a random string using lowercase ASCII characters and digits
import random, string
def random_string(length):
''.join(random.choice(string.ascii_lowercase+string.digits) for i in range(length))

Keybase proof

I hereby claim:

  • I am dtanham on github.
  • I am dtanham (https://keybase.io/dtanham) on keybase.
  • I have a public key ASBJ20ifsSwJ6VQ1id8WU6QXU6RkIC5rO8FAArGkHe_NFAo

To claim this, I am signing this object:

@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
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 / 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;
}
@dtanham
dtanham / loess.py
Created November 8, 2015 12:04
LOESS implementation in Python - courtesy of Phillip K Janert's O'Reilly book Data Analysis with Open Source Tools (aka the bible)
from pylab import *
# # x: location; h: bandwidth; xp, yp: data points (vectors)
def loess( x, h, xp, yp):
w = exp( -0.5*( ((x-xp)/h)**2)/sqrt(2*pi*h**2) )
b = sum(w*xp)*sum(w*yp) - sum(w)*sum(w*xp*yp)
b /= sum(w*xp)**2 - sum(w)*sum(w*xp**2)
a = ( sum(w*yp) - b*sum(w*xp) )/sum(w)
return a + b*x
@dtanham
dtanham / bootstrap-cdn.html
Created June 30, 2015 21:56
Exactly like the getbootstrap.com basic template, but with CDN hosted css and js to make getting started even faster.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
@dtanham
dtanham / flask-mongo_requirements.txt
Created June 30, 2015 19:30
Basic PIP requirements file for quickstarting a Flask app
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.10.4
itsdangerous==0.24
mongoengine==0.10.0
pymongo==3.0.2
wsgiref==0.1.2
@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://");
}