Skip to content

Instantly share code, notes, and snippets.

View ssokolow's full-sized avatar

Stephan Sokolow ssokolow

View GitHub Profile
@timtrueman
timtrueman / django_cached_count_proxy.py
Created November 18, 2010 00:15
Django cached .count() proxy for querysets that is generic and works with pagination in object_list (which clones and overrides any monkeypatched count method so you have to override the clone method first).
class CachedCountCloneProxy(object):
''' This allows us to monkey-patch count() on QuerySets so we can cache it and speed things up.
._clone is called so we have to monkey-patch that first...
'''
def __init__(self, queryset):
self._queryset = queryset
self._queryset._clone_original = self._queryset._clone
def __call__(self):
@friggeri
friggeri / gist:1570840
Created January 6, 2012 14:30
More CoffeeScriptish
do ($ = jQuery) ->
$.fn.zebraTable = (options) ->
defaults =
evenColor: '#ccc'
oddColor : '#eee'
options = $.extend(defaults, options)
@each ->
$("tr:even", @).css('background-color', options.evenColor)
$("tr:odd", @).css('background-color', options.oddColor)
#!/usr/bin/python
# https://lists.fedoraproject.org/pipermail/test/2009-May/081959.html
# from http://askubuntu.com/questions/4499/how-can-i-diagnose-debug-maximum-number-of-clients-reached-x-errors/6639#6639
from subprocess import Popen, PIPE
client_sockets = []
match = 0
[package]
authors = ["SethDusek <shibe@openmailbox.org>"]
name = "catch_match"
version = "0.1.0"
[dependencies]
quasi = "0.28.0"
quasi_macros = "0.28.0"
[lib]
@anp
anp / coverage.py
Created September 20, 2016 16:13
rust code coverage with kcov
#!/usr/bin/env python2
# butchered from https://github.com/huonw/travis-cargo
# under MIT license
from __future__ import print_function
import argparse
import os
import sys
import subprocess
@alkis
alkis / the-case-for-deadlines.md
Last active April 19, 2018 12:49
The case for deadlines

The case for deadlines

Rust aims to be the foundation of fast and robust software. A thorn in that side is the choice of timeout-centric APIs for I/O and multithreading. I posit this was a bad choice and it needs to be remedied as soon as possible before more APIs proliferate this (possibly accidental) design decision.

Motivating example: time limited network client request

Task: connect to a remote server, send a request, receive response with an end-to-end timeout of 10 seconds.

Attempt #1

gnome-cups-manager
------------------
Once upon a time there was a printer who lived in the woods. He was a
lonely printer, because nobody knew how to configure him. He hoped
and hoped for someone to play with.
One day, the wind passed by the printer's cottage. "Whoosh," said the
wind. The printer became excited. Maybe the wind would be his
friend!
#!/bin/bash
trap 'rm -rf "$tempdir"' EXIT
tempdir=$(mktemp -d)
cd "$tempdir" || exit 1
printf '%s\n' \
'(return 2>/dev/null); echo $?' \
> bash_return
@selenamarie
selenamarie / prod_postgres.md
Last active March 15, 2019 05:12
An Ideal Postgres Environment

Ideal Postgres environment

Documentation

  • Documented replication topology
  • Documented network topology
  • Documented interface topology - including users, passwords, connection estimates, load balancers, connection proxies
  • Documented procedure, schedule for failover and testing
  • Documented procedure, schedule for disaster recovery and testing