Skip to content

Instantly share code, notes, and snippets.

View joanmolinas's full-sized avatar
🎯
Focusing

Joan Molinas joanmolinas

🎯
Focusing
View GitHub Profile
extension Double {
static var min : Double {
get {
return -2147483648
}
}
static var max : Double {
get {
return 2147483647
}
extension String {
subscript(index : Int) -> Character{
get {
return self[advance(self.startIndex, index)]
} set(newValue) {
self = self.stringByReplacingCharactersInRange(Range<String.Index>(start: advance(startIndex, index), end: advance(startIndex, index+1)), withString: String(newValue))
}
}
}
func addPrefix(c : Character) -> (String) -> String {
return {
(currentString : String) -> String in
let result = String(c) + currentString
return result
}
}
//OR
func recursiveFibonacci(number : Int) -> Int {
return number <= 1 ? 1 : recursiveFibonacci(number - 2) + recursiveFibonacci(number - 1)
}
var fibonacci : Int -> Int = recursiveFibonacci
fibonacci(5)
let word = "detartrated"
func palindromeWord(word : String) ->Bool {
return String(reverse(word)) == word ? true : false
}
palindromeWord(word) // OUTPUT -> True
@joanmolinas
joanmolinas / Crackle.swift
Last active August 29, 2015 14:17
HackerSchool
for i in 1...100 {
switch (i) {
case let x where x%15 == 0:
println("CracklePop")
case let x where x%3 == 0:
println("Crackle")
case let x where x%5 == 0:
println("Pop")
default:
break;
for i in 1...10{
switch (i) {
case let x where x%2 == 0:
println("even")
case let x where x%2 != 0:
println("odd")
default:
break;
}
}
@joanmolinas
joanmolinas / CountriesFactory.swift
Last active February 1, 2016 17:18
Factory Pattern
//Enum
enum Country {
case Spain, France
}
//Classes
class Spain : Language {
func code() -> String {
return "SP"
}
//REQUIRE PARSE
var Parse = require('parse').Parse;
//ADD NECESSARY KEYS - FOR MODIFY IS NECESSARY MASTER KEY
Parse.initialize(APP_KEY, JSC_KEY, MASTER_KEY);
//YOU HAVE USE THIS COMMAND FOR USE MASTER KEY
Parse.Cloud.useMasterKey();
var UserClass = Parse.Object.extend('_User');
//For use Gson, you need a Gson jar. Download from this https://code.google.com/p/google-gson/
class Student {
private String name;
private int mark;
private String city;
public Student(String name, int mark, String city) {
this.name = name;
this.mark = mark;
this.city = city;