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 bash | |
| set -e | |
| # example: ./backup_to_s3 [/var/log] [s3-bucket[/sub-dir]] | |
| # log directory | |
| log_dir=${1:-"/var/log"} | |
| # filename for the tarball of all the logs | |
| logball_fname=`date +%FT%H%M`.tgz | |
| # absolute filepath + filename of the tarball |
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
| #!/bin/bash | |
| # This script will check for tmux session, | |
| # attach to it or create a new one | |
| # For debugging uncomment below | |
| # set -o verbose | |
| USERNAME=${USERNAME:-wamsachel} | |
| TMUX_SESSION="${USERNAME}s_session" |
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 python3 | |
| """ | |
| web_app.py | |
| Author: wamsachel | |
| Date: today | |
| web_app is a simple bottle-drive web app which examines how to better handle internet vitriol, | |
| rather than waiting for lawmakers to do so | |
| Usage: $python3 web_app.py |
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 to_bytes3(bytes_or_str): | |
| """Python3 helper return bytes type of bytes_or_str """ | |
| if isinstance(bytes_or_str, str): | |
| ret_val = bytes_or_str.encode('utf-8') | |
| else: | |
| ret_val = bytes_or_str | |
| return ret_val | |
| def to_str3(bytes_or_str): |
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 gen_bytestr(dec_val, byte_str_len=4): | |
| """ takes dec_val, converts to hex and returns byte_str that is byte_str_len long | |
| e.g. gen_bytestr(255, 4) -> '\x00\x00\x00\xff' | |
| """ | |
| # first check if dec_val can even be represented by a byte string of byte_str_len length | |
| byte_count = (int.bit_length(dec_val) / 4) | |
| if byte_count > byte_str_len: | |
| raise Exception('[!] {val} too large for {max} byte length. (requires {req} bytes)'.format( | |
| val=dec_val, max=byte_str_len, req=byte_count)) | |
| hex_val = hex(dec_val) |
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 configparser | |
| CONFIGURATION_FILE = 'CONFIG.ini' | |
| def configure(): | |
| """ Step the user through the configuration options """ | |
| try: | |
| config = configparser.ConfigParser() | |
| config.read(CONFIGURATION_FILE) | |
| print ('[*] {} read successfully'.format(CONFIGURATION_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
| #!/usr/bin/env python | |
| import argparse | |
| import os | |
| # Handle command line args | |
| try: | |
| arg_parser = argparse.ArgumentParser(description = 'Will recursively traverse a directory tree,\ | |
| and remove all files and directories that match any passed in regular expressions') | |
| arg_parser.add_argument('dir', help = 'dir to start tree traversal process') |
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
| #Taken from http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python | |
| def enum(**enums): | |
| return type('Enum', (), enums) | |
| Numbers = enum(ONE = 1, TWO = 2, THREE = 'three') | |
| Numbers.ONE | |
| >> 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
| For OS X: | |
| alias whereami='ifconfig | grep "inet " | cut -d " " -f 2' | |
| For Linux: | |
| alias whereami='ifconfig | grep "inet addr:" | cut -d : -f 2 | cut -d " " -f 1' |