Skip to content

Instantly share code, notes, and snippets.

View messa's full-sized avatar

Petr Messner messa

View GitHub Profile
@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
@messa
messa / graf.dot
Last active December 26, 2015 10:39
TVS cv. 5
digraph cv5 {
// public int fnc() {
node [fontname="menlo-regular"];
edge [fontname="arial"];
// B999();
// int d999 = 808;
@messa
messa / tcpproxy.py
Created December 10, 2013 18:44
TCP proxy in Python - some IP-restricted programs requre a bit of TCP magic...
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from optparse import OptionParser
import os
from select import select
import socket
def main():
op = OptionParser()
import logging
from time import monotonic as monotime
logger = logging.getLogger(__name__)
class TimingWrapper:
'''
Wrapper na jakoukoli strukturu objektů, který měří dobu trvání běhu metod
@messa
messa / client.js
Last active April 29, 2016 21:54
node zeromq problem demonstration for https://github.com/JustinTulloss/zeromq.node/issues/523
var zmq = require('zmq');
var socket = zmq.socket('dealer');
socket.connect('tcp://127.0.0.1:3333');
socket.on('message', function(payload) {
console.info('Received:', payload.toString());
});
console.info('Sending...');
@messa
messa / potom.py
Last active May 27, 2016 14:30
funkce (Pyladies CZ 2015)
def ano_nebo_ne(otazka):
"Vrátí True nebo False, podle odpovědi uživatele"
while True:
odpoved = input(otazka)
if odpoved == 'ano':
return True
elif odpoved == 'ne':
return False
else:
print('Nerozumím! Odpověz "ano" nebo "ne".')
@messa
messa / multiprocess_logging_example.py
Last active August 18, 2016 16:13
Python multiprocess logging
from contextlib import contextmanager
import multiprocessing
def main():
multiprocessing.current_process().name = 'master'
mgr = multiprocessing.Manager()
with setup_logging(mgr):
pass # do cool stuff here
@messa
messa / json_api.py
Last active September 12, 2016 18:39
#!?usr/bin/env python3
import flask
import json
app = flask.Flask(__name__)
@app.route('/')
def index():
return '''