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
@johnnyclem
johnnyclem / gist:11015360
Created April 17, 2014 22:35
CMSamplebufferRef to CIImage
CVImageBufferRef cvImage = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:cvImage];
@martin-nearsoft
martin-nearsoft / ThingSpecs.m
Last active April 14, 2024 04:26
Objective-C Unit Testing - Specs
#define EXP_SHORTHAND
#import <Specta/Specta.h> // A light-weight TDD / BDD framework for Objective-C & Cocoa.
#import <Expecta/Expecta.h> // A Matcher Framework for Objective-C/Cocoa
#import <OCMock/OCMock.h> // An Objective-C implementation of mock objects
#import <OCMock/NSInvocation+OCMAdditions.h>
// 'beforeEach' and 'afterEach' are also aliased as 'before' and 'after' respectively.
// 'describe' is also aliased as 'context'.
// 'it' is also aliased as 'example' and 'specify'.
@seanlilmateus
seanlilmateus / channel.swift
Last active November 22, 2017 14:02
swift Go like channels
import Foundation
// Playground - noun: a place where people can play
class Channel<T> {
var stream: Array<T>
let queue: dispatch_queue_t
let semaphore: dispatch_semaphore_t
init() {
self.stream = []
@d-ronnqvist
d-ronnqvist / re-enable delete action.markdown
Last active January 6, 2024 07:23
How to break (and re-enable) the native accessibility "delete" action for table views

If you've haven't seen it before, there is a cool accessibility feature in UITableView that allows the user to toggle between different actions. It's really very elegant and it's a powerful and convenient implementation for VoiceOver users on iOS. One could say that it's the VoiceOver version of the swipe-to-delete feature.

To try it out yourselves, open one of the built in apps like Mail or Notes and turn on VoiceOver. If you are afraid to accidentally delete some of your important notes or email, you can also create a new Master-Detail Application in Xcode and run it on your device. Navigate to one of the cells and use the "Rotor" (rotate with two fingers on the screen) to find the "Actions" item. Now you can swipe up and down do toggle between "Activate Item (default action)" and "Delete". If you now double tap, the cell gets deleted instead of selected.

image with actions

This is the default behavior and you get this accessibility out of the box with UITableView.

@DenTelezhkin
DenTelezhkin / gist:beab675d853fcd2fd464
Created July 22, 2014 15:02
Multipart-form PUT request for image upload. NSURLSession, iOS 7
+(void)uploadUserPhoto:(UIImage *)image
success:(void (^)(void))success
failure:(FailureBlock)failure
{
GTSessionManager * manager = [GTSessionManager manager];
NSString* tmpFilename = [NSString stringWithFormat:@"%f", [NSDate timeIntervalSinceReferenceDate]];
NSURL* tmpFileUrl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:tmpFilename]];
NSString * query = [NSString stringWithFormat:@"%@user?auth_token=%@",[manager.baseURL absoluteString],[[UserManager shared] authToken]];
@kirsteins
kirsteins / Array -> UnsafeMutablePointer -> Array
Last active October 11, 2022 12:25
Array -> UnsafeMutablePointer -> Array
var initalArray = [1, 2, 3]
let pointer: UnsafeMutablePointer<Int> = UnsafeMutablePointer(initalArray)
let arrary = Array(UnsafeBufferPointer(start: pointer, count: initalArray.count))
@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)
@JadenGeller
JadenGeller / Semaphore.swift
Last active May 16, 2017 15:51
Swift Semaphore
struct Semaphore {
let semaphore: dispatch_semaphore_t
init(value: Int = 0) {
semaphore = dispatch_semaphore_create(value)
}
// Blocks the thread until the semaphore is free and returns true
// or until the timeout passes and returns false
@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
//
// 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