Skip to content

Instantly share code, notes, and snippets.

@saghul
saghul / gist:1237794
Created September 23, 2011 16:24
MySQL random number between 0 and biggest possible integer
SELECT FLOOR(RAND()*(~0));
@saghul
saghul / gdb.rb
Created March 13, 2012 16:40 — forked from hirofumi/gdb.rb
Homebrew Formula of GDB 7.4
require 'formula'
class Gdb < Formula
url 'http://ftp.gnu.org/gnu/gdb/gdb-7.4.tar.bz2'
homepage 'http://www.gnu.org/software/gdb/'
md5 '95a9a8305fed4d30a30a6dc28ff9d060'
def install
args = ["--prefix=#{prefix}",
"--disable-debug",
@saghul
saghul / setup.py
Created April 23, 2012 20:29
PyStructSequence usage example
# coding=utf8
from distutils.core import setup, Extension
setup(name = "foo",
version = "0.0.1",
author = "Saúl Ibarra Corretgé",
author_email = "[email protected]",
description = "PyStructSequence example",
ext_modules = [Extension('foo',
@saghul
saghul / gist:2873512
Created June 5, 2012 08:05
Making ab work on OSX
# http://stackoverflow.com/questions/1216267/ab-program-freezes-after-lots-of-requests-why
sudo sysctl -w net.inet.ip.portrange.first=32768
sudo sysctl -w net.inet.tcp.msl=1000
@saghul
saghul / gist:2882835
Created June 6, 2012 15:49
Local APT repository
# Create local repository
mkdir /location/debs
cp package-file.deb /location/debs
dpkg-scanpackages /location/debs /dev/null | gzip > /location/debs/Packages.gz
# Add repository to APT
deb file:/location debs/
@saghul
saghul / html2text.py
Created July 5, 2012 10:12
HTML to text
# Based on http://stackoverflow.com/questions/328356/extracting-text-from-html-file-using-python
from cStringIO import StringIO
from formatter import AbstractFormatter, DumbWriter
from htmllib import HTMLParser, HTMLParseError
def html2text(data):
f = StringIO()
@saghul
saghul / gist:3660656
Created September 6, 2012 21:55
Python concurrent.futures example
from concurrent.futures import ProcessPoolExecutor, wait
from multiprocessing import cpu_count
try:
workers = cpu_count()
except NotImplementedError:
workers = 1
pool = ProcessPoolExecutor(max_workers=workers)
@saghul
saghul / t1.py
Created September 8, 2012 22:19
SSL connected socket pair in Python (blocking)
import select
import socket
import ssl
bindsocket = socket.socket()
bindsocket.bind(('127.0.0.1', 10000))
bindsocket.listen(1)
connect_address = bindsocket.getsockname()
@saghul
saghul / backdoor.py
Created September 17, 2012 21:11
Tornado backdoor example
import signal
from tornado.ioloop import IOLoop
from tornado_backdoor import BackdoorServer
def handle_SIGINT(signum, frame):
io_loop = IOLoop.instance()
io_loop.add_callback(io_loop.stop)
@saghul
saghul / child.py
Created October 4, 2012 06:23
pyuv child process example
#!/usr/bin/env python
import os
import pyuv
import sys
fd = os.getenv('PYUV_CHANNEL_FD')
if fd is None:
print "[Child] No channel fd found"