Skip to content

Instantly share code, notes, and snippets.

Viktor Rutberg vrutberg

Block or report user

Report or block vrutberg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View SwiftUnwrapExamples-2.swift
if let petName = people.first?.pets.first?.name {
View SwiftUnwrapExamples-1.swift
struct Pet {
let name: String
struct Person {
let name: String
let pets: [Pet]
// a conditional unwrap - people is an array of Person objects
View Codable.swift
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 / .profile
Last active Aug 29, 2015
Handy .profile stuff
View .profile
# 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() {
vrutberg / urlhash.js
Created Nov 29, 2010
quick n dirty functions for setting/getting url hash values
View urlhash.js
// 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) {
View smallestInteger.js
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);
View queryParam.js
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 / notesname.js
Created Sep 22, 2009
JavaScript implementation of the NotesName class
View notesname.js
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+)$/,
# get the latest wordpress files
echo "Downloading Wordpress and unpacking..."
vrutberg /
Created Aug 21, 2009
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++) {
You can’t perform that action at this time.