Skip to content

Instantly share code, notes, and snippets.

View yuhangch's full-sized avatar
🚶
exhausted

陈昱行|Chen Yu-hang yuhangch

🚶
exhausted
View GitHub Profile
@yuhangch
yuhangch / generate_uid.sql
Created November 27, 2021 08:31
postgresql short id function
-- https://stackoverflow.com/a/41988979/10936088
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE OR REPLACE FUNCTION generate_uid(size INT) RETURNS TEXT AS $$
DECLARE
characters TEXT := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
bytes BYTEA := gen_random_bytes(size);
l INT := length(characters);
i INT := 0;
output TEXT := '';
BEGIN
@yuhangch
yuhangch / GeoJSONSchemes.cs
Last active January 18, 2024 18:00
GeoJSON Schemes description for OpenAPI/Swagger in ASP.NET
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace hello.Common;
@yuhangch
yuhangch / deleta_all.sql
Created November 22, 2021 05:27
Postgresql delete all table in a scheme exclude 'spatial_ref_sys'
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE (schemaname = current_schema() and tablename != 'spatial_ref_sys')) LOOP
EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END $$;
@yuhangch
yuhangch / stop-process.cs
Created September 15, 2021 01:01
Sending Ctrl-C signal to another application on Windows
// https://blog.codetitans.pl/post/sending-ctrl-c-signal-to-another-application-on-windows/
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AttachConsole(uint dwProcessId);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool FreeConsole();
[DllImport("kernel32.dll")]
static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate handler, bool add);
@yuhangch
yuhangch / capslock-ime
Last active October 9, 2021 02:12
Auto switch IME for different app && CapsLock > IME switch
SetStoreCapsLockMode False
CapsLock::
{
KeyWait "CapsLock"
time := A_TimeSinceThisHotkey
if (time > 300) {
SetTimer SendCaps, -4
}
else {
@yuhangch
yuhangch / blog
Created December 24, 2020 10:47
hugox V2
#! /bin/bash
blog_path=~/path/to/blog
cd $blog_path
hugo new --editor typora posts/$1.md
@yuhangch
yuhangch / tiny-png.py
Last active December 24, 2020 07:41
Tiny PNG & tinify demo
import os
import tinify
tinify.key = "your key"
root = "./images"
dst_path = "./images-compress"
for origin, _, files in os.walk(root, topdown=False):
for name in files:
@yuhangch
yuhangch / x.py
Last active December 3, 2020 10:49
Python Zipfile 中文文件名乱码
from zipfile import ZipFile
from pathlib import Path
target_directory = "."
with ZipFile(src, 'r') as f:
for file_name in f.namelist():
file_name = f.extract(file_name, path=target_directory)
try:
@yuhangch
yuhangch / minio-boto3-rasterio-memoryfile.py
Created August 14, 2020 02:55
Boto3 use in Minio with Rasterio memoryFIle
import boto3
from botocore.client import Config
from rasterio.io import MemoryFile
session = boto3.session.Session()
client = session.client(
service_name="s3",
endpoint_url="http://localhost:9000",
aws_access_key_id='KEY',
aws_secret_access_key="SECRET"
@yuhangch
yuhangch / do.md
Created August 13, 2020 08:06
rio-color windows

LIB

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\VC\lib; C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\SDK\lib;

PATH

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\SDK\include\ucrt; C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\VC\bin; C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\SDK\bin;