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
@sohayb
sohayb / ArrayDeepCopy.swift
Last active October 13, 2023 07:58
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@thebrankoo
thebrankoo / TBAsyncOperation.swift
Last active June 14, 2016 15:19
Simple custom NSOperation subclass that handles piece of work with completion block
import UIKit
typealias TBAsyncBlock = (completionHandler: dispatch_block_t ) -> Void
class TBAsyncOperation: NSOperation {
private var block : TBAsyncBlock!
private var _executing : Bool = false
override var executing : Bool {
@ericdke
ericdke / splitBy.swift
Last active July 10, 2023 09:55
Swift: split array by chunks of given size
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
extension Array {
func splitBy(subSize: Int) -> [[Element]] {
return 0.stride(to: self.count, by: subSize).map { startIndex in
let endIndex = startIndex.advancedBy(subSize, limit: self.count)
return Array(self[startIndex ..< endIndex])
}
}
}
@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 {
@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()
}
}
IFS=$'\n'
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
PATH=${PATH}:/usr/local/bin
function checkFileExists () {
if [[ ! -e "$1" ]]; then
echo "Required file unable to be found: $1"
exit 1
fi
@evgenyneu
evgenyneu / concatenate_swift_files.sh
Last active March 27, 2023 00:35
Concatenates all Swift files into one file. Used in Xcode to build a single swift distributive file. In Xcode it is done by creating an external build tool configuration.
#!/bin/bash
#
# Combines *.swift files into a single file. Used in Xcode to build a single swift distributive file.
#
# Here is how to use it in Xcode:
#
# 1. Create an "External build system" target.
# 2. Click "Info" tab in target settings.
# 3. In "Build Tool" field specify the path to this script file, for example: $PROJECT_DIR/scripts/concatenate_swift_files.sh
@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 {
//
// SimpleScrollingStack.swift
// A super-simple demo of a scrolling UIStackView in iOS 9
//
// Created by Paul Hudson on 10/06/2015.
// Learn Swift at www.hackingwithswift.com
// @twostraws
//
import UIKit
@JadenGeller
JadenGeller / Init Bool With Int.swift
Created March 23, 2015 07:48
Cast Int to Bool in Swift
extension Bool {
init<T : IntegerType>(_ integer: T){
self.init(integer != 0)
}
}
// Now you can do this
let x = Bool(5) // true
let y = Bool(-1) // true
let z = Bool(0) // false