This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ZODB.DB, ZODB.FileStorage | |
import hlib.runtime, hruntime, lib.datalayer # Moje knihovny, aby byly "citelne" objekty ve stromu, ktery lezi v db | |
storage = ZODB.FileStorage.FileStorage('/data/virtualenv/settlers/osadnici/db.test/settlers') | |
db = ZODB.DB(storage) | |
connection = db.open() | |
root = connection.root() | |
>>> print root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER="$1" | |
HOST="$2" | |
while `/bin/true`; do | |
echo 'loop...' | |
ping -c 3 $HOST &> /dev/null | |
[ "$?" = "0" ] && break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generic one, any fns accepted | |
def reduce_to_false(*ps): | |
def __reduce_to_false(*args, **kwargs): | |
return all([p(*args, **kwargs) for p in ps]) | |
return __reduce_to_false | |
# this one should work too but it's limited only to fns with exactly one parameter | |
def reduce_to_false_short(*ps): | |
return lambda arg: all([p(arg) for p in ps]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[local:0]: mprchlik@dhcp-25-152 ~ $ cat t.py | |
def f(l = []): | |
l.append('foo') | |
return l | |
print f() | |
print f() | |
[local:0]: mprchlik@dhcp-25-152 ~ $ python t.py | |
['foo'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from netaddr import IPNetwork | |
with open('workfile', 'r') as f: | |
print '\n'.join(['{0},{1}-{2}'.format(name, ip.network + 1, ip.broadcast - 1) for name, ip in [(net_name, IPNetwork(net_addr + '/' + net_mask)) for net_name, net_addr, net_mask in [line.strip().split() for line in f]]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
import time | |
class Timeout(object): | |
def __init__(self, retry, timeout): | |
self.retry = retry | |
self.timeout = timeout | |
def __enter__(self): | |
def timeout_handler(signum, frame): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# This file is part of Cockpit. | |
# | |
# Copyright (C) 2016 Red Hat, Inc. | |
# | |
# Cockpit is free software; you can redistribute it and/or modify it | |
# under the terms of the GNU Lesser General Public License as published by | |
# the Free Software Foundation; either version 2.1 of the License, or |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(): | |
def query(sql_query, sql_params = None, dryrun = None, fetchall = False): | |
# execute query | |
if fetchall: | |
result = cur.fetchall() | |
... | |
def select(self, *args, **kwargs): | |
kwargs['fetchall'] = True | |
return self.query(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createdb proormedent | |
createuser -e -E -l -P proormed | |
REVOKE ALL ON DATABASE proormedent FROM public; -- shut out the general public | |
GRANT CONNECT ON DATABASE proormedent TO proormed; -- since we revoked from public | |
GRANT USAGE ON SCHEMA public TO proormed; | |
GRANT ALL ON ALL TABLES IN SCHEMA public TO proormed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import filters | |
def _import_filters(directory): | |
filters = [] | |
for name in os.listdir(directory): | |
if name == '__init__.py' or name.endswith('.pyc') or not name.endswith('.py'): | |
continue | |
mod_name = name[0:-3] # 'foo.py' => 'foo' |