Skip to content

Instantly share code, notes, and snippets.

View huaxlin's full-sized avatar
🎯
Focusing

huaxlin huaxlin

🎯
Focusing
View GitHub Profile
"""
$ python sqlalchemy-high-concurrency-issue.py
...
$ echo "select * from steal;" | mysql -uscott -ptiger test
user_id money
89b65422-36ed-48db-ba25-68c3b27eedcc 2
$
$ python -O sqlalchemy-high-concurrency-issue.py
...
"""
@huaxlin
huaxlin / mock-app-running.md
Last active June 15, 2023 03:42
Use `unittest.mock` to mock object when app running.

code structure:

$ tree .
.
├── mock_app_running.py
└── chatbot
   └── webhook.py
<html>
<head>
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<div id="output"></div>
<py-script>
import asyncio
async def main():
@huaxlin
huaxlin / myScreenshot.js
Last active May 24, 2023 01:41
puppeteer use headless browser to capture screenshot
/*
Usage:
```
$ mkdir myscreenshot
$ cd myscreenshot
$ npm i puppeteer --save
$
$ vim myScreenshot.js
const puppeteer = require('puppeteer');
...

You can then restrict a test run to only run tests marked with webtest:

$ pytest -v -m webtest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-7.x.y, pluggy-1.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: /home/sweet/project
collecting ... collected 4 items / 3 deselected / 1 selected
@huaxlin
huaxlin / Basic Testing of Testing Click Applications.md
Last active February 20, 2023 07:12
Basic Testing of Testing Click Applications

Basic Click Application

$ pip install click
$ python click_hello.py Jeff
Hello Jeff!
$ python click_hello.py Alice
Hello Alice!
def mergesort(seq):
mid = len(seq) // 2
lft, rgt = seq[:mid], seq[mid:]
if len(lft) > 1: lft = mergesort(lft)
if len(rgt) > 1: rgt = mergesort(rgt)
res = []
while lft and rgt:
if lft[-1] >= rgt[-1]: res.append(lft.pop())
else: res.append(rgt.pop())
return (lft or rgt) + res[::-1]
def is_balance(s) -> bool:
open, close = '<{[(', ')]}>'
brackets = dict(zip(open, close[::-1]))
# print( brackets )
stack = []
for c in s:
if c in brackets: # open; O(1)
stack.append(c) # .push
elif c in brackets.values(): # close; O(4)
@huaxlin
huaxlin / config.py
Last active December 15, 2022 07:56
from pathlib import Path
from typing import Any, Dict, Optional, Union
from hydra import compose, initialize_config_dir
from omegaconf import DictConfig
from pydantic import BaseModel, BaseSettings
from pydantic.env_settings import SettingsSourceCallable
# {python project}/app/config.py
project_dir = Path(__file__).parent.parent
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 6 columns, instead of 5 in line 6.
Requirement\Solution, conf.py , config.ini , config/ directory , proj-ops/ repository , Config Server
change config , ✅ , ✅ , ✅ , ✅ , ✅
Simple(in minutes) , ✅ , ✅ , ✅ , ❌(required opration technology), ❌(not a problem if has a great library)
Coupling , ❌ , ✅ , ✅ config/prd.ini ❌ config/prd.py, -- , ✅
mulitple environment, ❌ , ❌ , ✅ , ✅ , ✅
security , ❌ , ❌ , ❌ , ✅ , ✅
maintenance cost , ✅ , ✅ , ✅ , ✅