Skip to content

Instantly share code, notes, and snippets.

View sbhmajd's full-sized avatar

Majd Sabah sbhmajd

View GitHub Profile

If .DS_Store was never added to your git repository, simply add it to your .gitignore file.

If you don't have one, create a file called

.gitignore

In your the root directory of your app and simply write

@robertmryan
robertmryan / Ranges.swift
Last active February 29, 2024 16:16
Swift 4 string extension to find all ranges of some substring
extension StringProtocol where Index == String.Index {
func ranges<T: StringProtocol>(of substring: T, options: String.CompareOptions = [], locale: Locale? = nil) -> [Range<Index>] {
var ranges: [Range<Index>] = []
while let result = range(of: substring, options: options, range: (ranges.last?.upperBound ?? startIndex)..<endIndex, locale: locale) {
ranges.append(result)
}
return ranges
}
}
@GenoZhou
GenoZhou / UITableView.swift
Created November 5, 2017 15:34
Swift 4 UITableView extensions.
public protocol ReusableView: class { }
extension ReusableView where Self: UIView {
public static var reuseIdentifier: String {
return String(describing: self)
}
}
extension UITableViewCell: ReusableView { }
extension UITableViewHeaderFooterView: ReusableView { }
@PaulWagener
PaulWagener / Keychain.swift
Created November 1, 2017 07:09
Easy Keychain use with Swift 4
//
// Keychain.swift
// SecKeychain
//
// Created by Paul Wagener on 01-11-17.
// Copyright © 2017 Paul Wagener. All rights reserved.
//
import Foundation
@brennanMKE
brennanMKE / BytesPlayground.swift
Last active December 16, 2023 18:30
Copy bytes from Data with Swift
import Foundation
let size = MemoryLayout<Int16>.stride
let data = Data(bytes: [1, 0, 2, 0, 3, 0]) // little endian for 16-bit values
let int16s = data.withUnsafeBytes { (bytes: UnsafePointer<Int16>) in
Array(UnsafeBufferPointer(start: bytes, count: data.count / size))
}
let length = data.count * MemoryLayout<Int16>.stride
@nyg
nyg / AddJPEGComment.swift
Last active February 21, 2021 05:17
Add a JPEG comment marker to file in pure Swift.
//
// Inspired by wrjpgcom of libjpeg
// https://github.com/libjpeg-turbo/libjpeg-turbo/blob/master/wrjpgcom.c
//
// https://stackoverflow.com/a/46045524/5536516
//
// Note: To add an EXIF UserComment go here:
// https://gist.github.com/nyg/c90f36abbd30f72c8b6681ef23db886b
import Foundation
@JulianAlonso
JulianAlonso / Regex&Matcher-Playground.swift
Last active March 7, 2023 06:22
Mapping URL (Deep linking) on iOS.
import Foundation
extension String {
//Know if self is only composed by numbers
var isNumber: Bool {
return !self.isEmpty && CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: self))
}
}
//Struct to check Regular Expresions
@codediodeio
codediodeio / database.rules.json
Last active January 10, 2025 22:28
Common Database Rules for Firebase
// No Security
{
"rules": {
".read": true,
".write": true
}
}
@brunophilipe
brunophilipe / GuardURLProtocol.swift
Last active March 12, 2023 13:19
GuardURLProtocol class to monitor all connections initiated by app
//
// GuardURLProtocol.swift
// URLProtocol
//
// Created by Bruno Philipe on 16/2/17.
// Copyright © 2017 Bruno Philipe. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
extension UIImageView {
/// Loads image from web asynchronosly and caches it, in case you have to load url
/// again, it will be loaded from cache if available
func load(url: URL, placeholder: UIImage?, cache: URLCache? = nil) {
let cache = cache ?? URLCache.shared
let request = URLRequest(url: url)
if let data = cache.cachedResponse(for: request)?.data, let image = UIImage(data: data) {
self.image = image
} else {
self.image = placeholder