This file contains hidden or 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
# WARNING Untested | |
# Assume the 'employees' table has the following columns: first_name, last_name, department, | |
# manager, salary, hire_date | |
from collections import namedtuple | |
EmployeeRow = namedtuple('EmployeeRow', ['first_name', 'last_name', 'department', | |
'manager', 'salary', 'hire_date']) | |
EMPLOYEE_INFO_FMT = '{last_name}, {first_name} was hired on \ |
This file contains hidden or 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 BaseHTTPServer | |
def keep_running(): | |
user_keystroke = raw_input() | |
if user_keystroke == 'q': | |
return False | |
else: | |
return True | |
def run_while_true(server_class=BaseHTTPServer.HTTPServer, |
This file contains hidden or 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 sys | |
import random | |
import logging | |
logging.basicConfig(format='[%(levelname)5s] %(message)s',level=logging.DEBUG) | |
def run(program=''): | |
"""Function to be wrapped""" | |
if not program: | |
raise OSError('Not program specified to run.') | |
This file contains hidden or 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 JLI(object): | |
"""JLI""" | |
def __init__(self): | |
pass | |
def check_verbose(self): | |
try: | |
self.verbose | |
except AttributeError: | |
return False |
This file contains hidden or 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
# In case you're using more than one shell at a time, say, bash, then ksh then bash .. and so forth | |
# you may wanna know which is the current shell active | |
# $$ contains the PID of the parent process (i.e., the spawned shell) | |
my_shell=`ps -p $$ | tail -1 | awk '{print $NF}'` | |
echo ${my_shell} |
This file contains hidden or 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
def prepare_logger(options, logging_config_file='logging.ini'): | |
"""Logging configuration, via logging configuration file and initialization. | |
@param options: a dictionary with the values of the variables reference in the logging configuration file. | |
@param logging_config_file: (Optional) If specified, its a full qualified path name to a logging configuration file | |
@raise IOError: If the logging configuration file is not accesible""" | |
if logging_config_file: | |
log_ini_path = logging_config_file |
This file contains hidden or 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 sys | |
def force_trust(): | |
'''Checks if we need to trust all certificates | |
#FIXME: Not only check Jython, check if Jython was compiled with SSL support''' | |
if 'java' in sys.platform: | |
return True | |
else: | |
return False |
This file contains hidden or 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
grep --color='auto' -P -n "[\x80-\xFF]" /file.txt |
This file contains hidden or 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 email.mime.text import MIMEText | |
from email.mime.image import MIMEImage | |
from email.mime.multipart import MIMEMultipart | |
from email.Utils import formatdate | |
from logging.handlers import SMTPHandler | |
import logging | |
import os.path | |
import smtplib | |
This file contains hidden or 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
Folder structure should be like | |
test_my_package.py | |
my_package/ | |
__init__.py | |
my_module.py | |
Requieres mock to be available | |
Usage: python test_my_package |