Skip to content

Instantly share code, notes, and snippets.

View mfaani's full-sized avatar

Mohammad Faani mfaani

View GitHub Profile
@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
}
@mfaani
mfaani / BinaryTree.swift
Last active November 23, 2023 15:47
Binary Tree
// Code inside modules can be shared between pages and other source files.
public class BinaryNode {
public var val: Int
public var left: BinaryNode?
public var right: BinaryNode?
public init() { self.val = 0
self.left = nil
self.right = nil
}
@mfaani
mfaani / README.md
Created July 6, 2023 20:18 — forked from IsaacXen/README.md
(Almost) Every WWDC videos download links for aria2c.
@mfaani
mfaani / how-to-modify-your-git-config-based-on-directory.md
Last active June 8, 2023 22:42
How to modify your git config based on directory - gist

There are some nuances. Took me a bit to piece it all together.

  1. Just add an if condition at the end of your existing global .gitconfig at your root directory.
[includeIf "gitdir:~/something/personal/"]
  path = .gitconfig-personal
[includeIf "gitdir:~/elsewhere/work/"]
  path = .gitconfig-work
@mfaani
mfaani / bash.md
Created April 25, 2023 20:31
Useful bash commands

Find all file names that start with 'App'

find path/to/folder -name "App*"

Show the next 3 lines (trailing context) after a match

cat Foo.swift | grep -A 3 methodA
@mfaani
mfaani / NSURLError AND CFNetworkErrors.h
Created February 15, 2023 18:44
NSURL Error + iOS Network Error codes
/*
ATTENTION: I've added two files here.
Steps to find this yourself.
1. Xcode >> Find >> New Scope >> Set the 'Search the following locations:' to SDK; Then set the other dropdown to 'iOS <whateverVersion>'
2. Then search for the error code number.
*/