Skip to content

Instantly share code, notes, and snippets.

View lemonlatte's full-sized avatar

Jim Yeh lemonlatte

View GitHub Profile
@lemonlatte
lemonlatte / pydantic_errors_zh.py
Created May 9, 2024 01:23
pydantic error 翻譯
# import inspect
# from pydantic import errors
# gpt_translate(
# {
# k: v.msg_template
# for k, v in dict(inspect.getmembers(errors, inspect.isclass)).items()
# if issubclass(v, errors.PydanticValueError) and hasattr(v, "msg_template")
# }
# )
PYDANTIC_ERROR_MSG_TEMPLATE_ZH: dict[str, str] = {
@lemonlatte
lemonlatte / streaming-csv-generator.py
Created March 27, 2024 12:11
streaming-csv-generator
def streaming_csv_data(supplier_id: str):
buffer = io.StringIO()
with CSVWriter(buffer) as writer:
for row in _iter_data():
writer.writerow(row)
buffer.seek(0)
yield buffer.read()
buffer.seek(0)
buffer.truncate(0)
@lemonlatte
lemonlatte / setup.sh
Created February 24, 2024 05:29
Install tensorflow over mac m1
brew install miniconda
conda init (basename "$SHELL")
conda create -n tensorflow-env-39 python=3.9
conda install -c apple tensorflow-deps
conda install scikit-learn pandas jupyter
pip install tensorflow-macos
@lemonlatte
lemonlatte / openssl.sh
Last active January 16, 2024 05:59
Make HTTPS requests by openssl
openssl s_client -connect example.com:443 -ign_eof
POST /your-endpoint HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: <LengthOfYourJSONData>
{"key1":"value1", "key2":"value2"}
@lemonlatte
lemonlatte / Caddyfile
Created December 11, 2023 01:13
Simple Caddyfile
https://localhost:8888 {
tls /usr/local/etc/ssl/localhost.pem /usr/local/etc/ssl/localhost-key.pem
handle_path /api* {
rewrite /api/ /
reverse_proxy localhost:8000
}
reverse_proxy /* localhost:8080
}
@lemonlatte
lemonlatte / iftop.sh
Last active September 13, 2023 04:27
Amazon Linux install iftop
amazon-linux-extras install epel -y
yum-config-manager --enable epel
yum install iftop
@lemonlatte
lemonlatte / ingress.yaml
Created April 6, 2021 09:31
ingress nginx www redirect
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
if ($host = "www.example.com") {
return 308 https://example.com$request_uri;
}
name: example-www
@lemonlatte
lemonlatte / run.sh
Created December 18, 2020 09:04 — forked from detunized/run.sh
Mount a read-only folder inside a Docker container with OverlayFS on top
# On the host to run the container
docker run --privileged -i -t -v ~/host-folder-to-mount:/root/folder-ro:ro ubuntu
# Inside the container
# Need to create the upper and work dirs inside a tmpfs.
# Otherwise OverlayFS complains about AUFS folders.
mkdir -p /tmp/overlay && \
mount -t tmpfs tmpfs /tmp/overlay && \
mkdir -p /tmp/overlay/{upper,work} && \
mkdir -p /root/folder && \
@lemonlatte
lemonlatte / odd.py
Created September 19, 2020 14:56
check odd number
#!/usr/bin/python
def main():
n = input("input a number:")
n = int(n)
if n % 2 == 0:
print(True)
else:
print(False)
{
"@context": "https://w3id.org/security/v2",
"id": "https://bitmark.com/cap/bitmarkd",
"parentCapability": "https://gist.githubusercontent.com/lemonlatte/105581b2d8e1be1a1f3b000a9cfbe2b1/raw/5119e7df6e3b33e5a873bb143dacccc31a7761ac/my-repo.jsonld",
"invoker": "https://social.example#alyssa"
}