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 os | |
import sys | |
# BEGIN PYTHONPATH FIX # | |
# appends root of project if PYTHONPATH is not set; | |
# relies on the presence of .git in project root. | |
root_proj_path = os.getcwd() | |
root_flag = False | |
while not('.git' in os.listdir(root_proj_path)) and not(root_flag): | |
if root_proj_path == '/': |
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 pip | |
from subprocess import call | |
for dist in pip.get_installed_distributions(): | |
call("pip install --upgrade " + dist.project_name, shell=True) |
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
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U |
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
tell application "System Preferences" | |
reveal pane "com.apple.preference.energysaver" | |
end tell | |
tell application "System Events" to tell process "System Preferences" to tell window "Energy Saver" | |
set status to value of checkbox "Automatic graphics switching" of group 1 | |
click checkbox "Automatic graphics switching" of group 1 | |
end tell | |
quit application "System Preferences" | |
if status is 0 then | |
return "Automatic switch activated" |
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/python | |
import shelve | |
class UnicodeShelve(shelve.DbfilenameShelf, object): | |
"""Wrapper around shelve.DbfilenameShelf that ensure unicode strings | |
are properly encoded/decoded before being insered/after being extracted | |
from the database.""" |
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
\newcommand{\lcb}{{\tt {\char '173}}} | |
\newcommand{\rcb}{{\tt {\char '175}}} |
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
# built-in modules | |
import json | |
from argparse import ArgumentParser | |
from time import time as now | |
# installed modules | |
from elasticsearch import Elasticsearch | |
from elasticsearch.helpers import scan | |
from elasticsearch.exceptions import ConflictError |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Type check demo</title> | |
</head> | |
<body> | |
<form> | |
Insert only digit here<br> | |
<input id="digitsInput" type="text" name="digits" onblur="checkdigits()"> |
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 sys | |
import traceback | |
from functools import wraps | |
def error_wrapper_pool(method): | |
""" Make sure that your multiprocessing pool workers report | |
their full traceback when crashing! | |
""" | |
@wraps(method) |
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 hashlib | |
import json | |
import sys | |
def hash_obj(obj): | |
try: | |
return hashlib.md5(json.dumps(obj)).hexdigest() | |
except TypeError: | |
pass |
OlderNewer