Skip to content

Instantly share code, notes, and snippets.

View reidrac's full-sized avatar

Juan J. Martínez reidrac

View GitHub Profile
@reidrac
reidrac / fdtest.sh
Created January 20, 2010 11:08
Testing file descriptor count
#/!bin/sh
if [ $# -ne 3 ]; then
echo "$0 URL loops timeout"
exit 1;
fi
PID=`pgrep cherokee-worker`
echo "Start: cherokee-worker PID: $PID"
#!/bin/bash
# CONFIGURATION
URL=http://127.0.0.1:8081/index.html
LOOPS=10
# DEFAULT
TIME=16
if [ $# -eq 1 ]; then
args = {
'db': connect['database'],
'user': connect['username'],
'passwd': connect['password'],
}
if 'hostname' in connect:
# hostname implies port (although it can be default)
args['host'] = connect['hostname']
args['port'] = connect['port']
@reidrac
reidrac / gist:825144
Created February 13, 2011 21:19
django fastcgi sig handler
#!/usr/bin/python
import sys, os
import signal
quit_requested = False
def intSigHandler(signal, frame):
quit_requested = True
@reidrac
reidrac / secret_key.py
Created June 1, 2011 17:20
Generate a new random secret_key
#random key
from random import choice
charset = [chr(i) for i in range(32,38) + range(40,127)]
secret_key = ''.join([choice(charset) for i in range(64)])
print secret_key
@reidrac
reidrac / password.py
Created June 4, 2011 19:56
Manage hash-salted passwords
from hashlib import sha1
from random import random, choice
class Password(object):
"""Manage hash-salted passwords."""
HASH = sha1
SALT_LEN = 24
HASHED_LEN = len(HASH().hexdigest()) + SALT_LEN
@reidrac
reidrac / gist:1021402
Created June 12, 2011 10:11
Awesome C debug macro
#define DEBUG(fmt, args...) fprintf(stderr, "DEBUG[%s:%d]: "fmt, __FILE__, __LINE__, args)
/* disable debug logs */
#undef DEBUG
#define DEBUG(args...) /* args */
@reidrac
reidrac / gist:1941700
Created February 29, 2012 15:33
Using a dict to discard repeated items in a list of tuples
>>> a = [(1, 'red'), (2, 'red'), (1, 'blue'), (3, 'green')]
>>> b = dict(a)
>>> b
{1: 'blue', 2: 'red', 3: 'green'}
>>>
# keep in mind 2d occurrence of the key will be the one remaining in the dict
#include<stdio.h>
#define BUTTON1 1
#define BUTTON2 3
#define BUTTON3 6
#define BUTTON4 12
/* button, value */
#define IS_PRESSED(x, y) (y >> 4 == x)
@reidrac
reidrac / test.py
Created May 27, 2012 15:19
Dajango tests using sessions without the Django internal user system
from django.test.client import Client
from django.test import TestCase
from django.conf import settings
from django.utils.importlib import import_module
from project.app.models import User
class MyTestCase(TestCase):
def setUp(self):
settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'