Skip to content

Instantly share code, notes, and snippets.

@khanlou
khanlou / UIImageView+Network.h
Last active June 9, 2020 07:34
Quick and dirty UIImageView with networking
//
// UIImage+Network.h
// Fireside
//
// Created by Soroush Khanlou on 8/25/12.
//
//
#import <UIKit/UIKit.h>
@khanlou
khanlou / gist:6091415
Created July 26, 2013 19:06
Blocks are created on the stack frame that they are on
void (^block)();
if (condition) {
block = ^{
NSLog(@"some code");
};
} else {
block = ^{
NSLog(@"other code");
};
}
@khanlou
khanlou / download_all_cloud_app_files.py
Created September 2, 2013 14:26
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.
# requires https://github.com/originell/pycloudapp
from cloudapp.cloud import Cloud
import urllib
mycloud = Cloud()
mycloud.auth("username", "password")
@khanlou
khanlou / gist:7156174
Created October 25, 2013 15:07
Scottish Wizard Voodoo Drink
@khanlou
khanlou / SKValueObject.h
Last active August 29, 2015 14:01
SKValueObject
//
// SKValueObject.h
// TinyType
//
// Created by Soroush Khanlou on 5/15/14.
// Copyright (c) 2014 Soroush Khanlou. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
@interface NSObject (IfClass)
- (id)ifClass:(Class)aClass;
@end
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)
}
@interface MappedArray ()
@property (nonatomic) NSArray *backingArray;
@end
@implementation MappedArray
- (instancetype)initWithArray:(NSArray *)array transformationBlock:(id (^)(id object))block {
self = [super init];
@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 November 4, 2019 23:14
`any`, `all`, `none`, `first`, and `count` on SequenceType in 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
}