Skip to content

Instantly share code, notes, and snippets.

View mfaani's full-sized avatar

Mohammad Faani mfaani

View GitHub Profile
@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.
*/
@mfaani
mfaani / codeabe.swift
Last active December 19, 2022 15:42
A quick example of codeable based off of a Hackingwithswift tutorial
// https://www.hackingwithswift.com/articles/119/codable-cheat-sheet
import Foundation
struct Packet: Decodable {
var value: Int
var array: [Packet]?
}
enum Lett {
indirect case a(m: M)
@mfaani
mfaani / stdin_vs_stdout.md
Last active September 16, 2022 18:20
stdin vs stdout

Great video on stdin vs stdout: https://www.youtube.com/watch?v=OsErpB0-mWY

stdin

As a standard your input usually comes from the keyboard. Ex cat file.txt. <- here you're passing file.txt as a parameter.

However you can do cat < $file_name i.e. make the input to the cat command a variable.

Both cat file.txt & cat < file.txt achieve the same, but through different mechanics. < is passing something as an input.

I suppose it's because the cat command has abilities to handle file names as arguments and through stdin

@mfaani
mfaani / learning.md
Created May 15, 2021 23:08
Gatsby learning
  1. Learned how to search for files in VSC. Need to use cmmd+P
  2. The config.js is king
  3. For the config.js stuff to come to an affect, you need to do gatsby develop again.
  4. gatsby build doesn't work locally. Not sure what it does. ?????
  5. The location of media assets are under the static/media not sure why it's in there. For more see https://www.gatsbyjs.com/docs/how-to/images-and-media/static-folder/
@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)
@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 / 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 / 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 {