Skip to content

Instantly share code, notes, and snippets.

View igorcoding's full-sized avatar
🍹
Having fun

Igor Latkin igorcoding

🍹
Having fun
View GitHub Profile
class CustomJsonEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, JsonSerializable):
return obj.__to_json__()
if isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date):
return int(time.mktime(obj.timetuple()))
return super(CustomJsonEncoder, self).default(obj)
class JsonSerializable:
local function alter_package_path(paths, base)local isroot=function(s)return string.sub(s,1,1)=='/'end;local slashends=function(s)return string.sub(s,-1,-1)=='/'end;local fio=require('fio');local bf=debug.getinfo(2,"S").source:sub(2);local lb=fio.readlink(bf);if lb~=nil then bf=lb end;local b=bf:match("(.*/)");if not isroot(b) then b=fio.abspath(b);if not slashends(b)then b=b..'/'end;end;if base~=nil and base~="" then if isroot(base) then b=base;else b=b..base..'/';end;end;local pkg='';for _,p in ipairs(paths)do if isroot(p) then pkg=pkg..";"..p;else pkg = pkg..";"..b..p;end;end;package.path=package.path..pkg;return b;end
local base = alter_package_path({
'?.lua',
'?/init.lua',
'libs/tnt-luas16/?.lua',
})
-- Full function here:
local function alter_package_path(paths, base)
local isroot=function(s)return string.sub(s,1,1)=='/'end;
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -c -s`-pgdg main 9.6" > /etc/apt/sources.list.d/pgdg.list
import multiprocessing
def map_parallel(func, iterable, chunksize=1, *,
pool=None,
n_processes=None,
progress_bar_func=None,
pool_kwargs=None,
progress_bar_func_kwargs=None,
total=None
):
@igorcoding
igorcoding / rps.py
Last active October 11, 2017 13:10
import asyncio
import collections
import time
import uvloop; asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
def chunkify(lst, n):
s = len(lst) // n
o = 0