Skip to content

Instantly share code, notes, and snippets.

View weihanglo's full-sized avatar

Weihang Lo weihanglo

View GitHub Profile

I/O Redirection 常用指令紀錄

greptrsedawk 是幾個很常見的標準串流 [Standard Streams][1] 處理工具,靠著regex的加持,這些工具使用在 I/O redirection 比起寫個python script快多了,唯一的壞處就是options太多,容易遺忘。本文主要紀錄上述工具使用筆記與心得。

(撰於 2016 年年初,致青春)

sed

sedStream EDitor 的縮寫,最常用來處理pipeline。特色是一次只讀取一行input到buffer處理,導向至「標準輸出(STDOUT)」後,再處理下一行。

@weihanglo
weihanglo / 0-promise.md
Last active October 17, 2017 06:36
Modern Concurrency in JavaScript - Promises

Modern Concurrency in JavaScript - Promises

所謂良好的使用者體驗,有個基本要求:「能即時回饋使用者的互動」。在 Mobile Native,常利用多線程(Multi-threading)分散主線程(main thread)的負擔,讓其能即時響應使用者點擊等事件。反觀 web 端的霸主 JavaScript,卻是易被阻塞的單線程(single-threaded)語言,不過藉由 Event Loop 的設計,仍可達成非同步操作,線程不至完全阻塞,或多或少彌補了單線程的不足。

眾所周知,[Concurrency is hard!][concurrency-joke]設計不良的非同步程式,絕對會讓你痛不欲生。本文將簡單介紹 Promise 這個現代 JavaScript Concurrency Features,讓 JS 新標準帶你從地獄回到另一個煉獄人間。

(撰於 2017-06-12,基於 ECMAScript 6+)

@weihanglo
weihanglo / DispatchDemo.swift
Last active December 26, 2017 04:24
Grand Central Dispatch (GCD, Dispatch in Swift 3) DispatchGroup and DispatchSemaphore Demo
// import Dispatch
import Foundation
let semaphore = DispatchSemaphore(value: 0)
let group = DispatchGroup()
let globalQueue = DispatchQueue.global(qos: .default)
print("Tasks started!!!")
print()
@weihanglo
weihanglo / async-functions.md
Last active July 27, 2018 10:00
Modern Concurrency in JavaScript - Async Functions

Modern Concurrency in JavaScript - Async Functions

在前一篇介紹 [JavaScript Concurrency 的文章][weihanglo-promise]中,Promise 提供開發者安全統一的標準 API,透過 thenable 減少 callback hell,巨幅降低開發非同步程式的門檻,大大提升可維護性。不過,Promise 仍沒達到 JS 社群的目標「Write async code synchronously」。本篇文章將簡單最新的 Concurrency Solution「Async Functions」,利用同步的語法寫非同步的程式,整個人都變潮了呢!

(撰於 2017-06-17,基於 ECMAScript 7+)

Introduction

Keybase proof

I hereby claim:

  • I am weihanglo on github.
  • I am weihanglo (https://keybase.io/weihanglo) on keybase.
  • I have a public key whose fingerprint is 7D84 EA07 47C1 240C 2A16 D2A6 D7DB F189 825E 82E7

To claim this, I am signing this object:

@weihanglo
weihanglo / swift-generics.md
Last active October 24, 2018 04:19
Generics in Swift

Generics in Swift

泛型程式設計(Generic Programming) 是經典的程式設計典範之一,不論是老牌的 C++,還是潮潮的 TypeScript,都能一睹泛型的風采。近年來,程式設計吹的是 static typing 風,泛型又開始被廣泛討論。

本篇將簡單介紹泛型的背景,再來理解並學習 Swift 語言的泛型寫法。

(撰於 2017-05-08,基於 Swift 3.1)

@weihanglo
weihanglo / days-with-internet-explorer-2.md
Last active February 3, 2020 06:20
與 IE 相處的日子二:淺談網頁相容性

與 IE 相處的日子二:淺談網頁相容性

還記得之前整理的 [IE 相容性][days-with-internet-explorer] 一文嗎?筆者最近參與公司新版 Web App 架構規劃與開發,又遇到許多相容性的問題,連新版瀏覽器也無法倖免。就讓我們再次探討瀏覽器相容性吧!

(撰於 2017-12-09,基於各種莫名其妙的狀況)

@weihanglo
weihanglo / k8s-autoscaling.md
Last active March 31, 2020 14:53
Kuberenetes Autoscaling 相關知識小整理

Kuberenetes Autoscaling 相關知識小整理

K8s 有好用的 autoscaling 功能,但你知道除了 pod 之外,node 也可以 auto scaling 嗎?帥,你知道就不用分享了啊 🚬

本文以重點整理的方式,先介紹目前常見的 Autoscaler,再介紹一些防止 pod 被亂殺的 config。

(撰於 2020-03-23,基於 Kubernetes 1.17,但 Api Versions 太多請自行查閱手冊)

@weihanglo
weihanglo / xor_shift64.rs
Last active August 26, 2020 07:34
Single pseudo-random generator in Rust
pub struct XorShift64 {
a: u64,
}
impl XorShift64 {
pub fn next(&mut self) -> u64 {
let mut x = self.a;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
@weihanglo
weihanglo / openssl-cheatsheet.sh
Last active December 5, 2020 02:01
OpenSSL CheatSheet
# Create X509 self-signed certificate.
openssl req \
-newkey rsa:2048 -nodes -keyout cert.key \
-x509 -days 365 -out cert.pem
# Convert from PEM format to DER.
openssl pkcs12 \
-inkey cert.key -in cert.pem \
-export -out cert.pfx