This file contains hidden or 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) | |
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 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) { |
This file contains hidden or 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 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+)$/, |
This file contains hidden or 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
#!/bin/bash | |
wp_blogs=( | |
"/var/www/someblog/" | |
"/var/www/anotherblog/" | |
"/var/www/thirdblog/" | |
) | |
# get the latest wordpress files | |
echo "Downloading Wordpress and unpacking..." |
This file contains hidden or 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
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++) { |
NewerOlder