Skip to content

Instantly share code, notes, and snippets.

@agness
agness / vanilla_nginx.conf
Created May 31, 2013 15:51
Vanilla nginx.conf to work with upstream (Tornado) instances.
# one worker per CPU core
worker_processes 1;
events {
worker_connections 1024;
}
http {
# enumerate Tornado servers here
upstream main {
@agness
agness / nginx_port_proxy
Created June 10, 2013 18:16
nginx proxy to any port; i.e. requesting `http://ec2-xx-xx-xx-xx.compute.amazonaws.com/9001/` will forward to `localhost:9001`
server {
listen 80;
server_name localhost;
location ~ /(\d+) {
resolver 8.8.8.8;
rewrite ^/(\d+)/(.*) /$2 break;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
@agness
agness / Tornado HTTP stream
Created August 6, 2013 14:26
Tornado server that sends data to all clients ad infinitum.
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from random import randrange
import logging
from tornado.options import define, options
define("port", default=7777, help="run on the given port", type=int)
@agness
agness / js_prettyprint_date.js
Created August 22, 2013 15:33
Prettyprint formating for JS Date objects, without library.
Date.prototype.customFormat = function(formatString){
var YYYY,YY,MMMM,MMM,MM,M,DDDD,DDD,DD,D,hhh,hh,h,mm,m,ss,s,ampm,AMPM,dMod,th;
var dateObject = this;
YY = ((YYYY=dateObject.getFullYear())+"").slice(-2);
MM = (M=dateObject.getMonth()+1)<10?('0'+M):M;
MMM = (MMMM=["January","February","March","April","May","June","July","August","September","October","November","December"][M-1]).substring(0,3);
DD = (D=dateObject.getDate())<10?('0'+D):D;
DDD = (DDDD=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][dateObject.getDay()]).substring(0,3);
th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':(dMod==3)?'rd':'th';
formatString = formatString.replace("#YYYY#",YYYY).replace("#YY#",YY).replace("#MMMM#",MMMM).replace("#MMM#",MMM).replace("#MM#",MM).replace("#M#",M).replace("#DD\
@agness
agness / custom_logging.py
Created August 22, 2013 17:32
Logging in Python with Tornado's pretty print formatter and routing all messages with INFO level and above to STDOUT, and all messages below to STDERR.
#!/usr/bin/env python
import sys
import logging
import tornado.log
# For pretty log messages, if available
try:
import curses
except ImportError:
curses = None
@agness
agness / supervisord.conf
Created August 26, 2013 15:40
Basic supervisor config with stderr and stdout logging to separate output files
[include]
files = *.supervisor
[supervisord]
pidfile = /Users/hi/Desktop/quips/logs/supervisord.pid
logfile = /Users/hi/Desktop/quips/logs/supervisord.log
[supervisorctl]
serverurl = unix:///tmp/supervisord.sock
"""
Logistic Regression with Stochastic Gradient Descent.
Copyright (c) 2009, Naoaki Okazaki
http://www.chokkan.org/publication/survey/logistic_regression_sgd.html
This code illustrates an implementation of logistic regression models
trained by Stochastic Gradient Decent (SGD).
This program reads a training set from STDIN, trains a logistic regression
model, evaluates the model on a test set (given by the first argument) if
@agness
agness / gist:7099741
Created October 22, 2013 12:28
Fix invalid-email-address when converting from hg to git.
git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL="somehwere@gmail.com";GIT_AUTHOR_NAME="Moseley Swift"'
@agness
agness / css-scale3d-transition
Created December 5, 2013 01:54
css lightbox transition (3 yrs old now?)
.overlay {
-webkit-transition: all .3s;
-moz-transition: all .3s;
-ms-transition: all .3s;
-o-transition: all .3s;
transition: all .3s;
-webkit-transform: scale3d(0.1,0.1,1);
-moz-transform: scale3d(0.1,0.1,1);
-o-transform: scale3d(0.1,0.1,1);
transform: scale3d(0.1,0.1,1);
@agness
agness / stumbleupon_ml.py
Created January 20, 2014 23:31
StumbleUpon evergreen webpages ML challenge submission from http://www.laurenatphysics.com/2013/11/followup-to-stumbleupon-challenge.html
import csv
import numpy as np
import scipy as scipy
import re
from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.stem import LancasterStemmer,SnowballStemmer
from nltk.stem.snowball import EnglishStemmer
from nltk import word_tokenize
from sklearn import preprocessing,metrics,cross_validation
from sklearn.cross_validation import StratifiedKFold