Wednesday, October 28, 2015

Leetcode question 241: Different ways to add parentheses


  Read the blog,

  and write C# code, compile it, build it, pass online judge, check in Github, and then, write a new code using memorization.

1. First step, write down C# code, compile ok.

2. Read the most popular blog about this leetcode question through Google,

and then, take Java code as a sample, write C# version of implementation.

read the leetcode string algorithms blog (A plus):

The leetcode question 241 is just a medium  question in difficulties.

Dec. 17, 2015
Review the solution, and then, need to write down the solution - a script to help solve the problem:
1. 1+2*3
-> read a substring from leftmost to convert it to number, for the example, read '1', integer 1, and then, visit '+' stop,
-> now, let us use recursive function call to get the first part of substring before '+', and get second part of substring after '+', and then, two lists, each one of list1 will operate '+' with each one of list2, add into return list.

Not convincing, try again:
use binary tree to model this problem:

So, get the root node - operator, and then, deal with left child, right child, and root node does the evaluate function.

Monday, October 26, 2015

Back to leetcode code algorithms


  Spent 2 weeks vacation in China from Oct. 2 - Oct. 16.

  Enjoyed the tennis practice in the city of yichun, jiangxi province, and also the Rolex tennis Master, 2015 in Shanghai.


Start to read blogs about leetcode algorithms in the evening, back to training and practice. My favorite blogs to read tonight.

  Read 6 more blogs from the above blog.

Sunday, October 25, 2015

reading time on Sunday - housing issue, health issue, problem solving


Spent time to watch the video on this Sunday. Learn how billionaire educate their kids, what philosophy they hold, I do not have money but I definitely like the wisdom. Enjoy the perfect English and forget my concerns about money, Vancouver and all other things.

Enjoy reading, and also find interesting things to read.


Melinda Gates - talk about puzzle, nonprofit, problem solving in general

Personal story to help parents to do rental business - so encouraging me to work hard as well - start from small business.

Melinda French Gates: What nonprofits can learn from Coca-Cola


read linkedin profile about site reliability engineer work experience

Building Pinterest's Mobile Apps ()

How we've scaled dropbox

Discover Pinterest: Mobile Engineering and Design

Nags - Nag placement, Home view placement, Pin Tutorial Card

Further reading Nov. 3, 2015

Responsive Web Design: Relying Too Much on Screen Size

Nov. 6, 2015
Discover Pinterest: Search and Discovery

Read the article
Venture Beat article.

Nov. 7, 2015

Google I/O 2012 - SQL vs NoSQL: Battle of the Backends

Julia spent time to learn NoSQL, and got some basic ideas using NoSQL.

Google I/O 2012 - Building Mobile App Engine Backends for Android, IOS and the Web

Google I/O 2011: HTML5 versus Android: Apps or Web for Mobile Development?

O'Reilly Webcast: Building Mobile HTML5 Apps in Hours, Not Days

Study notes - "The clean code talks - 'Global State and Singletons' "


Google talks:

The clean code talks - "Global State and Singletons"

Global state:

 Julia tries to understand global state in this talk:

 Run same thing a multiple time, will get different test results;

A. Multiple Executions can product different results
1. Flakiness
2. Order of tests matters
3. Can not run test in parallel

B. Unbounded location of state

C. Hidden Global State in JVM
    1. System.currentTime()
    2. new Date()
    3. Math.random()

D. Testing above code is hard
  1. Therefore inject in doubles

Singleton: Good vs Bad

1. Application Global vs. JVM Global
2. Usually we have one application per JVM
    A. Hence we incorreclty assume that:
         Application Global state = JVM Global

3. Each test is a different configuration of a portion of our application

Deceptive API
1. API that lies about what it needs
2. Spooky action at a distance

Julia's comment, the talk is interesting and worth time to watch again later.

The clean code talks - unit testing


Watch the google talk "The clean code talks - unit testing", write down notes and then learn better for next time.

  video link:

Video time:
02:02 / 32:07
Hard to test code

Most People say:
Make things private
Using final keyword
Long methods

Real issues:  (interview questions)
Mixing new with logic
Work in constructor
Global state
Static Methods   (procedure programming) (leaf method vs way-up method)
Deep inheritance (Divorce myself from inheritance at run time. )
Too many conditionals ()

Procedure code - Seam - Polymorphism - Julia's comment: look into it, read more about it. 10/25/2015

Video time:
Progression of Testing:

1. Scenario / Large Tests
  Test whole applicatio by prentending to be a user
  slow / Flaky / Mostly happy paths

2. Functional / Medium Tests
  External dependencies simulated
  Test class interaction

3. Unit / Small Tests
    Focus on application logic
    Very Fast / No I/O / No Need for a debugger

4. Think of it more as a continuum than discrete

5. All tests levels important
    Not all levels have the same probability of a bug
    Because smaller tests cover less need more of them

6. Testability more important as you get more focused

Video time:
17:05 /32:07
Different kinds of Tests
Execution time :
unit test -> Functional Tests -> Scenario

Test individual  ->
Test collections of classes as subsytems ->
Test the whole system pretending to be a user

Video time:
How do you write hard to test code?

You mix object creation code with business logic
This will assure that a test case never can construct a graph of objects different from production. Hence nothing can be tested in isolation.

Unit test class -
Seam - friendly - try to understand the dependency injection
class depends on a lot of other classes, mocking, seam, learned through hacking,

object graph
construction & lookup
business logic

Take Away
 Unit tests are a preferred way of testing

 Unit tests require seperation of instantiation of object graph from business logic under test

1. Global variable - make test unpredictable, the order of test matters and so on and so forth.

    Do not clean up after yourself, another test will fail;
    Counter argument: framework than DI framework.

    Monkey-patching - evil on the global state - dependency injection

    C++ / Java / frameworks - dependency injection difference

And read the slideshow using the following link:

Thursday, October 22, 2015

Good API video watching and notes taken

Oct. 22, 2015

  Spent time to look into the note through the video, and then study more later:

How To Design A Good API and Why it Matters (Julia's rating: A+)

1. Watched again on 10/21/2015, notes taken to share:
Use Appropriate Parameter and Return Types
. Favor interface types over classes for input
- provides flexibility, performance
. Use most specific possible input parameter type
- Moves error from runtime to compile time (Julia's comment: Great tip, reduce time on debugging, fix things in compiling time!)
. Don't use string if a better type exists
- Strings are cumbersome, error-prone, and slow
. Don't use floating point for monetary values
- Binary floating point causes inexact results!
- Use double (64 bits) rather than float (32bits)
-Precision loss is real, performance loss negligible

2. watched again on 10/21/2015, notes taken to share:
Don't violate the Principle of Least Astonishment

Read more on this article:

3. watched again on 10/21/2015, notes taken to share:

Subclass only where it Makes Sense
. Subclassing implies substitutability (Liskov)
-- Subclass only when is-a relationship exists
-- Otherwise, use composition 

. Public classes should not subclass other public classes for ease of implementation
Bad: Properties extends Hashtable 
        Stack extends Vector 

Good: Set extends Collection