Skip to content

Instantly share code, notes, and snippets.

#import "fishhook.h" // from https://github.com/facebook/fishhook
// Replace write and writev, the two "chokepoint" functions that writes to stderr and stdout will probably pass through
static int (*originalWritev)(int fd, const struct iovec *v, int n);
static int (*originalWrite)(int fd, const void *buf, size_t size);
void checkForBadConstraintsMessage(int fd, const char *string, size_t size) {
if (strnstr(string, "UIViewAlertForUnsatisfiableConstraints", size)) {
// Write it to the console anyways before crashing
originalWrite(fd, string, size);
extension CGRect {
var isAligned: Bool {
get {
return origin.x.isAligned && origin.y.isAligned && size.width.isAligned && size.height.isAligned
}
}
}
extension CGFloat {
var isAligned: Bool {
func iterateOverViewAndSubviews(view: UIView, block: (UIView) -> Void) {
block(view)
for subview in view.subviews {
iterateOverViewAndSubviews(view: subview, block: block)
}
}
func runCheckers() {
if let keyWindow = UIApplication.shared.keyWindow {
iterateOverViewAndSubviews(view: keyWindow) { (view) in
static dispatch_source_t msp;
static void func() {
msp = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, NULL, DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
dispatch_source_set_event_handler(msp, ^{
unsigned long l = dispatch_source_get_data(msp);
NSLog@"%@", @(l));
});
}
@michaeleisel
michaeleisel / main.m
Last active November 24, 2018 02:53
#import <sys/sysctl.h>
static CFTimeInterval processStartTime() {
size_t len = 4;
int mib[len];
struct kinfo_proc kp;
sysctlnametomib("kern.proc.pid", mib, &len);
mib[3] = getpid();
len = sizeof(kp);
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
default_username='michaeleisel'
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
#!/usr/bin/ruby
=begin
#### DIRECTIONS ####
Run `/usr/bin/ruby savings.rb <path to executable>`, and it will report the estimated savings for that executable.
*However*, the executable cannot have been downloaded from the app store (or else it will already be the encrypted version, and we can't unencrypt it to calculate the savings)
Also, it should be a binary for a specific architecture, and not a fat binary. I'd assume arm64 would be way to go.
How to get an arm64 binary that is not encrypted?
Run Product -> Archive in Xcode, then export the app Ad Hoc, and for the device to thin for, select a device with arm64 (an iPhone 5s or above)
Unzip the .ipa file that was exported, and Payload/<app name>.app/<app name> should be the executable that you want
These are just common sets of args. For your app, it may vary. But these should cover most of the size of the __TEXT segment
For an app with just Objective-C:
-Wl,-rename_section,__TEXT,__text,__MY_TEXT,__text
-Wl,-rename_section,__TEXT,__stubs,__MY_TEXT,__stubs
-Wl,-rename_section,__TEXT,__stub_helper,__MY_TEXT,__stub_helper
-Wl,-rename_section,__TEXT,__objc_classname,__MY_TEXT,__objc_classname
-Wl,-rename_section,__TEXT,__cstring,__MY_TEXT,__cstring
-Wl,-rename_section,__TEXT,__objc_methname,__MY_TEXT,__objc_methname
#!/usr/bin/ruby
raise "Usage: ./args.rb <path to executable>" unless ARGV.size == 1
new_seg_name = "__MY_TEXT"
binary = ARGV.first
sect_regex = /\s*Section (\S+)/
sects = `xcrun size -x -l -m #{binary}`.split("\n").drop_while do |line|
// HOW TO USE:
// This makes debugging auto-layout easier by telling you the variable names of the views in your constraints
// Search for "hasPrefix:" in this file and fill in the prefix for your app
// FYI: in order to do this, it swizzles -description and -debugDescription of NSLayoutConstraint in a +load method when you start the app
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@interface UIView (SCIvars)