- You can find the article published here: http://www.javiersoto.me/post/106875422394
- For questions, it's also available on Github: https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md
This file contains 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
/** | |
Copyright (c) 2014 Julian Asamer | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
This file contains 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
func delay(delay:Double, closure:()->()) { | |
dispatch_after( | |
dispatch_time( | |
DISPATCH_TIME_NOW, | |
Int64(delay * Double(NSEC_PER_SEC)) | |
), | |
dispatch_get_main_queue(), closure) | |
} |
This file contains 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
/** | |
FIXME: Box exists to prevent the "Unimplemented IR generation feature non-fixed multi-payload enum layout" error. */ | |
final class Box<T> { | |
let value: T | |
init(_ value: T) { | |
self.value = value | |
} | |
} |
This file contains 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
/* | |
* Alex Bosworth | |
* | |
* A straightforward S3 library | |
* | |
* USE: var s3 = new S3(AWS_KEY, AWS_SECRET, {defaultBucket : MY_BUCKET}); | |
* s3.put(KEY, DATA); | |
* s3.get(KEY).on('success', function(data) { console.log(data); }); | |
* (more operations: buckets, info, list) | |
* |
This file contains 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
// node-jquery - port of jquery 1.4.2 (http://jquery.com/)to node.js by alex bosworth (http://alexbosworth.net/) | |
function now() { | |
return (new Date).getTime(); | |
} | |
var window = {}, | |
jsc = now(), | |
rscript = /<script(.|\s)*?\/script>/gi, | |
rselectTextarea = /select|textarea/i, |
This file contains 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
// for node-jquery.js (http://gist.github.com/599831) | |
// add this to a script to show how long it took to complete | |
process.on('exit', $.proxy(function () { | |
var sec = Math.round((new Date().getTime() - this.start.getTime()) / 1000); | |
console.log('completed', 'in ' + sec + ' seconds'); | |
}, {start:new Date()})); |
This file contains 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
/* | |
* Alex Bosworth | |
* | |
* A straightforward S3 library | |
* | |
* USE: var s3 = new S3(AWS_KEY, AWS_SECRET, {defaultBucket : MY_BUCKET}); | |
* s3.put(KEY, {data:{},headers:{}}, [bucket]); | |
* s3.get(KEY, [bucket]).on('success', function(data) { console.log(data); }); | |
* (more operations: buckets, info, list) | |
* |
This file contains 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
// Deferreds are useful for chaining: doSomething().success(doSomethingElse).failure(stopStuff); | |
function Deferred() { | |
this._successCbk = function() {}, | |
this._failureCbk = function() {}; | |
return this; | |
} | |
Deferred.prototype.success = function(cbk) { | |
this._successCbk = cbk; |
This file contains 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
+ (NSDictionary *)downloadableFonts | |
{ | |
CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)@{(id)kCTFontDownloadableAttribute : (id)kCFBooleanTrue}); | |
CFArrayRef matchedDescs = CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL); | |
NSArray *array = (__bridge NSArray *)matchedDescs; | |
NSMutableDictionary *families = [NSMutableDictionary dictionary]; | |
for (UIFontDescriptor *fontDescriptor in array) { | |
NSString *familyName = fontDescriptor.fontAttributes[UIFontDescriptorFamilyAttribute]; |
OlderNewer