Skip to content

Instantly share code, notes, and snippets.

View alejandrobernardis's full-sized avatar
🐻

Alejandro M. BERNARDIS alejandrobernardis

🐻
View GitHub Profile
@tessro
tessro / redis-server
Created December 16, 2009 14:20
A CentOS initscript for Redis
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
#!/bin/bash
#
# MongoDB Backup Script
# VER. 0.1
# Note, this is a lobotomized port of AutoMySQLBackup
# (http://sourceforge.net/projects/automysqlbackup/) for use with
# MongoDB.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# Copyright (c) 2010, Philip Plante of EndlessPaths.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@bdarnell
bdarnell / gist:736778
Created December 10, 2010 20:43
benchmark: with vs try
#!/usr/bin/env python
# simple benchmark comparing with and try statements
import contextlib
import timeit
def work_pass():
pass
@bdarnell
bdarnell / result_collector.py
Created December 14, 2010 20:27
result_collector.py
import functools
import logging
import sys
class ResultCollector(object):
'''Like a BarrierCallback, but saves results passed to the callback.
>>> rc = ResultCollector()
>>> cb_foo = rc.get_callback('foo')
>>> cb_bar = rc.get_callback('bar')
@pplante
pplante / exception-mixin.py
Created April 10, 2011 00:28
template for nicer debugging of tornado exceptions
# Copyright (c) 2011 Phil Plante <unhappyrobot AT gmail DOT com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
from cStringIO import StringIO
import gnupg
import logging
import os
import shutil
def generate_key(gpg, first_name, last_name, domain, passphrase=None):
"Generate a key"
params = {
'Key-Type': 'DSA',
@FSX
FSX / forms.py
Created May 7, 2011 14:07
Making use of Tornado's locale functionality in WTForms. By Ben Darnell.
import tornado.locale
from wtforms import Form, TextField, PasswordField, SubmitField, validators
# Later use e.g. FORMS['es'].LoginForm
FORMS = {}
error_msgs = (
'You must enter a username.',
@ymirpl
ymirpl / gist:1052094
Created June 28, 2011 20:21
Python unicode e-mail sending
#coding: utf-8
from cStringIO import StringIO
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from email import Charset
from email.generator import Generator
import smtplib
# Example address data
@bdarnell
bdarnell / fdserver.py
Created July 9, 2011 20:41
Demonstration of sharing file descriptors across processes
#!/usr/bin/env python
"""This is a demonstration of sharing file descriptors across processes.
It uses Tornado (need a recent post-2.0 version from github) and the
multiprocessing module (from python 2.6+). To run it, start one copy
of fdserver.py and one or more copies of testserver.py (in different
terminals, or backgrounded, etc). Fetch http://localhost:8000 and
you'll see the requests getting answered by different processes (it's
normal for several requests to go to the same process under light
load, but under heavier load it tends to even out).