Skip to content

Instantly share code, notes, and snippets.

View kastiglione's full-sized avatar

Dave Lee kastiglione

View GitHub Profile
@kastiglione
kastiglione / helpers.swift
Last active June 2, 2022 02:02
Swift helpers, and the lldb setup to use them. Presented @ SLUG https://speakerdeck.com/kastiglione/advanced-debugging-and-swift
extension UIView {
/// Example: call someView.nudge(0, 30)
func nudge(_ dx: CGFloat, _ dy: CGFloat) {
self.frame = self.frame.offsetBy(dx: dx, dy: dy)
CATransaction.flush()
}
}
extension UIView {
/// Example: po UIView.root
@kastiglione
kastiglione / aliases.lldb
Last active May 29, 2019 04:09
Mnemonic lldb commands
# Calling functions
expression CATransaction.flush()
call CATransaction.flush()
# Assigning variables
expression didLoad = true
command alias assign expression --
assign didLoad = true
# Symbolic breakpoints
/*
* 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
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, _):
@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
@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+'
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
}
b hitTest:withEvent:
break command add -s python -o 'print frame.EvaluateExpression("$arg1").description; return False'
@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];
@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;