Skip to content

Instantly share code, notes, and snippets.

Felix Yuan yyscamper

Block or report user

Report or block yyscamper

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@yyscamper
yyscamper / quote.py
Last active Jan 7, 2019
SQLAlchemy Postgresql Quote Identifier
View quote.py
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 Jan 7, 2019
wait-for-it.sh with MAC support
View wait-for-it.sh
#!/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 Apr 28, 2018
Postgresql function to create partition table by city_id
View create_city_partition.sql
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 Feb 26, 2018
PostgreSQL: Remove Multiple Keys From JSONB
View jsonb_remove_keys.sql
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 Feb 26, 2018
PostgreSQL: Rename JSONB Keys (Batch Mode)
View jsonb_rename_keys.sql
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 Dec 1, 2017
Script to Download GeoIP Database for Logstash
View geoip.sh
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 Aug 2, 2017
An advance ParseFloat for golang, support scientific notation, comma separated number
View parseFloat.go
package main
import (
"fmt"
"math"
"strconv"
"strings"
)
func ParseFloat(str string) (float64, error) {
@yyscamper
yyscamper / .eslintrc.yml
Last active Mar 29, 2017
ESLint Configuration, based on Airbnb JavaScript Standard, but with some customization
View .eslintrc.yml
env:
es6: true
node: true
parserOptions:
ecmaFeatures:
experimentalObjectRestSpread: true
generators: false
objectLiteralDuplicateProperties: false
ecmaVersion: 6
sourceType: module
@yyscamper
yyscamper / .eslintrc.json
Created Mar 29, 2017
ESLint Airbnb Javascript Standard Configuration (Single File Version)
View .eslintrc.json
{
"rules": {
"strict": [
"error",
"never"
],
"import/no-unresolved": [
"error",
{
"commonjs": true,
@yyscamper
yyscamper / compact-eslint-airbnb.js
Created Mar 29, 2017
Convert ESLint airbnb JavaScript config into single file
View compact-eslint-airbnb.js
'use strict';
var _ = require('lodash');
var airbnb = require('eslint-config-airbnb');
var yaml = require('js-yaml');
function load(filename) {
console.log('load file ' + filename);
return require(filename);
}
You can’t perform that action at this time.