Skip to content

Instantly share code, notes, and snippets.

View pythononwheels's full-sized avatar

khz pythononwheels

View GitHub Profile
@pythononwheels
pythononwheels / DCPU-16Spec.txt
Created July 26, 2019 20:54 — forked from metaphox/DCPU-16Spec.txt
DCPU-16 Specification
DCPU-16 Specification
Copyright 1985 Mojang
Version 1.7
=== SUMMARY ====================================================================
* 16 bit words
* 0x10000 words of ram
class Todo(TinyModel):
schema = {
'title' : { 'type' : 'string', 'maxlength' : 35 },
'text' : { 'type' : 'string' },
'tags' : { 'type' : 'list', "default" : [] },
"votes" : { "type" : "integer", "default" : 0 }
}
@app.make_method_routes()
class HelloHandler(BaseHandler):
@route(r'/hello/<int:identifier>', dispatch=["get"])
def hello(self, identifier=None):
self.write("Hello world! " + str(identifier))
@app.add_rest_routes("task")
class Task(BaseHandler):
#
# every pow handler automatically gets these RESTful routes
# when you add the : app.add_rest_routes() decorator.
#
# 1 GET /todo #=> list
# 2 GET /todo/<uuid:identifier> #=> show
# 3 GET /todo/new #=> new
# 4 GET /todo/<uuid:identifier>/edit #=> edit
@relation.has_many("subtasks")
@relation.setup_sql_schema()
class Task(Base):
schema = {
'title' : { 'type' : 'string', 'maxlength' : 35 },
'text' : { 'type' : 'string' },
"votes" : { "type" : "integer", "default" : 0 }
}
schema = {
'title' : { 'type' : 'string', 'maxlength' : 35 },
'text' : { 'type' : 'string' },
'tags' : { 'type' : 'list', "default" : [] },
"votes" : { "type" : "integer", "default" : 0 }
}
@pythononwheels
pythononwheels / json2cerberus.py
Created November 14, 2018 21:05
Convert given JSON input (file.json) to a basic cerberus schema
#
# convert json data to a cerberus schema.
# Cerberus types see here: http://docs.python-cerberus.org/en/stable/validation-rules.html#type
#
# sampledata: https://www.json-generator.com/
#
# this uses the first data element in a given json file to create
# a model(cerberus) schema from it. Trying to guess the right types (without too much effort)
#
@pythononwheels
pythononwheels / data_classes.py
Last active August 31, 2022 21:08
python cerberus dataclass support proposal / idea
# -*-: coding utf-8 -*-
"""
This module is a proposal to add python's dataclass support to cerberus.
See Issue: #397
https://github.com/pyeve/cerberus/issues/397
And road-map:
1.3
Checklist:
The module dataclasses is implemented. This may get postponed 'til a following minor release. (#397)
@pythononwheels
pythononwheels / test_string_comparison.py
Created April 16, 2016 20:32
compare tuples of strings with a given pattern in python using difflib.
#
# Test string comparison of string tuples
# python 3.4
# using difflib.
#
# see also: http://stackoverflow.com/questions/36643618/scoring-consistency-within-dataset
# khz 04/2016
#
import difflib
import random
@pythononwheels
pythononwheels / csv_to_json.py
Created August 12, 2014 11:10
Short python utility that converts a given csv to the according json. Fieldnames are taken from the first line of the csv.
import csv
import json
import sys
#
#
# converts csv to json
# fieldnames are taken from the first line of the csv input file
#
# khz / 2014