This file contains 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 json_iterator(url, method='GET', content=None, credentials=None, datanodename='data'): | |
""" | |
Rufe JSON-Daten ab. | |
Es wird die seitenweise Darstellung von gaetk.BasicHandler.paginate unterstützt. | |
""" | |
if content is None: | |
content = {} |
This file contains 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
numbers = {} | |
for i in range(1, 200): | |
for j in range(1, 200): | |
number = i ** 4 + j ** 4 | |
numbers.setdefault(number, set()).add(tuple(sorted((i, j)))) | |
print min(dict((number, pairs) for number, pairs in numbers.items() if len(pairs) > 1)) |
This file contains 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
ek = 21. | |
vk = 2 * ek | |
x = (vk - ek) / (vk * 0.9 - ek) | |
for menge in 5, 23, 712, 8544, 3344444: | |
x = ((vk - ek) / (vk * 0.9 - ek)) | |
print menge * vk - menge * ek, (menge * x * (vk * 0.9)) - (menge * x * ek) |
This file contains 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
<?xml version="1.0"?> | |
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<xs:element name="order"> | |
<xs:complexType> | |
<xs:all> | |
<xs:element name="empfaenger_iln" type="GLN"/> | |
<xs:element name="orderid_client" type="xs:string"/> | |
<xs:element name="anlieferdatum_von" type="xs:date"/> | |
<xs:element name="anlieferdatum_bis" type="xs:date"/> | |
<xs:element name="auftragsnr_kunde" type="xs:string"/> |
This file contains 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
class ConverterProperty(db.Property): | |
"""Property class for converting data | |
Example: | |
Given a class MyModel which an IntegerProperty that should be converted to a StringProperty: | |
class MyModel(db.Model): | |
value = IntegerProperty() | |
In the conversion step the model would look like this: |
This file contains 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
# Beispiel einer parallelen Suche mit asynctools: | |
def parallelsearch(tenant, term): | |
"""Suche, die eine parallele Abfrage des Datastores durchführt""" | |
from asynctools import AsyncMultiTask, QueryTask | |
results = [] | |
runner = AsyncMultiTask() |
This file contains 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
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
execgae.py | |
Created by Christian Klein on 2010-12-23. | |
Copyright (c) 2010 HUDORA. All rights reserved. | |
""" | |
import urllib |
This file contains 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
# Enforce maximum length contrains | |
for field in instance._meta.fields: | |
if isinstance(field, models.CharField): | |
value = getattr(instance, field.name, '') | |
if len(value) > field.max_length: | |
setattr(instance, field.name, value[:field.max_length]) |
This file contains 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
#!/bin/sh | |
# cheyenne.sh - kill apache processes | |
# Created by Christian Klein on 2010-04-01. | |
# Copyright (c) 2010 HUDORA GmbH. All rights reserved. | |
ps -U www -o pid,time | tail +2 | while read pid time; do | |
hours=${time%:*} | |
minutes=${time#*:} | |
if [ $(printf %0.f $minutes) -gt 30 ] ; then |
This file contains 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_unique_object(model, pk, handlers=None): | |
"""Get object or call exception handler""" | |
def call_handler(exception): | |
"""Get handler for exception""" | |
name = exception.__class__.__name__ | |
if name in handlers: | |
fnc, args, kwargs = handlers[name] | |
fnc(*args, **kwargs) |
NewerOlder