Skip to content

Instantly share code, notes, and snippets.

View verebes1's full-sized avatar

David verebes1

View GitHub Profile
import network
import socket
import time
import struct
from machine import Pin
NTP_DELTA = 2208988800
host = "pool.ntp.org"
@verebes1
verebes1 / UIApplication+AppVersion.swift
Created October 30, 2019 13:15 — forked from ashleymills/UIApplication+AppVersion.swift
UIApplication extension to get app version / build
extension UIApplication {
class func appVersion() -> String {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
}
class func appBuild() -> String {
return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String
}
@verebes1
verebes1 / ColorSupport.swift
Last active August 18, 2021 19:09
Using UIColors from iOS13 with backward compatibility to previous iOS versions.
import UIKit
public enum ColorSupport {
public static var label: UIColor {
if #available(iOS 13, *) {
return .label
}
return UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
}
@verebes1
verebes1 / Data+PrettyPrint.swift
Created March 20, 2019 17:01 — forked from cprovatas/Data+PrettyPrint.swift
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@verebes1
verebes1 / Network.swift
Created March 15, 2019 15:00 — forked from ankitthakur/Network.swift
Swift Network Request
public class Network:NSObject, URLSessionDelegate, URLSessionTaskDelegate, URLSessionDataDelegate {
internal static let sharedInstance = Network()
fileprivate var networkParams:Array<NetworkParams> = Array()
fileprivate func networkCall(_ request:URLRequest, completionBlock:@escaping NetworkCompletionBlock)
{
let configurationId = String(format: "Network%d", arc4random())
let configuration = URLSessionConfiguration.background(withIdentifier: configurationId)
configuration.timeoutIntervalForRequest = request.timeoutInterval
@verebes1
verebes1 / HackerRank-Input-Reading-Stdin.swift
Last active June 13, 2022 09:36
HackerRank Input Reading Arrays of Ints or Doubles Stdin swift
//Reading an Int
let number = Int(readLine()!)!
//Reading a Double
let decimalNumber = Double(readLine()!)!
//Reading a string
let text = readLine()!
//reading an array of Ints
@verebes1
verebes1 / ThemeManager.swift
Created July 11, 2018 17:28 — forked from durul/ThemeManager.swift
ThemeManager.swift
//
// ThemeManager.swift
import UIKit
import Foundation
/// Enum Theme Manager
/// - Note: https://github.com/durul/DRL-Theme-Manager
enum Theme: Int {
@verebes1
verebes1 / ThemeManager.swift
Created July 10, 2018 20:26 — forked from abhimuralidharan/ThemeManager.swift
A guide on how to create a theme manager class in swift so that the code is flexible and the developer can change the theme colour anytime with ease.
//
// ThemeManager.swift
// ProjectThemeTest
//
// Copyright (c) 2017 Abhilash
//
import UIKit
import Foundation
@verebes1
verebes1 / RealmReorderIDAfterTableDrag.swift
Created April 30, 2018 12:12
Using Long Press Reorder for swift reorder realm objects ID after dragging
extension CategoryViewController {
override func positionChanged(currentIndex: IndexPath, newIndex: IndexPath) {
// currentIndex and newIndex rows are swapped, implement accordingly
}
override func reorderFinished(initialIndex: IndexPath, finalIndex: IndexPath) {
// Gesture is finished and cell is back inside the table at finalIndex position
try! realm.write {
guard let sourceObject = categories?[initialIndex.row] else {fatalError()}
@verebes1
verebes1 / RealmCascadeDeletion.swift
Last active March 6, 2024 19:47
Realm Cascade Deletion in Swift
import RealmSwift
import Realm
protocol CascadeDeleting {
func delete<S: Sequence>(_ objects: S, cascading: Bool) where S.Iterator.Element: Object
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
extension Realm: CascadeDeleting {
func delete<S: Sequence>(_ objects: S, cascading: Bool) where S.Iterator.Element: Object {