Skip to content

Instantly share code, notes, and snippets.

View davefowler's full-sized avatar

Dave Fowler davefowler

View GitHub Profile
@davefowler
davefowler / usesgoogle.py
Last active August 29, 2015 14:02
Determine whether an email address uses google apps
import dns.resolver # requires pip install dnspython
def uses_google_apps(email):
domain = email.lower().split('@')[1]
if domain.lower() not in ('gmail.com', 'googlemail.com'):
try:
answers = dns.resolver.query(domain, 'MX')
for rdata in answers:
if 'google' in rdata.exchange.to_text().lower():
return True
SELECT strftime('%Y-W%W', "ch0"."Date") AS "Week of Date",
"ch0"."Winner" AS "Winner",
COUNT(DISTINCT "ch0"."_row_id") AS "Count of Chess - Sheet1"
FROM "Chess - Sheet1" AS "ch0"
GROUP BY "Week of Date", "Winner"
ORDER BY "Week of Date" ASC, "Winner" ASC LIMIT 1000;
@davefowler
davefowler / youtubepin.js
Last active December 17, 2015 20:38
Javascript snippet to get youtube code and thumbnail of a youtube video
var youtubelink = $('object param[name="movie"]').val(); // grabs the video link from an embedded video
// OLD EMBED STYLE CODE var youtubecode = youtubelink.match(/\/v\/(.*)\?/)[1];
var youtubecode = youtubelink.match(/\/embed\/(.*)/)[1];
var pinimage = 'http://img.youtube.com/vi/' + youtubecode + '/0.jpg';
@davefowler
davefowler / pin.js
Created May 29, 2013 07:18
This is a snippet for controlling the pinterest embed button described here http://business.pinterest.com/widget-builder/#do_pin_it_button
var pinurl = window.location.href; // link to the page that the pin was found on
var pinimage = 'http://your-image.png'; // link to the pin's image
var pindescription = document.title; // description of the pin
// button - The full HTML needed for the embedded pin it button. Place this where you'd like the button to be: $('#placeholder').append(button)
var button = '<a class="pinbutton" href="//pinterest.com/pin/create/button/?url='+escape(pinurl)+'&media=' + escape(pinimage) + '&description=' + escape(pindescription) + '" data-pin-do="bu\
ttonPin" data-pin-config="above"><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" /></a>';
import sqlalchemy
from sqlalchemy import Column, Integer, ForeignKey, String, MetaData
from sqlalchemy.ext.declarative import declarative_base
engine_url = 'postgresql://postgres@localhost/joins'
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
# coding: utf-8
import os, fnmatch, sys
def findReplace(directory, find, rep, filePattern):
for path, dirs, files in os.walk(os.path.abspath(directory)):
for filename in fnmatch.filter(files, filePattern):
filepath = os.path.join(path, filename)
with open(filepath) as f:
s = f.read()
new = s.replace(find, rep)