Skip to content

Instantly share code, notes, and snippets.

$ script/plugin install [email protected]:contrast/uploadify-s3.git
Initialized empty Git repository in ../vendor/plugins/uploadify-s3/.git/
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
@interface NSString (A)
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target options:(NSStringCompareOptions)options range:(NSRange)searchRange withHandler:(NSString * (^)(NSString * occurrence, NSRange rangeOfString))replaceBlock;
@end
@implementation NSString (A)
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target options:(NSStringCompareOptions)options range:(NSRange)searchRange withHandler:(NSString * (^)(NSString * occurrence, NSRange rangeOfString))replaceBlock;
{
NSMutableString * ms = [[self mutableCopy] autorelease];
int main(int argc, const char * argv[])
{
@autoreleasepool {
// Create a pretend Desktop and Documents folder
NSString * desktopFolderPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Desktop"];
NSString * documentsFolderPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Documents"];
[[NSFileManager defaultManager] createDirectoryAtPath:desktopFolderPath withIntermediateDirectories:NO attributes:nil error:nil];
[[NSFileManager defaultManager] createDirectoryAtPath:documentsFolderPath withIntermediateDirectories:NO attributes:nil error:nil];
int main(int argc, const char * argv[])
{
@autoreleasepool {
// Create a pretend Desktop and Documents folder
NSString * desktopFolderPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Desktop"];
NSString * documentsFolderPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Documents"];
[[NSFileManager defaultManager] createDirectoryAtPath:desktopFolderPath withIntermediateDirectories:NO attributes:nil error:nil];
[[NSFileManager defaultManager] createDirectoryAtPath:documentsFolderPath withIntermediateDirectories:NO attributes:nil error:nil];
void __AllowOnceEvery(double seconds, void (^block)(void), NSTimeInterval * lastTime)
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
if (now - *lastTime > seconds) {
*lastTime = now;
block();
}
}
@swillits
swillits / Private Launch Services Flags
Created August 29, 2012 16:56
Private Launch Services Flags
0 2 4 06105 (SMW)
0 2 4 04285 (FFV)
1 0 7 0488e (ML TE)
1 4 3 0488e (L TE)
0 4 1 0408e (SF)
1 0 1 0408e (BT64)
0 4 1 0408e (BT32)
0 0 5 0408e (MQD iOS)
1 4 1 0488e (App Store)
@interface GCDCoalescent : NSObject
- (void)dispatchOn:(dispatch_queue_t)queue after:(double)seconds block:(dispatch_block_t)block;
@end
@implementation GCDCoalescent
{
uint64_t count;
}
@swillits
swillits / gist:5184433
Last active December 15, 2015 01:59
Coalesced Blocks
@interface GCDCoalescent : NSObject
- (void)dispatchOn:(dispatch_queue_t)queue after:(double)seconds block:(dispatch_block_t)block;
@end
@implementation GCDCoalescent
{
uint64_t count;
}
dispatch_source_t dispatch_coalesce_source_create(dispatch_queue_t queue)
{
dispatch_source_t src = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_resume(src);
return src;
}
void dispatch_coalesce(dispatch_source_t src, double time, void (^block)(void))
{
void MethodSwizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if (class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, newMethod);
}
}