Skip to content

Instantly share code, notes, and snippets.

View shon's full-sized avatar

Shekhar shon

View GitHub Profile
@shon
shon / data.json
Created January 15, 2020 06:55
For TiptapY testing
{
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Here is an example of simple formatted text"
}
@shon
shon / TiptapY.py
Created January 15, 2020 04:27
TiptapY - Simpler Approach
import json
def convert_any(node):
typ = node.get('type', '')
print('node type: ', typ)
if typ == 'doc':
out = convert_doc(node)
elif typ == 'paragraph':
out = convert_paragraph(node)
@shon
shon / TiptapY-oo.py
Last active January 16, 2020 12:09
TiptapY (Object Oriented) Approach
import json
from dataclasses import dataclass, field
from typing import List
from inspect import isclass
renderers = {}
@shon
shon / noorm.py
Created November 25, 2019 11:14
NoORM | SQL Construction library
from dataclasses import dataclass
@dataclass
class Query:
db: object = None
def sql(self):
raise NotImplementedError
@shon
shon / pg_db_tenants_benchmark.py
Created November 18, 2019 09:07
Benchmarking Multi tenant | Shared Table vs Postgres Schema
import datetime
import os
import string
from random import randrange
from peewee import Model, PostgresqlDatabase
from peewee import BooleanField, TextField, CharField
from playhouse.postgres_ext import ArrayField, BinaryJSONField
NO_OF_DBS = 500
@shon
shon / pg_db_tenants.py
Last active September 20, 2019 13:48
[Postgresql multi tenant] Multiple Databases vs Single Database | Performance Comparison
import datetime
import os
import string
from random import randrange
from peewee import Model, DatabaseProxy, PostgresqlDatabase
from peewee import ForeignKeyField, BooleanField, TextField, IntegerField, CharField
NO_OF_DBS = 800
NO_OF_POSTS = 50
@shon
shon / monty_hall.py
Created August 30, 2019 17:27
Monty Hall Problem Verification
import random
from dataclasses import dataclass
NO_OF_DOORS = 3
@dataclass
class Door:
@shon
shon / schematest.py
Last active April 9, 2019 11:50
Hug Bug
# - hug version: 2.4.7
# - marshmallow: 3.0.0rc4
# - Python: 3.6.7 on Ubuntu 18.10
import hug
from marshmallow import Schema, fields
class ItemSchema(Schema):
name = fields.Str()
id = fields.Int()
@shon
shon / fa.py
Created April 3, 2019 19:02
FastAPI Python function -> API (sort of)
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
name: str
class CreateSignature(BaseModel):
id: int
import json
import pickle
import msgpack
TEST_REDIS = False
if TEST_REDIS:
import redis
rconn = redis.StrictRedis()
dataset = [(('key:%d' % i), {'a': 1, 'b': list(range(100)), 'c': ('z' * 25)}) for i in range(1000000)]