Skip to content

Instantly share code, notes, and snippets.

View jeremyjbowers's full-sized avatar

Jeremy Bowers jeremyjbowers

View GitHub Profile
@jeremyjbowers
jeremyjbowers / varnish-complex.vcl
Created December 31, 2011 05:27
A complex Varnish configuration file.
/*
*
* Instead of a single backend, let's set up a more complex multi-server director.
* This director will randomly assign each request to one of three application servers.
*
*/
director backend random {
.retries = 5;
{
.backend = {
@jeremyjbowers
jeremyjbowers / views.py
Created February 21, 2012 22:56
Django class-based view for PyMongo.
"""
I am sure everyone has something like this already.
I think PyDanny may have even built this into Django-Mongonaut.
But I needed to have this without installing any extra stuff.
Please enjoy version 0.0.3 of my class-based list/detail views for PyMongo.
"""
from bson.objectid import ObjectId
from common.mongo import MongoConnection
from django.conf import settings
from django.views.generic.base import View
@jeremyjbowers
jeremyjbowers / nltk_tokenize_tag_chunk.rst
Created February 25, 2012 17:41 — forked from japerk/nltk_tokenize_tag_chunk.rst
NLTK Tokenization, Tagging, Chunking, Treebank

Sentence Tokenization

>>> from nltk import tokenize
>>> para = "Hello. My name is Jacob. Today you'll be learning NLTK."
>>> sents = tokenize.sent_tokenize(para)
>>> sents
['Hello.', 'My name is Jacob.', "Today you'll be learning NLTK."]
@jeremyjbowers
jeremyjbowers / passer_rating.py
Created March 27, 2012 14:46
A python function to compute NFL passer rating.
def handle_nfl_passer_rating(cmpls, yds, tds, ints):
""" Defines a function which handles passer rating calculation for the NFL."""
def _min_max(x, xmin, xmax):
"""
Defines a function which enforces a minimum and maximum value.
Input: x, the value to check.
Input: xmin, the minumum value.
Input: xmax, the maximum value.
Output: Either x, xmin or xmax, depending.
"""
@jeremyjbowers
jeremyjbowers / cfb_passer_rating.py
Created March 27, 2012 15:27
A function to compute College Football passer rating.
def handle_cfb_passer_rating(yds, tds, cmpls, ints, atts):
""" Defines a function which computes NCAA passer rating."""
yards = 8.4 * yds
touchdowns = 330 * tds
completions = 100 * cmpls
interceptions = 200 * ints
rating = yards + touchdowns + completions - interceptions
return float(rating / atts)
@jeremyjbowers
jeremyjbowers / varnish
Created August 22, 2012 22:25
A sample Varnish Bash script.
#!/bin/bash
#PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/programs/varnish/sbin
HOST=`hostname | cut -d. -f1`
DAEMON='/programs/varnish/sbin/varnishd'
PROC="varnishd"
NAME="varnish"
# This list contains the values for project arg ($2) case statement
# The values should match vcl files in /data/conf/varnish/PROJECT.vcl
# Please keep it alphabetical
@jeremyjbowers
jeremyjbowers / georgia_red_velvet_cookies
Created September 17, 2012 12:00
Georgia Red Velvet Cookie Recipe
#Georgia Christmas
(Red velvet sandwich cookies)
Recipe contains two parts: Cookies and frosting.
##Cookies
(One batch makes 12-15 sandwich cookies)
###Ingredients
* 2 1/2 cups White Lily flour (or other low-protein flour)
@jeremyjbowers
jeremyjbowers / red_velvet_cake.md
Last active March 30, 2022 17:33
Georgia Red Velvet Cake

Red Velvet Cake

Red Velvet cake recipe Red Velvet cake finished

Cake

Ingredients

From original recipe

@jeremyjbowers
jeremyjbowers / nginx.conf
Created December 31, 2012 01:22
A standard Nginx configuration for a uWSGI/Python application.
worker_processes 2; # sets two workers. might need 4 in a very high-traffic environment.
user www-data; # user to run nginx as.
pid /var/run/nginx.pid; # you'll have to create this pidfile or else things won't work.
events {
worker_connections 1024; # connections each worker can take.
use epoll; # epoll is vastly superior to other alternatives.
}
http {
@jeremyjbowers
jeremyjbowers / my_app.conf
Created December 31, 2012 01:29
This is an upstart configuration file to execute uWSGI as a daemon on Ubuntu-recent (10.x, 12.x). For more info on upstart: http://upstart.ubuntu.com/getting-started.html. This file would live in /etc/init/ and you'd need to do sudo initctl reload-configuration on the initial file creation and then sudo service my_app start/restart/stop to contr…
description "uWSGI server for electris CMS"
start on runlevel [2345] # start on all runlevels.
stop on runlevel [!2345] # stop when shutting down.
respawn # respawn if job crashes or is stopped ungracefully.
env DEPLOYMENT_TARGET=production # set any environment variables you like here.
env DJANGO_SETTINGS_FILE=conf/settings.py # more environment variables if you like.
env PYTHONPATH=/home/ubuntu/apps/my_app:/home/ubuntu/.virtualenv/my_app