This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Author: Pierre Bernard, Jonathan Sterling | |
| // Source: http://www.bernard-web.com/pierre/blog/index.php?id=2624434753771423706 | |
| // Caveat: Consider using http://github.com/andrep/RMModelObject instead. | |
| @implementation NSObject (PropertyDealloc) | |
| - (void)releaseProperties { | |
| Class class = [self class]; | |
| unsigned int pCount; | |
| objc_property_t *properties = class_copyPropertyList(class, &pCount); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)saveManagedObjectContext { | |
| id result = [[FKEither return:self.managedObjectContext] bind:^(id moc) { | |
| NSError *err = nil; | |
| [moc save:&err]; | |
| return [FKEither right:@"Success!" orLeft:err]; | |
| }]; | |
| NSLog(@"Saving managedObjectContext: %@", [result value]); | |
| } | |
| // hopefully => Saving managedObjectContext: Success! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* NOTES: | |
| Fun use of a higher-order-block and some maybe objects. | |
| */ | |
| - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { | |
| Function (^blockForEncoding)(NSStringEncoding) = ^Function (NSStringEncoding enc) { | |
| return [^(id d) { return [[[NSString alloc] initWithData:d encoding:enc] autorelease]; } copyrelease]; | |
| }; | |
| id utf8Str = [[FKMaybe return:CDATABlock] map:blockForEncoding(NSUTF8StringEncoding)]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <feed xmlns="http://www.w3.org/2005/Atom"> | |
| <title>Example Channel</title> | |
| <subtitle>A subtitle.</subtitle> | |
| <description>This is an example feed to be used in an application for O'Reilly Media. Some more text to make this go multi-line in the header label.</description> | |
| <link href="http://example.org/feed/" rel="self" /> | |
| <link href="http://example.org/" /> | |
| <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // JSSettingsController.h | |
| // | |
| // Created by Jon on 7/24/10. | |
| // Copyright (c) 2010 Jonathan Sterling. All rights reserved. | |
| // | |
| @interface JSSettingsController : NSObject | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- This is a really terrible parser I'm working on to learn Haskell & Parsec. | |
| -- Sorry if it makes your eyes bleed. | |
| module Main where | |
| import Control.Monad(liftM) | |
| import Text.ParserCombinators.Parsec | |
| import Text.ParserCombinators.Parsec.Expr | |
| import qualified Text.ParserCombinators.Parsec.Token as P | |
| import Text.ParserCombinators.Parsec.Language |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // JSProtocolChecker.h | |
| // | |
| // Created by Jon on 7/25/10. | |
| // Copyright (c) 2010 Jonathan Sterling. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface JSProtocolChecker : NSProxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main () { | |
| size_t n = 100; | |
| int odds[n]; | |
| size_t i; | |
| for(i = 0; i < n; ++i) { | |
| odds[i] = 2 * i + 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| #import <CoreGraphics/CoreGraphics.h> | |
| #import <objc/message.h> | |
| #import <string> | |
| #import <map> | |
| #import <typeinfo> | |
| #define $(value) box<typeof(value)>(value) | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename T> NSArray *fk::arr (T obj1, ...) NS_REQUIRES_NIL_TERMINATION; | |
| template <typename T> NSArray *fk::lift_arr (T obj); | |
| // we started with the following, which would be better represented as a C-array of ints: | |
| [NSArray arrayWithObjects: | |
| [NSNumber numberWithInt:2], | |
| [NSNumber numberWithInt:5], | |
| [NSNumber numberWithInt:1], | |
| [NSNumber numberWithInt:45], | |
| nil]; |