Skip to content

Instantly share code, notes, and snippets.

@spff
spff / README.md
Last active November 5, 2021 07:16 — forked from int128/README.md
Example of Envoy TCP Proxy With SSL Termination
@spff
spff / clickhouse-get-tables-size.sql
Last active November 26, 2024 02:17 — forked from sanchezzzhak/clickhouse-get-tables-size.sql
clickhouse get tables size
SELECT
database,
table,
formatReadableSize(sum(bytes)) as size
FROM system.parts
WHERE active
GROUP BY database, table
ORDER BY sum(bytes)
@spff
spff / svg2pdf.md
Last active September 5, 2021 03:20

兩種套路

  • svg->raster(jpg, png, bmp...) 塞進 pdf
    • 產生的 pdf 的文字無法被選取
    • (linux) rsvg-convert -f pdf in.svg > out.pdf 沒試過
    • js
      •   const canvas = document.createElement('canvas')
          canvas.width  = 800
          canvas.height = 800
          document.body.appendChild(canvas)

AWS

lambda(w/wo container)

  • For short running jobs
  • 如果十分鐘執行一次每次半分鐘,最小的每個月十塊錢台幣
  • stateful 的作法是自己實作 global lock (eg via dynamodb) 或把平行度設為 1
  • 需要 filesystem 可以掛 efs (須注意 efs is nfsv3 存取檔案曾要實作 advisory lock,或是 app 層 guarantee lock 如同上述 stateful 的作法)
  • 需要 DB 可用 sqlite on efs (一樣要注意上述的 lock)
  • 可以當作 cron job (eventbridge)
  • 可以搭配 API Gateway 來 serve http, 要避免 cold start 可用 eventbridge 設定定時戳諸如 healthcheck 這種馬上 return 的 endpoint to avoid introducing additional cost.
@spff
spff / components.js
Created August 9, 2020 09:48 — forked from steveclarke/components.js
Globally register your custom components in Quasar. Add this file to your /boot dir
// Globally register all base components for convenience, because they
// will be used very frequently. Components are registered using the
// PascalCased version of their file name.
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'
export default async ({ Vue }) => {
console.log('loading components')
// https://webpack.js.org/guides/dependency-management/#require-context
@spff
spff / pd.txt
Created March 4, 2020 19:25
常用 pd 統計
$ grep pd\\.[^\(]*\( app -roh | sort -u
pd.concat(
pd.DataFrame(
pd.DataFrame.from_dict(
pd.ExcelWriter(
pd.merge(
pd.pivot_table(
pd.read_csv(
pd.read_sql_query(
pd.Series).stack(
@spff
spff / sql.md
Last active December 5, 2019 01:29
XD

邪惡博士在進行人體實驗,他把收集到的病人分類,你可以想像成用性別或血型來分,也就是每個病人只會落在某一個 group。
然後被咬過的人會丟進小房間所以一個人只會被咬過一次。
Given two tables, 1. bite,2. mutate,一張記錄被咬的事件,另一張記錄病人突變的事件。同一個病人被咬到之後可能突變任意次,但一天最多突變一次。

下面是半年前他徒弟為了協助研究而寫的 SQL ,他想調查的內容如下:

某一個時段區間內 begin_timestamp ~ end_timestamp (bts ~ ets),可能跨了很多天,每天被咬的病人在三天內突變的情況。
我們不在乎具體哪一天被咬,只在乎這段時間所有被咬的事件,在三天內(日曆天)突變的情況。
所以最終的輸出會是 每一組(patient_group_id) 在幾天後(day_diff) 的 被咬數量(分母) 以及 突變數量(分子)

@spff
spff / programming_for_normal_gup_lesson_1_main.py
Last active November 10, 2019 16:35
Programming for normal guy(Lesson1)
# this is a comment line
print('Hello World')
print("Hello World")
print('''
Hello
World
:D
''')
print(1)
@spff
spff / gist:3846be7268d5ee6bb72014a1fb835cb9
Last active August 11, 2019 04:23 — forked from singhabhinav/gist:132b8196abac026b43fa
Install SSL certificate in Nginx (Using .crt & .ca-bundle certificate files)
Step 0 - Get three files from sslforfree
Step 1 - Create .crt file
echo -e "`cat domainname.crt`\n`cat domainname.ca-bundle.crt`" > domainname-ssl-bundle.crt
Step 2-
Add lines for ssl_certificate in nginx configuration
@spff
spff / git checkout-all-branches.sh
Created November 29, 2017 05:39
git checkout-all-branches
#!/bin/bash
#Whenever you clone a repo, you do not clone all of its branches by default.
#If you wish to do so, use the following script:
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done