Skip to content

Instantly share code, notes, and snippets.

View kolinkrewinkel's full-sized avatar

Kolin Krewinkel kolinkrewinkel

View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@jwilling
jwilling / gist:4186817
Last active March 5, 2023 22:01
Lets help improve AppKit.

Is AppKit causing you frustration? Instead of just complaining about it, lets try to make it better by compiling a list of specific problems with AppKit. Leave a comment below, and I'll include it in the list.


##NSView##

  • NSView does not have the ability to set an affine transform (rdar://15608609)
  • Controls that have cells (such as NSTextField) do not respond properly when layer-backed. Take NSButton as an example. When not layer-backed, it will animate properly using the animator proxy. When layer-backed, using the animator proxy breaks focus rings (they jump to destination immediately). Currently, directly manipulating the layer of a cell-based control is not supported (and will lead to a broken interface), but is much needed. (rdar://15608822)

##NSViewController##

  • NSViewController could be more useful. It has -loadView but no other lifecycle methods. (rdar://15608948)
@JaviSoto
JaviSoto / gist:5703432
Created June 4, 2013 03:46
Natural String Sorting
@implementation NSString (JSRemoveIrrelevantTags)
- (NSString *)js_stringByRemovingIrrelevantTags
{
NSMutableString *filteredString = [NSMutableString string];
NSSet *filteredLinguisticTags = [NSSet setWithArray:@[NSLinguisticTagDeterminer, NSLinguisticTagPreposition]];
[self enumerateLinguisticTagsInRange:NSMakeRange(0, self.length)
scheme:NSLinguisticTagSchemeLexicalClass
@jordanekay
jordanekay / gist:5703459
Last active December 18, 2015 01:19
Naturally sorting a list of titles in Cocoa
#import <Foundation/Foundation.h>
@implementation NSString (JEKNormalization)
- (NSString *)jek_normalizedString
{
__block NSString *normalizedString = self;
[self enumerateLinguisticTagsInRange:NSMakeRange(0, self.length) scheme:NSLinguisticTagSchemeLexicalClass options:~NSLinguisticTaggerOmitWords orthography:nil usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
if (tag == NSLinguisticTagDeterminer && tokenRange.location == 0) {
normalizedString = [self substringFromIndex:tokenRange.length + 1];
@mattt
mattt / alfred-wwdc.url
Last active September 25, 2018 10:01
Alfred ASCIIwwdc Web Search
alfred://customsearch/Search%20WWDC%20Sessions/wwdc/utf8/noplus/http://asciiwwdc.com/search?q={query}
@cdl
cdl / colorjs.js
Last active December 30, 2015 16:09
// colorjs.js
// @description An implementation of how I did the color changing background
// on my site. Essentially, I'm using the HSLA color space because
// it makes it really easy to control the general lightness of a
// color and maintain it throughout a bunch of hues. For instance:
// take a look at http://cl.ly/SrT1. Notice how all the colors
// have the same contrast? That's because all that's changed between
// them is the hue values. That's what we're replicating here.
//
// @requirements jQuery –– http://jquery.com/
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.
@jordanekay
jordanekay / gist:8855193
Created February 7, 2014 00:15
Debug -[UIScrollView setContentOffset:animated:] by changing duration
NSTimeInterval duration = 3.0;
SEL selector = @selector(_setContentOffsetAnimationDuration:);
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[scrollView methodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:scrollView];
[invocation setArgument:&duration atIndex:2];
[invocation invoke];
[scrollView setContentOffset:contentOffset animated:YES]
@indragiek
indragiek / LTClientBrowser.h
Last active August 29, 2015 14:01
ReactiveCocoa-based wrapper around NSNetServiceBrowser
//
// LTClientBrowser.h
// LayerTreeServer
//
// Created by Indragie Karunaratne on 2014-05-21.
// Copyright (c) 2014 Indragie Karunaratne. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <LayerTreeKit/LayerTreeKit.h>
@genadyo
genadyo / gist:295a5e8f0d743f57137f
Created November 27, 2014 17:21
app_store_app_data.json
{
"491289025" : "ijinshan-kappmarket://",
"301521403" : "fb103361823069955://",
"492178411" : "ils492178411://",
"346142396" : "fb234434003713://",
"310633997" : "whatsapp://",
"370614765" : "com.condenet.newyorker://",
"325058491" : "rnmddisco://",
"382952264" : "epichttp://",
"477048487" : "predictwind://",