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 json | |
import pprint | |
from jsondiff import diff | |
def prompt_merge_attr(*attrs_list): | |
''' Given multiple versions of an attribute dictionary, | |
facilitate merging them into a single version. | |
''' | |
final_attrs = {} | |
all_attrs = set([ |
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 bind(func, *args, **kwargs): | |
''' Bind positional and named arguments to `func`. | |
e.g. | |
Input: | |
new_print = bind(print, '>', sep=' ', end='!\n') | |
Output: | |
new_print('Test') | |
> Test! | |
''' | |
def func_wrapper(*_args, **_kwargs): |
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
''' Usage: | |
from pyswagger_wrapper import SwaggerClient | |
client = SwaggerClient('your_swagger_url', headers={'auth': 'whatever', 'if': 'necessary'}) | |
client.actions.your_op_id.call(your=params) | |
''' | |
import json | |
from urllib import request | |
from pyswagger import App |
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 | |
# Usage: | |
# no-proofpoint < broken_file.txt > fixed_file.txt | |
import re, sys | |
proofpoint_re = re.compile(r'https?://.+?/url\?u=(.+?)&d=.+?&e=') | |
encode_re = re.compile(r'-(\w{2})') | |
stdin = sys.stdin.read() | |
prev = 0 | |
for match in proofpoint_re.finditer(stdin): |
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 sh | |
# Parse a normal uri--e.g. http://user:pass@host:1234 into a custom perl-based substitution format. | |
# e.g. parse_uri "http://localhost:80" '$+{port}' ==> 80 | |
function parse_uri() { | |
URI=$1 | |
FMT=$2 | |
echo ${URI} | perl -pe "s#(?<proto>[\w\+-]+)://((?<user>[-\w]+):(?<pass>[-\w]+)@)?((?<host>[-\w]+)(:(?<port>\d+))?)#${FMT}#g" | |
} |
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/sh | |
HOME="/home/${USER}" | |
PROFILE="${HOME}/.profile" | |
install_env() { | |
ENV_CMD="$1" | |
ENV_URL="$2" | |
ENV_ROOT="${HOME}/.${ENV_CMD}" | |
ENV_CMD_ROOT="$(echo ${ENV_CMD} | tr /a-z/ /A-Z/)_ROOT" |
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
# Usage: | |
#FROM u8sand/archlinux-devel-yaourt | |
#RUN echo "Instaling dependencies..." | |
#RUN pacman -Sy --noconfirm && sudo -u docker yaourt -S --noconfirm all your packages | |
# | |
# Your scripts | |
# | |
#Optional: Remove privileged account for security reasons | |
#RUN userdel -r docker && rm /etc/sudoers.d/docker |
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
pkgname=('pacman-mirrorlist-hook') | |
pkgver=1 | |
pkgrel=1 | |
pkgdesc='Pacman mirrorlist hook.' | |
arch=('any') | |
depends=('pacman' 'pacman-mirrorlist') | |
source=('pacman-mirrorlist.hook' 'rank-mirror-list.sh') | |
md5sums=('b51e1a45b23b2831709e7732fe88d4c8' | |
'5cceded6741d705fd09b919de9e1234b') |
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/env python | |
def enforce(func): | |
''' Decorator to enforce type decorators at runtime via | |
type assertion. Usage: | |
@enforce | |
def foo(a : str, b : int, c = True : bool) -> str: | |
return None | |
''' | |
def enforce_wrapper(*args, **kwargs): |
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 | |
if [ $(id -u) != 0 ]; then | |
exec sudo -- "$0" "$@" | |
else | |
cat /etc/pacman.d/mirrorlist.pacnew | awk -v RS='\n\n' '/^## United States/{print $0}' | awk '/^#Server/{print substr($0, 2)}' | rankmirrors - > /etc/pacman.d/mirrorlist | |
rm /etc/pacman.d/mirrorlist.pacnew | |
fi | |