Skip to content

Instantly share code, notes, and snippets.

@seanh
seanh / formatFilename.py
Created April 11, 2009 18:30
Turn any string into a valid filename in Python.
def format_filename(s):
"""Take a string and return a valid filename constructed from the string.
Uses a whitelist approach: any characters not present in valid_chars are
removed. Also spaces are replaced with underscores.
Note: this method may produce invalid filenames such as ``, `.` or `..`
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
and append a file extension like '.txt', so I avoid the potential of using
an invalid filename.
@btbytes
btbytes / nginx_userdir.conf
Created July 13, 2009 19:37
User-based Website Directories with Nginx
## REF: http://blog.sbf5.com/?p=6
# For requests starting with a tilde, break them into three components:
# 1. The username, everything after the tilde up to the first slash
# 2. The file location, everything after the username up to the last slash
# 3. The trailing slash(es)
# Then, rewrite to go to the f~/ branch.
location /~ {
if ($request_uri ~ ^/~([^/]*)(/.*[^/]|)(/*)$) {
set $homedir $1;
set $filedir $2;
import httplib
import urllib
import re
import os.path
def gist_write(name, content, ext=None, login=None, token=None):
if ext is None:
ext = os.path.splitext(name)[1]
// ==UserScript==
// @name Export Github Issues
// @namespace http://userscripts.org/users/tim
// @description Can export issues by state and label
// @include http://github.com/*/issues*
// ==/UserScript==
(function() {
var GITHUB_API_URL, GithubRequest, URL_EXPRESSION, formatOutput, menuCallback, repo, url, user;
URL_EXPRESSION = /^.*\/(.*?)\/(.*?)\/issues.*$/;
GITHUB_API_URL = 'http://github.com/api/v2/json';
@tylerhall
tylerhall / strong-passwords.php
Created August 12, 2010 21:38
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by
@geoffb
geoffb / simple_websocket_client.html
Created October 7, 2010 23:37
Super simple websockets client/server using Python. Compatible with the draft 76 challenge/response.
<!DOCTYPE html>
<html lang="en">
<head>
<title>WebSocket Client</title>
<style>
#output {
border: solid 1px #000;
}
</style>
</head>
@justquick
justquick / fabfile.py
Created October 11, 2010 18:58
Ubuntu update manager for Fabric. Checks for updates, installs them and reboots if needed across multiple servers
"""
Ubuntu update manager for Fabric
Checks for updates, installs them and reboots if needed across multiple servers
Create a "hosts" file alongside this fabfile and put your hosts in there one per line
Updating package list::
fab update
@koenbollen
koenbollen / mastersteam.py
Created October 25, 2010 22:44
Query the Steam master servers.
#!/usr/bin/env python
#
# Query the Steam master servers.
#
# See: http://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol
#
# Koen Bollen <meneer koenbollen nl>
# 2010 GPL
#
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@dbb
dbb / fancy_urxvt
Created January 18, 2011 23:07
urxvt with transparency, blur, Xft font, etc
urxvt.perl-ext-common: default,tabbed,matcher,searchable-scrollback
urxvt*cutchars: "()*,<>[]{}|'
urxvt*termName: rxvt-unicode
urxvt*urlLauncher: iceweasel
urxvt*matcher.button: 1
urxvt*keysym.S-Prior: ^[[5;2~
urxvt*keysym.S-Next: ^[[6;2~
urxvt*geometry: 100x30
urxvt*highlightSelection: true