Skip to content

Instantly share code, notes, and snippets.

View mattdennewitz's full-sized avatar

Matt Dennewitz mattdennewitz

  • Lancaster, OH
View GitHub Profile
@mattdennewitz
mattdennewitz / cwgame__ext_game_header.diff
Created September 17, 2011 23:26
Patch for printing extended headers in 'cwgame'
*** cwgame.c 2011-09-17 18:24:18.000000000 -0500
--- cwgame__print_ext_hdrs.c 2011-09-17 18:24:12.000000000 -0500
***************
*** 2229,2234 ****
--- 2229,2246 ----
}
}
+ for (i = 0; i <= max_ext_field; i++) {
+ if (ext_fields[i]) {
@mattdennewitz
mattdennewitz / gist:1222935
Created September 16, 2011 19:39
VCL Redirect Hack
sub vcl_recv {
# ...
# detect reader's device, redirect if necessary
if (req.http.user-agent ~ "iPhone|iPod|Android") {
if(req.http.host ~ "^example.com") {
# mobile reader is on desktop site.
# raise an error with status=700 and use correct url as response body.
# vcl_error will use this response body as the Location: header.
error 700 "http://m.example.com" + req.url;
@mattdennewitz
mattdennewitz / chadwick.rb
Created September 10, 2011 22:56
chadwick 0.5.3 homebrew formula
require 'formula'
class Chadwick <Formula
url 'http://cdnetworks-us-2.dl.sourceforge.net/project/chadwick/chadwick-0.5/0.5.3/chadwick-0.5.3.tar.gz'
homepage 'http://chadwick.sourceforge.net/doc/index.html'
md5 'd8941a0bc0d075e9eb612cf7744657bf'
def install
system "./configure"
system "make"
@mattdennewitz
mattdennewitz / gist:638800
Created October 21, 2010 16:22
s3 can stream a file to the user with a different filename
from boto.s3.connection import S3Connection
file_to_upload = "e434b232c2e4f70aa2819d708dfd30fb4cebcf6c.zip"
s3 = S3Connection(YOUR_AWS_ACCESS_KEY, YOUR_AWS_SECRET_KEY)
bucket = s3.get_bucket(YOUR_BUCKET_NAME)
# user will receive "mixtape.zip" instead of "e434b232c2e4f70aa2819d708dfd30fb4cebcf6c.zip"
s3_headers = {'Content-Disposition': "attachment; filename=mixtape.zip"}
@mattdennewitz
mattdennewitz / corrupt.py
Created October 15, 2010 02:44
python port of corrupt, for image disruption.
#!/usr/bin/env python
"""
corrupt
usage: ./corrupt.py --source=input.jpg [--output=corrupted.jpg] [--iterations=10]
originally: http://www.recyclism.com/corrupt.php
ported: @mattdennewitz
"""
curl -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null -s http://www.domain.com/

Runs/Replacement

Use 20 runs per 600 pa as baseline and scale from there, eg, 23.3 runs per 700 pa.

FIP

(13*hr+3*bb-2*k)/ip

def test_map_reduce_finalize(self):
"""Ensure finalize is running by simulating "hotness"
ranking with Reddit algorithm.
"""
from time import mktime
class Link(Document):
title = StringField()
up_votes = IntField()
down_votes = IntField()
# quick & dirty example
def get_placemark_point(raw_location):
"""Attempt to resolve ``raw_location`` using Google's geocoder.
Returns a tuple with the canonical address and GEOS point
"""
import cjson
from urllib import urlencode
from urllib2 import urlopen
import sys
from math import log, sqrt
def pnormaldist(qn):
b = [1.570796288, 0.03706987906, -0.8364353589e-3,
-0.2250947176e-3, 0.6841218299e-5, 0.5824238515e-5,
-0.104527497e-5, 0.8360937017e-7, -0.3231081277e-8,
0.3657763036e-10, 0.6936233982e-12]
if qn < 0.0 or 1.0 < qn: