This file contains 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 ObjectiveC.runtime; | |
#import "LETextField.h" | |
@interface LETextField () <UITextFieldDelegate> | |
@end | |
@implementation LETextField { | |
__weak id<UITextFieldDelegate> _realDelegate; | |
} |
This file contains 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/Foundation.h> | |
#define Attempt(...) ({ \ | |
NSError *__err; \ | |
typeof([__VA_ARGS__ error:NULL]) __result = [__VA_ARGS__ error:&__err]; \ | |
if(!__result) \ | |
@throw __err; \ | |
__result; \ | |
}) |
This file contains 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
// @property(nonatomic) int foo; | |
; Function Attrs: nounwind ssp uwtable | |
define internal void @"\01-[Obj setFoo:]"(%0* nocapture %self, i8* nocapture readnone %_cmd, i32 %foo) #1 { | |
entry: | |
%ivar = load i64* @"OBJC_IVAR_$_Obj._foo", align 8, !invariant.load !5 | |
%0 = bitcast %0* %self to i8* | |
%add.ptr = getelementptr inbounds i8* %0, i64 %ivar | |
%1 = bitcast i8* %add.ptr to i32* | |
store i32 %foo, i32* %1, align 4, !tbaa !6 | |
ret void |
This file contains 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
// Ref: http://clang.llvm.org/doxygen/ConvertUTF_8c_source.html | |
#import <Foundation/Foundation.h> | |
static uint8_t const firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; | |
static uint32_t const byteMark = 0x80; | |
static uint32_t const byteMask = 0xBF; | |
int main(int argc, char *argv[]) { | |
unsigned int input = strtol("0001F30D", NULL, 16); | |
This file contains 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
// | |
// NSObject+BlockObservation.h | |
// Version 1.0 | |
// | |
// Andy Matuschak | |
// andy@andymatuschak.org | |
// Public domain because I love you. Let me know how you use it. | |
// | |
@import Foundation; |
This file contains 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
// Returns results sorted by rank | |
var search = function(searchString, haystack) { | |
// Split search string into an array of terms (grouping together quoted strings) | |
var terms = searchString.match(/"(?:\\"|\\\\|[^"])*"|\S+/g).map(function(term) { | |
return term.replace(/^"/, "").replace(/"$/, ""); | |
}); | |
// Calculates the rank for a single value | |
var calculateRank = function(value) { | |
if(typeof value == "number") |
This file contains 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; | |
typedef NS_ENUM(NSUInteger, LENumberFormatterAbbreviationStyle) { | |
kLEAbbreviateShort, // 2.5m | |
kLEAbbreviateNormal // 2m 5k | |
}; | |
@interface LENumberFormatter : NSNumberFormatter | |
@property(nonatomic) BOOL abbreviateLargeNumbers; | |
@property(nonatomic) LENumberFormatterAbbreviationStyle abbreviationStyle; |
This file contains 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
#!/bin/bash | |
PASTE_BUF=~/.cutpastebuf | |
function copy() { | |
echo "" > $PASTE_BUF | |
for arg in $@; do | |
echo "COPY:$arg" >> $PASTE_BUF | |
done | |
} |
This file contains 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
// Ray intersection point = ro + rd*t | t > 0 | |
float sphere(vec3 center, float r, vec3 ro, vec3 rd) | |
{ | |
vec3 ray = ro - center; | |
float c = dot(ray, ray) - (r*r); | |
float b = dot(rd, ray); | |
float d = b*b - c; | |
float t = -b - sqrt(abs(d)); | |
float st = step(0.0, min(t, d)); | |
return mix(-1.0, t, st); |