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 | |
# | |
# Checks SPF records for recursion level | |
# (see https://tools.ietf.org/html/rfc7208#section-4.6.4) | |
# | |
check_domain="${1:?Specify a domain to check!}" | |
check_record() { | |
local domain="$1" |
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 -*- | |
"""Пример декоратора. | |
Декоратор - функция, которая принимает функцию, как аргумент, и подменяет | |
её имплементацию другой функцией. | |
Например, @cached заворачивает свою функцию-аргумент в функцию try_cache, | |
которая перед возвращением значения будет класть его в кеш для ускорения | |
повторного вызова. |
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
"""Single instance locking for your scripts. | |
Usage: | |
from instance_lock import lock_instance | |
def i_am_busy(): | |
print "I'm busy!" | |
with lock_instance(locked_callback=i_am_busy): | |
do_something_long() |
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
"""Library to use Redis for the cache. | |
Usage: | |
from redis_cache import redis_cached | |
@redis_cached | |
def foo(bar, baz, misc=123): | |
return bar + baz + misc | |
""" |
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 bash | |
# | |
# Example of parallel SSH execution with colorized hostnames. | |
# Requires a 256 color-compatible terminal. | |
# | |
set -u | |
declare -a SERVERS=( | |
my.server.001 |
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
#view current chains | |
$ iptables -L | |
#remove/flush all rules & delete chains | |
$ iptables -F | |
$ iptables -X | |
$ iptables -t nat -F | |
$ iptables -t nat -X | |
$ iptables -t mangle -F | |
$ iptables -t mangle -X |
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 -*- | |
"""Dumps Elasticsearch index; handy for backing up Kibana.""" | |
import sys | |
import argparse | |
import json | |
import logging | |
import requests |
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 re | |
_RE_HMS = re.compile( | |
r'^\s*(?:(?P<h>\d+)h)?\s*(?:(?P<m>\d+)m)?\s*(?:(?P<s>\d+)s?)?\s*$') | |
def to_hms(seconds): | |
"""Converts seconds (int) to "h m s" (str).""" | |
minutes, seconds = divmod(seconds, 60) |
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
""" | |
Safe way to call subprocess.Popen.communicate() and str from it. | |
""" | |
def shell(exe, *args, **kwargs): | |
if sys.version_info >= (3, 6) and 'encoding' not in kwargs: # for Python >=3.6 | |
kwargs['encoding'] = 'utf8' | |
args = [exe] + list(args) | |
proc = subprocess.Popen(args, stdout=subprocess.PIPE) | |
out, _ = proc.communicate() |