Skip to content

Instantly share code, notes, and snippets.

@rbarbera
rbarbera / algebraicBinaryTree.swift
Last active October 31, 2018 16:00
Algebraic Binary tree implementation in Swift
import Foundation
indirect enum Tree<T> {
case empty
case node(_ value: T, _ left: Tree<T>, _ right: Tree<T>)
}
extension Tree: CustomStringConvertible where T: CustomStringConvertible {
var description: String {
switch self {
@rbarbera
rbarbera / gist:241f2b5b3d4663f262e2
Created July 3, 2014 06:48
This will print "Ops!"
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var monitor1 = Monitor.sharedMonitor()
_sharedMonitor = Monitor()
var monitor2 = Monitor.sharedMonitor()
if monitor1 === monitor2 {
println("Singleton are working")
@rbarbera
rbarbera / gist:73dc24af0ad4477837bd
Created May 21, 2014 08:08
Autolayout bug with NSLayoutAttributeBaseLine
//
// ALEViewController.m
// FLKAutoLayoutExample
//
// Created by Rafa on 2014/05/21.
//
#import "ALEViewController.h"
#import "UIView+FLKAutoLayout.h"
__block NSUInteger outerIndex = -1;
[lista enumerateObjectsUsingBlock:^(NSString *word, NSUInteger idx, BOOL *stop) {
__block NSUInteger innerIndex = -1;
[datos enumerateObjectsUsingBlock:^(NSString *palabra, NSUInteger indice, BOOL *parada) {
if ([word isEqualToString:palabra]) {
NSLog(@"log1: coinciden el %d", indice); //(log1) si pongo este log deja de aparecer el log3
innerIndex = idx;
@rbarbera
rbarbera / gist:5465425
Created April 26, 2013 06:54
Stopping an enumerateObjectUsingBlock
//
// main.m
// enumeration
//
// Created by Rafa Barberá on 26/04/13.
// Copyright (c) 2013 Rafa Barbera. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>