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
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()) {
@MMnasrabadi
MMnasrabadi / CopyLabel.swift
Created June 20, 2020 11:42 — forked from AliSoftware/CopyLabel.swift
An UILabel subclass which allows you to show the "copy" MenuController item to copy its content to the pasteboard
import UIKit
class CopyLabel : UILabel {
// MARK: Setup
override init(frame: CGRect) {
super.init(frame: frame)
configureMenu()
}
@MMnasrabadi
MMnasrabadi / Bindings.swift
Created June 20, 2020 11:39 — forked from AliSoftware/Bindings.swift
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
enum Demo {
case simple
case oneValue(Int)
case twoValues(String, Double)
case threeValues(one: Int, two: Float, [Int])
}
//: # Direct exposition in the enum
//: ## Sourcery Template
// Xcode 11b1
@propertyDelegate
struct Clamped<Value: Comparable> {
private var storage: Value
private var clamp: (Value) -> Value
init(min: Value, max: Value, initialValue: Value) {
let clampingFunction = { ($0...$0).clamped(to: min...max).lowerBound }
self.storage = clampingFunction(initialValue)
import Foundation
protocol TransformerType {
associatedtype BaseType
associatedtype TypeForCoding: Codable
static var encodeTransform: (BaseType) throws -> TypeForCoding { get }
static var decodeTransform: (TypeForCoding) throws -> BaseType { get }
}
@propertyWrapper
@MMnasrabadi
MMnasrabadi / Demo.swift
Created June 20, 2020 11:20 — forked from AliSoftware/Demo.swift
NestableCodingKey: Nice way to define nested coding keys for properties
struct Contact: Decodable, CustomStringConvertible {
var id: String
@NestedKey
var firstname: String
@NestedKey
var lastname: String
@NestedKey
var address: String
enum CodingKeys: String, NestableCodingKey {
@MMnasrabadi
MMnasrabadi / CodablePro.swift
Created March 23, 2020 15:18
extension on Codable
// Create by love : Mohammad Nasrabadi [github](https://github.com/mmnasrabadi)
import UIKit
protocol CodablePro: Codable {
func toJsonString() -> String
typealias JSON = [String : Any]
func toDictionary() -> JSON?
init?(json: JSON)
@MMnasrabadi
MMnasrabadi / ZSH and Oh My ZSH installations
Last active March 14, 2020 05:43
Setting up the beautiful terminal by ZSH and Oh My ZSH installations
Setting up the beautiful terminal by ZSH and Oh My ZSH installations
ohmyzsh github page:
https://github.com/ohmyzsh/ohmyzsh
Themes :
https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
@MMnasrabadi
MMnasrabadi / fazl-cheshmak-zan.sh
Last active June 25, 2020 11:34 — forked from iamvee/fazl-cheshmak-zan.sh
This is from the grace of my Lord
echo "\033[31;32m \033[0m"
echo "\033[31;32m ## \033[0m"
echo "\033[31;32m ### \033[0m"
echo "\033[31;32m ###** #########*####**** \033[0m"
echo "\033[31;32m ## ############********* #* \033[0m"
echo "\033[31;32m *######***** ### #* \033[0m"
echo "\033[31;32m # * #* \033[0m"
echo "\033[31;32m ## # # ## ###' #*