Whiteboard White-knuckling – Part 3

img_1729Today I had J do an insertion sort. We only had about 20 minutes to work through it today. As the timer ticked down, I stopped him when he had 5 minutes left before his shift ended.

He wasn’t able to complete the insertion sort today. When he described where he got stuck he said, “I feel like I’m suppose to move the selected element above the list then move all of the items that have been previously passed through all to the left at once.”

He’s going to attempt to code out the insertion sort on Wednesday. I asked him not to look up the insertion sort online in the meantime. I look forward to these sorting algorithm challenges 🙂

Click here to see Part 2 – Merge Sort

Click here to see Part 1 – Bubble Sort

As we begin to see and appreciate our essential selves, we manifest automatically that beauty and our true capacities, simply by letting them happen

41psrbzymcl-_ac_us160_“Many people carry around with them an image of the kind of person they wish they were, much as a tennis player imagines the kind of serve he wishes he could deliver. When our behavior does not seem to measure up to our ideal, we grow dejected and then start trying hard to correct it (‘Perhaps I should take a series of lessons, or a course on personality development, or read a book about how to become less self-critical, or undergo therapy, or join an encounter group’). Such steps are not necessarily foolish – I have taken them all – but what is needed is not so much the effort to improve ourselves, as the effort to become more aware of the beauty of what we already are. As we begin to see and appreciate our essential selves, we manifest automatically that beauty and our true capacities, simply by letting them happen.” – Gallaway

During the last few weeks of high school, we were asked to come up with a quote that would accompany our senior portrait in the yearbook. If you open my high school yearbook and flip to my portrait you’ll find the following quote next to my face:

“Each day I will strive to be better than my former self.” – Thom Yorke

But what does better mean? Better in what ways? Who are we competing against? How will we know if we’ve won? When does it end?

Ask any of my friends and they’ll tell you I spend too much time in my head. “But I’m striving to get better,” I’ll tell them. That’s when they say, “Yeah, but you think too much.”

“What is needed is not so much the effort to improve ourselves, as the effort to become more aware of the beauty of what we already are.” – Galloway

Where are we meant to draw the line in self-improvement? What is good enough? Does it exist at all?

“As we being to see and appreciate our essential selves, we manifest automatically that beauty and our true capacities, simply letting them happen.” – Galloway

Perhaps the lesson lies within the striving.

Charles Duhigg, author of “The Power of Habit” suggests setting cues and rewards to make any habit stick. He goes on to say that we need to perform a behavior for at least 30 days before it becomes a habit.

We aggressively block off our precious time for our most desirable habits. Let’s take it a step further. How about we start aggressively scheduling our downtime too? We need time to appreciate our accomplishments.

Let’s play a game

In our over-scheduled lives, why not lean into the obstacle?

Get your phone. No, really. Go get your phone. Go ahead, I’ll wait.

Got it? Good. Open your calendar. Add a recurring 20-minute event: “Me Time.” Now set it and forget it. Each time that reminder comes up, stop, take a deep breath and shake it out.

Come back in a few weeks and let me know how it’s helped. You might find that this one little break in your routine will ease your mind, slow things down, and give you a chance to reflect on the accomplishments you’ve made this week.

We need to check in with ourselves to be better than our former selves.

We have to earn the attention and trust of our listeners and readers


“None of us ever truly has a captive audience. We have to earn the attention and trust of our listeners and readers.” – Rachel Toor

I find myself talking at length about subjects I am most interested in. Perhaps to the chagrin of my colleagues. Sometimes I get heated and animated because I love the concepts or feel that I have something brilliant to say and I speak loudly, quickly, and intrusively.

After reading this article on the Chronicle of Education I’m having second thoughts.

In every situation, simply carrying on, is going to bore your audience. A conversation needs a back and forth. Or else it’s a soliloquy.

This aint no Shakespeare play. This is real life!

“Early-career professors who worry about their authority may feel the need to prove that they deserve to be at the head of the class. They may suffer from impostor syndrome, having just learned the stuff they’re teaching. Eager to cover any inadequacies or incomplete knowledge, they trot out what they do know. They may be uncomfortable with silence and rush to fill it.” – Rachel Toor


“Or it’s possible that, like me, they just get so excited about the material that they can’t refrain from pointing out every single thing they think is cool. I’ve learned that it’s often a bad idea to teach a book I adore because if my students don’t love it as much as I do, first my feelings get hurt and then I rush in to show them what they’re missing. In class I’ll talk too much instead of waiting for them to say all the things they would have said if I’d only given them a chance. I try to be aware of that; sometimes I succeed.” – Rachel Toor


“How do they manage to miss the way the temperature in the room cools when they filibuster? Do they not see how people shut down? How suddenly everyone’s cuticles need picking or there’s a rush to use the bathroom?” – Rachel Toor



“Since then, at the start of every course, I ask each student to wait until three others have had a chance speak before they pipe up again. That can allow time and space for those who need a few extra moments to have their say. I try to follow the same rule myself in meetings.” – Rachel Toor

I love simple rules. Rules to live by. Rules that can be applied universally. When I find a rule like this I immediately put it into place and test it out. What’s your experience with this?

Can you stop yourself from talking about subjects you love until at least 3 people have had a chance to talk? Test it out and let me know!

Swift Pair Programming – Session 1

Just finished pair programming with Nick. He’s in San Francisco. And I’m in Hawaii. We’re using ScreenHero to pair and it’s fantastic. There was a bit of a lag in screensharing because my internet connection was pretty bad. Next time I’ll be pairing from the library or from Hi Capacity. An hour goes by really quickly. Maybe we need to meet for longer?

Prior to meeting I made a list of the topics that I understand the least:

  • Closures
  • Coalescing operators
  • Optional binding
  • Force unwrapping
  • Guard statements
  • Optional chaining
  • veratic parameters
  • inout parameters
  • Nested function that returns a function
  • Currying

Questions that came up this session

How to we indicate a multi type array?

Lessons learned

  • Playground will not show up the play button if its a playground inside of the xcode project.
  • edit all in scope.
  • can’t do ++ in swift
  • Figure out how to do a next item in swift that is safe
  • Use inout in your parameter list to mutate parameter. Be sure to call method with & on parameter to indicate inout status

Shared tools:

SpectacleApp – FREE mac app to move and resize windows with ease. Window control with simple and customizable keyboard shortcuts. For mac.

Next Week:

We’re planning on finishing the bubble sort.

White-knuckle Whiteboarding Part 2 – Merge Sort

mergeToday I had J do a merge sort. This time I held silent. I managed to stay silent for 40 minutes while J worked on the code. This time through, the code is more robust and cleaner. J is showing more familiarity with arrays and sorting.

Feedback given today:

  • “Keep your left indentation clearer so others can follow along while you trace through the program.”
  • “Good to see you started manipulating the data before writing any code.”
  • “Now that you’ve explained how your code works, please run through the code with the sample data given.”

Check out White-Knuckle Whiteboarding Part 1 here

Magritte in the age of Augmented Reality

Everything we see hides another thing, we always want to see what is hidden by what we see. – Rene Magritte

I can’t shake this thought. Magritte’s paintings show a world that is undone. Images overlap and obscure other images. Loaded objects are pulled from obscurity and placed into a familiar scene.

In an episode of Black Mirror  people tune each other out when they don’t want to talk. The person is still visually there, but their speech is washed out and they appear grainy and unwanted.


Augmented Reality (AR) seems loaded. Like there’s an insidiousness within it that I can’t help but foresee. Dangerous potential lurks in projecting the coveted, desired, and wanted over the unwanted, unfortunate, unwashed, and unseen.

AR by definition edits out things.

How do we decide what cannot be edited out? How do we force people to confront truths as more and more technology exists to obscure it?

In order to see what we add, we must hide what was there before.

Swift Pair Programming – Session 3

Playground supports markup
  //: Playground - noun: a place where people can play

import AppKit for osx
import UIKit for ios

source files in sources folder will be compiled once
image files in resources file will make those resources available to your playground

each page has its own sources and resources files

previous and next links allows us to go back and forth between pages

markup allows us to create links between pages.

semicolons are optional in swift.
  do not put them into the code.
  only time to use is when you have two statements on a single line

0..<64 means 0 to 64

NSLog still works. Good to use if you want a timestamp in your console

veratic function can take multiple parameters

print() default separator and terminator can be found in function definition

show graph of function by clicking on Show Result button in the result side bar

"//TODO:" inserts a bolded label in the jump bar


func printLiteralExpressions() {

	print("Function: \(__FUNCTION__)")
	print("Function: \(__FILE__)")
	print("Function: \(__LINE__)")
	print("Function: \(__COLUMN__)")
  Function: printLiteralExpresions()\n // name of this function
  File<EXPR>\n // does not work in named playground file but works in all source files
  Line7\n // line in source file
  Column:20\n // column in source file

Literal expressions are preceeded and succeeded by __ (2 underscores)


Create landmarks in swift playgrounds with the following one line comments:

// MARK: This is viewable in the jump bar
// MARK: - Add separator above this line
// TODO: Do this
// FIXME: Fix this

MARKUP: (make sure "render demarcation" is enabled in the right gutter )

## Header
### Header
> Block quote
* list item 1
* list item 2
1. List item 1
2. List item 2
`code format`
quick help comments
/// A quick help comment
Quick help multiline comment
- seealso: `someComplexFunction` // allows to embed link to function in playground


type swift in command line
press return
use up and down to shuffle through history
#> means waiting for input
#. means waiting for more input
Press tab for autocompletion in terminal
:q to quit
REPL can be started in the middle of a paused xcode app
  just type repl in console


use . notation to access property of class
use same . notation to set the property of a class
can chain multi dot notation
Good to cut up long dot notation like so:
  .print() // works because when compiler encounters . on line, looks for line above for reference


Swift has 2 types of values
  Value types (passed by copy)
	    Floating points
	    Tuples // forgetting what these are
	    Optionals // any datatype may have a value or be nil
  Reference types (passed by reference)
    **Closures // really want to focus on closures

Value types are passed by copy
  passed to a function
  changes to copy will not affect original
  value types are not copied until they are changed (implementation detail)
Reference types are passed by reference
  Uses a pointer to a reference
  Both pointing to the same exact instance

Variables are mutable (var)
Constants are immutable and cannot be changed (let)

Always create as constant if you don't need to change it later

Swift is a strongly typed language
Compiler will infer type of instance based on what is being assigned to it.

All types in swift should begin with capital
Variables and constants should begin wtih lowercase letter
Camel casing should be used to distinguish multiword types and instance names
Variable names and characters can be used with unicode and emojis!

Equivalent ways to explicitly state what kind of data type it is:

let aCharacter : Character = "a"
let bCharacter = "b" as Character // as operator literally casts the previous character

Write unicode scalars with \u <unicode value>
  let uWithUmlaut: Character = "\u{75}\u{308}"

When defining ints, use underscores to denote placement for easy reading
  1000000 can be written as 1_000_000
When writing an unsigned int:
  let anUnsignedInteger : UInt = 1_234_567

Float - 6 decimal precision
Double - 15 decimal place precision
  Use Double as default is recommendation from apple

Booleans are defined with true and false
  explicitly define your bools with let bool : Boolean = true


let binaryTen = 0b1010 // 0b
let octalTen = 0o12 // 0o
let hexTen = 0xA // 0x
let twelveMillion = 1.2e7 // 1.2 * 10^7

DEFINING TYPE ALIASES // option click to see what type it is aliasing

typealias IPOctet = UInt8 // use alias to lessen typing
  alias keyword followed by original word
let minOctetValue = IPOctet.min
let maxOctetValue = IPOctet.max

Type must be explictly declared when a value is not assigned on declaration

Constants accessed before defining value, will error.

Optionals allow us to declare
  suffix with a ?
    contains some value or nil
    nil is a valueless state
    empty string is not same as nil

Optional type is a box
  access a value we know has a string, must unwrap it.
  force unwrapping is used by following optional with !
  keeps your code as safe as possible.
  run time error will be cause if it is used unwrapped

String instances are passed by copy

M_PI is a constant imported in Foundation

print(String(format:"The %@ with a radius of %.0f", shape, radius))

String manipulation:

let quote : String = "In the end, we only regret the chnages we didn't take."
quote.hasPrefix("In the end") // true
quote.hasSuffix("Abraham Lincon") // false

let firstCharacter = quote[quote.startIndex] // gets substring

let eigthCharacter = quote[7] // does not work, will not accept int as index here
let eigthIndex = quote.startIndex.advancedBy(7) // use advancedBy method to get index
let eightCharacter = quote[eightIndex]
let lastCharacter = quote[quote.endIndex.predecessor()] // gets the eigth index

Insert and delete string componenets:

quote.insert("!", atIndex: quote.endIndex.predecessor()) // insert character at end of string
let period = quote.removeAtIndex(quote.endIndex.predecessor()) // returns last character in string

Create range:

To and including last number
  let aRange = 1...3
  let startIndex = quote.endIndex.advanceBy(-41)
  let range = startIndex..<quote.endIndex // creates range start to last number inclusive
  quote.replaceRange(range, with: replacementString)

Escape Characters:

\n - new line
\t - tab
\ - escape \ and "
\0 - null character

Swift has 3 formal collection types:

Default initializer:
var testScores = [Double]()
var testScores2 = Array<Double>()

Set array with multiple values at once
var scores = [Double](count: 4, repeatedValue: 10.0)
var scores2 = Array(count: 20, repeatedValue: 0) // element types infered by repeated value

Can be inialized wtih optionals
Pick a style that works for you and stick with it.

threeStooges.isEmpty // checks if has any elements
threeStooges.contains("Moe") // returns true or false

let twoStooges = threeStooger[0..<2].sort(>) // sorts array in ascending order

Arrays passed by copy

Use + to join 2 arrays.

myArray + ["David", "Shemp"]

// Nesting arrays

Break them into separate lines to make it look good.

print(famousGroupsOfThree.flatMap( { $0 } )) // flaten multidimensional arrays
// this is a closure function
// short hand argumenting

Store values of the same type in Dictionaries.
No redundant keys are allowed.

Declare Dictionary

var birthYears : [String : Int] = [:]
var raceResults = Dictionary<Int, String>()
var tourDeFranceResults : [Int:String]

Setting a value to nil removes it from the dictionary

Get all values in array


Modifying Dictionaries

Remove value for key returns key

You can nest dictionaries as well

Optional chaining
If any part is nil along the way to resolving the value, return nil.

Sets have a long form

var teachers = Set<String>()
var staff : Set<String> = []

When adding items to a set, any dupblicates will be removed.

Set supports count and isEmpty


Insert and remove values in Sets

Need to force unwrap arguments if the method does not accept an optional.

Defining Tuples

Group multiple values into a combinatorial value.

Useful to return multiple values from a function.

let httpStatus = (200, "Ok")

var playerScores: ([Int], firstName: String, lastName: String?)

Tuples can be accessed by index or by the name of the variable

**Tuples seem like a light-weight class replacement.

Add up the scores in tuples liek this:
let averageScore = scores.reduce(0, combine: +) / scores.count

Writing underscores for unneeded values can speed up compile time.

let (httpStatusCode, _) = httpStatus200

** use the letter t to switch lynda.com viewer from fullscreen to normal

Use dot notation to access nested tuples.

// Operators

Compiler will change int values to float implicitly

Division of integers will return an integer. Change one of those to a double and it will give you a decimal.

Swift modulus does floating point modulus as well!

a &+ 1
wraps around to maximum value.

Strings can use + and += to concatenate string

Arrays can use + and += to join two arrays

Instances of a class are passed by reference.

== checks for equality between operands
**=== checks if two operands are pointing to the exact same instance

Supports ternary operators ? true : false

Ternary operators can be nested like so:

let generation = birthYear < 1945 ? "Greatest Generation" : // switch statement is better than this
birthYear < 1965 ? "Baby Boomers" :
birthYear < 1982 ? "Generation X" :
birthYear < 1965 ? "Generation Y" :
"Generation Z"

**Coalescing operators
let defaultSize = "M"
var selectedSize: String?
let orderSize = selectedSize ?? defaultSize // not sure I get this one

Range operators

to but not including the ending value

let rangeA = 0..<10 // 0 through 9
let rangeB = 0...10 // equals 0 through 10 including 10

Type checking and casting operators:

Classes are reference types

class ClassB : ClassA // Class b inherits from Class A

let arrayOfClassInstances = [a, b]

item2 is ClassB // checks to see if this is an instance of the ClassB class type

// as! is a forced downcast
let classBInstance = item2 as! ClassB

// as casts a subclass as its superclass

let classBACtingAsClassAInstance = classBInstance as ClassA

[AnyObject]  // allows for any kind of class in the array
[Any] // allows for any kind of class or value in the array

Preceding zeros can be removed in a 0b00001010 binary value
rewrite as 0b1010

For loops do not need to be wrapped in paranthesis

for i in 0..<10 {

for _ in 0..<3 {  // underscore used here when the variable i is not needed.
print("I will not waste chalk")

// Stride method allows us to iterate through a loop at different step lengths between

for i in 3.stride(to: 30, by: 3) {

// print out key value pairs in an array

for (k, v) in people {
print("\(k): \(v)")

// iterat through values in a Set
for v in letters {

// iterate through array with conditional
for n in numbers where n.isPrime {
print("\(n) is a prime number")

//While loops

click blue play button in playground to re-execute the playground code

if statements don't need parenthesis

// if available

if #available(iOS 9, OSX 10.11, watchOS 2.0, *) { // stars indicate a wildcard. Parens required for #available()

    // Use applicable API from iOS 9, OS X
} else {
    // execute other API code if those platforms are not available

**// Optional binding

var firstName: String? = "Betty"
if let firstName = firstName { // set as constant

**// Guard statement

guard birthday.earlierDate(twentyOnesBirthday) == birthday
  else { // falls through if false
    print("\(name) is not old enough")

  print("\(name) can enter")

values assigned in a guard statement endure for the lenght of the guard statement.

// Switch

// create switch based on 2 values

let die1 = [1, 2, 3, 4, 5, 6].randomItem()
let die2 = [1, 2, 3, 4, 5, 6].randomItem()

switch(die1, die2) {
    case (1,1):
    case (6,6):
      print("30 points")

// Using Labels // NEVER GOING TO USE THIS!!!

var i = 0
let hello = "Hello, Playground!"

start: do { // here is the label
  do {
  if i < 3 {     continue start // goto label   } } // Enums Use dot notation to write out the enumeration quickly // Defering code execution if allSystemGO {     defer { // runs only after the for loop completes and reaches end of if scope       print("lift off!")     }     for i in (1...10).reverse() {       print(i, terminator: " ")     } } // Optional chaining **if let marciasAge = hank.children?.first?.children?[1]. // if anything along the way is nil, whole thing is nil //optional chain always returns an optional. func sayGreeting(greeting: String, toName name: String) { // sets name with directive toName:     print("\(greeting), \(name)!") } func addTwoIntegers(a: Int, _ b: Int) { //underscore suppresses the parameter name     print("\(a+b)") } addTwoIntegers(3,5) func addTwoIntegers(a: Int, _ b: Int) { //underscore suppresses the parameter name     return a + b } let sumOfIntegers = addTwoIntegers(3,5) // set a function name to be reused let integerAdder = addTwoIntegers // this sets the method to this new method name let integerAdder: (Int, Int) -> (Int) = addTwoIntegers


let helloWorldSayer: () -> () = sayHelloWorld // keep in mind to keep off parens for the method itself

Void is just a type alias for an empty tuple

so it can be rewritten like this:

let helloWorldSayer2: Void -> Void = sayHelloWorld

// set methods with default parameters like this, set default parameter at end of parameter list.

func sayGreeting(greeting: String, toName name: String = "friend") { // sets with default param
    print("\(greeting), \(name)!")

sayGreeting("Hey") // now we can omit the name because it has a default value set on it

**veriatic parameters

**inout parameters // pass values by reference

// prefix argument with & to show that it is an inout parameter and passes by reference

// Create contextual help

Mutates passed in score
- parameter score: raw score
- parameter meanScore: average score
- parameter deviation: standard deviation

@available(*, introduced=1.2, depreciated=2.0, message="Use different version") // used to depricate a function

// Pass reference type parameter to function

Pass a function into another function:

func addTwoIntegers(a: Int, _ b: Int) -> Int {
  return a+b

func performIntegerOperation(operation: (Int, Int) -> Int, a: Int, b: Int) -> Int {
    return operation(a, b)

// rewritten to take a function instead of parameters

performIntegerOperation(addTwoIntegers, a: 10, b: 8) // notice we do not pass the parens, we pass the function name followed by a list of parameters

**// create nested function that returns function
  // requires returning an alias of the function that is created inside of the nested function

**// Currying

replace multiparameter fucntion with a single curried function

func addLineItem(product: String, price: Double)(quantity: Int) -> String {
    let discountMultiplier: Double
    switch quantity {

    return String(format.....)
let sellCustomTShirt = addLineItem("Custom Tshirt", price: 10.0)
var lineItem = sellCustomTshirt(quantity: 5) // here is the result of currying the function, can call with default vars and a single param

**// Error Handling

Handling Errors

use enumerations for swift error handling.

define functions that throw errors

func performAction() throws {
  guard encounteredErrorA = false else {
    throw Error.A  // control will be moved out of the function
  guard encounteredErrorB = false else {
    throw Error.B(code: randomCode, function: __FUNCTION__.
      line: __LINE__)  // throws literal function name and line number
    print("Action completed successfully")

do {
    try performAction() // need to call with try to a func that throws
} catch Error.A {
    print("Error: \(error)") // local error value is created by a catch clause
} catch Error.B(code, function, line) where code > 4 {
    print("Error occured in \(function) at line \(line) code" \(code)") // local error value is created by a catch clause
} catch {
    print("Something went wrong: \(error)") // catch all statement here

Overloading Function // same name, different inputs
  can coexist when they have different parameters
  can coexist when they have return types parameters

Create custom operators
  Start wtih ascii characters or unicode calendars
  Must be declared globally

infix operator <==> { precendence 130 associativity left}

func <==> (left: CGPoint, right: CGPoint) -> Bool {
    return left.x == right.x && left.y == right.y

pointA <==> pointB

****Closures // supports so many varieties of a closure!

Functions in swift are actually a type of closure
  Can be coded inline, blocks, lambdas, or anonymous functions
var names = ["David", "Jenny", "Mock", "Pie"]
let sName = names.filter({ (name: String) -> Bool in
    return name.lowercaseString.characters.first! == "s"
let sName2 = names.filter {
    $0.lowercaseString.characters.first! == "s"
let reversedSortedName = names.sort { $0 > $1}

Deposits and Withdrawls – What’s your balance?

“You can think of relationships – in the marketplace and in your personal life – as a set of deposits and withdrawls. At JetBlue, devotion over the years of being people-friendly was a major deposit. The Valentine’s Day massacre was a big withdrawal. Expressing a genuine, heartfelt apology, offering compensation, and creating the Customer Bill of Rights were new deposits that helped the company recoup public confidence.” – Peterson

I like the metaphor of banks here. Everyone knows what a bank is. They store your money. You put in $100 one week. You take out $100 the other week. Take out too much money and you go into overdraft – we’re all guilty of this at some point in our lives.

It’s a zero sum game. You’re not going to get rich leaving your money in the bank.

In order for money to be useful it must be used.

Consider actions that strengthen relationships:

  • Calling when we haven’t heard from our friends in a while.
  • Texting a friend, “Happy Birthday!!!!!!”
  • Buying a round of drinks.
  • Saying “Thank you.”
  • Saying, “I’m sorry.”
  • Treating your friends friends as friends
  • Picking up the tab.
  • Telling someone they look nice today.
  • Listening.

Next, consider actions that weaken relationships:

  • Failing to celebrate the achievements of your friends.
  • Not calling your Mom on her birthday.
  • Forgetting important details.
  • Not really listening when your friend is telling a story.
  • Taking control of the situation without asking for feedback.
  • Not really caring
  • Not returning calls
  • Ghosting

“Trust inescapably contemplates risk.” – Peterson

With these ideas firmly in place, consider the ways that you are taking and not giving back. Mary consistently goes out with us. But she never offers to buy the next round. Instead she soaks up the good times and doesn’t refill the petty cash.

Don’t be like Mary. Repay your friends and colleagues  for the withdrawls you make. Buy the next round. Celebrate the achievements of your co-workers. Don’t be a user. Be a schmoozer!

“Life is a carnival ride and a game of dice.”

How much have you benefited from the deposits of your friends and family? What’s your balance? Gained something? Out of balance? Pay it back and we all benefit  🙂