Skip to content

Instantly share code, notes, and snippets.

View alexdrone's full-sized avatar

Alex Usbergo alexdrone

View GitHub Profile
@alexdrone
alexdrone / cblocks
Created April 4, 2012 11:56
Snippet of C with blocks
#include <stdio.h>
#include <stdlib.h>
typedef struct _Object{
const char *objectClass;
int objectId;
int (^isEqualToObject) (void *other);
} Object;
@alexdrone
alexdrone / UIBlockButton
Created April 18, 2012 14:52
UIButton with blocks
typedef void (^ActionBlock)();
@interface UIBlockButton : UIButton {
@private
ActionBlock _actionBlock;
}
-(void) handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock) action;
@implementation UIBlockButton
@alexdrone
alexdrone / dynamic-impl
Created April 23, 2012 05:41
@dynamic implementation
Person.h (Person)
@interface Person : NSObject
@property (copy) NSString *givenName;
@property (copy) NSString *surname;
@end
Person.m (Person)
@interface Person ()
@property (strong) NSMutableDictionary *properties;
@end
@alexdrone
alexdrone / block-action
Created May 8, 2012 12:21
block based target-action
// BlockInvocation.h
#import <Cocoa/Cocoa.h>
@interface BlockInvocation : NSObject {
void *block;
}
-(id)initWithBlock:(void *)aBlock;
//
// AsynchronousOperation.swift
// Primer
//
// Created by Alex Usbergo on 18/10/15.
// Copyright © 2015 Alex Usbergo. All rights reserved.
//
import Foundation
import UIKit
//1.1
extension String {
///Implement an algorithm to determine if a string has all unique characters.
///What if you cannot use additional data structures
public func hasUniqueCharacter(useAdditionalDataStructures: Bool = true) -> Bool {
import Foundation
//9.1
public func memoize<T:Hashable,U>(body: (T->U, T)->U) -> T->U {
var memo = [T : U]()
var result: (T->U)!
result = { x in
if let q = memo[x] { return q }
import UIKit
//17.2
public enum TicTacToe { case X, O, Empty }
var matrix = Matrix<TicTacToe>(rows: 3, columns: 3, repeatedValue: TicTacToe.Empty)
var m1 = matrix
m1[0,0] = TicTacToe.X
m1[1,1] = TicTacToe.X
@alexdrone
alexdrone / AnyStateful.swift
Created January 22, 2017 13:42
Unidirectional data-flow in Swift with Dependency Injection.
protocol AnyStateful: class {
/// The children of this node.
var statefulChildren: [AnyStateful] { get }
// Internal call to propagate the render call.
func _render(state: Any?)
/// The controller that is used as delegate for this stateful object.
weak var _controller: StatefulControllerType? { get set }
@alexdrone
alexdrone / FirebaseBackedStore.swift
Last active May 12, 2017 10:08
DispatchStore + Firebase
import Foundation
import DispatchStore
import Firebase
import FirebaseDatabase
import Wrap
import Unbox
// MARK: - Firebase specific logic