Skip to content

Instantly share code, notes, and snippets.

View weihanglo's full-sized avatar

Weihang Lo weihanglo

View GitHub Profile
@weihanglo
weihanglo / xitou_gis.R
Last active August 28, 2016 04:12
Generate SpatialPointDataFrame based on dataset in Xitou
#!/usr/bin/env Rscript
#
# ----- For NTU Forestry 3049 Course Only -----
#
# Generate SpatialPointDataFrame based on dataset in Xitou
#
# This Gist: https://git.io/v6ozP
#
# Mail: b01605002@ntu.edu.tw
# Author: Weihang Lo
@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 / .swiftlint.yml
Last active December 24, 2016 15:46
Configurations of iOS Project
opt_in_rules:
- closure_end_indentation
- closure_spacing
- empty_count
- force_unwrapping
- missing_docs
- operator_usage_whitespace
- private_outlet
- redundant_nil_coalescing
- overridden_super_call
@weihanglo
weihanglo / draw_gradient_pillow.py
Last active June 15, 2023 04:10
Draw gradient color with Pillow
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw
im = Image.open('img_original.png')
def interpolate(f_co, t_co, interval):
det_co =[(t - f) / interval for f , t in zip(f_co, t_co)]
for i in range(interval):
@weihanglo
weihanglo / carthage-intro.md
Last active January 9, 2024 06:54
Carthage 簡介

Carthage

[Carthage][carthage] 是一個較新的 Cocoa 開發第三方套件管理工具,相較於知名 [CocoaPods][cocoapods] 管理工具的複雜配置,輕巧的 Carthage 在推出之後廣受 Swift 社群喜愛。

本文基於 Carthage 0.20: Unary, Binary, Ternary

特色

  • 時代潮流:Written in Swift! (v.s. CocoaPods in Ruby)
  • 主流現代:iOS 8+, dynamic framework only
@weihanglo
weihanglo / fed-toolchain.md
Last active July 28, 2021 01:57
Front End Development Toolchain

Front End Development Toolchain

React Tech Stack

在大前端的時代,開發 Web app 不再像以前使用一個 jQuery 的 CDN 這麼容易,從 html 模板的抉擇,css 預處理器的挑選,Javascript 模組化的方法,自動化工具的使用等等,都是一門學問。本文將從建置基本的前端開發環境起頭,簡單介紹個人愛用現代常用的前端開發工具。

(撰於 2017-03-10)

Contents

@weihanglo
weihanglo / swift-error-handling.md
Last active August 1, 2017 03:45
Understanding Error Handling in Swift

Understanding Error Handling in Swift

如何利用 Swift 的語言特性來處理例外?使用 Optional 是常見的做法。如果成功就返回 value,失敗則返回 nil,這種模式常用於簡單的狀況。然而,面對複雜的情況,例如網路請求,若只簡單返回 nil,調用者並無法得知是 404,抑或 500。為了解決這個問題,我們必須緊緊抱住[錯誤/例外處理][wiki-exception-handling]的大腿。

(撰於 2017-04-10,基於 Swift 3.1)

@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 / 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 / inline-worker.js
Created June 17, 2017 00:38
Inline web worker
const blobURL = URL.createObjectURL(new Blob([ '(',
function () {
function fibonacci () {}
onmessage = function (ev) {
const result = processData(ev.data)
postMessage(result)
}
}.toString(),