Skip to content

Instantly share code, notes, and snippets.

View nicoknoll's full-sized avatar
💯
Getting things done.

Nico Knoll nicoknoll

💯
Getting things done.
View GitHub Profile
class CxmlNode:
dtd = etree.DTD(dtd_file)
def __init__(self, *args, **kwargs):
self.payload_id = kwargs['payload_id']
self.timestamp = kwargs.get('timestamp') # datetime.now().isoformat()
def __str__(self):
return self.render().decode('UTF-8')
def convert(name, remove_ns=True):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
# remove namespaces
if remove_ns:
s1 = re.sub(r'^\{http.*\}', '', s1)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
from django.template.loader import get_template
class ValidationError(Exception):
pass
class Field:
def __init__(self, default=None, required=False, allowed_type=None):
self.allowed_type = allowed_type
from django.template.loader import get_template
class ValidationError(Exception):
pass
class Field:
def __init__(self, default=None, required=False, allowed_type=None):
self.allowed_type = allowed_type

ImageProxy Run times

LOCAL:

Memory cache

timeit.timeit("requests.get('http://127.0.0.1:8080/200/http://127.0.0.1:8000/media/product_images/egg.jpg?a={}'.format(random.randint(100, 400)))", "import requests; import random", number=100)

100 calls = 3.4494818639941514

No cache

How to run imageproxy

  1. Install go if you haven't so far
  2. Install imageproxy
    • Using standalone installation:
      • go get willnorris.com/go/imageproxy/cmd/imageproxy
  • go build willnorris.com/go/imageproxy/cmd/imageproxy
@nicoknoll
nicoknoll / track.py
Created January 10, 2018 16:04
Easy python tracking of whole functions or blocks of code
class Track:
def print_result(self, name, start_time, end_time):
time_delta = end_time - start_time
result = '%r took: %2.4f sec' % (name, time_delta)
print(result)
def time(self, func):
@wraps(func)
def func_wrapper(*args, **kwargs):
start_time = time.time()
import os, sys, datetime
# Static variables
dateformat = {
"eu": "%d.%m.%Y",
"us": "%Y.%m.%d"
};
# Check that script is properly called
@nicoknoll
nicoknoll / structure.md
Last active February 1, 2019 18:48
Basic App Structure for feathers.js

This guide describes a way to structure a feathers-client application with react and node. It is based on ideas from Mantra and personal experience.

Root level:

node_modules/
└── ...
dist/