Skip to content

Instantly share code, notes, and snippets.

View whchi's full-sized avatar
:octocat:

whchi whchi

:octocat:
View GitHub Profile
@whchi
whchi / usage.js
Created September 22, 2024 16:08
Using Debounce in a React Hook with TypeScript
import { useDebounce } from 'useDebounce';
const debouncedEmail = useDebounce(email, 500);
@whchi
whchi / docker-compose.yml
Created September 22, 2024 16:05
vault local docker compose
services:
vault:
image: vault:1.17.5
container_name: vault
restart: on-failure:10
ports:
- '8200:8200'
environment:
VAULT_ADDR: 'http://0.0.0.0:8200'
VAULT_LOCAL_CONFIG: |
@whchi
whchi / upgrade_pkgs.sh
Created March 4, 2024 11:37
upgrade all poetry packages to latest
#!/bin/sh
UPDATE_TYPE=${1:-all}
DEV_LIBS=$(poetry show --only=dev -o -T |awk '{print $1}')
MAIN_LIBS=$(poetry show --only=main -o -T |awk '{print $1}')
if [ "$UPDATE_TYPE" = "main" ]; then
LIBS=$(poetry show --only=main -o -T |awk '{print $1}')
elif [ "$UPDATE_TYPE" = "dev" ]; then
@whchi
whchi / reset.css
Created January 15, 2024 05:18
reset.css in 2024
* {
box-sizing: border-box;
position: relative;
min-width: 0;
}
body {
min-height: 100dvh;
}
@whchi
whchi / mutex_locker.py
Created December 25, 2023 14:15
mutex locker using redis in python
import redis
import time
import uuid
class RedisMutex:
def __init__(self, key, host='localhost', port=6379, db=0):
self.key = key
self.redis = redis.Redis(host=host, port=port, db=db)
self.lock_id = uuid.uuid4().hex
@whchi
whchi / example.py
Created September 5, 2023 02:54
mock httpx in pytest
@patch('httpx.put')
def test_update_application_basic_info(mock_put):
mock_response = mock.Mock()
mock_response.status_code = 200
mock_response.json.return_value = {'data': {'ec_add_on_id': 123}}
mock_put.return_value = mock_response
...
@whchi
whchi / gist:bb9f0249c407cd21c924dad131ac31a2
Created August 6, 2023 14:15
nginx subdomain to next.js by pages with i18n
upstream nextjs {
server localhost:3000;
}
server {
listen 8080;
server_name SUBDOMAIN1_HOST;
server_tokens off;
@whchi
whchi / link_storage.py
Created June 15, 2023 04:06
python link storage like laravel example
@whchi
whchi / simple_data_with_counter_factory.py
Last active June 8, 2023 03:21
sinple counter for data factory
class DataFactory:
counter = count(start=1)
def model(self):
return ApplicationCarousel
def definition(self):
faker = Faker()
faker.add_provider(internet)
return {
@whchi
whchi / find_object_kw.js
Created May 18, 2023 09:47
find object members contain specific string with depth
function searchObject(object, searchTerm, maxDepth, currentPath = [], currentDepth = 0) {
if (currentDepth > maxDepth) {
return;
}
for (let key in object) {
try {
if (key.toLowerCase().includes(searchTerm.toLowerCase())) {
console.log(`Path: ${currentPath.join('.')}.${key}`);
}