Skip to content

Instantly share code, notes, and snippets.

@yyscamper
yyscamper / antchain_baas_deposit_demo.py
Last active March 23, 2023 06:45
蚂蚁区块链BaaS登录、存证、取证示例代码
#!/usr/bin/env python
import base64
import codecs
import json
import logging
import os
import sys
import uuid
from datetime import datetime
@yyscamper
yyscamper / quote.py
Last active December 12, 2019 10:35
SQLAlchemy Postgresql Quote Identifier
from sqlalchemy import create_engine
engine = create_engine('postgresql://user:passwd@127.0.0.1:5432/dbname')
engine.dialect.identifier_preparer.quote('table')
engine.dialect.identifier_preparer.quote_identifier('table')
@yyscamper
yyscamper / wait-for-it.sh
Created January 7, 2019 09:22
wait-for-it.sh with MAC support
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
# This is script is download from
# https://github.com/vishnubob/wait-for-it/blob/9995b721327eac7a88f0dce314ea074d5169634f/wait-for-it.sh
# Modify by on 2019-1-7, with support for MACOS
# solution is found from:
# - https://github.com/vishnubob/wait-for-it/issues/13
# - https://stackoverflow.com/questions/3504945/timeout-command-on-mac-os-x
@yyscamper
yyscamper / create_city_partition.sql
Created April 28, 2018 09:58
Postgresql function to create partition table by city_id
CREATE OR REPLACE FUNCTION create_city_partition(schema_name text, parent_table_name text, city_id int)
RETURNS text AS
$func$
DECLARE
partition_table_name text;
BEGIN
partition_table_name := parent_table_name || '_' || city_id::text;
EXECUTE format('
CREATE TABLE %I.%I PARTITION OF %I FOR VALUES IN (%L)
', schema_name, partition_table_name, parent_table_name, city_id);
@yyscamper
yyscamper / jsonb_remove_keys.sql
Created February 26, 2018 09:49
PostgreSQL: Remove Multiple Keys From JSONB
CREATE OR REPLACE FUNCTION jsonb_remove_keys(
jdata JSONB,
keys TEXT[]
)
RETURNS JSONB AS $$
DECLARE
result JSONB;
len INT;
target TEXT;
@yyscamper
yyscamper / jsonb_rename_keys.sql
Created February 26, 2018 09:07
PostgreSQL: Rename JSONB Keys (Batch Mode)
CREATE OR REPLACE FUNCTION jsonb_rename_keys(
jdata JSONB,
keys TEXT[]
)
RETURNS JSONB AS $$
DECLARE
result JSONB;
len INT;
newkey TEXT;
oldkey TEXT;
@yyscamper
yyscamper / geoip.sh
Created December 1, 2017 08:39
Script to Download GeoIP Database for Logstash
TARGET=/root/geoip
wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz -O $TARGET/tmp.tar.gz
tar -xvzf GeoLite2-City.tar.gz -C $TARGET --strip-components 1
rm $TARGET/tmp.tar.gz
@yyscamper
yyscamper / parseFloat.go
Created August 2, 2017 06:59
An advance ParseFloat for golang, support scientific notation, comma separated number
package main
import (
"fmt"
"math"
"strconv"
"strings"
)
func ParseFloat(str string) (float64, error) {
@yyscamper
yyscamper / .eslintrc.yml
Last active March 29, 2017 06:46
ESLint Configuration, based on Airbnb JavaScript Standard, but with some customization
env:
es6: true
node: true
parserOptions:
ecmaFeatures:
experimentalObjectRestSpread: true
generators: false
objectLiteralDuplicateProperties: false
ecmaVersion: 6
sourceType: module
@yyscamper
yyscamper / .eslintrc.json
Created March 29, 2017 06:41
ESLint Airbnb Javascript Standard Configuration (Single File Version)
{
"rules": {
"strict": [
"error",
"never"
],
"import/no-unresolved": [
"error",
{
"commonjs": true,