Skip to content

Instantly share code, notes, and snippets.

View tk42's full-sized avatar
💭
changed from @jimako1989

tk42 tk42

💭
changed from @jimako1989
View GitHub Profile
@tk42
tk42 / flowchart.md
Created May 17, 2022 21:51
Backend flowchart
flowchart TD
    B{Documented entity?}
    B -- Yes --> C[NoSQL]
    C --> D{CRUD?}
    B -- No --> E[RDBMS]
    E --> F{CRUD?}
    D -- Yes --> K[FastAPI + Firestore]
    D -- No ----> H[gRPC + Firestore]
 F -- Yes --> I{Use Python libalies?}
@tk42
tk42 / auth.ts
Created May 9, 2022 06:03
Next.js API Routes snippet for connecting to REST API
import { API_URL, ENDPOINT_TOKEN } from '../../components/const';
import type { NextApiRequest, NextApiResponse } from "next";
type Todo = {
userId: number;
id: number;
title: string;
completed: boolean;
};
@tk42
tk42 / engine.py
Created May 7, 2022 06:50
Connection to MySQL in PlanetScale with SQLAlchemy
#!/usr/bin/env python3
import os
from sqlalchemy import create_engine
## assertion
for key in ['USERNAME', 'PASSWORD', 'HOST', 'DATABASE']:
assert os.getenv(key), f'{key} is empty'
@tk42
tk42 / cleanarchitecture.md
Last active September 22, 2022 13:26
CleanArchitecture Memo
@tk42
tk42 / App.tsx
Created February 4, 2022 13:33
createAppContainer
import React from 'react';
import AppContainer from './appcontainer';
export default function App() {
return (
<AppContainer />
)
}
@tk42
tk42 / 1.dhall
Created September 17, 2021 05:02
higher-order-function
λ(n : Natural) -> [ n, n + 1 ]
@tk42
tk42 / mytype.dhall
Created September 16, 2021 11:48
parameter template in dhall
{
Type = {
key : Text,
},
default = {
key = "default",
}
}
@tk42
tk42 / redis_conn.py
Last active June 24, 2021 03:01
async connection pool class to Redis
import logging
import aioredis
class RedisConn:
_pool = {}
# Singleton
def __new__(cls, *args, **kwargs):
if not hasattr(cls, "_instance"):
@tk42
tk42 / dotted_dict.py
Created February 19, 2021 19:50
dotaccess dictionary
class dict2(dict):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__dict__ = self
@tk42
tk42 / mymap.py
Last active February 19, 2021 20:46
shared memory example with multiprocessing.manager
from multiprocessing import Process, Manager
class MyMap():
def __new__(cls):
self = Manager().dict()
return self
def f(d):
d[1] += '1'
d['2'] += 2