Skip to content

Instantly share code, notes, and snippets.

View tian-im's full-sized avatar
🌅
WFH

Tianwen (Tian) Chen tian-im

🌅
WFH
View GitHub Profile
@tian-im
tian-im / non-ascii_detector.rb
Created September 18, 2017 06:20
Detect non-ASCII charaters
"‐a".each_codepoint do |c|
if c & 0xff80 != 0
puts "#{c} is non-ASCII char"
end
end
@tian-im
tian-im / install.sh
Created October 23, 2017 04:16
Install chrome in ubuntu
#!/bin/sh
set -e
if [ -e /.installed ]; then
echo 'Already installed.'
else
echo ''
echo 'INSTALLING'
echo '----------'
@tian-im
tian-im / reset.md
Last active October 24, 2018 01:27
Reset Mysql root password in Ubuntu
# 1. stop mysqld service
# after this command, remember to double check if /var/run/mysqld folder exists and its owner is mysql:mysql
sudo /etc/init.d/mysql stop

# might have to do this
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

# 2. start mysql without password
@tian-im
tian-im / reset.md
Created November 28, 2019 02:11
Correct Postgres Encoding
pg_createcluster --start -e UTF-8 8.4 main
@tian-im
tian-im / vagrant_export_reload.sh
Created December 3, 2019 13:26
Vagrant reload export
sudo rm /etc/exports
sudo touch /etc/exports
vagrant reload
@tian-im
tian-im / readme.md
Created March 5, 2020 05:21
How to start using git version control

cd to target directory, run the following commands to start using git version control:

# start a local repository
git init

# add all files under directory to git repository
git add .

# commit the current version
@tian-im
tian-im / utf8.sql
Last active April 2, 2020 14:28
UTF8 template1 for Postgres db create
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
-- if it complains the locale name -- run `locale -a` to list all locale names in terminal
create database template1 with owner=postgres encoding='UTF-8' lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate=true where datname='template1';
@tian-im
tian-im / queries.md
Last active January 29, 2025 03:20
Query table size and count in Postgres
  • Query table size:

    SELECT 
        relname AS table_name,
        pg_size_pretty(pg_total_relation_size(relid)) AS total_size,
        pg_size_pretty(pg_relation_size(relid)) AS data_size,
        pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) AS index_size
    FROM 
        pg_stat_user_tables