Skip to content

Instantly share code, notes, and snippets.

View morajabi's full-sized avatar

Mo morajabi

View GitHub Profile
@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 {
@dena-sohrabi
dena-sohrabi / AppDatabase.swift
Created October 16, 2024 12:27
Encrypted Database (GRDB + SQLCipher)
import Foundation
import GRDB
// MARK: - DB main class
public final class AppDatabase: Sendable {
public let dbWriter: any DatabaseWriter
public init(_ dbWriter: any GRDB.DatabaseWriter) throws {
self.dbWriter = dbWriter
@morajabi
morajabi / FormState.swift
Last active October 16, 2024 12:28
Form state management in Swift UI
import SwiftUI
struct FormStateData {
var loading: Bool
var error: String?
var succeeded: Bool?
}
// A helper for easier state management for simple forms
class FormState: ObservableObject {
@Shpigford
Shpigford / .cursorrules
Last active February 19, 2025 09:13
Cursor Rules
# Original instructions: https://forum.cursor.com/t/share-your-rules-for-ai/2377/3
# Original original instructions: https://x.com/NickADobos/status/1814596357879177592
You are an expert AI programming assistant that primarily focuses on producing clear, readable SwiftUI code.
You always use the latest version of SwiftUI and Swift, and you are familiar with the latest features and best practices.
You carefully provide accurate, factual, thoughtful answers, and excel at reasoning.
- Follow the user’s requirements carefully & to the letter.
@charrondev
charrondev / tauri_traffic_light_positioner_plugin.rs
Last active December 26, 2024 16:06
This code describes a mechanism to adjust traffic light positioning on MacOS with Tauri 2.x
use objc::{msg_send, sel, sel_impl};
use rand::{distributions::Alphanumeric, Rng};
use tauri::{
plugin::{Builder, TauriPlugin},
Manager, Runtime, Window,
}; // 0.8
const WINDOW_CONTROL_PAD_X: f64 = 15.0;
const WINDOW_CONTROL_PAD_Y: f64 = 23.0;
class TimeElapsed: CustomStringConvertible {
private let startTime: CFAbsoluteTime
private var endTime: CFAbsoluteTime?
init() {
startTime = CFAbsoluteTimeGetCurrent()
}
var description: String {
time
@bdsqqq
bdsqqq / vesper-dark.json
Last active December 1, 2024 20:38
Vesper theme for zed.dev
{
"$schema": "https://zed.dev/schema/themes/v0.1.0.json",
"name": "Vesper",
"author": "Rauno Freiberg",
"themes": [
{
"name": "Vesper",
"appearance": "dark",
"style": {
"border": "#101010",
@msanford1540
msanford1540 / MultiPartFormData.swift
Last active January 28, 2025 10:10
Swift 5/6 Multipart form-data Support
//
// MultiPartFormData.swift
//
import Foundation
/* Example Call site: */
func upload(imageData: Data) async throws {
guard let url = URL(string: "https://example.com/upload") else { return }
var multipartFormData = MultipartFormData()
@hoishing
hoishing / HowTo.md
Last active March 4, 2025 11:14
VSCode keybindings for Xcode

VSCode keybindings for Xcode

  • copy VSCode.idekeybindings to ~/Library/Developer/Xcode/UserData/KeyBindings
  • in Xcode preferences -> key bindings, select VSCode
@alii
alii / ensure-keys.ts
Created August 25, 2021 14:12
Infer object values while strictly specifying keys in TypeScript
/**
* TypeScript currently lacks a way of typing a record of keys only but not values.
* we need this because we want an object of typed keys but we want to leave the values inferred.
* thankfully, we can do this with generics. This function allows the second generic's values to be inferred
* so that our object is fully type safe for hugely complex types, but we can guarantee that all the keys we need exist.
* It's not perfect, but it gets the job done for the time being
*/
export function ensureKeys<T>() {
/**
* Function that returns the value that gets put in, values are type-safely inferred