Skip to content

Instantly share code, notes, and snippets.

Avatar

Alejandro Ramirez janodev

View GitHub Profile
View GIFDownloader.h
//
// GIFDownloader.h
// TheJoysOfCode
//
// Created by Bob on 29/10/12.
// Copyright (c) 2012 Tall Developments. All rights reserved.
//
#import <Foundation/Foundation.h>
@janodev
janodev / chrome.sh
Created Nov 26, 2014
Use chrome.sh to launch a stable patched Chrome from the terminal. See https://devforums.apple.com/message/1076597#1076597
View chrome.sh
clang -dynamiclib -framework AppKit patch.m -o patch.dylib
env DYLD_INSERT_LIBRARIES=patch.dylib "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
@janodev
janodev / puke.m
Created Sep 8, 2011
Describing an object using introspection
View puke.m
+(NSString*) describe:(id) object {
NSMutableString *string = [NSMutableString stringWithString:@""];
unsigned int propertyCount;
objc_property_t *properties = class_copyPropertyList([object class], &propertyCount);
for (unsigned int i = 0; i < propertyCount; i++)
{
NSString *selector = [NSString stringWithCString:property_getName(properties[i])
encoding:NSUTF8StringEncoding] ;
@janodev
janodev / gist:1290641
Created Oct 16, 2011
Prevent the keyboard covering the view
View gist:1290641
/**
* Register keyboard notifications.
*/
-(void) registerKeyboardNotifications {
trace(@"register keyboard notifications");
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardWillShowNotification object:nil];
[center addObserver:self
@janodev
janodev / gist:1980044
Created Mar 5, 2012
O(n) performance types
View gist:1980044
Needs["PlotLegends`"]
Plot[{1, Log[n], n, n*Log[n], n^2, n!, 2^n}, {n, 0, 40},
PlotRange -> {0, 200}, PlotLabel -> "O(n) Performance types",
PlotLegend -> {"1", "Log[n]", "n", "n*Log[n]", "n^2", "n!", "2^n"},
LegendShadow -> None, LegendBorder -> None,
LegendPosition -> {0.9, -0.4}]
@janodev
janodev / gist:2983678
Created Jun 24, 2012
Asynchronous testing. Runs in CodeRunner.
View gist:2983678
// TEST ASYNCHRONOUS CODE
// Runs in Code Runner
#import <Foundation/Foundation.h>
@interface Test : NSObject
-(void)test1BooleanFlag;
-(void)test2BooleanFlagAndTimeLimit;
-(void)test3Semaphore;
@janodev
janodev / gist:3043614
Created Jul 3, 2012
timer with dispatch source
View gist:3043614
typedef void (^loop_work_t)(void);
@interface TaxiLoop : NSObject
@property (nonatomic,assign) loop_work_t block;
@property (nonatomic,assign) NSTimeInterval interval;
@property (nonatomic,assign) dispatch_source_t timerSource;
View gist:3649261
- (dispatch_queue_t)internalQueue
{
static dispatch_once_t onceToken;
static dispatch_queue_t *internalQueue;
dispatch_once(&onceToken, ^{
internalQueue = dispatch_queue_create...
});
return internalQueue;
}
@janodev
janodev / Array.m
Created Nov 1, 2012
NSFastEnumeration over a C array crashing with BAD_ACCESS
View Array.m
#import <Foundation/Foundation.h>
@interface Array : NSObject <NSFastEnumeration> {
id __strong *_objs;
NSUInteger _count;
}
@end
@implementation Array
@janodev
janodev / gist:4041078
Created Nov 8, 2012
Running code on a specified queue
View gist:4041078
// queue name
static const char* s_myqueue = "myqueue";
// return the specific queue
dispatch_queue_t my_queue() {
static dispatch_queue_t _q;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_q = dispatch_queue_create(s_myqueue, 0);
// sets the key/value data for the specified dispatch queue