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 argparse | |
import contextlib | |
""" | |
Example usage: | |
python2.7 distinct_files.py --fileA=<fileA> --fileB=<fileB> > filenames_in_fileA_not_in_fileB.txt | |
""" | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() |
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
def stdev_sample(n): | |
diff = sum(n) / len(n) | |
diff_n_squared = map(lambda x: (x-diff) ** 2, n) | |
variance = sum(diff_n_squared) / (len(diff_n_squared) -1) | |
return math.sqrt(variance), variance | |
stdev_sample([1.23, 1.25, 1.21, 1.55]) |
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
$ ls .git/hooks | |
applypatch-msg.sample | |
commit-msg.sample | |
post-update.sample | |
pre-applypatch.sample | |
pre-commit.sample | |
prepare-commit-msg.sample | |
pre-rebase.sample | |
update.sample |
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
$ echo "{" >> bad.json | |
$ git add bad.json | |
$ git commit | |
Invalid json in bad.json: | |
Expecting object: line 1 column 1 (char 1) |
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 json | |
def precommit(git_state): | |
for fname in git_state["files"]: | |
if fname.endswith(".json"): | |
with open(fname, "r") as f: | |
try: | |
json.loads(f.read()) | |
continue |
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
$ hooked.py --help | |
Usage: hooked.py [options] | |
Options: | |
-h, --help show this help message and exit | |
--git-root=GITROOT the root directory of the git folder to inject hook | |
--clean Clean up after yourself | |
$ # lets make a new repo |
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
# in settings.py | |
USERS: { | |
"alice": { | |
"alice_specific_information" : True | |
}, | |
"bob": { | |
"bob_specific_information": 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
class NiceNumber(long): | |
def __new__(cls, *args): | |
x = 0 | |
if long(args[0]) >= 0: | |
sign = 1 | |
else: | |
sign = -1 | |
for i in range(0, len(args)): | |
reverse_i = (len(args) - 1) - i | |
x += (1000 ** i) * abs(long(args[reverse_i])) |
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 random | |
def roll_dice(): | |
return random.randint(1, 6) | |
def sum_two_dice(): | |
sum_one = roll_dice() | |
sum_two = roll_dice() |
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
def restore_cwd(func): | |
""" | |
decorator to restore the current working directory | |
""" | |
def wrapper(*args, **kwargs): | |
cwd = os.getcwd() | |
results = func(*args, **kwargs) | |
os.chdir(cwd) | |
return results |
NewerOlder