Skip to content

Instantly share code, notes, and snippets.

Avatar
💯
Getting things done.

Nico Knoll nicoknoll

💯
Getting things done.
View GitHub Profile
View cxml.py
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')
View test.py
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()
View template_component.py
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
View template_component.py
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
View timing.md

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

View README.md

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 Jan 10, 2018
Easy python tracking of whole functions or blocks of code
View track.py
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()
View gist:85abd04b16b9b9069aa0e34dc7f75b72
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 Feb 1, 2019
Basic App Structure for feathers.js
View structure.md

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/