Skip to content

Instantly share code, notes, and snippets.

Avatar

Francisco Ryan Tolmasky I tolmasky

View GitHub Profile
View gist:00eaa5e056b6637b7c18
- (void)setArray:(NSArray *)anArray
{
_myArray = anArray; // aha! subtle bug because anArray MAY be a mutable array, so you need to do [anArray copy]. With the magic of inheritance, the type system becomes confusingly worthless, telling you that yes, a mutable array is an immutable array. Yay for confusing first time programmers!
}
// This problem exists EVERYWHERE:
- (void)doSomethingWithView:(NSView *)aView
{
[aView addSubview:controlView]; // This may or may not work depending what aView is. Despite the docs telling you that addSubview is a perfectly fine PUBLIC API, subclasses of NSView may make it effectively private, thus breaking here. So what's the point of saying "give me a view" if subclasses of NSView can willy-nilly change the exposed API?
View gist:12920f84747cfefb9149
Given object X
Given type A
if X isa A, BUT X.m isnot A::m
then I am unhappy.
For example (classical):
class A { func one() { return 1 } }
class B : A { func one() { return 2 } }
View haight-ashbury.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View tonic.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View gist:11732
[importButton setBordered:NO];
[importButton setImagePosition:CPImageLeft];
[importButton setTitle:@"blah"];
[importButton setTextColor:[CPColor blackColor]];
[importButton setFont:[CPFont systemFontOfSize:16.0]];
[importButton setImage:[[CPImage alloc] initWithContentsOfFile:path1 size:CGSizeMake(32.0, 32.0)]];
[importButton setAlternateImage:[[CPImage alloc] initWithContentsOfFile:path2 size:CGSizeMake(32.0, 32.0)]];
[importButton setAlignment:CPLeftTextAlignment];
[importButton setDelegate:self];
View gist:13552
@implementation TheCell : CPView
{
id myRepresentedObject
}
- (void)mouseDragged:(CPEvent)anEvent
{
var dragView = [[TheCell alloc] initWithFrame:[self bounds]];
[dragView setRepresentedObject:myRepresentedObject];
View gist:23136
- (CPString)stringByDeletingLastPathComponent
{
var path = self,
start = length - 1;
while (path.charAt(start) === '/')
start--;
path = path.substr(0, path.lastIndexOf('/', start));
View gist:24700
for(; index < count; ++index)
{
var lhs = self[index],
rhs = anArray[index];
if (lhs === rhs || lhs.isa && rhs.isa && [lhs isEqual:rhs])
continue;
return NO;
}
View gist:24699
for(; index < count; ++index)
{
var lhs = self[index],
rhs = anArray[index];
if (lhs !== rhs && (!lhs.isa || !rhs.isa || ![lhs isEqual:rhs]))
return NO;
}
View gist:28722
--- a/Foundation/CPTimer.j
+++ b/Foundation/CPTimer.j
@@ -243,13 +243,13 @@ var _CPTimerBridgeTimer = function(codeOrFunction, aDelay, shouldRepeat, functio
theFunction = nil;
if (typeof codeOrFunction === "string")
- theFunction = function() { new Function(codeOrFunction)(); CPTimersForTimeoutIDs[timeoutID] = nil; }
+ theFunction = function() { new Function(codeOrFunction)(); if (!shouldRepeat) CPTimersForTimeoutIDs[timeoutID] = nil; }
else
{