Skip to content

Instantly share code, notes, and snippets.

View Bluehorn's full-sized avatar

Torsten Landschoff Bluehorn

  • Scale GmbH
  • Dresden
View GitHub Profile
@Bluehorn
Bluehorn / redis_autostart.py
Created March 5, 2015 11:33
Redis: Starting a redis server automatically on connection failure
"""
Setup
>>> connection_pool = redis.ConnectionPool(connection_class=AutoStartConnection)
>>> client = redis.StrictRedis(connection_pool=connection_pool)
Does it work? It auto starts on first access:
>>> client.set("answer", "42")
Redis offline, starting it.
@Bluehorn
Bluehorn / apache_manifests_init.pp
Created April 5, 2014 14:07
Puppet: roundcube module notifies apache
class apache {
include apache::packages
include apache::service
}

Trivial test for paramiko issue #22

This demonstrates issue #22. For this to expose the problem, you have to reconfigure your local sshd to listen only on a IPv4 socket. I had to add the following line to /etc/ssh/sshd_config (on a Debian system):

ListenAddress 0.0.0.0

With that change, paramiko can not connect to localhost anymore:

@Bluehorn
Bluehorn / Output from cmd.exe (garbled as usual)
Created April 19, 2013 16:40
Errors when trying to build the librsvg lib file from librsvg-2-2.def
C:\jenkins\workspace\dynasdk-loco2-win7_32>call make.exe stamps/make-rsvg2-lib
cd C:\\opt\\gtk\\bin && lib -def:librsvg-2-2.def -machine:x86
Microsoft (R) Library Manager Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
librsvg-2-2.def(1) : warning LNK4017: rsvg_error_quark statement not supported f
or the target platform; ignored
librsvg-2-2.def(2) : warning LNK4017: rsvg_error_get_type statement not supporte
d for the target platform; ignored
librsvg-2-2.def(3) : warning LNK4017: rsvg_init statement not supported for the
@Bluehorn
Bluehorn / http_over_paramiko.py
Created August 31, 2012 21:26
Snippet to tunnel an HTTP connection via paramiko (using urllib3)
import urllib3
import paramiko
from pprint import pprint
from httplib import HTTPConnection
import logging
logging.basicConfig(level=logging.DEBUG)
class TunnelingPoolManager(urllib3.PoolManager):
@Bluehorn
Bluehorn / thread_stop_fail.py
Created May 25, 2012 10:29
An example of how Thread._Thread__stop() does not stop a thread
#! /usr/bin/python
import time
import threading
def f():
for x in range(10):
print "I am alive and running"
time.sleep(0.1)
@Bluehorn
Bluehorn / requests_keeps_connections.py
Created March 29, 2012 06:45
Simple example that shows how the requests module does not clean up connections
import gc, os, subprocess, requests
gc.disable() # Just to make sure - I have seen this with gc enabled
for x in range(20):
requests.head("http://www.google.de/")
print "Open sockets after 20 head requests:"
pid = os.getpid()
subprocess.call("lsof -p%d -a -iTCP" % (pid,), shell=True)