Skip to content

Instantly share code, notes, and snippets.

View mfaani's full-sized avatar

Mohammad Faani mfaani

View GitHub Profile
//
// ViewController.swift
// IntrinsicLabel
//
// Created by Faani, Mohammad on 10/5/01.
// Copyright © 2018 Funnex. All rights reserved.
//
import UIKit
// https://stackoverflow.com/questions/7367472/why-does-url-pathcomponents-contain-an/7368129#7368129
import Foundation
let urlString1 = "http://yahoo.com/video/3" // scheme: http | host: yahoo.com | comps ["/", "video", "3"]
let urlString2 = "video/3" // scheme: Empty | host: Empty | comps ["video", "3"]
let urlString3 = "/video/3" // scheme: Empty | host: Empty | comps ["/", "video", "3"]
let urlString4 = "Facebook://Feed/3" // scheme: Facebook | host: Feed | comps ["/", "3"]
let urlString5 = "yahoo.com" // scheme: Empty | host: Empty | comps ["yahoo.com"]
let urlString6 = "giberish://yahoo.com/video/3" // scheme: giberish | host: yahoo.com | comps ["/", "video", "3"]
@mfaani
mfaani / gist:2efc6dba501cca174ffd5772880329e1
Last active March 12, 2019 15:30
Increase WWDC Playback speed on Chrome/Safari
// Just open your browser's inspector. In its console, type:
document.getElementsByTagName("video")[0].playbackRate = 2.0
@mfaani
mfaani / closures.swift
Last active March 20, 2019 20:32
how to write weird closures :)
class C {
lazy var x: () -> Void = {
return { print("hi") }
}()
lazy var y: (Int) -> Void = { // `input in` shouldn't be written here!
return { input in
print(input)
}
}()
// https://stackoverflow.com/questions/55446713/true-false-question-about-swift-subclass-superclass
class Person {
var age : Int?
func incrementAge() {
guard age != nil else {
age = 1
return
}
import Foundation
//Cancel without setting `item` to `nil`
class Foo {
func testDispatchItems() {
let queue = DispatchQueue.global()
var item: DispatchWorkItem?
item = DispatchWorkItem { [weak self] in
@mfaani
mfaani / DispatchWorkItemCanceled
Created April 1, 2020 14:42
Related to https://stackoverflow.com/a/38372384/5175709 Trying to show setting `item` to `nil` doesn't seem to be necessary
import Foundation
class Foo {
func testDispatchItems() {
let queue = DispatchQueue.global()
var item: DispatchWorkItem?
item = DispatchWorkItem { [weak self] in
for i in 0 ... 10 {
@mfaani
mfaani / original-proposal.md
Created January 19, 2021 06:00
original proposal written for privacy_details cocoapods contribution
  • Authors: @prohoney, @AliSoftware
  • Date: 1 Jan, 2021

Motivation

Starting from December 8, 2020, Apple has required new apps and app updates to include App privacy details on the App Store. App owners have to go through every pod and all its dependency's readmes or if nothing is revealed then reach out to pod creators to just figure out what information the pod collects. The current process is not transparent nor easy.

Proposal

@mfaani
mfaani / removeKdigits
Created April 27, 2021 01:56
// Remove K Digits
class Solution {
func removeKdigits(_ num: String, _ k: Int) -> String {
var drops = k
var maxStack: [Character] = []
for digit in num {
// only if there is something bigger in the stack to drop...
while drops > 0 && !maxStack.isEmpty && maxStack.last! > digit {
maxStack.popLast()
drops -= 1
@mfaani
mfaani / hasValidParenthesis.swift
Last active April 29, 2021 14:01
Valid Parentheses
class Solution {
var remaining : [String: Int] = ["(": 0, "[": 0, "{": 0]
func isValid(_ s: String) -> Bool {
let validChars = ["(", ")", "[", "]","{", "}"]
let opens = ["[", "(", "{"]
let closes = ["]", ")", "}"]
for c in s {
let c = String(c)