Skip to content

Instantly share code, notes, and snippets.

View vcancy's full-sized avatar

Vcancy vcancy

View GitHub Profile
@vcancy
vcancy / fastapi_cbv.py
Created March 1, 2020 08:34 — forked from dmontagu/fastapi_cbv.py
FastAPI CBV
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__"
# -*- 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)
@vcancy
vcancy / hbase-demo.py
Created June 29, 2018 08:09
hbase demo
import happybase
import time
import traceback
import json
def put(pool):
with pool.connection() as conn:
table = conn.table('Log')
@vcancy
vcancy / grpc_tools.sh
Created June 29, 2018 08:00
grpc_tools for generate python code
#!/usr/bin/env bash
python -m grpc_tools.protoc -I ./ --python_out=../server/ --grpc_python_out=../server/ ./grpcserver.proto
@vcancy
vcancy / Dockerfile
Created June 8, 2018 01:52 — forked from magno32/Dockerfile
Dockerfile that creates a build environment for Metabase
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 \
@vcancy
vcancy / AlchemyEncoder.py
Created May 8, 2018 11:02
Alchemy object json Encoder
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 = {}
@vcancy
vcancy / alchemy_to_dict.py
Created May 8, 2018 11:01
sqlalchemy object to dict
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')
@vcancy
vcancy / changeBase
Created April 18, 2018 08:08
decimal base to Any(<62) denary notation
def changeBase(n,b):
baseList = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
x,y = divmod(n,b)
if x>0:
return changeBase(x,b) + baseList[y]
else:
return baseList[y]
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