Skip to content

Instantly share code, notes, and snippets.

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)
}
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
@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) {
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);
}
function queryParam(key) {
// if it doesn't contain a question mark, return undefined
var qmPos = window.location.href.indexOf("?");
if(qmPos === -1) {
return undefined;
}
// if it doesn't contain our key, also return undefined
var keyPos = window.location.href.indexOf(key+"=", qmPos);
if(keyPos === -1) {
@vrutberg
vrutberg / notesname.js
Created September 22, 2009 08:53
JavaScript implementation of the NotesName class
function NotesName(p) {
var name = p;
// regular expressions that we use to extract information
var Regexp = {
abbreviated: /(?:CN|OU|O|C)=/gi,
isName: /CN=.+(?:\/OU=.+)*\/O=.+(?:\/C=.+)?/i,
common: /CN=([\w\s]*)\//i,
given: /^(\w+)\s/,
surname: /\s(\w+)$/,
#!/bin/bash
wp_blogs=(
"/var/www/someblog/"
"/var/www/anotherblog/"
"/var/www/thirdblog/"
)
# get the latest wordpress files
echo "Downloading Wordpress and unpacking..."
@vrutberg
vrutberg / QueryParser.java
Created August 21, 2009 14:31
Query Parser class for Lotus Notes/Domino written in Java
private class QueryParser {
public Hashtable parseQueryString(String qsd) {
// we will return this
Hashtable data = new Hashtable();
// check if it contains pairs of k/v
if(qsd.indexOf("&") > -1) {
String[] pairs = qsd.split("&");
for(int i = 0; i < pairs.length; i++) {
#!/bin/bash
# edit this, should be login details for sms.se and your phone number
loginnumber="0701234567"
password="abc123"
sendTo="0701234567"
# you shouldn't have to edit anything beyond this point
if [ $# != 1 ]; then