Monday, August 15, 2016

grand central dispatch

Last week,  through a mini project I got to work on GCD for the first time and all of the sudden it started making sense to me.


So the project loads a tableview of a list of Guests type.  In the cell,

  1. on main thread, label loads the name of the guests from firebase , and the imageView loads a placeholder image temperily. 
  2. and on the separated thread the photos of the guests(a cat picture in this sample) being loaded and replace the placeholder image once it is done downloading from Firebase storeage. 



https://github.com/lingzt/FirebaseDatabasePra

grand central dispatch

Last week,  through a mini project I got to work on GCD for the first time and all of the sudden it started making sense to me.


So the project loads a tableview of list of Guests type.  In the cell,

  1. on main thread, label loads the name of the guests from firebase , and the imageView loads a placeholder image temperily. 
  2. and on the separated thread the photos of the guests(a cat picture in this sample) being loaded and replace the placeholder image once it is done downloading from Firebase storeage. 



https://github.com/lingzt/FirebaseDatabasePra

Saturday, August 13, 2016

Supper cool way to store Array to Firebase

https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html
Great article, I was really confused at the beginning. However, the magic happens.

I store a JSON file to firebase,

{
"guest": {
"randomGidForGuestOne":{
"gid": "randomGidForGuestOne",
"guestAndPlusOneNumber": "1",
"guestAndPlusOneList":{"0": "randomGidForGuestOne","1":"randomGidForGuestTwo"},
"gImage":"gs://fir-databasepra.appspot.com/guestImage/randomGidForGuestOne.png"
},
"randomGidForGuestTwo":{
"gid": "randomGidForGuestTwo",
"guestAndPlusOneNumber": "0",
"guestAndPlusOneList":{"0": "randomGidForGuestTwo"}
}
}
}

and got back a dictionary with array in snapshot.  So it looks like this


{
"guest": {
"randomGidForGuestOne":{
"gid": "randomGidForGuestOne",
"guestAndPlusOneNumber": "1",
"guestAndPlusOneList": ["randomGidForGuestOne","randomGidForGuestTwo"],
"gImage":"gs://fir-databasepra.appspot.com/guestImage/randomGidForGuestOne.png"
},
"randomGidForGuestTwo":{
"gid": "randomGidForGuestTwo",
"guestAndPlusOneNumber": "0",
"guestAndPlusOneList":{"0": "randomGidForGuestTwo"}
}
}
}


Supper cool!!! Detail please see github.

https://github.com/lingzt/FirebaseDatabasePra/commit/e282cac346e747b22a669d26d000bb7e84caecb3 


Thursday, August 11, 2016

Vocation? Work from home?

A whole week break after demo day was a little rough.  I am really having a hard time slowing things down.

Basically I am working on this Apache Spark course from UCBerkeley for the week. Progress has been made, it has just been slow...................

Somehow I feel Spark will come handy one day,  I think.  It's worth my time.

Friday, July 22, 2016

SeatHero day10

2 weeks into SeatHero.
So far, have the key function half way done. Sign up and Log in done. Way to go.

All of the sudden I feel the pressure of the deadlines.

Friday, April 8, 2016

Closure Expressions and Closure Shorthand Syntax

Today, finally I figured it out what is $0 stands for. 
Thanks to treehouse, and Pasan Premaratne is a great instructor 

https://teamtreehouse.com/library/swift-closures/closures-and-closure-expressions/closure-expression-syntax




//: Closure Expressions

func doubler(i: Int) -> Int {
    return i * 2
}

let doubleFunction = doubler
doubleFunction(4)

let numbers = [1,2,3,4,5]
let doubledNumbers = numbers.map(doubleFunction)

// Using closure expressions with the map function
let tripledNumbers = numbers.map({(i: Int) -> Int in return i * 3 })

// Using closure expressions with the sorted function
var names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]

// Function to sort strings in ascending order
func backwards(s1: String, s2: String) -> Bool {
    return s1 > s2
}

//sorted(names, backwards)

//let sortedNames = sorted(names, {(s1: String, s2: String) -> Bool in return s1 > s2 })

//////////////////////////////
// Closure Shorthand Syntax //
//////////////////////////////

// Rule #1
[1,2,3,4,5].map({ (i: Int) -> Int in return i * 3 })

// Rule #2: Infering Type from Context
[1,2,3,4,5].map({i in return i * 3})

// Rule #3: Implicit Return from Single Expression Closures
[1,2,3,4,5].map({i in i * 3})

// Rule #4: Shorthand Argument Names
[1,2,3,4,5].map({$0 * 3})

// Rule #5: Trailing Closures
[1,2,3,4,5].map() {$0 * 3}

// Rule #6: Ignoring Parentheses

[1,2,3,4,5].map {$0 * 3}

Next step: backend.

Parse will be close down pretty soon so I have to look for the alternative database server. Debating bw backendless.com and AWS. My goal this coming week is to test both of them out, if lucky.