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 re | |
import os | |
import argparse | |
from urllib import request | |
from urllib.parse import urljoin | |
from html.parser import HTMLParser | |
class ArticleParser(HTMLParser): |
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
# Check existing | |
- name: Ansible check file exists. | |
stat: | |
path: /etc/filename | |
register: file_status | |
- debug: | |
msg: "File exists..." | |
when: file_status.stat.exists | |
- debug: | |
msg: "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
import os | |
KEY1 = 'VALUE1' | |
KEY2 = 'VALUE2' | |
# Override values from config_local.py if exists | |
try: | |
import config_local | |
for key, value in config_local.__dict__.items(): | |
if key.isupper() and key in globals(): |
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 | |
class Runner(object): | |
def __init__(self): | |
logging.basicConfig(level=logging.DEBUG) | |
logger = logging.getLogger(__name__) | |
adapter = CustomAdapter(logger, {'runner': self}) | |
# adapter.debug('Some debug message') |
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
# Get generation time from ObjectId | |
>>> k['_id'] | |
ObjectId('5991ba6cd241bf1001790c26') | |
>>> k['_id'].generation_time | |
datetime.datetime(2017, 8, 14, 14, 57, 48, tzinfo=<bson.tz_util.FixedOffset object at 0x7f1beb8d9550>) | |
>>> k['_id'].generation_time.strftime('%H:%M') | |
'14:57' | |
>>> k['_id'].generation_time.strftime('%H:%M:%S %d/%b/%Y') | |
'14:57:48 14/Aug/2017' |
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 click | |
from datetime import datetime | |
from jinja2 import Environment, PackageLoader, StrictUndefined | |
@click.command() | |
@click.option('--version') | |
def do_it(version): | |
click.secho('yellow text', fg='yellow') | |
env = Environment( |
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 | |
import glob | |
# Get current directory | |
dir_path = os.path.dirname(os.path.realpath(__file__)) | |
# Walk match files by a pattern within directory | |
glob.glob('your-directory/*') | |
# Recursively walk through all the files/directories within a folder |
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 term | |
exp = '(+|-|e)dd*' | |
class InvalidInput(ValueError): | |
pass | |
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
vagrant up | |
vagrant ssh | |
cd workspace | |
virtualenv venv | |
source venv/bin/activate | |
python my_script.py | |
deactivate | |
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 operator | |
import inspect | |
def get_module_functions(module, function_prefix=''): | |
""" | |
Get all the functions located inside a module which name started with | |
`function_prefix` | |
""" | |
def filter_function(inspected_function): |