Skip to content

Instantly share code, notes, and snippets.

@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);
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));
});
}
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
extension CGRect {
var isAligned: Bool {
get {
return origin.x.isAligned && origin.y.isAligned && size.width.isAligned && size.height.isAligned
}
}
}
extension CGFloat {
var isAligned: Bool {
#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);
// 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()
// 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++) {
import Foundation
import UIKit
class ViewPool {
private var freeViews: [UIView] = []
private var allViews: [UIView] = []
init() {
}
-(id)retain
{
NSIncrementExtraRefCount(self);
return self;
}
-(void)release
{
if(NSDecrementExtraRefCountWasZero(self))
{
#!/usr/bin/ruby
require 'mechanize'
require 'parallel'
def should_follow_url(h)
return [
h.size > 0,
!h.include?(".."),
!h.include?("//"),