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 truncate_db(engine): | |
# delete all table data (but keep tables) | |
# we do cleanup before test 'cause if previous test errored, | |
# DB can contain dust | |
meta = MetaData(bind=engine, reflect=True) | |
con = engine.connect() | |
trans = con.begin() | |
con.execute('SET FOREIGN_KEY_CHECKS = 0;') | |
for table in meta.sorted_tables: | |
con.execute(table.delete()) |
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
# @source: https://medium.com/@DorIndivo/how-we-migrated-from-python-multithreading-to-asyncio-128b0c8e4ec5 | |
async def run_func_async(func:Callable, func_args:List[Any], executor:ThreadPoolExecutor): | |
if asyncio.iscoroutinefunction(func): | |
return await func(*func_args) | |
else: | |
return await asyncio.get_event_loop().run_in_executor( | |
func=lambda:func(*func_args), executor=executor) |
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
const { defineAbility } = require('@casl/ability'); | |
const { rulesToQuery } = require('@casl/ability/extra'); | |
const Knex = require('knex'); | |
const { Model } = require('objection'); | |
const { interpret } = require('@ucast/objection') | |
const { CompoundCondition } = require('@ucast/core') | |
const knex = Knex({ | |
client: 'sqlite3', | |
connection: ':memory:' |
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
/* ========================================= | |
IMPORTS | |
-------------------------------------- */ | |
const fs = require('fs') | |
const path = require('path') | |
const _yaml = require('js-yaml') |
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
sudo rmmod nvidia_uvm | |
sudo rmmod nvidia | |
sudo modprobe nvidia | |
sudo modprobe nvidia_uvm |
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
const createFor = (exported = {}) => { | |
return (defaults = {}) => { | |
const functions = {} | |
exported['defaults'] = {...defaults} | |
for (const [key, value] of Object.entries(exported)) { | |
if (typeof value === 'function') { | |
functions[key] = exported[key] |
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 CombinedStream extends stream.PassThrough { | |
constructor (...streams) { | |
super() | |
this._streams = streams | |
this._transformStream = undefined | |
this.on('pipe', this.onPipe) | |
} |
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
/* ========================================= | |
IMPORTS | |
-------------------------------------- */ | |
const fs = require('fs') | |
const { promisify } = require('util') | |
sleep = promisify(setTimeout) |
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
/* ============================================= | |
Dependencies | |
------------------------------------------ */ | |
const debug = require('debug') | |
const chalk = require('chalk') | |
const { Readable, Writable, Transform, pipeline } = require('stream') |
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
import coloredlogs, logging | |
# TODO: find library similar to `debug` in Node/NPM | |
def debug(name): | |
logger = logging.getLogger(name) | |
coloredlogs.install(level='DEBUG', logger=logger) |
NewerOlder