Skip to content

Instantly share code, notes, and snippets.

View dz0's full-sized avatar

Jurgis Pralgauskis dz0

  • 17:53 (UTC +03:00)
View GitHub Profile
from ._anvil_designer import Form1Template
from anvil import *
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import plotly.graph_objects as go
txt_list = []
class Form1(Form1Template):
from hamcrest import *
native = {
'runtime': {
'err': {'data validation': anything(), 'evaluation': anything()},
},
'schema': {
'sheet_names': {'err': {'missing': ['Loans']}},
},
# palyginimui su https://www.facebook.com/photo.php?fbid=10158413583218323&set=p.10158413583218323&type=3
def varza(grandine):
R = 0
for varzu_eil in grandine:
atvirkstiniu_suma = sum(1/x for x in varzu_eil)
R += 1 / atvirkstiniu_suma
return R
@dz0
dz0 / function_call_log_decorator.py
Last active September 30, 2020 06:50
function_call_log_decorator.py
def log_call(func):
"""generic decorator"""
import functools
import inspect
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
args_repr = list(map(repr, args)) + [f"{key}={repr(val)}" for key, val in kwargs.items()]
@dz0
dz0 / SupervisedCallable.py
Created May 29, 2020 05:43
similar to mock/wrap, but with return logs
class SupervisedCallable:
"""
calls function and logs: `args`, `kwargs`, `result`
can add `side_effect` - idea is similar to the one in Mock:
has more options: mapping/list/callable/value
`NO_SIDE_EFFECT` sentinel -- fallback to original `fun` -- so can "mix" side_effect with fallback
>>> mock_randint = SupervisedCallable(randint, side_effect=[0, 13, ZeroDivisionError, SupervisedCallable.NO_SIDE_EFFECT, 2])
>>> for x in range(6):
; nice formatting of https://www.vertica.com/blog/vertica-quick-tip-splitting-string-rows/
=> SELECT * FROM test;
id | c2
----+-------
1 | A|B|C
2 | D|E|F
(2 rows)
;;;;;
#%%
data = ...
#%%
import numpy
import scipy
values = []
for rand_state in range(1000):
mask = numpy.random.rand(len(data)) < 0.5
@dz0
dz0 / scratch.py
Last active October 9, 2019 12:34
# based on found https://repl.it/repls/EnlightenedWetFacts
import reprlib
import traceback, sys
traceback.repr = reprlib.repr # make traceback use the reprlib repr because it dumps locals, including the ENTIRETY of __builtins__, which can get a little annoying.
i = 0
def foo():
"""adapters/extensions to caldav lib for incremental (old-fashioned) sync https://github.com/python-caldav/caldav/issues/69
does monkey-patching on import!!
mostly by guide http://sabre.io/dav/building-a-caldav-client/
"""
from caldav.objects import *
from caldav.objects import _fix_tz
class InjectUrlDataMixin:
"""Used for POST on nested router (so it can take infromation from URL instead of repeting in serializer).
overrides `get_serializer`
(ps.: does not make sense for PUT/PATCH -- as the instance is selected by url-kwargs)
"""
def get_serializer(self, *args, **kwargs):
# standart `get_serializer` logic
serializer_class = self.get_serializer_class()
kwargs['context'] = self.get_serializer_context()