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 clean_json(google_json): | |
# delete anti-xss junk ")]}'\n" (5 chars); | |
google_json = google_json[4:] | |
# pass through result and turn empty elements into nulls | |
instring = False | |
inescape = False | |
lastchar = '' | |
normal_json = "" |
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 logging | |
logging.basicConfig(level=logging.DEBUG) | |
import zmq | |
import zmq.auth | |
def main(recreate): | |
if recreate: | |
zmq.auth.create_certificates('.curve', 'client') |
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
>>> l = [' key1 ', ' value1 ', ' \tkey2', 'value2\t\n'] | |
>>> l = [s.strip() for s in l] | |
>>> d = dict(zip(l[::2], [1::2])) | |
>>> d | |
{ | |
'key1': 'value1', | |
'key2': 'value2' | |
} |
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
>>> l = ['key1', 'value1', 'key2', 'value2'] | |
>>> l = map(str.strip, l) | |
>>> l = iter(l) # if not already an iterator | |
>>> d = dict(zip(l, l)) | |
>>> d | |
{ | |
'key1': 'value1', | |
'key2': 'value2' | |
} |
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
list(A) ::= LIST_ITEM(B). { A=B; } | |
list(A) ::= LIST_ITEM(B) list_clause(C). { | |
A=B; | |
append_contents of C to B | |
} | |
list_clause(A) ::= COMMA list(B). { A=B; } |
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 math | |
def area_of_circle(diameter): | |
return math.pi * (diameter / 2 ** 2) | |
def volume_of_pipe(inner_diameter, outer_diameter, length): | |
area_of_pipe_end = ( | |
area_of_circle(outer_diameter) - |
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 re | |
import requests | |
from os.path import basename | |
from urllib.parse import urljoin | |
def generate_files(filenames): | |
return [ | |
( | |
'input_files[]', |
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
files = { | |
'unique_filename': 'file_data', | |
'unique_filename': ('filename', 'file_data'), | |
'unique_filename': ('filename', 'file_data', 'custom file content type'), | |
'unique_filename': ( | |
'filename', | |
'file_data', | |
'custom file content type', | |
<custom headers in tuple or dict> | |
) |
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 functools import wraps | |
def specific_magic(f): | |
@wraps(f) | |
def wrapper(self, *args, **kwargs): | |
for arg in args: | |
if type(arg) != self.__class__: | |
raise TypeError('{} not of type {}'.format( | |
arg, self.__class__.__name__ |
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
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |