Skip to content

Instantly share code, notes, and snippets.

@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@mayoff
mayoff / gist:3384659
Created August 18, 2012 05:24
Make objc_msgSend without a cast give a warning
#define objc_msgSend(...) (objc_msgSend_without_cast())(__VA_ARGS__)
static inline id (*objc_msgSend_without_cast(void))(id, SEL, ...) __attribute__((deprecated("objc_msgSend must be cast to the correct type")));
static inline id (*objc_msgSend_without_cast(void))(id, SEL, ...) {
return objc_msgSend;
}
@proger
proger / iosdtrace.md
Last active March 4, 2024 08:01
iosdtrace.md

DTrace Sessions for iOS Development

DTrace is a comprehensive dynamic tracing framework created by Sun Microsystems for troubleshooting kernel and application problems on production systems in real time. Originally developed for Solaris, it has since been released to open source community in 2004 and has been ported to several other Unix systems.

Apple ported DTrace for OS X Leopard, including a GUI called Instruments and made it co-exist with the existing legacy stack of performance troubleshooting toolkits.

We are going to tame this beast to help us hunt down and eliminate all sorts of application and system-wide troubles when doing development of iOS and OS X apps.

the chat

@steipete
steipete / gist:3713233
Created September 13, 2012 09:39
I often use dispatch queues for locking, and this function just makes life SO MUCH EASIER. Accidental deadlocks in more complex code paths are a PITA otherwise. But Apple deprecated dispatch_get_current_queue with iOS6?
nline void pspdf_dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_block_t block) {
dispatch_get_current_queue() == queue ? block() : dispatch_sync(queue, block);
}
@stuartcarnie
stuartcarnie / main.m
Created September 16, 2012 04:30
tail call with fake msgSend in Objective C
#import <Foundation/Foundation.h>
#import <objc/message.h>
extern id fake_msgSend(id, SEL, int) __attribute__((noinline));
@interface Foo : NSObject
- (id)foo:(int)n;
@end
@sydneyitguy
sydneyitguy / http_status_code
Last active October 12, 2015 14:38
Rails HTTP Status Code to Symbol Mapping
Status Code Status Message Symbol
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
201 Created :created
202 Accepted :accepted
@mattt
mattt / NSHipster-Call-For-Tricks-And-Tips.md
Created November 26, 2012 13:59
NSHipster Call for Tips & Tricks!

Howdy howdy, NSHipsters!

If you alloc init an NSCalendar, you'll notice that New Year's Eve falls on a Monday this year, a.k.a. "the day NSHipster is published every week". What fun!

So in celebration of the upcoming year++, I thought it'd be fun to compile a list of some of your favorite tips and tricks of the trade. Submit your favorite piece of Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

Here are a few examples of the kind of things I'd like to see:

@atg
atg / gist:4179737
Created December 1, 2012 00:24
(requires Objective-C++)
typedef id (^Tuple)(int i);
#define MUT_INTERNAL_VAARG_COUNT(...) (sizeof((__strong id[]){__VA_ARGS__}) / sizeof(__strong id))
#define TUPLE(...) ({ \
const unsigned mut_n = MUT_INTERNAL_VAARG_COUNT(__VA_ARGS__); \
struct { __strong id mut_objs[mut_n]; } mut_innards = {{ __VA_ARGS__ }}; \
^ id (int mut_i) { \
return (mut_i < 0 || mut_i >= mut_n) ? nil : mut_innards.mut_objs[mut_i]; \
}; \
@Coneko
Coneko / gist:4234842
Created December 7, 2012 17:24
How to get your code to run on different cores in OSX / iOS without CHUD.
#import <pthread.h>
#import <mach/thread_act.h>
// These two functions are declared in mach/thread_policy.h, but are commented out.
// They are documented here: https://developer.apple.com/library/mac/#releasenotes/Performance/RN-AffinityAPI/_index.html
kern_return_t thread_policy_set(
thread_t thread,
thread_policy_flavor_t flavor,
thread_policy_t policy_info,
mach_msg_type_number_t count);
@joshaber
joshaber / gist:4238342
Created December 8, 2012 02:54
ReactiveCocoa stopwatch with reset
self.startButton.rac_command = [RACCommand command];
self.stopButton.rac_command = [RACCommand command];
self.resetButton.rac_command = [RACCommand command];
static const CGFloat interval = 0.01;
__unsafe_unretained id weakSelf = self;
// Signal id -> Signal Signal Number
// Map each click of the start button to a signal that fires at our interval
// and stops when the stop button's clicked.
id<RACSignal> start = [self.startButton.rac_command map:^(id _) {