Skip to content

Instantly share code, notes, and snippets.

View flexih's full-sized avatar

Xinghua flexih

  • Beijing
  • 14:30 (UTC +08:00)
View GitHub Profile
@BenLumenDigital
BenLumenDigital / PacManLoader.swift
Created April 14, 2025 09:21
SwiftUI Pacman loader
//
// PacManLoader.swift
// ScriptReader
//
// Created by Ben Harraway on 14/04/2025.
//
import SwiftUI
struct PacManLoader: View {
@State private var progress: CGFloat = 1.0
@morajabi
morajabi / FPSCounter.swift
Created December 29, 2024 19:16
An FPS Counter for macOS apps built for inline.chat
import AppKit
import Charts
import CoreVideo
import SwiftUI
struct FPSMeasurement: Identifiable, Equatable {
let id: Int
let fps: Int
static func == (lhs: FPSMeasurement, rhs: FPSMeasurement) -> Bool {
@Kyle-Ye
Kyle-Ye / UICollectionViewCell+RCTRootViewDemo.swift
Last active November 17, 2024 04:44
Workaround for UICollectionViewCell+RCTRootView
import Dispatch
import Foundation
import UIKit
extension DispatchQueue {
/// Run the action immediately if it's on the main thread, otherwise dispatch it to the main thread asynchronously.
public static func onMainThread(_ action: @escaping () -> Void) {
if Thread.isMainThread {
action()
} else {
@sebjvidal
sebjvidal / ViewController.swift
Created May 28, 2024 16:39
UICustomViewMenuElement Demo
//
// ViewController.swift
// UIMenu-Demo
//
// Created by Seb Vidal on 28/05/2024.
//
import UIKit
class ViewController: UIViewController {
@stephancasas
stephancasas / sonoma-text-insertion-point-downgrade.jxa.js
Created October 7, 2023 02:58
Disable Sonoma Text Insertion Point ("Cursor" / "Caret")
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
const kCFPrefsFeatureFlagsDir = '/Library/Preferences/FeatureFlags/Domain';
const kCFPrefsFeatureEnabledKey = 'Enabled';
const kUIKitDomainPrefsTemporaryPath = '/tmp/UIKit.plist';
const kUIKitRedesignedTextCursorKey = 'redesigned_text_cursor';
@finestructure
finestructure / async-defer.swift
Last active August 5, 2024 01:34
Async defer
@discardableResult
func run<T>(_ operation: () async throws -> T,
defer deferredOperation: () async throws -> Void) async throws -> T {
do {
let result = try await operation()
try await deferredOperation()
return result
} catch {
try await deferredOperation()
throw error
@Midbin
Midbin / ContentView.swift
Last active May 19, 2025 08:38
A big and long but performant scrolling Swift Chart
import SwiftUI
import Charts
import GameplayKit
let gaussianRandoms = GKGaussianDistribution(lowestValue: 0, highestValue: 20)
func date(year: Int, month: Int, day: Int = 1) -> Date {
Calendar.current.date(from: DateComponents(year: year, month: month, day: day)) ?? Date()
}
@dreampiggy
dreampiggy / objc_xrefs_helper_hopper_v5.py
Last active May 16, 2025 10:19
Hopper 5 script to support Objective-C relative method list (iOS 14/macOS 11+)
#objective-c xrefs hopper script
#rewrite the IDAPython script https://github.com/fireeye/flare-ida/blob/master/python/flare/objc2_xrefs_helper.py
#author: Kai Lu(@k3vinlusec)
#editor: Zhuoli Li(@dreampiggy)
def getRefPtr(doc,classMethodsVA,objcSelRefs, objcMsgRefs, objcConst):
ret = (None, None)
namePtr = doc.readUInt64LE(classMethodsVA) #get name field in struct __objc_method, it's selector
ctn = 0
@ariccio
ariccio / BluetoothConstants.ts
Created January 10, 2022 18:59
GATT services and characteristics
//Extracted 1/10/2022 from my COVID-CO2-tracker project, in case they're useful to anybody. I'm gonna file an issue/suggesting a few places, and it seems polite to dump it here rather than a long preformatted bit in an issue.
export const GENERIC_GATT_SERVICE_SHORT_ID_DESCRIPTIONS = new Map([
//these are hex strings, without the 0x. Chrome zero extends the devices... so 0x1800 becomes 0x00001800.
// This is a hack to make things easy.
['1800', "generic_access"],
['1801', "generic_attribute"],
['1802', "immediate_alert"],
['1803', "link_loss"],
@ethanhuang13
ethanhuang13 / VirtualKeyboard.swift
Last active June 25, 2025 08:44
MacBook Air M1 Zhuyin Keyboard written with SwiftUI ~=300 LOC, < 4hrs
//
// VirtualKeyboard.swift
// MacBook Air M1 Zhuyin Keyboard
// Written with SwiftUI ~=300 LOC, < 4hrs
// Created by Ethan Huang on 2021/1/13.
// Twitter: @ethanhuang13
import SwiftUI
struct VirtualKeyboard: View {