Skip to content

Instantly share code, notes, and snippets.

@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"'
"""
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 / 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
@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 / 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 / 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 / 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 / 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 {