Skip to content

Instantly share code, notes, and snippets.

View alexbosworth's full-sized avatar

Alex Bosworth alexbosworth

View GitHub Profile
@julasamer
julasamer / Timer.swift
Last active August 29, 2015 14:05
Timer.swift - A Timer class
/**
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:
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
@JaviSoto
JaviSoto / gist:292435381bb2e0d31402
Last active August 29, 2015 14:12
Functor and Monad in Swift blog post
@pixelspark
pixelspark / Fallible.swift
Created June 3, 2015 18:02
Swift Fallible type
/**
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
}
}
@alexbosworth
alexbosworth / amazon-s3.js
Created September 27, 2010 21:21
A straightforward S3 library
/*
* 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)
*
@alexbosworth
alexbosworth / node-jquery.js
Created September 27, 2010 21:05
A port of jQuery to Node.js (required for all my other scripts)
// 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,
@alexbosworth
alexbosworth / end_script_timer.js
Created October 7, 2010 06:21
a runtime calculator for scripts
// 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()}));
@alexbosworth
alexbosworth / amazon-sdb.js
Created October 13, 2010 10:14
An AWS SimpleDb library
/*
* 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)
*
@alexbosworth
alexbosworth / deferred.js
Created August 30, 2011 02:09
Deferred for Node.js
// 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;
@fdstevex
fdstevex / gist:6741638
Created September 28, 2013 12:34
Method to retrieve a list of downloadable fonts on iOS 7. This method may block for a while (it can involve a network call) so don't call on main thread. The return is a dictionary that maps font families to arrays of font names in that family.
+ (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];