Skip to content

Instantly share code, notes, and snippets.

@yosemitebandit
yosemitebandit / csv-processor.py
Created June 30, 2011 17:28
process a csv, write to another csv
input_data = open('data.csv', 'r')
output_data = open('out.csv', 'w')
for line in input_data:
data = line[0:-2] # snip off the new line character and trailing comma
output_data.write( data + '\n' ) # add the newline back
input_data.close()
output_data.close()
#!/usr/bin/env python
'''
optparse_testing.py
some recipes from http://www.alexonlinux.com/pythons-optparse-for-human-beings
'''
import optparse
parser = optparse.OptionParser()
# basics
@yosemitebandit
yosemitebandit / ibm_queue.py
Created August 17, 2011 23:28
IBM's python threading example with Queues
#!/usr/bin/python
# -*- coding: utf-8 -*-
import Queue
import threading
import urllib2
import time
hosts = ['http://yahoo.com', 'http://google.com', 'http://amazon.com',
'http://ibm.com', 'http://apple.com']
@yosemitebandit
yosemitebandit / baby_thread.py
Created August 19, 2011 00:09
small threading example
# http://www.neotitans.com/resources/python/python-threads-multithreading-tutorial.html
import sys
import time
import random
import threading
def worker(name):
print 'I am %s and starting now' % name
wait = random.randint(2,7)
time.sleep(wait)
@yosemitebandit
yosemitebandit / gist:1221451
Created September 16, 2011 07:33
css background repeat
body {
background-image: url(img/striped.jpg);
background-repeat: repeat;
}
@yosemitebandit
yosemitebandit / runrunrun.py
Created September 29, 2011 02:19
gunicorn target
from werkzeug.contrib.fixers import ProxyFix
from flask_app import *
app.wsgi_app = ProxyFix(app.wsgi_app)
@yosemitebandit
yosemitebandit / gun.py
Created September 29, 2011 02:21
tiniest gunicorn config
workers = 2
bind = '127.0.0.1:8000'
proc_name = 'www.yupyupnope.com'
pidfile = '/tmp/www.yupyupnope.com.pid'
@yosemitebandit
yosemitebandit / nginx.conf
Created September 29, 2011 23:34
umbrella nginx conf for flask
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
@yosemitebandit
yosemitebandit / yupyupnope.conf
Created September 29, 2011 23:37
nginx config file for flask app (behind gunicorn) with ssl
server {
listen 80;
server_name www.yupyupnope.com;
rewrite ^/(.*) https://yupyupnope.com/$1 permanent;
}
server {
listen 80;
server_name yupyupnope.com;
rewrite ^/(.*) https://yupyupnope.com/$1 permanent;
@yosemitebandit
yosemitebandit / readme
Created October 18, 2011 22:27
uppify web demo with flask
This little 'app' responds in uppercase with whatever url path you specify.
It's the Flask-based alternative of the Django example written up here: http://gun.io/blog/python-for-the-web/
to make it work, create this directory structure:
uppify/
| - serve.py
| - templates/
| - uppify.html