Skip to content

Instantly share code, notes, and snippets.

View 0x1306a94's full-sized avatar
😶
depressed

0x1306a94 0x1306a94

😶
depressed
  • 00:29 (UTC +08:00)
View GitHub Profile
@onevcat
onevcat / Default.swift
Created November 10, 2020 03:56
Sample code of using Default to decode a property to the default value
import UIKit
protocol DefaultValue {
associatedtype Value: Decodable
static var defaultValue: Value { get }
}
@propertyWrapper
struct Default<T: DefaultValue> {
var wrappedValue: T.Value
@JakeLin
JakeLin / 10118-create-app-clips-for-other-businesses-article-zh.md
Last active November 15, 2021 19:44
Create app clips for other businesses 中文

这是一个 Draft,更新会在 https://github.com/JakeLin/wwdc2020/blob/master/10118-create-app-clips-for-other-businesses/10118-create-app-clips-for-other-businesses-article-zh.md

为其他商户构建 App Clips

WWDC20 10118 - Create app clips for other businesses 视频

概述

这个主题讲述如何为其他商户构建 App Clips 体验,例如某外卖 App 如何帮各个不同餐饮商户构建基于他们自己品牌的 App Clips 来支持预定餐桌,点餐等服务。只需在一个主 App 中创建唯一的 App Clips 库就可以为不同商户提供各自独特的 App Clip 体验。同时讲述了 App Clips 的最佳实践,包括如何上传独特的商户信息,处理入口链接,路由推送消息,处理存储和恢复会话状态等等。也讲述了各种 App Clips 体验图标类型的差异性,如何呈现和定制这些图标。

@IsaacXen
IsaacXen / README.md
Last active August 20, 2025 10:30
(Almost) Every WWDC videos download links for aria2c.
@kemchenj
kemchenj / CodeTextField.swift
Last active January 6, 2025 10:24
CodeTextField
import UIKit
class CodeTextField: UITextField, UITextFieldDelegate {
let codeLength: Int
var characterSize: CGSize
var characterSpacing: CGFloat
let textPreprocess: (String) -> String
let validCharacterSet: CharacterSet
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active July 8, 2025 03:48
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@endavid
endavid / FontAtlas.swift
Created May 27, 2017 18:03
Signed Distance Field in Metal/Swift
public class FontAtlas: NSObject, NSSecureCoding {
public static var supportsSecureCoding: Bool { get { return true } }
static let atlasSize: Int = 2048 // 4096 runs out of mem...
var glyphs : [GlyphDescriptor] = []
let parentFont: UIFont
var fontPointSize: CGFloat
let textureSize: Int
var textureData: [UInt8] = []
@wxdao
wxdao / open_utun.c
Last active April 13, 2024 18:39 — forked from bringhurst/gist:1693075
How to open utun device in OS X
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/kern_control.h>
#include <net/if_utun.h>
#include <sys/ioctl.h>
#include <sys/kern_event.h>
int open_utun(int num) {
int err;
import Foundation
extension Dictionary {
mutating public func setValue(val: AnyObject, forKeyPath keyPath: String) {
var keys = keyPath.componentsSeparatedByString(".")
guard let first = keys.first as? Key else { print("Unable to use string as key on type: \(Key.self)"); return }
keys.removeAtIndex(0)
if keys.isEmpty, let settable = val as? Value {
self[first] = settable
} else {
@elbeno
elbeno / fix.cpp
Created May 16, 2015 21:58
Fixed-point (Y) combinator in C++
#include <functional>
#include <iostream>
using namespace std;
template <typename F>
struct Y
{
Y(F f) : m_f(f) {}
template <typename T>