Skip to content

Instantly share code, notes, and snippets.

@I159
I159 / server.py
Created August 13, 2020 17:14 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class S(BaseHTTPRequestHandler):
#!/usr/bin/env python3
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
# Adapted to Python 3 by Ilya "I159" Pekenly (2019)
import json
import pprint
from http import server
from optparse import OptionParser
def _get_shard_iterator(self, shard, stream_arn):
return self.client.get_shard_iterator(
StreamArn=stream_arn,
ShardId=shard["ShardId"],
ShardIteratorType="TRIM_HORIZON",
)
def _process_signals(self, shards, remaining_items, termination_moment):
for shard_iterator in shards:
while remaining_items and dt.datetime.utcnow() <= termination_moment:
"""Infrastructure level of the application.
No logic is implemented here, only data retrieved from requests
passed to a controllers level. This module is not for testing,
a framework is trusted since it is ouf of our responsibility.
"""
from my_application.controllers_level import implemented_use_cases
import chalice
import abc
# Entities level
class Entity(metaclass=abc.ABCMeta):
@abc.abstractmethod
def _lower_level_meth(self):
raise NotImplementedError
@property
def entity_prop(self):
@I159
I159 / di.py
Created October 27, 2018 16:17
#Framework Code:
class TokenInterface():
def getUserFromToken(self, token):
raise NotImplementedError
class FrameworkClass(TokenInterface):
def do_the_job(self, ...):
# some stuff
self.user = super().getUserFromToken(...)
@I159
I159 / ioc.py
Last active July 25, 2018 16:39
# Framework internal
def MetaIoC(name, bases, namespace):
cls = type("IoC{}".format(name), tuple(), namespace)
return type(name, bases + (cls,), {})
# Entities level
class Entity:
def _lower_level_meth(self):
raise NotImplementedError
from datetime import datetime, timedelta
from time import sleep
class Delay:
def __init__(self, secs):
self._secs = secs
self.when = datetime.now() + timedelta(seconds=secs)
def __await__(self):
typedef struct _frame {
PyObject_VAR_HEAD
struct _frame *f_back; /* previous frame, or NULL */
PyCodeObject *f_code; /* code segment */
PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
PyObject *f_globals; /* global symbol table (PyDictObject) */
PyObject *f_locals; /* local symbol table (any mapping) */
PyObject **f_valuestack; /* points after the last local */
/* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
Frame evaluation usually NULLs it, but a frame that yields sets it
package main
import (
"fmt"
)
var IDENTITY = [2][2]int64{{1, 0}, {0, 1}}
var DEFAULT = [2][2]int64{{1, 1}, {1, 0}}
func dotProduct(a, b [2][2]int64) (res [2][2]int64) {