Skip to content

Instantly share code, notes, and snippets.

@khanlou
khanlou / UIImageView+Network.h
Last active Jun 9, 2020
Quick and dirty UIImageView with networking
View UIImageView+Network.h
//
// UIImage+Network.h
// Fireside
//
// Created by Soroush Khanlou on 8/25/12.
//
//
#import <UIKit/UIKit.h>
@khanlou
khanlou / gist:6091415
Created Jul 26, 2013
Blocks are created on the stack frame that they are on
View gist:6091415
void (^block)();
if (condition) {
block = ^{
NSLog(@"some code");
};
} else {
block = ^{
NSLog(@"other code");
};
}
@khanlou
khanlou / download_all_cloud_app_files.py
Created Sep 2, 2013
This is a simple python script for downloading all of the files in your cloud app. Caveats: "bookmarks" can't be downloaded, so they'll be outputted in the log. All files will be downloaded into the same directory as the python script. It requires pycloudapp, which you can find here: https://github.com/originell/pycloudapp.
View download_all_cloud_app_files.py
# requires https://github.com/originell/pycloudapp
from cloudapp.cloud import Cloud
import urllib
mycloud = Cloud()
mycloud.auth("username", "password")
@khanlou
khanlou / gist:7156174
Created Oct 25, 2013
Scottish Wizard Voodoo Drink
View gist:7156174
@khanlou
khanlou / SKValueObject.h
Last active Aug 29, 2015
SKValueObject
View SKValueObject.h
//
// SKValueObject.h
// TinyType
//
// Created by Soroush Khanlou on 5/15/14.
// Copyright (c) 2014 Soroush Khanlou. All rights reserved.
//
#import <Foundation/Foundation.h>
View NSObject+IfClass.h
#import <Foundation/Foundation.h>
@interface NSObject (IfClass)
- (id)ifClass:(Class)aClass;
@end
View UIColor+LiteralConvertible.swift
import UIKit
extension UIColor: IntegerLiteralConvertible {
class func convertFromIntegerLiteral(value: IntegerLiteralType) -> UIColor {
let r = Double((value >> 16) & 0xFF) / 255;
let g = Double((value >> 8) & 0xFF) / 255;
let b = Double((value) & 0xFF) / 255;
return UIColor(red:r, green:g, blue:b, alpha:1.0)
}
View MappedArray.m
@interface MappedArray ()
@property (nonatomic) NSArray *backingArray;
@end
@implementation MappedArray
- (instancetype)initWithArray:(NSArray *)array transformationBlock:(id (^)(id object))block {
self = [super init];
View LazyMappedArray.m
@interface MappedArraySentinel : NSObject @end
@implementation MappedArraySentinel @end
@interface LazyMappedArray ()
@property (nonatomic) NSArray *originalArray;
@property (nonatomic) NSMutableArray *backingArray;
@property (nonatomic, copy) id (^block)(id);
@end
@khanlou
khanlou / Swift2.swift
Last active Nov 4, 2019
`any`, `all`, `none`, `first`, and `count` on SequenceType in Swift
View Swift2.swift
import Foundation
extension SequenceType {
@warn_unused_result
func any(@noescape predicate: (Self.Generator.Element) throws -> Bool) rethrows -> Bool {
for element in self {
let result = try predicate(element)
if result {
return true
}