Skip to content

Instantly share code, notes, and snippets.

View Mause's full-sized avatar
:shipit:
Still trying to figure out what I'm doing

Elliana May Mause

:shipit:
Still trying to figure out what I'm doing
View GitHub Profile
@Mause
Mause / gist:8884395
Last active August 29, 2015 13:56
simple example of type specialisation with Python
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__
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>
)
import re
import requests
from os.path import basename
from urllib.parse import urljoin
def generate_files(filenames):
return [
(
'input_files[]',
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) -
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; }
>>> 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'
}
>>> 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'
}
@Mause
Mause / client.py
Created June 14, 2014 07:06
A as simple as possible example of a ZMQ ROUTER-to-REQ configuration with curve authentication; ironhouse
import logging
logging.basicConfig(level=logging.DEBUG)
import zmq
import zmq.auth
def main(recreate):
if recreate:
zmq.auth.create_certificates('.curve', 'client')
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 = ""
#include <string.h>
bool startswith(char* poss, char* chunk) {
char* result = strstr(poss, chunk);
return result != NULL && result == poss;
}