Skip to content

Instantly share code, notes, and snippets.

View pfote's full-sized avatar

Andreas Pfotenhauer pfote

  • Ypsilon.NET AG
  • Frankfurt
View GitHub Profile
#!/usr/bin/env python
# whats mysql? MySQLdb?
from mysql.connector import errorcode, connect, Error
class JobQueue:
"""docstrings are missing"""
def __init__(self, dbConfig):
"""docstrings for methods as well"""
#!/usr/bin/env python
"""
statistics for netstat tcp
"""
from pprint import pformat
from optparse import OptionParser,OptionGroup
import re
import socket
import sys
<?php
$list = array(
array('page_id' => '3',
'url' => '/johtamisjarjestelma/yritys',
'title' => 'Yritys'),
array(
'page_id' => '4',
'url' => '/johtamisjarjestelma/yritys/historia',
'title' => 'Historia'),
@pfote
pfote / AsyncNotify.py
Created December 5, 2013 12:39
postgres LISTEN/NOTIFY psycopg2/twisted
import psycopg2
import psycopg2.extensions
from select import select
from twisted.internet import threads
class AsyncNotify():
"""
based on http://divillo.com/, adapted to newer psycopg version
Class to trigger a function via PostgreSQL NOTIFY messages.
function is_write_type($sql)
{
if (( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
AND
( ! preg_match('/^\s*INSERT.*RETURNING\s+[\w\*,]+$/i', $sql))
)
{
return FALSE;
}
return TRUE;
@pfote
pfote / gist:5452297
Created April 24, 2013 13:54
mod_php conf
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
@pfote
pfote / gist:5444238
Created April 23, 2013 14:55
sample deploy script
#!/bin/sh
# script zum lifestellen
cd /var/www/ypsilon_git
revision=$1
host=`hostname`
if [ x$revision == 'x' ]; then
revision='master'
fi
@pfote
pfote / AesCrypt.py
Created March 6, 2013 13:01
AES256 with PKCS5 padding
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import base64
import random
import hashlib
import os
class AesCrypt256:
@pfote
pfote / gist:5057323
Created February 28, 2013 14:55
sample CI monolog log
[2013-02-28 15:53:39] codeigniter.DEBUG: Monolog replacement logger initialized
[2013-02-28 15:53:39] codeigniter.DEBUG: Config Class Initialized
[2013-02-28 15:53:39] codeigniter.DEBUG: Hooks Class Initialized
[2013-02-28 15:53:39] codeigniter.DEBUG: Utf8 Class Initialized
[2013-02-28 15:53:39] codeigniter.DEBUG: UTF-8 Support Enabled
[2013-02-28 15:53:39] codeigniter.DEBUG: URI Class Initialized
[2013-02-28 15:53:39] codeigniter.DEBUG: Router Class Initialized
[2013-02-28 15:53:39] codeigniter.DEBUG: No URI present. Default controller set.
[2013-02-28 15:53:39] codeigniter.DEBUG: Output Class Initialized
[2013-02-28 15:53:39] codeigniter.DEBUG: Security Class Initialized
@pfote
pfote / gist:4960286
Created February 15, 2013 13:11
sample selenium webdriver test
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class FlwebBookingWebdriver(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)