This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retry_on_connection_error(retries=2, sleep=0.1): | |
""" Retries on Autoreconnect errors. Wrap functions you want to ensure they | |
retry if there's a connection failure, giving the chance to mongo to failover. | |
params: | |
retries: the number of retries | |
sleep: seconds to sleep between retries | |
>>> @retry_on_connection_error(retries=1) | |
... def super_sensitive_function(data=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
perl -pi -e 's/^#?Port 22$/Port 443/' /etc/ssh/sshd_config | |
service sshd restart || service ssh restart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import math | |
def friendly_ago_string(d): | |
""" | |
Returns a friendly string like "8 minutes ago" representing the | |
differences between now and d. | |
""" | |
if not d or not isinstance(d, datetime): | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def worker(n): | |
return n**2 | |
squared = mtmap(worker, [2, 3, 4, 5]) | |
#= [4, 9, 16, 25] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mtmap(fn, iterable): | |
""" A multi-threaded map(). Must be used with care - large | |
iterables might cause a machine to crash from too many | |
threads. If an exception is thrown in a thread, | |
the iteration stops and that exception is thrown. | |
""" | |
result = {} | |
threads = [] | |
exception_q = Queue.Queue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @fileOverview Signup page JS code. | |
* @author <a href="mailto:hi@alexmic.com"> Alex Michael </a> | |
* @requires PK.js, facebox.js | |
*/ | |
PK.onPageLoad(function(){ | |
// Once the register page is loaded, make | |
// a request to FB and fill in user fields. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import string | |
import os | |
import uuid | |
import mimetypes | |
class Uploader: | |
def __init__(self, request = None): |
NewerOlder