This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function smallest(ints) { | |
if(ints.length == 1) { return ints[0]; } | |
ints.splice(0, 2, ints[0] < ints[1] ? ints[0] : ints[1]); | |
return smallest(ints); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to read the url hash (the part after #), and turns it into an object for serialization | |
var getUrlHash = function() { | |
var tmpPos = location.href.indexOf("#"), hashObj = {}; | |
if(tmpPos !== -1) { | |
var hash = location.href.substring(tmpPos+1, location.href.length); | |
// if it has multiple values (separated by an ampersand), we need to consider that | |
tmpPos = hash.indexOf("&"); | |
if(tmpPos !== -1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# finds files that by filename matches $1, does not reside in a target folder, and contains the string $2 | |
findgrep() { | |
find . -name "*$1*" -and -type f -and -not -path "*/target/*" -and -not -path "*/.git/*" -print0 | xargs -0 fgrep -n --color=auto "$2" | |
} | |
# searches pom.xml files for $1 | |
alias poms="findgrep 'pom.xml' $1" | |
# copies the output of the last command to the clipboard | |
copylast() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class Person: Codable { | |
let givenName: String | |
let surName: String | |
let middleName: String? | |
let gender: Gender | |
init(givenName: String, surName: String, middleName: String?, gender: Gender) { | |
self.givenName = givenName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Pet { | |
let name: String | |
} | |
struct Person { | |
let name: String | |
let pets: [Pet] | |
} | |
// a conditional unwrap - people is an array of Person objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let petName = people.first?.pets.first?.name { | |
print(petName) | |
} |
OlderNewer