Skip to content

Instantly share code, notes, and snippets.

View marklit's full-sized avatar

Mark Litwintschik marklit

View GitHub Profile
var song = new Backbone.Model({
title: "Lucy In The Sky With Diamonds",
album: new Backbone.Model({
title: "Sgt. Pepper's Lonely Hearts Club Band",
release: {
year: "1987"
}
})
});
@marklit
marklit / gist:2805184
Created May 27, 2012 11:05 — forked from gabesmed/gist:376015
The routing algorithm from Scenic Route (http://scenicroute.info)
import math
import random
import operator
from django.contrib.gis.geos import LineString, Point
from scenicroute.apps.hunts.routing.triangulation import (
build_triangulation, START_INDEX, END_INDEX)
from scenicroute.apps.hunts.routing.culling import no_dupes
from scenicroute.apps.hunts.routing.estimation import (duration_for_distance,
#! /usr/bin/env python
from boto.ses.connection import SESConnection
import sys
import subprocess
import socket
if __name__ == '__main__':
return_code = 'unknown'
host = socket.getfqdn()
try:
@marklit
marklit / gist:3177385
Created July 25, 2012 17:24 — forked from mikeyk/gist:1329319
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
def apply_filters(self, request, applicable_filters):
"""
An ORM-specific implementation of ``apply_filters``.
The default simply applies the ``applicable_filters`` as ``**kwargs``,
but should make it possible to do more advanced things.
"""
positive_filters = {}
negative_filters = {}
for lookup in applicable_filters.keys():
import requests
for x in xrange(0, 40000):
r = requests.get('http://127.0.0.1:8080/solr/select')
assert r.status_code == 200, r.status_code
print r.content
@marklit
marklit / playbook.yml
Created November 8, 2014 08:27
Setup a load-balanced, two-node Django cluster
---
- name: SSH tightening
hosts: all
sudo: True
tasks:
- name: Disable root's ssh account
action: >
lineinfile
dest=/etc/ssh/sshd_config
@marklit
marklit / generate.sh
Created November 11, 2014 22:13
Generate messages with serial ids
# From: http://www.reddit.com/r/Python/comments/2lzry9/most_efficient_way_to_generate_random_dataevents/clzoj3t
head -c <large number> /dev/zero ¦ tr '\0' '\n' ¦ cat -n ¦ xargs -L1 printf 'This is message number %s\n'
@marklit
marklit / english.py
Last active August 29, 2015 14:10
Generate English Sentences
from itertools import chain, product
from re import match, findall
GRAMMAR = '''
<sentence> ::= <noun phrase=""> <verb phrase="">
<noun> ::= "boy " | "troll " | "moon " | "telescope "
<transitive verb=""> ::= "hits " | "sees "
<intransitive verb=""> ::= "runs " | "sleeps "
<adjective> ::= "big " | "red "