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 os | |
def list_files(startpath): | |
for root, dirs, files in os.walk(startpath): | |
level = root.replace(startpath, '').count(os.sep) | |
indent = ' ' * 4 * (level) | |
yield ('{}{}/'.format(indent, os.path.basename(root))) | |
subindent = ' ' * 4 * (level + 1) | |
for f in files: | |
yield ('{}{}'.format(subindent, f)) |
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 list_zipper(list_1, list_2): | |
for (x_1, x_2) in zip(list_1, list_2): | |
if not x_1: | |
yield '{x_2}_vacio'.format(x_2=x_2) | |
else: | |
yield x_1 | |
if __name__ == '__main__': | |
list_1 = ['aaa', '', 'ccc'] | |
list_2 = ['titulo_1', 'titulo_2', 'titulo_3'] |
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
curl -v -j -k -L -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u25-b18/jdk-8u25-windows-i586.exe > jdk-8u25-windows-i586.exe |
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
df -P file/goes/here | tail -1 | cut -d' ' -f 1 |
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
################## | |
##### RedHat ##### | |
################## | |
## 32 or 64 bits? | |
uname -i | |
### i386: 32 bits | |
### x86_64: 64 bits |
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
#!/usr/bin/env python | |
import logging | |
import os | |
import subprocess | |
import sys | |
VPN_NAME='vpnc' |
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
""" | |
A simple HTTP Server. It admits port and ip as optional parameters | |
""" | |
import sys | |
import BaseHTTPServer | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
HandlerClass = SimpleHTTPRequestHandler |
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 this example we try to re raise an exception changing its class | |
""" | |
import sys | |
class InputFileNotFoundError(IOError): | |
""" | |
Input file not found |
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 ask_boolean(message): | |
""" | |
Asks a yes/no question to the user and looks if the answer is yes or no | |
@return answer: A boolean representing the user answer | |
""" | |
yes = ['YES', 'Yes', 'yes', 'y'] | |
no = ['NO', 'No', 'n'] | |
answer = raw_input(message+'{new_line}Choose one of [{yes}] or [{no}] {new_line}'.format(new_line=os.linesep, yes=' '.join(yes), no=' '.join(no))) |
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 logging | |
def setup_logging(name=__name__, level=logging.DEBUG, formatter=logging.Formatter('%(asctime)s %(levelname)s : %(message)s - (%(module)s, line %(lineno)s)')): | |
""" | |
Setups a logger with a `StreamHandler` that prints to `stdout` with `debug` logging | |
level and the following formatter | |
%(asctime)s %(levelname)s : %(message)s - (%(module)s, line %(lineno)s') | |
@return logger: The previously formatted logger |