Skip to content

Instantly share code, notes, and snippets.

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);
}
@vrutberg
vrutberg / urlhash.js
Created November 29, 2010 10:43
quick n dirty functions for setting/getting url hash values
// 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) {
@vrutberg
vrutberg / .profile
Last active August 29, 2015 13:56
Handy .profile stuff
# 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() {
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
struct Pet {
let name: String
}
struct Person {
let name: String
let pets: [Pet]
}
// a conditional unwrap - people is an array of Person objects
if let petName = people.first?.pets.first?.name {
print(petName)
}