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 itertools | |
| def fizzbuzz(): | |
| for i in itertools.count(1): | |
| fizz = i % 3 == 0 | |
| buzz = i % 5 == 0 | |
| if fizz and buzz: | |
| yield 'fizz buzz' | |
| elif fizz: |
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 bitcoinrpc.connection import BitcoinConnection | |
| con = BitcoinConnection(host='127.0.0.1', port=18332, user='u', password='p') | |
| destination_addr = 'mh5YsB8cSLT2NxLKkdaZANBqhLSDgMFgGj' | |
| num_signatures = 2 | |
| signer_addr = 'mfcWQhBtWGPcSBPiPDeUJZ5n1Ud7XF2hSK' | |
| additional_signer_addr = 'mr37a4xtZZByapa9neEPC3oYLxbEaFyCkP' | |
| amount = 20.0 |
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 start_rql(rql, access_token): | |
| base_url = 'https://api.rollbar.com' | |
| start_job_url = base_url + '/api/1/rql/jobs?access_token=' + access_token | |
| body = json.dumps({'query_string': rql}) | |
| resp = requests.post(start_job_url, data=body, headers={'Content-Type': 'application/json'}).json() | |
| get_job_res = '{}/api/1/rql/job/{}?access_token={}&expand=result'.format(base_url, resp['result']['id'], access_token) | |
| def getter(): | |
| return requests.get(get_job_res).json()['result']['result']['rows'] | |
| return getter |
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
| SET FOREIGN_KEY_CHECKS = 0; | |
| SET GROUP_CONCAT_MAX_LEN=32768; | |
| SET @tables = NULL; | |
| SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables | |
| FROM information_schema.tables | |
| WHERE table_schema = (SELECT DATABASE()); | |
| SELECT IFNULL(@tables,'dummy') INTO @tables; | |
| SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables); | |
| PREPARE stmt FROM @tables; |
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
| nc -U /var/run/memcached/memcached.sock |
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 iter_stack(tb, limit=None): | |
| """modified version of traceback.extract_stack. it yields same tuples, but with frame.f_locals appended.""" | |
| if limit is None: | |
| if hasattr(sys, 'tracebacklimit'): | |
| limit = sys.tracebacklimit | |
| n = 0 | |
| while tb is not None and (limit is None or n < limit): | |
| f = tb.tb_frame | |
| lineno = tb.tb_lineno | |
| co = f.f_code |
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 json | |
| from pprint import pprint | |
| import requests | |
| rtb_request = { | |
| "id": "1234FcDe", | |
| "imp": [{ | |
| "id": "1", | |
| "banner": { | |
| "w": 100, # width - this be used as width parameter in request in case of dynamic size placements |
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
| SELECT relname, pg_size_pretty(relpages::bigint * 8 * 1024) as size, relkind, reltuples::bigint as rows, relpages, relfilenode FROM pg_class ORDER BY relpages DESC; |
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
| @classmethod | |
| def start(cls, port=8080, extra_workers=0): | |
| reactor.listenTCP(port, server.Site(cls())) | |
| for i in range(extra_workers): | |
| pid = os.fork() | |
| if pid == 0: | |
| # Proceed immediately onward in the children. | |
| # The parent will continue the for loop. | |
| break | |
| else: |
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 get_classname(): | |
| return traceback.extract_stack()[-2][2] # in inner call | |
| def get_classname_for_method_decorator(): | |
| return traceback.extract_stack()[-3][2] # in inner call | |
| def decorator(func): | |
| classname = get_classname_for_method_decorator() | |
| return func |
NewerOlder