Skip to content

Instantly share code, notes, and snippets.

View iSame7's full-sized avatar

Sameh Mabrouk iSame7

View GitHub Profile
@AvdLee
AvdLee / largest-file.sh
Last active December 10, 2023 19:24
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;}'
//
// Config.swift
// Analytics
//
public protocol AnalyticsConfig {
static var analyticsKey: String { get }
static var appVersion: String { get }
}
// Three different lexer implementations. First a "consume everything" lexer, then a "lazy" lexer (that is, an iterator), then a lazy lexer without explicit state.
enum Token {
case heading(level: Int)
case star
case text(String)
}
import Foundation
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: view.topAnchor),
@lattner
lattner / TaskConcurrencyManifesto.md
Last active October 27, 2025 08:04
Swift Concurrency Manifesto
@AlexanderZ-aFrogleap
AlexanderZ-aFrogleap / SectionedTableViewAdapter.swift
Created October 15, 2016 20:12
Generic UITableView adapter with sections
//: Playground - noun: a place where people can play
import UIKit
protocol SectionModel {
var count: Int { get }
func cell(at: Int) -> UITableViewCell
func selected(at: Int)
}
@avdyushin
avdyushin / ASCII.swift
Created February 15, 2016 09:59
Swift Character get ASCII code value
extension Character {
var asciiValue: Int {
get {
let s = String(self).unicodeScalars
return Int(s[s.startIndex].value)
}
}
}
@parmentf
parmentf / GitCommitEmoji.md
Last active October 29, 2025 09:52
Git Commit message Emoji

Inspired by dannyfritz/commit-message-emoji

See also gitmoji.

Commit type Emoji
Initial commit πŸŽ‰ :tada:
Version tag πŸ”– :bookmark:
New feature ✨ :sparkles:
Bugfix πŸ› :bug:
@erynofwales
erynofwales / AlmostEquatable.swift
Created November 7, 2015 07:14
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 }
}
@IanKeen
IanKeen / DictionaryConvertable.swift
Last active August 3, 2017 16:18
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? {