Skip to content

Instantly share code, notes, and snippets.

View dbspringer's full-sized avatar

Derek Springer dbspringer

View GitHub Profile
@dbspringer
dbspringer / gist:1287873
Created October 14, 2011 18:17 — forked from fennb/gist:1283573
nginx microcaching config example
# Set cache dir
proxy_cache_path /var/cache/nginx levels=1:2
keys_zone=microcache:5m max_size=1000m;
# Virtualhost/server configuration
server {
listen 80;
server_name yourhost.domain.com;
# Define cached location (may not be whole site)
@dbspringer
dbspringer / scramble.py
Created October 6, 2011 18:25
A function to scramble the inner letters of a word/sentence.
#!/usr/bin/python
# -*- coding: utf-8 -*-
def scramble(unscrambled):
'''
Scrambles the word(s) in unscrambled such that the first and last letter remain the same,
but the inner letters are scrambled. Preserves the punctuation.
See also: http://science.slashdot.org/story/03/09/15/2227256/can-you-raed-tihs
'''
import string, random, re
@dbspringer
dbspringer / substr.c
Created September 13, 2011 00:05
Substring in C
#include <stdio.h>
#include <string.h>
/* If you're feeling sassy, a macro one-liner w/out checks */
#define substr(dest, src, dest_size, startPos, strLen) snprintf(dest, dest_size, "%.*s", strLen, src+startPos)
/* Python-like idiom of negative values to count from the end of the string. */
void substr (char *dest, const char *src, int startPos, size_t strLen) {
/* Cannot do anything with NULL. */
if (dest == NULL || src == NULL) return;