Skip to content

Instantly share code, notes, and snippets.

View huaxlin's full-sized avatar
🎯
Focusing

huaxlin huaxlin

🎯
Focusing
View GitHub Profile
#!/usr/bin/env bash
set -e
help()
{
echo "Usage: $0 [[-c | --container]"
echo " --]"
echo ""
echo "Script Options:"
@huaxlin
huaxlin / jsonable_encoder_pandas_dataframe.py
Last active August 11, 2022 03:22
encode pandas.DataFrame object to jsonable dict object
import json
from typing import Optional
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pandas import DataFrame
class JsonableEncoderError(Exception):
pass
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 , ✅ , ✅ , ✅ , ✅
@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
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)
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]
@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!

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 / 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');
...
<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():