Skip to content

Instantly share code, notes, and snippets.

View mwicat's full-sized avatar

Marek Wiewiorski mwicat

View GitHub Profile
@mwicat
mwicat / twisted_manhole.py
Created April 1, 2012 19:11
Python shell in twisted
from twisted.internet import reactor
from twisted.manhole import telnet
def createShellServer( ):
print 'Creating shell server instance'
factory = telnet.ShellFactory()
port = reactor.listenTCP( 8787, factory)
factory.namespace['x'] = 'hello world'
factory.username = 'guest'
factory.password = 'guest'
print 'Listening on port 2000'
@mwicat
mwicat / send_sms.sh
Created April 8, 2012 12:32
send sms with skrypty-sms
#!/bin/bash
# sudo apt-get install libwww-perl libcrypt-ssleay-perl
. ~/.smsrc
body="$(cat)"
perl ~/src/skrypty-sms-read-only/sms.miastoplusa.pl $1 "$body" "$username" "$password"
@mwicat
mwicat / parse_html.py
Created April 28, 2012 10:12
parse html
from BeautifulSoup import BeautifulSoup
import sys
soup = BeautifulSoup(sys.stdin.read())
inp = soup.find(lambda t: t.get('name') == 'LDAPserver')
if inp is not None: print inp['value']
import sys
from xml.etree.ElementTree import ElementTree
tree = ElementTree()
tree.parse(sys.stdin)
buttons = tree.findall(".//buttons/button")
entries = [(button.get('caller-name'), button.get('value')) for button in buttons]
ldapsearch -h myhost.com -b 'ou=People,dc=google,dc=pl' -x '(givenName=Marek)'
# -*- coding: utf-8 -*-
import re
intab = u"ąćęłńóśżźĄĆĘŁŃÓŚŻŹ"
ottab = u"acelnoszzACELNOSZZ"
def translate(s):
for i, o in zip(intab, ottab):
s = re.sub(i, o, s)
@mwicat
mwicat / reformat.sed
Created June 17, 2012 08:59
Remove blank lines, strip whitespaces, replace multi whitespaces with single one
/^[ \t]*$/d
s/^[ \t]*//
s/[ \t]*$//
s/[ \t][ \t]/\t/g
@mwicat
mwicat / wx_reactor.py
Created June 28, 2012 12:33
wx with twisted reactor
import wx
class CustomerClientFactory(ClientFactory):
def __init__(self, app):
self.app = app
def buildProtocol(self, addr):
print 'Connected.'
return CustomerChatClient(self.app)
@mwicat
mwicat / SimpleHTTPServer_xml.py
Created July 6, 2012 11:18
Standard Python server that returns content-type text/xml for all requests
"""Simple HTTP Server.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
__version__ = "0.6"
#!/usr/bin/env python
import plac
from ESL import *
from xml.etree.ElementTree import ElementTree, fromstring
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 8021