Skip to content

Instantly share code, notes, and snippets.

View numist's full-sized avatar

Scott Perry numist

View GitHub Profile
@numist
numist / infScr-1.0.0.js
Created November 29, 2011 07:20
generic lazyloader
/*
* Copyright © 2011 by Alexander Micek and Scott Perry
* Released under the MIT License; its terms are at the end of this file.
*
* This file depends on:
* • jQuery (tested against v1.4.2)
* http://jquery.com/
* • jQuery doTimeout (tested against v1.0)
* by "Cowboy" Ben Alman
* http://benalman.com/projects/jquery-dotimeout-plugin/
@numist
numist / jk-1.0.1.js
Created December 5, 2011 13:18
generic keyboard navigation
/*
* Copyright © 2011 by Scott Perry
* Released under the MIT License; its terms are at the end of this file.
*
* This file depends on:
* • jQuery (tested against v1.4.2)
* http://jquery.com/
*
* To use this file, ensure that:
* • jkInterestingElements() returns all available scroll targets
@numist
numist / jsLoad-1.0.0.js
Created December 5, 2011 19:17
javascript resource loader
/*
* Copyright © 2011 by Scott Perry
* Released under the MIT License; its terms are at the end of this file.
*
* This file depends on:
* • jQuery (tested against v1.4.2)
* http://jquery.com/
*
* Pages that include this file should load all their javascript files (other
@numist
numist / irsz.js
Created January 29, 2012 06:58
dynamically resize images to fit viewport (intelligently!)
/*
* Copyright © 2012 by Scott Perry
* Released under the MIT License; its terms are at the end of this file.
*
* This file depends on:
* • jQuery (tested against 1.7.1)
* http://jquery.com/
*
* Basic logic of this file:
* + if irsz_auto is true
@numist
numist / selector_belongsToProtocol.m
Last active April 26, 2022 07:16
Detect if a selector belongs to a protocol
/*
* Copyright © 2012 Scott Perry (http://numist.net)
*
* Released under the MIT License; its terms are at the end of this file.
*/
#import <objc/runtime.h>
/**
* `selector_belongsToProtocol` solves a common problem in proxy objects for delegates where selectors that are not part of the protocol may be unintentionally forwarded to the actual delegate.
//
// Generated on Sun Dec 02 00:41:17 -0800 2012.
// Contents copyright © 2012 Scott Perry (http://numist.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// 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 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
@numist
numist / main.m
Created January 30, 2013 18:31
After a lifetime of being humiliated by the static analyzer, it has a false positive and I am vindicated.
#import <Foundation/Foundation.h>
void doSomething(id obj) __attribute__((nonnull(1)));
void doSomething(id obj)
{
NSLog(@"%@", obj);
}
int main(int argc, const char * argv[])
@numist
numist / property_copyAttributeList.m
Last active December 12, 2015 08:19
Function returning something useful for passing directly into `class_addProperty` when copying properties from one class to another.
#import <objc/runtime.h>
// Lifted from https://github.com/numist/Debugger/blob/master/debugger.h
#define BailWithBlockUnless(exp,block) \
do { \
if (!(exp)) { \
return block(); \
} \
} while(0)
@numist
numist / stret.m
Last active December 13, 2015 16:48
I'm not proud of this, but it's the cleanest answer available to me right now.
// It would be a mistake to use this code and expect it to work at any point in the future.
NSNumber *encoding_requiresStret(const char *encoding) {
NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:encoding];
// This information is obviously available internally, but it's only publicly exposed here.
NSString *signatureDescription = [signature debugDescription];
BOOL isStret = [signatureDescription rangeOfString:@"is special struct return? YES"].location != NSNotFound;
BOOL isNotStret = [signatureDescription rangeOfString:@"is special struct return? NO"].location != NSNotFound;
@numist
numist / NSFastEnumeration.m
Created February 21, 2013 01:45
Annotated disassembly of NSFastEnumeration
function _MyEnumerator {
stackGuard = **__stack_chk_guard;
rax = objc_retain();
collection = rax;
memset(&fastEnumerationState, 0x0, 0x40);
rax = [collection retain];
collection = rax;
rax = [rax countByEnumeratingWithState:&fastEnumerationState objects:&stackbuf count:0x10];
initialStackbufCount = rax;
if (rax != 0x0) {