Skip to content

Instantly share code, notes, and snippets.

View shirakaba's full-sized avatar
💭
🧙‍♂️

Jamie Birch shirakaba

💭
🧙‍♂️
View GitHub Profile
@quietcricket
quietcricket / gist:1593632
Created January 11, 2012 07:58
Fuzzy string match objective-c (Levenshtein Distance Algorithm)
-(float)compareString:(NSString *)originalString withString:(NSString *)comparisonString
{
// Normalize strings
[originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[comparisonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
originalString = [originalString lowercaseString];
comparisonString = [comparisonString lowercaseString];
// Step 1 (Steps follow description at http://www.merriampark.com/ld.htm)
@TiernanKennedy
TiernanKennedy / Instantiation
Created March 26, 2013 18:39
New Obj C Syntax
// Updates to LLVM give us better instantiation methods
NSNumber *n1 = @1000; // [NSNumber numberWithInt:1000]
NSNumber *n2 = @3.1415926; // [NSNumber numberWithDouble:3.1415926]
NSNumber *c = @'c'; // [NSNumber numberWithChar:'c']
NSNumber *b = @YES; // [NSNumber numberWithBool:YES]
Arrays
// before
NSArray *words = [NSArray arrayWithObjects:@"list", @"of", @"words", nil];
@markd2
markd2 / runtime.m
Created July 9, 2013 20:55
Objective-C runtime metadata dumper.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import "typestring.h"
// clang -g -fobjc-arc -Wall -framework Foundation -o runtime typestring.m runtime.m
// Runtime reference, at least until Apple breaks the link
// http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html
@mikeash
mikeash / runtime-class.m
Created November 22, 2013 16:46
Creating a usable class purely at runtime using the Objective-C runtime APIs.
// clang -fobjc-arc -framework Foundation runtime-class.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Person : NSObject
- (id)initWithFirstName: (NSString *)firstName lastName: (NSString *)lastName age: (NSUInteger)age;
@alloy
alloy / STFU_UIAccessibilityLoader.m
Last active October 17, 2021 04:31
(If you too like to live dangerously) this will get rid of the following error message when running on the iOS Simulator: `Cannot find executable for CFBundle <CertUIFramework.axbundle>`
// When the `accessibility inspector' is enabled on the iOS Simulator the private `UIAccessibility'
// framework is loaded. In turn it will try to load a list of bundles amongst which is one that has
// only resources, no executable. This leads to `CFBundleLoadExecutableAndReturnError' logging this
// offending error message.
//
// This code omits the `SDK_ROOT/System/Library/AccessibilityBundles/CertUIFramework.axbundle'
// bundle from ever being attempted to load.
//
// This code is available under the MIT license: http://opensource.org/licenses/MIT
//
@mediavrog
mediavrog / JapaneseCharacter.java
Last active August 26, 2020 09:03
Simple string conversion from Hiragana to Katakana and vice versa. Uses the JapaneseCharacter class from Duane J. May and combines it with a simple Utility class method to perform the actual conversion.
/**
* JapaneseCharacter contains static functions to do various tests
* on characters to determine if it is one of the various types of
* characters used in the japanese writing system.
* <p/>
* There are also a functions to translate between Katakana, Hiragana,
* and Romaji.
*
* @author Duane J. May <djmay@mayhoo.com>
* @version $Id: JapaneseCharacter.java,v 1.2 2002/04/20 18:10:24 djmay Exp $
@sciolist
sciolist / CorsProxy.swift
Created July 8, 2015 08:07
GCDWebServer Cors proxy
import GCDWebServer
class CorsProxy {
init(webserver : GCDWebServer!, urlPrefix: String) {
var prefix =
(urlPrefix.hasPrefix("/") ? "" : "/")
+ urlPrefix
+ (urlPrefix.hasSuffix("/") ? "" : "/")
let pattern = "^" + NSRegularExpression.escapedPatternForString(prefix) + ".*"
@dermotmcguire
dermotmcguire / A4 CSS page template.markdown
Created September 14, 2015 08:48
A4 CSS page template
@paulirish
paulirish / what-forces-layout.md
Last active May 23, 2024 14:12
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@bazhenovc
bazhenovc / v8_wrap_class.cpp
Created September 28, 2015 15:25 — forked from mythagel/v8_wrap_class.cpp
Complete example of binding a C++ class with Google V8.
/*
* v8_wrap_class.cpp
*
* Created on: 14/01/2013
* Author: nicholas
* License: public domain
*/
/* CMakeLists.txt
project(v8_wrap_class)