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 unittest | |
from mock import call, patch | |
class PatcherTestCase(unittest.TestCase): | |
def setUp(self): | |
self.patcher = patch('some_module.some_object') | |
self.mock_object = self.patcher.start() |
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 cProfile | |
import contextlib | |
import os | |
@contextlib.contextmanager | |
def profile(filename='~/python.profile', *args, **kwargs): | |
profile = cProfile.Profile(*args, **kwargs) | |
profile.enable() |
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
type: map_type | base_type | |
map_type: | |
'map' '<' base_type ',' 'map' '<' base_type ',' type '>>' | | |
'map' '<' base_type ',' type '>' | |
base_type: NAME |
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/env bash | |
_usage() { | |
printf 'usage: %s [-p|--poll <sec per poll>] [-a|--all] [<find args>] -- <command> [<args>]\n' "$(basename "$0")" >&2 | |
exit 64 | |
} | |
# Default arg values | |
sec_per_poll=2 | |
find_all=false |
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
[uwsgi] | |
socket = /tmp/example.com.sock | |
; Worker processes | |
master = 1 | |
processes = 4 | |
; Virtualenv and home directory | |
virtualenv = /var/virtualenvs/example.com | |
chdir = /var/www/example.com |
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/env python3 | |
import argparse | |
import json | |
import sys | |
parser = argparse.ArgumentParser(description='Manipulate JSON documents.') | |
parser.add_argument( | |
'-i', '--indent', | |
metavar='N', |
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 parsimonious | |
parser = parsimonious.Grammar(r""" | |
type = tuple_type / basic_type | |
tuple_type = "(" type next_type* ")" | |
next_type = "," type | |
basic_type = base sub? arrlist? |
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 parsimonious | |
parser = parsimonious.Grammar(r""" | |
type = tuple_type / basic_type | |
tuple_type = "(" type ("," type)* ")" | |
basic_type = base sub? arrlist? | |
base = alphas |
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
Python 3.6.4 (default, Mar 14 2018, 11:02:01) | |
Type 'copyright', 'credits' or 'license' for more information | |
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help. | |
In [1]: from functools import lru_cache | |
In [2]: class Adder: | |
...: def __init__(self, n): | |
...: self.n = n | |
...: @lru_cache() |
NewerOlder