Skip to content

Instantly share code, notes, and snippets.

View huaweigu's full-sized avatar

Huawei huaweigu

  • Circle Internet Financial
  • Boston
  • 22:43 (UTC -05:00)
View GitHub Profile
@huaweigu
huaweigu / repo-rinse.sh
Created May 17, 2023 19:12 — forked from nicktoumpelis/repo-rinse.sh
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
1. table and index hit
with stats as (
with table_stats as (
select psut.relname,
psut.n_live_tup,
1.0 * psut.idx_scan / greatest(1, psut.seq_scan + psut.idx_scan) as index_use_ratio
from pg_stat_user_tables psut
where schemaname = 'txcore'
order by psut.n_live_tup desc
),
@huaweigu
huaweigu / ssl-certs.md
Created July 8, 2018 17:24 — forked from Eng-Fouad/ssl-certs.md
Generate self-signed PKCS#12 SSL certificate and export its keys using Java keytool and openssl.

Steps to generate self-signed PKCS#12 SSL certificate and export its keys:

1- Create PKCS#12 keystore (.p12 or .pfx file)

keytool -genkeypair -keystore myKeystore.p12 -storetype PKCS12 -storepass MY_PASSWORD -alias KEYSTORE_ENTRY -keyalg RSA -keysize 2048 -validity 99999 -dname "CN=My SSL Certificate, OU=My Team, O=My Company, L=My City, ST=My State, C=SA" -ext san=dns:mydomain.com,dns:localhost,ip:127.0.0.1
  • myKeystore.p12 = keystore filename. It can with .pfx extension as well.
  • MY_PASSWORD = password used for the keystore and the private key as well.
  • CN = commonName, it will be shown as certiciate name in certificates list.
  • OU = organizationUnit, department name for example.
@huaweigu
huaweigu / How to Write a Git Commit Message
Last active April 23, 2017 19:36
How to Write a Git Commit Message
Separate subject from body with a blank line
Limit the subject line to 50 characters
Capitalize the subject line
Do not end the subject line with a period
Use the imperative mood in the subject line
Wrap the body at 72 characters
Use the body to explain what and why vs. how
More: https://chris.beams.io/posts/git-commit/
@huaweigu
huaweigu / safe.md
Last active September 14, 2017 12:18 — forked from bryanrite/safe.md
Safe Postgres Operations on High Volume Tables

Safe Operations For High Volume PostgreSQL

Safe

  • Add a new column
  • Drop a column
  • Rename a column
  • Add an index concurrently (Example), Note: it will still take a long time to run the migration, but it won't write-lock the table.
  • Drop a constraint (for example, non-nullable)
  • Add a default value to an existing column
@huaweigu
huaweigu / gist:8298b3df1d80b4e6c2b1
Created December 8, 2015 20:15 — forked from petetronic/gist:c6274f33ffea1c7d1956
PostgreSQL conditional anonymous code block
DO $$
DECLARE updated_rows INT;
BEGIN
UPDATE some_table
SET some_column = 'new'
WHERE some_column = 'old';
GET DIAGNOSTICS updated_rows = ROW_COUNT;