Skip to content

Instantly share code, notes, and snippets.

View Weiyuan-Lane's full-sized avatar
🐈
Code. Code! CODE! CODE!!!!!!

Weiyuan Liu Weiyuan-Lane

🐈
Code. Code! CODE! CODE!!!!!!
View GitHub Profile
function hideCommentsBy(username) {
let hiddenCommentCount = 0;
$('.discussion-notes.diff-discussions').each((_, elem) => {
const $elem = $(elem);
const foundTags = $elem.find(`a[data-username="${username}"]`)
if (foundTags.length > 1) {
throw new Error('More than one tag found per comment. Code might not work due to changes made on Gitlab frontend');
} else if (foundTags.length == 0) {
@Weiyuan-Lane
Weiyuan-Lane / restart_dp.sh
Created June 21, 2021 02:34
Restarting deployments for a given delay
#!/bin/bash
namespace="production"
delay_seconds=30
deployments=(
)
for deployment in "${deployments[@]}"
do
echo "Restarting deployment [$deployment] on namespace [$namespace]"
@Weiyuan-Lane
Weiyuan-Lane / pg_comparisons.md
Last active June 10, 2021 17:58
Comparing PgHero, and Cloud Sql's Query Insights

In the following, we compare the features of PgHero against Cloud SQL with Query Insights. They will be scored up to three ticks each. The comments will justify the decision, but give you the opportunity to reassess on your own terms.

Feature PgHero Cloud SQL + Query Insights Addn. comments
Disk Space monitoring ✅ ✅ ✅ ✅ In PgHero, you can monitor the current disk space of each tables and index. It will also advise the user on unused indexes.

In Query Insights and Cloud SQL, you can't view the breakdown and receive recommendations, but Cloud SQL features a dashboard with a 30 day time record of disk space, which can be a plus for tracking across time.
Connection monitoring ✅ ✅ ✅ ✅ In PgHero, you can monitor the current connections by database and user.

In Cloud SQL, you can monitor the database connections across the last 30 days.
Data Retention ✅ ✅ ✅ Query Insights' data retention is reliant on [Cloud Monitoring](https://cloud.google.com/moni
@Weiyuan-Lane
Weiyuan-Lane / mean_query_check.sql
Created May 16, 2021 13:00
pg_stat_statement mean query
SELECT
pg_stat_statements.query as query,
round(pg_stat_statements.total_exec_time::numeric, 2) AS total_time,
pg_stat_statements.calls,
round(pg_stat_statements.mean_exec_time::numeric, 2) AS mean,
round((100 * pg_stat_statements.total_exec_time /
sum(pg_stat_statements.total_exec_time::numeric) OVER ())::numeric, 2) AS percentage_cpu,
round((100 * pg_stat_statements.calls /
sum(pg_stat_statements.calls::numeric) OVER ())::numeric, 2) AS percentage_calls,
pg_user.usename as username,
#!/bin/sh
apk add stunnel redis openssl gcc
# Remember to replace the host and port
cat > /etc/stunnel/redis-cli.conf <<EOF
fips = no
setuid = root
setgid = root
pid = /var/run/stunnel.pid
#!/bin/sh
rm -rf build 2> /dev/null
bundle exec rake publish BRANCH_NAME=gh-pages
@Weiyuan-Lane
Weiyuan-Lane / existing_file_write_results.txt
Created February 15, 2021 18:48
Both mem and cpu time measurements
Iterate and write per line to existing file, mode "w"
2.009M memsize ( 0.000 retained)
50.007k objects ( 0.000 retained)
50.000 strings ( 0.000 retained)
Iterate and write per line to existing file, mode "a"
2.009M memsize ( 0.000 retained)
50.007k objects ( 0.000 retained)
50.000 strings ( 0.000 retained)
Iterate and write per line to existing file, mode "w+"
2.009M memsize ( 0.000 retained)
@Weiyuan-Lane
Weiyuan-Lane / file_write_results_100_chunks_cpu_time.txt
Created February 15, 2021 18:45
Comparison of file writing strategies
user system total real
Write all lines to file at once, mode "w" 0.349308 0.955585 1.304893 ( 1.321532)
Write all lines to file at once, mode "a" 0.215273 0.786001 1.001274 ( 1.008887)
Write all lines to file at once, mode "w+" 0.206097 0.729586 0.935683 ( 0.943146)
Write all lines to file at once, mode "a+" 0.219936 0.732151 0.952087 ( 0.960331)
Iterate and write per line to file, mode "w" 0.014412 0.014297 0.028709 ( 0.047540)
Iterate and write per line to file, mode "a" 0.015421 0.000931 0.016352 ( 0.035943)
Iterate and write per line to file, mode "w+" 0.014933 0.001423 0.016356 ( 0.038612)
Iterate and write per line to file, mode "a+" 0.016904 0.000542 0.017446 ( 0.040842)
Iterate and write per line to file (manual),
@Weiyuan-Lane
Weiyuan-Lane / file_write_results_10_chunks_cpu_time.txt
Last active February 15, 2021 18:44
Comparison of file writing strategies
user system total real
Write all lines to file at once, mode "w" 0.270430 0.901323 1.171753 ( 1.193794)
Write all lines to file at once, mode "a" 0.214400 0.794183 1.008583 ( 1.023748)
Write all lines to file at once, mode "w+" 0.222848 0.774039 0.996887 ( 1.004640)
Write all lines to file at once, mode "a+" 0.270665 0.777068 1.047733 ( 1.074217)
Iterate and write per line to file, mode "w" 0.017369 0.021650 0.039019 ( 0.060581)
Iterate and write per line to file, mode "a" 0.016263 0.000707 0.016970 ( 0.036163)
Iterate and write per line to file, mode "w+" 0.015498 0.001238 0.016736 ( 0.037824)
Iterate and write per line to file, mode "a+" 0.014625 0.001813 0.016438 ( 0.036621)
Iterate and write per line to file (manual),
@Weiyuan-Lane
Weiyuan-Lane / file_write_results_100_chunks_mem.txt
Created February 15, 2021 18:41
Comparison of file writing strategies
Write all lines to file at once, mode "w"
1.651B memsize ( 0.000 retained)
75.008k objects ( 0.000 retained)
50.000 strings ( 0.000 retained)
Write all lines to file at once, mode "a"
1.651B memsize ( 40.000 retained)
75.008k objects ( 1.000 retained)
50.000 strings ( 0.000 retained)
Write all lines to file at once, mode "w+"
1.651B memsize ( 40.000 retained)