Skip to content

Instantly share code, notes, and snippets.

View mfaani's full-sized avatar

Mohammad Faani mfaani

View GitHub Profile
@mfaani
mfaani / git-add-worktree.py
Last active September 1, 2026 03:17
Different ways to add a git work tree
# existing branch
git worktree add ../new-worktree-name branch-name
# new branch, explicitly named
git worktree add -b branch-name ../new-worktree-name
# new branch named after the directory
git worktree add ../new-worktree-name
@mfaani
mfaani / Dowload.sh
Created March 27, 2026 17:32
Extract wwdc
#!/usr/bin/env zsh
set -euo pipefail
# Extract high-resolution screenshots from WWDC 2021 session 10126
# Requires: ffmpeg, yt-dlp
VIDEO_URL="https://developer.apple.com/videos/play/wwdc2021/10126/"
# Store outputs under the discoverable-design folder
POST_DIR="$PWD/content/posts/design/discoverable-design"
OUT_DIR="$POST_DIR/images"
@mfaani
mfaani / 345. Reverse Vowels of a String.swift
Created September 29, 2025 01:29
#leetcode #string #array
class Solution {
let vowels: Set<Character> = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
func reverseVowels(_ s: String) -> String {
var foundIndices: [String.Index] = []
var ans = s
for i in s.indices {
if vowels.contains(s[i]) {
foundIndices.append(i)
}
}
@mfaani
mfaani / 605. Can Place Flowers.swift
Last active September 28, 2025 21:29
#leetcode #swift #arrays
/*
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.
Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise.
Example 1:
Input: flowerbed = [1,0,0,0,1], n = 1
Output: true
class Solution {
func gcdOfStrings(_ str1: String, _ str2: String) -> String {
if str2.count > str1.count {
return findGCDOf(str1: str2, str2: str1)
} else {
return findGCDOf(str1: str2, str2: str1)
}
}
func findGCDOf(str1: String, str2: String) -> String {
@mfaani
mfaani / EmojiRanger-watchos-simulator-error.md
Last active April 6, 2025 21:59
EmojiRanger-watchos-simulator-error.md

This happened after it successfully built, but didn't launch.

Simulator device failed to install the application.
Domain: IXErrorDomain
Code: 2
Failure Reason: Invalid placeholder attributes.
User Info: {
    DVTErrorCreationDateKey = "2025-04-06 19:35:47 +0000";
    FunctionName = "+[IXPlaceholder _placeholderForBundle:client:withParent:installType:metadata:placeholderType:mayBeDeltaPackage:isFromSerializedPlaceholder:error:]";
extension Character: Strideable {
public func distance(to other: Character) -> Int {
let selfValue = self.unicodeScalars.first?.value ?? 0
let otherValue = other.unicodeScalars.first?.value ?? 0
return Int(otherValue - selfValue)
}
public func advanced(by n: Int) -> Character {
guard let scalar = self.unicodeScalars.first else {
fatalError("Cannot advance an empty character")
@mfaani
mfaani / some-vs-some.md
Last active September 30, 2024 18:09
`some Equatable` vs another `some Equatable`
var a: some Equatable = 10
var c: some Equatable = 10
a = c // ERROR: Cannot assign value of type 'some Equatable' (type of 'c') to type 'some Equatable' (type of 'a')

You can't pass a different some Equatable to a. The compiler can't guarantee if a and c have identical underlying concrete types. Even though on the screen you can see c is an Int, to the compiler it's just some Equatable. It's NOT some Equatable_But_really_an_Int.

Because it's some Equatable then the compiler would be like, then 'What if c was "ten"? Let's just be safe an not allow it'

@mfaani
mfaani / longest-common-subsequence-memoization.swift
Last active September 28, 2024 18:32
Longest Common Subsequence using Memoization
/// start from m * n. Use RECURSION. End at 0 * 0
/// out of bounds could be the top and left edges.
func lcs(_ t1: [Character], _ t2: [Character]) -> Int {
var cache: [Stage: Int] = [:]
func helper(_ s: Stage) -> Int {
if let cached = cache[s] {
return cached
}
@mfaani
mfaani / longest-common-subsequence-tabulation.swift
Last active September 27, 2024 21:38
Longest Common Subsequence using Tabulation
func lcs(_ t1: [Character], _ t2: [Character]) -> Int {
// 1. build and default grid to 0
let row = Array(repeating: 0, count: t2.count)
var grid = Array(repeating: row, count: t1.count)
func lcs(_ s: Stage) -> Int {
// 3. Exit with a 0 for any point that's beyond the left or bottom edges
guard s.s1 >= 0 && s.s2 >= 0 else {
return 0
}