Skip to content

Instantly share code, notes, and snippets.

View iSame7's full-sized avatar

Sameh Mabrouk iSame7

View GitHub Profile
@iSame7
iSame7 / largest-file.sh
Last active September 8, 2019 14:45
Find your project's Swift file with the most lines of code
find . -type f -name "*.swift" -exec grep -H -c '[^[:space:]]' {} \; | \sort -nr -t":" -k2 | awk -F: '{printf("Your largest file %s contains: %s lines \n", $1, $2); exit;}'
//
// MobletError.swift
// Moblet
//
// Created by Sameh Mabrouk on 20/10/2017.
// Copyright © 2017 Mobiquity Inc. All rights reserved.
//
import Foundation
protocol EnumCollection: Hashable {
static func cases() -> AnySequence<Self>
static var allValues: [Self] { get }
}
extension EnumCollection {
static func cases() -> AnySequence<Self> {
return AnySequence { () -> AnyIterator<Self> in
var raw = 0
return AnyIterator() {
@iSame7
iSame7 / AlmostEquatable.swift
Created August 15, 2017 11:16 — forked from erynofwales/AlmostEquatable.swift
An AlmostEquatable protocol for Swift floating point types
import Foundation
public protocol AlmostEquatable {
@warn_unused_result
func ==~(lhs: Self, rhs: Self) -> Bool
}
public protocol EquatableWithinEpsilon: Strideable {
static var Epsilon: Self.Stride { get }
}
//
// ListAccountsInteractorTests.swift
// INGBankieren
//
// Created by Sameh Mabrouk on 30/05/2017.
// Copyright © 2017 Sameh Mabrouk. All rights reserved.
//
import XCTest
@testable import INGBankierenDataKit
@iSame7
iSame7 / ASCII.swift
Created February 19, 2017 00:24
Check if Swift String is Number or not
func isValidNumber(string: String) -> Bool {
for char in string.characters {
let scalarValues = String(char).unicodeScalars
let charAscii = scalarValues[scalarValues.startIndex].value
//ASCII value of 0 = 48, 9 = 57. So if value is outside of numeric range then fail
//Checking for negative sign "-" could be added: ASCII value 45.
if charAscii < 48 || charAscii > 57 {
return false
}
}
@iSame7
iSame7 / 0_reuse_code.js
Created January 12, 2017 21:48
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@iSame7
iSame7 / DictionaryConvertable.swift
Created August 24, 2016 01:39 — forked from IanKeen/DictionaryConvertable.swift
Protocol to handle conversions between Models (class or struct based) and Dictionaries. Model to Dictionary has a default implementation provided for simple 1:1 Models
protocol DictionaryConvertable {
static func fromDictionary(dictionary: [String: AnyObject]) throws -> Self
func toDictionary() -> [String: AnyObject]
}
protocol DictionaryValueType {
func dictionaryValue() -> AnyObject?
}
extension Optional: DictionaryValueType {
func dictionaryValue() -> AnyObject? {