Skip to content

Instantly share code, notes, and snippets.

View tolmasky's full-sized avatar

Francisco Ryan Tolmasky I tolmasky

View GitHub Profile
- (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?
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 } }
@tolmasky
tolmasky / haight-ashbury.json
Created August 7, 2015 02:26
Haight Ashbury
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[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];
@implementation TheCell : CPView
{
id myRepresentedObject
}
- (void)mouseDragged:(CPEvent)anEvent
{
var dragView = [[TheCell alloc] initWithFrame:[self bounds]];
[dragView setRepresentedObject:myRepresentedObject];
- (CPString)stringByDeletingLastPathComponent
{
var path = self,
start = length - 1;
while (path.charAt(start) === '/')
start--;
path = path.substr(0, path.lastIndexOf('/', start));
for(; index < count; ++index)
{
var lhs = self[index],
rhs = anArray[index];
if (lhs === rhs || lhs.isa && rhs.isa && [lhs isEqual:rhs])
continue;
return NO;
}
for(; index < count; ++index)
{
var lhs = self[index],
rhs = anArray[index];
if (lhs !== rhs && (!lhs.isa || !rhs.isa || ![lhs isEqual:rhs]))
return NO;
}
--- 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
{