Skip to content

Instantly share code, notes, and snippets.

View messa's full-sized avatar

Petr Messner messa

View GitHub Profile
@messa
messa / sifra.py
Created May 30, 2011 18:46
Python example - decryption of simple substitution cipher using recursion
#!/usr/bin/env python
from StringIO import StringIO
import unittest
import sys
sys.setrecursionlimit(4000)
def resolve(ciphertext, allWords):
@messa
messa / imgresize.py
Created January 11, 2012 16:13
imgresize
#!/usr/bin/env python
import optparse
from PIL import Image
def main():
op = optparse.OptionParser()
options, args = op.parse_args()
def connect(*args):
maps = list()
for collection, keyGetter in args:
m = dict()
for item in collection:
key = keyGetter(item)
m[key] = item
maps.append(m)
@messa
messa / create_report.py
Created May 25, 2012 07:48
Sklik API keyword stats example
#!/usr/bin/env python
"""
Command-line tool for creating Statistical report from Report template
using Sklik.cz API.
Sklik.cz API documentation: http://api.sklik.cz/
Contact: http://bit.ly/sklik-contact-form
"""
@messa
messa / sklik-api-creating-report-example.md
Created July 12, 2012 12:18
How to create report using Sklik API from report template in another account

How to create report from report template in another account using Sklik API

Demonstrated in Python.

>>> import xmlrpclib
>>> from pprint import pprint

Connect to Sklik API:

@messa
messa / stream.py
Created July 19, 2012 19:07
Twitter Streaming API example
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import json
import oauth2 # https://raw.github.com/brosner/python-oauth2/master/oauth2/__init__.py
from pprint import pprint
import urllib2
stream_url = "https://stream.twitter.com/1/statuses/filter.json"
@messa
messa / inject_ssl_version.py
Created October 10, 2012 14:57
Python snippet for forcing SSL version
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from contextlib import contextmanager
import ssl
@contextmanager
def inject_ssl_version(version=ssl.PROTOCOL_TLSv1):
"""
@messa
messa / strhash.txt
Created September 30, 2013 20:34
To, že mají dva řetězce stejný hash neznamená, že jsou stejné...
$ cat Demo.java
class Demo {
public static void main(String args[]) {
System.out.println("Aa".hashCode());
System.out.println("BB".hashCode());
}
}
$ javac Demo.java
$ java Demo
@messa
messa / overeni.py
Last active December 24, 2015 14:19
Ortogonální pole 2^4 3^2
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
tabulka = """
000002
011011
101100
110111
011120
100022
@messa
messa / main_paths.py
Created October 17, 2013 15:47
TVS 4. cv
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
fin = ("2",)
dvojice = """
0 1
1 2
1 3
3 4