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 inspect | |
from typing import Any, Callable, List, Type, TypeVar, Union, get_type_hints | |
from fastapi import APIRouter, Depends | |
from pydantic.typing import is_classvar | |
from starlette.routing import Route, WebSocketRoute | |
T = TypeVar("T") | |
CBV_CLASS_KEY = "__cbv_class__" |
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
# -*- coding: utf-8 -*- | |
# Print iterations progress | |
def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100): | |
""" | |
Call in a loop to create terminal progress bar | |
@params: | |
iteration - Required : current iteration (Int) | |
total - Required : total iterations (Int) | |
prefix - Optional : prefix string (Str) |
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 happybase | |
import time | |
import traceback | |
import json | |
def put(pool): | |
with pool.connection() as conn: | |
table = conn.table('Log') |
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
#!/usr/bin/env bash | |
python -m grpc_tools.protoc -I ./ --python_out=../server/ --grpc_python_out=../server/ ./grpcserver.proto |
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
FROM ubuntu:xenial | |
ENV DEBIAN_FRONTEND noninteractive | |
#Install git and java | |
RUN apt-get update && \ | |
apt-get -y install locales && \ | |
apt-get -y install \ | |
software-properties-common \ | |
sudo \ |
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 json | |
from datetime import datetime | |
from sqlalchemy.ext.declarative import DeclarativeMeta | |
class AlchemyEncoder(json.JSONEncoder): | |
def default(self, obj): | |
if isinstance(obj.__class__, DeclarativeMeta): | |
# an SQLAlchemy class | |
fields = {} |
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
from sqlalchemy import inspect | |
def alchemy_to_dict(obj): | |
# an SQLAlchemy class | |
fields = {} | |
for field in [c.key for c in inspect(obj).mapper.column_attrs]: | |
data = obj.__getattribute__(field) | |
try: | |
if isinstance(data, datetime): | |
data = data.strftime('%Y-%m-%d %H:%M:%S') |
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 changeBase(n,b): | |
baseList = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' | |
x,y = divmod(n,b) | |
if x>0: | |
return changeBase(x,b) + baseList[y] | |
else: | |
return baseList[y] |
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
DELIMITER // | |
CREATE FUNCTION STRINGDECODE(str TEXT CHARSET utf8) | |
RETURNS text CHARSET utf8 DETERMINISTIC | |
BEGIN | |
declare pos int; | |
declare escape char(6) charset utf8; | |
declare unescape char(3) charset utf8; | |
set pos = locate('\\u', str); | |
while pos > 0 do |