Skip to content

Instantly share code, notes, and snippets.

@outerpasta
outerpasta / gist:65dd37c215e062538bcc
Created July 3, 2014 16:54
Takes a dict with nested lists and dicts and searches all dicts for a key of the field provided.
def get_recursively(search_dict, field):
"""Takes a dict with nested lists and dicts,
and searches all dicts for a key of the field
provided.
"""
fields_found = []
for key, value in search_dict.iteritems():
if key == field:
# Delete git branches matching regex
git-delete-branches() {
git branch -D $(git branch | grep -E "$1")
}
# Checkout a temporary branch and commit changes. Like git stash but less easy to forget about.
alias tmp_commit='git checkout -b $(g rev-parse --abbrev-ref HEAD)_ && git add -u && git commit -m "$(git rev-parse --abbrev-ref HEAD): temporary commit."'
@outerpasta
outerpasta / gist:c6fcceee1686163bdc6b3a07cb5f92b9
Created May 3, 2016 18:28
remove untracked files from git repo
for i in $(git status -s | sed 's/\?\?//g'); do rm $i; done
#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
"""# For shell completion:
# eval "$(swear -c)"
_python_argcomplete() {
local IFS=' '
COMPREPLY=($(IFS="$IFS" COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT" \
_ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" _ARGCOMPLETE=1 "$1" \
8>&1 9>&2 1>/dev/null 2>/dev/null) )

Automatically escape a string for shell expansions!

$ alias shellescape="python -c 'import sys,subprocess;sys.stdout.write(subprocess.list2cmdline([sys.stdin.read()]))'"
$ echo '{"username":"$MYUSERNAME","password","$MYPASSWORD"}' | shellescape
{\"username\":\"$MYUSERNAME\",\"password\",\"$MYPASSWORD\"}
docker run --privileged -v /var/run/docker.sock:/run/docker.sock -ti -e TERM tomastomecek/sen
#!/usr/bin/env python
"""
Python wrapper thing"""
# encoding: utf-8
import os
from os.path import curdir, join, isfile
from subprocess import check_call
import sys
try:
from pip.locations import running_under_virtualenv
@outerpasta
outerpasta / uninstallatompackages.sh
Created December 27, 2016 06:31
uninstall all installed atom packages
apm uninstall `apm list --installed --bare | sed 's/@.*//g'`
from requests import ConnectTimeout, get
from os.path import join, dirname, isfile
from zipfile import ZipFile
import random
import csv
try:
from io import BytesIO
except ImportError:
from StringIO import StringIO
BytesIO = StringIO
@outerpasta
outerpasta / serve_and_open_browser
Created February 21, 2017 22:59
Starts a SimpleHTTPServer and opens the root in a browser
#!/usr/bin/env python2
"""Run server"""
import SimpleHTTPServer
import SocketServer
import webbrowser
import socket
import argparse
def main(port=8000):