Skip to content

Instantly share code, notes, and snippets.

View MMnasrabadi's full-sized avatar
🤠
i am happy

Mohammad Mohammadi Nasrabadi MMnasrabadi

🤠
i am happy
View GitHub Profile
Registered Name: https://zhile.io
License Key: 48891cf209c6d32bf4
// clean remore memory leak
protocol Weakifiable: class { }
extension NSObject: Weakifiable {}
extension Weakifiable {
func weakify<T, Z>(_ code: @escaping (Self, T) -> Z) -> (T) -> Z? {
return { [weak self] data in
guard let self = self else { return nil}
@MMnasrabadi
MMnasrabadi / DocumentPicker.swift
Created December 16, 2020 15:39 — forked from aheze/DocumentPicker.swift
UIDocumentPickerViewController example in Swift 5. Bug fixed version of this article: https://medium.com/flawless-app-stories/a-swifty-way-to-pick-documents-59cad1988a8a
//
// DocumentPicker.swift
import UIKit
import MobileCoreServices
protocol DocumentDelegate: class {
func didPickDocument(document: Document?)
}
@MMnasrabadi
MMnasrabadi / gist:4b256d2ab2af7257210911a99cd77a9c
Last active January 18, 2024 21:30
GitKraken open Private Repository
Installing older version of Gitkraken is the only solution I guess to work on private repo if you want it for free and without student developer pack.
From the release notes, the last version to support private repo is v6.5.1.
@MMnasrabadi
MMnasrabadi / simctl
Last active October 14, 2020 11:51
To open a custom URL scheme (or any website) in a simulator.
xcrun is a tool to run any tool inside Xcode from the command line. The tool for this job is simctl, which help you manage simulators.
@MMnasrabadi
MMnasrabadi / gist:c35337677c2d368dab967eeab685ff75
Created September 12, 2020 17:31 — forked from ebraminio/gist:5292017
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir
// Check Iranian National Code Validity - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، روبی، جاوااسکریپت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو، سوئیفت، کاتلین، گرووی، راست، هسکل، ارلنگ، الکسیر
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست http://www.fardanews.com/fa/news/127747
// بعضی از پیاده‌سازی‌ها سریع نیستند، می‌توانید نسخهٔ خود را بر پایهٔ
// نسخهٔ سی یا گو ایجاد کنید که بهترین سرعت را داشته باشد
/**
@MMnasrabadi
MMnasrabadi / UserDefaults+Codable+propertyWrapper.swift
Created August 26, 2020 12:59 — forked from quangDecember/UserDefaults+Codable+propertyWrapper.swift
property wrappers for saving to UserDefaults, generics or Codable
import Foundation
@propertyWrapper
struct UserDefault<T> {
let key: String
let defaultValue: T
init(_ key: String, defaultValue: T) {
self.key = key
@MMnasrabadi
MMnasrabadi / iranianBankCardCheck.swift
Created June 30, 2020 05:10
Check iranian Bank Card Validation
// Create by love : Mohammad Nasrabadi [github](https://github.com/mmnasrabadi)
iranianBankCardCheck(5041721046432655)
iranianBankCardCheck(6037997561388217)
iranianBankCardCheck(6362141802359837)
iranianBankCardCheck(6273811616832991)
iranianBankCardCheck(6037997561388217)
iranianBankCardCheck(6104337824093650)
iranianBankCardCheck(3982309207502750)
# Property Wrappers
https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md
func using<T: AnyObject>(object: T, execute: (T) throws -> Void) rethrows -> T {
try execute(object)
return object
}
import UIKit
// Then in some configureView() function of an UIViewController or whatnot…
let label1 = using(UILabel()) {