Skip to content

Instantly share code, notes, and snippets.

View erichsu's full-sized avatar

eric.hsu erichsu

  • Ubiquiti, Inc
  • Taipei, TW
View GitHub Profile
@erichsu
erichsu / Contents.swift
Created May 9, 2022 23:07 — forked from sgr-ksmt/Contents.swift
JSONDecoder+keypath
//: Playground - noun: a place where people can play
import UIKit
var json: String = """
{
"result": {
"persons": [
{
@ViewBuilder
private func build<#name#>(_ viewStore: ViewStoreType) -> some View {
}
@erichsu
erichsu / TypeErasure.swift
Created November 17, 2021 08:33 — forked from iwill/TypeErasure.swift
Code Snippet: Type Erasure for Protocol with AssociatedType, Self and static methods
// Type-Erasure
// - seealso: [AnyIterator](https://github.com/apple/swift/blob/2fe4254cb712fa101a220f95b6ade8f99f43dc74/stdlib/public/core/ExistentialCollection.swift.gyb#L45)
// MARK: remove `Equatable` if not needed
public protocol Protocol: Equatable {
// MARK: `Protocol` requirements
associatedtype AssociatedType
func methodOfProtocol() -> Self.AssociatedType
}
@erichsu
erichsu / remove_old_builds.sql
Created September 30, 2021 20:29 — forked from david-zw-liu/remove_old_builds.sql
Keep 1000 builds per repos for DroneCI (sqlite3 version >= 3.25 required)
-- Thank @sbengo to figure out foreign_keys constraints is defaults to false in sqlite
-- Enable to delete logs by cascading delete
PRAGMA foreign_keys = ON;
WITH n_build_ids_per_repo as (
SELECT build_id
FROM (
SELECT
build_id,
build_repo_id,
@erichsu
erichsu / jq_group_by_count.sh
Created January 28, 2021 14:29 — forked from stefaneng/jq_group_by_count.sh
jq - Group by count
echo '[{"key": 1}, {"key": 2}, {"key": 1}]' | jq 'group_by (.key)[] | {key: .[0].key, length: length}'
@erichsu
erichsu / MyPlayground.swift
Created September 27, 2020 09:31
Quiz 3: Contains 7s
import UIKit
import PlaygroundSupport
/*
Let g(N) be the count of numbers that contain a 7 when you write out all the numbers from 1 to N.
g(7) = 1
g(20) = 2
g(70) = 8
g(100) = 19
@erichsu
erichsu / quick-start.sh
Created May 21, 2019 13:58
Git LFS setup
## 首次使用 Git LFS
# 安裝 Git LFS CLI
brew install git-lfs
# 在 repo 位置下
git lfs install
## 設定 Git LFS 自定義位址
git config -f .lfsconfig lfs.url http://<UserName>@<SERVER>:3000/<User>/<Project>.git/info/lfs
@erichsu
erichsu / gitea-server.plist
Last active May 21, 2019 13:58
Gitea LFS Server
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>lfs-server</string>
<key>ProgramArguments</key>
<array><string>/Users/gitea/gitea</string></array>
<key>RunAtLoad</key>
<true/>
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash \
-v file-log-from-apple-review.crash \
XXXX.xcarchive/dSYMs/XXXX.app.dSYM/ > output.log
@erichsu
erichsu / jq-to-csv.sh
Created August 14, 2018 15:10
jq-to-csv
# e.g.
# echo '[{"a":1, "b":2}, {"a":3, "b":4}]' | jq '.[]'
jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv'