Skip to content

Instantly share code, notes, and snippets.

View dimohamdy's full-sized avatar
🏠
Working from home

Dimo Hamdy dimohamdy

🏠
Working from home
View GitHub Profile
@bocato
bocato / CacheService.swift
Last active November 13, 2019 08:37
Simple Cache Service implementation
import Foundation
/// Defines the CacheService errors
///
/// - encryptionFailed: the key encription has failed
/// - couldNotSaveData: the data could not be saved
/// - couldNotLoadData: the data could not be loaded
/// - raw: some system error, not previously defined
public enum CacheServiceError: Error {
case encryptionFailed
@aryaxt
aryaxt / Swift SequenceType GroupBy
Last active February 4, 2020 13:55
Swift Array GroupBy
extension Sequence {
func groupBy<G: Hashable>(closure: (Iterator.Element)->G) -> [G: [Iterator.Element]] {
var results = [G: Array<Iterator.Element>]()
forEach {
let key = closure($0)
if var array = results[key] {
array.append($0)
@bocato
bocato / CoordinatorExtended.swift
Last active May 19, 2020 20:11
An extended implementation of the Coordinator pattern.
import UIKit
/// An enum that defines an output to be passed on from
/// a child to it's parents over the responders Chain
public protocol CoordinatorOutput {}
/// An enum that defines an input to be passed on from
/// the parent to it's children
public protocol CoordinatorInput {}
@keicoder
keicoder / snippet.m
Created January 9, 2014 04:13
objective-c : assign and copy properties
assign and copy properties
Property with ’retain (or strong)’ attribute must be of object type
so, declare a property as assign if it has a primitive value
@property (nonatomic, assign) int someNumber;
You also use assign for structs, because they aren’t objects either
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@gabhi
gabhi / bogglesolver.java
Last active October 19, 2020 00:53
boggle solver java
package com.interview.graph;
import java.util.HashSet;
import java.util.Set;
/**
* http://www.careercup.com/question?id=14942063
*/
public class Boggle {
@tpae
tpae / Trie.swift
Last active May 9, 2021 20:59
Swift implementation of Trie Data Structure
import Foundation
class Node {
var val: String?
var parent: Node?
var children: [String: Node] = [:]
@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)
}
}
}
@feighter09
feighter09 / Fonts.swift
Last active June 25, 2021 19:24
Set global font for iOS app in one place
// MARK: - Swizzling
extension UIFont {
class var defaultFontFamily: String { return "Georgia" }
override public class func initialize()
{
if self == UIFont.self {
swizzleSystemFont()
}
}
@algal
algal / HTTPBasicAuthenticationSessionTaskDelegate.swift
Last active October 6, 2021 07:33
HTTP Basic Authentication in iOS
/*
Everyone on Stack Overflow does HTTP Basic Authentication on iOS by manually
building the HTTP headers.
This amounts to re-implementing HTTP.
Why? The Cocoa Touch URL Loading System aleady knows HTTP, and you can
configure your URLSession to supply HTTP Basic Authentication credentials
like so.
@steve228uk
steve228uk / SRCopyableLabel.swift
Last active February 26, 2022 21:08
Copyable UILabel
//
// SRCopyableLabel.swift
//
// Created by Stephen Radford on 08/09/2015.
// Copyright (c) 2015 Cocoon Development Ltd. All rights reserved.
//
import UIKit
class SRCopyableLabel: UILabel {