Skip to content

Instantly share code, notes, and snippets.

@fjolnir
fjolnir / FStaticNavigationBar.m
Last active August 29, 2015 14:24
Caveat: breaks if you start an interactive pop transition and change your mind.
@implementation FStaticNavigationBar {
__weak UIView *_navView;
}
- (void)layoutSubviews
{
[super layoutSubviews];
_navView.hidden = _staticTitleView != nil;
if(_staticTitleView) {
@import ObjectiveC.runtime;
#import "LETextField.h"
@interface LETextField () <UITextFieldDelegate>
@end
@implementation LETextField {
__weak id<UITextFieldDelegate> _realDelegate;
}
#import <Foundation/Foundation.h>
#define Attempt(...) ({ \
NSError *__err; \
typeof([__VA_ARGS__ error:NULL]) __result = [__VA_ARGS__ error:&__err]; \
if(!__result) \
@throw __err; \
__result; \
})
// @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
// 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);
@fjolnir
fjolnir / NSObject+BlockObservation.h
Last active August 29, 2015 14:19 — forked from andymatuschak/NSObject+BlockObservation.h
Made the thing build under ARC
//
// 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;
// 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")
@fjolnir
fjolnir / LENumberFormatter.h
Last active April 18, 2019 02:52
Abbreviates numbers like: 1234567 to 1m 234k 567, 1.23m, 123万4千5百67, 123.4万 etc..
@import Foundation;
typedef NS_ENUM(NSUInteger, LENumberFormatterAbbreviationStyle) {
kLEAbbreviateShort, // 2.5m
kLEAbbreviateNormal // 2m 5k
};
@interface LENumberFormatter : NSNumberFormatter
@property(nonatomic) BOOL abbreviateLargeNumbers;
@property(nonatomic) LENumberFormatterAbbreviationStyle abbreviationStyle;
#!/bin/bash
PASTE_BUF=~/.cutpastebuf
function copy() {
echo "" > $PASTE_BUF
for arg in $@; do
echo "COPY:$arg" >> $PASTE_BUF
done
}
// 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);