Skip to content

Instantly share code, notes, and snippets.

View kastiglione's full-sized avatar

Dave Lee kastiglione

View GitHub Profile
@kastiglione
kastiglione / gcd_map.mm
Last active January 6, 2017 20:52
Concurrent map benchmark
#import <Foundation/Foundation.h>
#import <libkern/OSAtomic.h>
@interface NSArray (ConcurrentMap)
- (NSArray*)semaphore_map:(id (^)(id))block;
- (NSArray*)serial_map:(id (^)(id))block;
- (NSArray*)spinlock_map:(id (^)(id))block;
@end
@implementation NSArray (ConcurrentMap)
void (^myBlock)(int);
__block __weak __typeof__(myBlock) myRecursiveBlock = myBlock = ^(int x) {
if (x > 5) {
return;
} else {
myRecursiveBlock(x + 1);
}
};
myBlock(1);
@kastiglione
kastiglione / signalForSelector.m
Last active August 29, 2015 13:58 — forked from bobspryn/signalForSelector.m
Delegate dance
- (void)viewDidLoad
{
[super viewDidLoad];
@weakify(self);
self.exploreSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, mTCTableViewFrameWidth, 44)];
self.exploreSearchBar.placeholder = @"Search";
[self.exploreSearchBar setBackgroundImage:[UIImage squareImageWithColor:mTCLightTanColor dimension:1] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
self.tableView.tableHeaderView = self.exploreSearchBar;
@kastiglione
kastiglione / distinct.m
Last active August 29, 2015 14:06
Distinct
- (RACSignal *)distinct {
return [RACSignal defer:^{
NSMutableSet *set = [NSMutableSet new];
NSObject *nullObject = [NSObject new];
return [self filter:^(id x) {
x = x ?: nullObject;
BOOL distinct = ![set containsObject:x];
if (distinct) [set addObject:x];
b hitTest:withEvent:
break command add -s python -o 'print frame.EvaluateExpression("$arg1").description; return False'
void addMainThreadCheck(Class cls, SEL selector) {
#if DEBUG
void *symbol = dlsym(RTLD_DEFAULT, "__main_thread_add_check_for_selector");
if (!symbol) {
return;
}
void (*addCheck)(Class, SEL) = (__typeof__(addCheck))symbol;
addCheck(cls, selector);
#endif
}
@kastiglione
kastiglione / hdrtomod.sh
Created December 27, 2017 18:47
Get the module that matches a given header
# Examples:
# hdrtomod objc/runtime.h
# hdrtomod mach-o/dyld.h
# hdrtomod Foundation/Foundation.h
hdrtomod() {
readonly header=$1
echo "#import <$header>" \
| clang -fmodules -fsyntax-only -x objective-c -Xclang -ast-dump - \
| grep ImportDecl \
| egrep -o 'implicit \S+'
@kastiglione
kastiglione / wut.sh
Last active May 6, 2021 00:47
Help identify a raw error code
wut() {
readonly error_code=$1
local domain
for domain in posix mach; do
tput bold; echo $domain; tput sgr0
launchctl error $domain $error_code
done
tput bold; echo security; tput sgr0
security error $error_code
import re
import __builtin__
from itertools import islice
# See https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience-Funs.html
# breakpoint command add -F '_caller_is("theCaller")'
# breakpoint command add -F 'not _caller_is("theCaller")'
def _caller_is(name):
def check(frame, loc, _):
/*
* This is an example provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN