Skip to content

Instantly share code, notes, and snippets.

View mmautner's full-sized avatar
🌊
chilling

Max Mautner mmautner

🌊
chilling
View GitHub Profile
@mmautner
mmautner / express_to_api.js
Created June 13, 2014 16:03
proxying requests to "/api/*" to an external HTTP API
var http = require('http'),
, httpProxy = require('http-proxy')
, express = require('express');
app = express();
var apiUrl = 'http://api.example.com:80';
var proxy = httpProxy.createProxyServer({target:apiUrl});
app.all('/api/*', function(req, res) {
@mmautner
mmautner / bombdiggity.py
Created June 6, 2014 15:23
A thin pandas/database-backed web app
#!/usr/bin/env python
from pandas.io.sql import read_sql
import MySQLdb
from flask import Flask
app = Flask(__name__)
qry = "select * from adh_bayescomp_msn limit 100"
db = MySQLdb.connect(read_default_file="~/.my.cnf.quark")
@mmautner
mmautner / app.py
Last active October 22, 2019 18:09
Example of caching API results w/ Flask-Restless
import json
import hashlib
import flask
import flask.ext.sqlalchemy
import flask.ext.restless
from flask.ext.restless import ProcessingException
app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
@mmautner
mmautner / gist:7303273
Created November 4, 2013 14:29
example sqlalchemy ORM query
# get count of users by birthday who've clicked in the last 7 days
results = session.query(User)\
.join(Click, User.id == Click.user_id)\
.filter(Click.created_at > datetime.datetime.today() - datetime.timedelta(days=7))\
.groupby(User.birthday)\
.orderby(User.birthday)\
.values(User.birthday,
func.count(func.distinct(User.id)))
@mmautner
mmautner / chatlogs
Last active December 18, 2015 08:29
a short script to demonstrate pulling down your google talk history
#!/usr/bin/env python
# Download your chat history
# http://stackoverflow.com/questions/8146970/accessing-chat-folder-in-python-using-imaplib
import imaplib
conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
conn.login("[email protected]", "password")
lb_list = conn.list()
@mmautner
mmautner / gist:5061958
Created March 1, 2013 02:08
alternative MySQLdb cursors
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="example")
c = MySQLdb.cursors.DictCursor(db)
c.execute("SELECT * FROM students")
result = c.fetchall()
for row in result:
do_something(row['first_name'], row['last_name'], row['grade'], row['year'])
c.close()
# effectively eliminating that ugly index-referencing of the row results--