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
# Python 2 | |
from mock import patch, mock_open | |
creds_file = "This text is not really in a file." | |
mocked_open = patch("__builtin__.open", mock_open(read_data=creds_file)) | |
mocked_open.start() | |
with open("any_file_name") as mocked_file: | |
print(mocked_file.read()) |
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 dictionaries_match(d1, d2): | |
# both are dicts, need to check values | |
if isinstance(d1, dict) and isinstance(d2, dict): | |
d1_keys = d1.keys() | |
d1_keys.sort() | |
d2_keys = d2.keys() | |
d2_keys.sort() | |
valid = d1_keys == d2_keys and all( | |
dictionaries_match(d1[k], d2[k]) for k in d1.keys() |
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
# NOTE: need to install oauth2client | |
# Signed URL generates correctly but I keep getting: | |
# <Error> | |
# <Code>SignatureDoesNotMatch</Code> | |
# <Message> | |
# The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method. | |
# </Message> | |
# ... | |
# </Error> |
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 copy | |
def replace(data, path_to_key, replacement_value): | |
""" | |
Will replace a nested value in a dict with the given value. | |
Args: | |
data (dict): a dictionary | |
path_to_key (str): nested/path/to/key. The value of this key will be | |
replaced | |
replacement_value (str): Replacement value for the key from |
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
# other stuff ... | |
# open git cola (https://git-cola.github.io/) easier | |
alias gc='git-cola &' | |
# enter friendly interactive shell easier (https://fishshell.com/) | |
alias f='fish' | |
# create and checkout new branch easier, stash stuff before if needed | |
gitbranch(){ |
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
from config import GOOGLE_APPLICATION_CREDENTIALS | |
from config import GOOGLE_APPLICATION_CREDENTIALS_P12 | |
from config import GOOGLE_CLOUD_IDENTITY_ADMIN_EMAIL | |
from googleapiclient.discovery import build | |
from httplib2 import Http | |
from oauth2client.service_account import ServiceAccountCredentials | |
def connection_test(): |
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
""" | |
NATURAL LOG LOOKUP TABLE GENERATOR | |
Generates a lookup table for the natural log function given a lower and upper bound | |
Points chosen ensure that linear approximation between the points minimize error | |
within the MAX_PERCENT_ERROR provided. | |
You can adjust the MAX_PERCENT_ERROR, realizing that a smaller error will require | |
more data points. The length of the resulting list should be printed to standard output. |
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 argparse | |
import sys | |
import os | |
def main(): | |
''' | |
Entry point of script | |
''' | |
# Parse arguments into script |
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
# Redirect print output to null device on operating system | |
print_redirect = open(os.devnull, 'w') | |
sys.stdout = print_redirect | |
# See this: http://stackoverflow.com/a/6735958/4175042 |
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
Purpose | |
-------------------------------------------------------------------------------------------- | |
Change Windows default name for copied files. Is usually OriginalFileName - Copy.ext | |
Directions | |
------------------------------------------------------------------------------------------- | |
In Windows registry: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer | |
- Add key : NamingTemplates | |
- Add new String Value : CopyNameTemplate | |
- Add Data for CopyNameTemplate: <New default here> |