This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pandas as pd | |
df = pd.read_csv('users.csv') | |
def flatten(user_df): | |
new_user_df = pd.DataFrame() | |
new_user_df['userid'] = user_df.userid | |
for send_number, row in user_df.set_index('send_number').iterrows(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask.ext.sa_restful import SaApi | |
from models import Todo | |
app = Flask(__name__) | |
api = SaApi(app, url_prefix='/api/v0.1') | |
# registers GET/POST/DELETE/PUT endpoints at '/api/v0.1/todos' (tablename used for url by default) | |
api.add_resource(Todo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
import psycopg2 | |
from secret import REDSHIFT_CREDS | |
from secret import AWS_ACCESS_KEY, AWS_SECRET_KEY | |
def get_primary_keys(tablename, db): | |
c = db.cursor() | |
sql = "select indexdef from pg_indexes where tablename = '%s';" % tablename | |
c.execute(sql) | |
result = c.fetchall()[0][0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('demoApp', ['ui.router']); | |
app.config(['$stateProvider', '$urlRouterProvider', | |
function($stateProvider, $urlRouterProvider) { | |
$stateProvider.state('home', { | |
url: '/', | |
controller: 'MainController', | |
template: '<h1>hello {{value}}!</h1>' | |
}); |
OlderNewer