This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGRect { | |
var isAligned: Bool { | |
get { | |
return origin.x.isAligned && origin.y.isAligned && size.width.isAligned && size.height.isAligned | |
} | |
} | |
} | |
extension CGFloat { | |
var isAligned: Bool { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note that this checker is always running, even when the app is in the background (where it doesn't matter if the main thread is blocked) | |
// You'll have to add more code if you don't want the checker to run while the app is in the background | |
final class ANRChecker { | |
private let ANRThreshold: CFTimeInterval = 5 | |
// This variable may be accessed from multiple threads at the same time. It won't cause issues, but if you want prevent the thread sanitizer from complaining, you can add locking around it or w/e | |
private lazy var lastResponseTime: CFTimeInterval = CACurrentMediaTime() | |
func beginChecking() { | |
updateLastResponseTime() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in asm_atoi.S... | |
fbld (%rdi) | |
fstpl -8(%rbp) | |
movq -8(%rbp), %xmm0 | |
// in main.c... | |
int main(int argc, const char * argv[]) { | |
const char *c = "2384"; | |
char b[10] = {0}; | |
for (int i = 0; i < sizeof(c); i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
class ViewPool { | |
private var freeViews: [UIView] = [] | |
private var allViews: [UIView] = [] | |
init() { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(id)retain | |
{ | |
NSIncrementExtraRefCount(self); | |
return self; | |
} | |
-(void)release | |
{ | |
if(NSDecrementExtraRefCountWasZero(self)) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'mechanize' | |
require 'parallel' | |
def should_follow_url(h) | |
return [ | |
h.size > 0, | |
!h.include?(".."), | |
!h.include?("//"), |