Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
@aleclarson
aleclarson / index.html
Last active August 29, 2015 13:56
OAuth Signing an HTTP request to Twitter's REST API v1.1 via Parse Cloud Code
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="text/javascript" src="https://cdn.jsdelivr.net/parse/1.2.9/parse.min.js"></script>
<script>
Parse.initialize('parse app id', 'parse app key');
Parse.Cloud.run('userFriends')
.always(function (res) {
console.log(JSON.parse(res.message));
@aleclarson
aleclarson / FBBatchRequest.h
Last active August 29, 2015 13:58
FBBatchRequest for Facebook iOS SDK
@interface FBBatchRequest : NSObject
#define emptyMutableArray [NSMutableArray array]
typedef void(^VoidCallback)();
- (void) addRequest:(FBRequest*)request completionBlock:(FBRequestHandler)completionBlock;
- (void) startWithCompletionBlock:(VoidCallback)completionBlock;
- (void) start;
@aleclarson
aleclarson / gist:53cc437e4e4a0daf9ed9
Created August 9, 2014 04:29
Byte Array to NSData
// This goes in an NSData extension
convenience init (byteArray: [NSNumber]) {
let bytes = byteArray.combine([]) {
(n, inout b: [Byte], _, _) in
b.append(n.unsignedCharValue)
}
self.init(bytes: bytes, length: bytes.count)
}
@aleclarson
aleclarson / Veil.swift
Last active August 29, 2015 14:06
Veil.swift
/// Veils a T as an NSObject.
public func veil <T> (value: T!) -> NSObject! {
if value == nil { return nil }
let value = value!
if let obj = value as? NSObject { return obj }
@aleclarson
aleclarson / Ease.swift
Created September 24, 2014 03:11
Ease.swift
import QuartzCore
import Foundation
public let EaseNone = Ease(0, 0, 1, 1)
public let EaseOutQuad = Ease(0.25, 0.46, 0.45, 0.94)
public let EaseInQuad = Ease(0.55, 0.085, 0.68, 0.53)
public let EaseInOutQuad = Ease(0.455, 0.03, 0.515, 0.955)
@objc public class Ease {
@aleclarson
aleclarson / DisplayLink.swift
Created October 4, 2014 08:39
DisplayLink.swift
@aleclarson
aleclarson / ListenerSet.swift
Created October 22, 2014 12:52
ListenerSet
import Foundation
public func += (set: ListenerSet, listener: Listener) {
set.list += listener
}
// An unordered set of Listeners.
public class ListenerSet {
@aleclarson
aleclarson / Reference.swift
Last active August 29, 2015 14:07
Reference
public enum ReferencePolicy {
case Strong, Weak
}
// Allows for a mix of strong and weak references inside Arrays and Dictionaries.
public class Reference <T: AnyObject> {
public var object: T! {
get { return _strong ?? _weak }
@aleclarson
aleclarson / Associated.swift
Last active August 29, 2015 14:07
Associated
import EmitterKit
/// Forces an `object` to retain the given `value` until the `object` is deallocated.
///
/// You must retain the returned Associated<T> object in order to keep the `value` retained by the `object`.
///
/// Alternatively, you can call `keepAlive()` on the Associated<T> to prevent the `value` from being deallocated when the Associated<T> is released.
///
public func associate <T> (value: T, with object: AnyObject) -> Associated<T> {
@aleclarson
aleclarson / commands.md
Last active August 29, 2015 14:08
Useful git stuff

See local commits not yet pushed to remote

git config --global alias.unpushed "diff origin/$(git name-rev --name-only HEAD)..HEAD --name-status"
git unpushed

Script that creates an "unstable" branch (if one does not exist) and commits all changes to it.

if [ -z "`git branch | grep unstable`" ]; then
 git checkout -b unstable