Skip to content

Instantly share code, notes, and snippets.

View joanmolinas's full-sized avatar
🎯
Focusing

Joan Molinas joanmolinas

🎯
Focusing
View GitHub Profile
let arr = (0...15).map {$0*2}
func binarySearch<T : Comparable>(arr : Array<T>, value : T) -> Bool {
let midPosition = arr.startIndex.advancedBy(arr.startIndex.distanceTo(arr.endIndex)/2)
let midElement = arr[midPosition]
guard midElement != value else {
return true
}
#import <Foundation/Foundation.h>
@interface NSObject (AssociatedObjects)
- (void)associatedValue:(id)value withKey:(void *)key;
- (id)associatedValueForKey:(void *)key;
@en
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define K 9000000000
typedef struct {
double i;
double j;
} pair;
@joanmolinas
joanmolinas / Tournament.java
Created April 24, 2017 19:47
Random groups for a tournament
import java.util.ArrayList;
import java.util.Random;
class Team {
private String name;
public Team(String name) {
this.name = name;
}
@joanmolinas
joanmolinas / SRP_Bad.swift
Last active March 8, 2018 19:04
Blog.firstSolidPrinciples
class UserInformationHandler {
// MARK: - Public api
func retrieve() {
let data = request()
let user = parse(data: data)
store(user: user)
}
}
@joanmolinas
joanmolinas / SRP_Good.swift
Last active March 8, 2018 19:10
Blog.firstSolidPrinciples
class UserInformationHandler {
// MARK: - Properties
let requester: UserInformationRequesteable
let parser: UserInformationParseable
let storer: UserInformationStoreable
// MARK - Life cycle
init(requester: UserInformationRequesteable,
parser: UserInformationParseable,
class Team {
var runners: [Runner] = ...
var riders: [Rider] = ...
func reset() {
runners.forEach{ $0.reset() }
riders.forEach { $0.reset() }
}
class Team {
var runners: [Runner] = ...
var riders: [Rider] = ...
var swimmers: [Swimmer] = ...
func reset() {
runners.forEach{ $0.reset() }
riders.forEach { $0.reset() }
swimmers.forEach { $0.reset() }
class Team {
var athletes: [Athlete] = ...
func reset() {
athletes.forEach{ $0.reset() }
}
}
class ContentController {
func show() {
// Do stuff
}
}
class SubscriptorContentController: ContentController {