Skip to content

Instantly share code, notes, and snippets.

@samsonjs
samsonjs / SendableWrapper.swift
Last active February 25, 2025 01:00
See https://github.com/samsonjs/SJSAssetExportSession — Exporting videos with AVFoundation in the strict concurrency world of Swift 6
//
// Created by Sami Samhuri on 2024-06-26.
//
import Foundation
final class SendableWrapper<T>: @unchecked Sendable {
private var unsafeValue: T
private let lock = NSLock()
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active August 1, 2025 10:06
FormatStyle in Excruciating Detail
@inket
inket / PreviewScreenshot.swift
Last active July 28, 2024 23:57
How to take screenshots of SwiftUI previews
#if DEBUG
import SwiftUI
private let screenshotDirectory = "/Users/inket/Desktop/"
struct PreviewScreenshot: ViewModifier {
struct LocatorView: UIViewRepresentable {
let tag: Int
func makeUIView(context: Context) -> UIView {
@douglashill
douglashill / KeyboardTableView.swift
Last active March 30, 2023 22:01
A UITableView that allows navigation and selection using a hardware keyboard.
// Douglas Hill, December 2018
// Made for https://douglashill.co/reading-app/
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit
import UIKit
/// A table view that allows navigation and selection using a hardware keyboard.
/// Only supports a single section.
class KeyboardTableView: UITableView {
// These properties may be set or overridden to provide discoverability titles for key commands.
@soulmachine
soulmachine / jwt-expiration.md
Last active June 19, 2025 15:38
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@lgo
lgo / redis-leases
Last active October 16, 2023 14:54
Redis lease implementation
# Redis lease pseudo-code
FUNCTION INIT_LEASES(lock_key, amt)
FOR i := 0; i < amt; i++ DO
LPUSH(lock_key, 0)
END
END
FUNCTION ACQUIRE_LEASE(lock_key)
@lattner
lattner / TaskConcurrencyManifesto.md
Last active July 31, 2025 13:12
Swift Concurrency Manifesto
@brennanMKE
brennanMKE / EventEmitter.swift
Last active July 15, 2025 09:06
React Native Event Emitter for RCTEventEmitter in Objective-C and Swift
class EventEmitter
/// Shared Instance.
public static var sharedInstance = EventEmitter()
// ReactNativeEventEmitter is instantiated by React Native with the bridge.
private static var eventEmitter: ReactNativeEventEmitter!
private init() {}
@chourobin
chourobin / 0-bridging-react-native-cheatsheet.md
Last active July 7, 2025 21:06
React Native Bridging Cheatsheet
@richardgill
richardgill / navigator.js
Created December 2, 2016 16:35
Gives you an idea of the sorts of things we needed from a general purpose navigator
import React, { Component } from 'react'
import { Navigator, StatusBar, View } from 'react-native'
import customNavigatorScenes from '../../common/customNavigatorScenes'
import style from './style'
import ErrorListener from './errorListener'
import NetworkConnectivity from '../networkConnectivity'
import _ from 'lodash'
import { brandPrimary } from '../../styleVariables'
import { reduxComponentName } from '../../common/reduxComponentName'