Skip to content

Instantly share code, notes, and snippets.


Fuxing Loh fuxingloh

View GitHub Profile
fuxingloh /
Last active October 14, 2021 01:08
A list of minimal effort image storage, transformation and delivery.

Minimal effort image storage, transformation and delivery.


AWS: Serverless Image Handler

  • Storage: You upload to S3
  • Delivery + Transformation: CloudFront -> API Gateway -> Lambda (Node, Sharp/Thumbor) -> S3
  • CloudFormation: 1 click and fill up some fields.
  • Only predefined S3 Bucket, no dynamic bucket routing.
  • Transformation is encoded into Base64 that can be generated by anyone. You can add Signed URL but it's quite troublesome.
fuxingloh / UICollectionView.swift
Last active February 23, 2023 08:38
iOS Swift: How to count the width of the UILabel. And how to size UICollectionViewCell dynamically with label.
View UICollectionView.swift
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let text = collections[indexPath.row].name
let width = UILabel.textWidth(font: titleFont, text: text)
return CGSize(width: width + left + right, height: height)
calebamiles /
Last active February 1, 2021 15:53
Notes on Open Source Governance Models

Node.js Foundation

  • Healthy Open Source
    • explicit goal to be a lightweight process
    • concrete ability to scale to hundreds of contributors
    • good fundamental goals
      • transparency
      • participation
      • efficacy
    • ecosystem projects encouraged but not required to adopt foundation governance templates
  • creation of projects under TSC explicity delegates authority from TSC to project TC
fuxingloh / app.js
Last active February 24, 2023 16:16
How to use express.js and passport.js with G Suite SAML Apps SSO
View app.js
const express = require('express')
const SamlStrategy = require('passport-saml').Strategy
const passport = require('passport')
const cookieSession = require('cookie-session')
const cookieParser = require('cookie-parser')
// Create express instance
const app = express()
fuxingloh / UILabelCountLines.swift
Last active April 24, 2023 18:55
iOS Swift: How to check if UILabel is truncated? Calculate number of lines for UILabel
View UILabelCountLines.swift
func countLabelLines(label: UILabel) -> Int {
// Call self.layoutIfNeeded() if your view uses auto layout
let myText = label.text! as NSString
let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
anvaka /
Last active June 5, 2023 01:36
npm rank

npm rank

This gist is updated daily via cron job and lists stats for npm packages:

  1. Top 1,000 most depended-upon packages
  2. Top 1,000 packages with largest number of dependencies
  3. Top 1,000 packages with highest PageRank score
jboner / latency.txt
Last active June 9, 2023 03:26
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers (~2012)
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
keeguon / countries.json
Created April 5, 2012 11:11
A list of countries in JSON
View countries.json
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},