Friday, August 12, 2016

Clip: cropping an image - CSS learning and sharing on JSFiddle

August 12, 2016

Clip is the CSS feature to clip an image using scripts. Julia spent more than one hour to work on a few lines of CSS code, and then, she chose to use a specific image to help.

If you have an image with 500px x 500px, you may like to get one small image with size 100px x 100px without using Microsoft paint to cut and save as a new file. The solution is to use CSS clip.

Basics to find out the solution:
CSS:
1. position relative/ absolute
2. rect
3. clip
4. an example to explain how to put together
5. play with Firefox firebug, and then figure out CSS settings.

Study the article:
http://www.xul.fr/en/css/clip.php

Spent more than 1 hour to figure out how to set up .clipzone width and height. There are a few ways to set up CSS, but she likes to write down her tips to solve the problem.

After more than one hour confusion, she decided to customize an image with some grids and text, with size of 500px x 500px, see the following:



With a few mistakes, she figured out how to configure them quickly. Let us talk about a problem, and then, solve the problem using CSS clip property based on the article (ref. 2).

Problem statement:
How to clip the image 100px x 100px in the center of the above image, with text 13?

Here is the image: 


The element is to be cropped in an outer container, and the clip zone
- Julia's tip 1:  make the zone the whole image:

.clipzone
{
    position: relative;
    width:  500px;
    height: 500px;
    overflow: hidden;
}

.clipped
{
    position: absolute;
}

<div class="clipzone"> <img class="clipped" id="image1" src="" /> </div>

This container is integrated in the flow of the contents of the page with the relative position and allows the content to have the absolution position. The property overflow: hidden avoids exceeding the limit of the container.

so add the clip css property and value into class clipped, and add this rule:
.clipped
{
position: absolute;
clip: rect(200px, 200px, 300px, 300px);   /* top left right bottom*/
}

And then, the image using clip CSS property will be:


Julia's tip 2: 
Add one more rule:
margin-left: -200px;

With the above rule, the clipped image will be positioned at 0 position; in other words, to get any image, for example,
with text: 11, set margin-left: 0px;
with text: 12: set margin-left: -100px;
with text: 13: set margin-left: -200px;
with text: 14, set margin-left: -300px;
with text: 15, set margin-left: -400px;

so the image is always positioned the same place.

References:
1. http://www.w3schools.com/cssref/pr_pos_clip.asp
2. http://www.xul.fr/en/css/clip.php

Actionable Items:

1. clip an image using CSS

https://jsfiddle.net/jianminchen/ksdcgomx/

2. original image vs clipped image

https://jsfiddle.net/jianminchen/hxgakk5n/
1. clipped image: 2. orginal image comparison to the clipped image

Blog reading: 
1. Google keyword search: JavaScript Separate of concern
how to structure JavaScript better?
Study the code - example to follow
 http://stephen-young.me.uk/2013/01/05/maintainable-js-with-modules.html

Watch and learn: Microsoft agile development - Bing






Microsoft Development Services for the DevOps Era

Thursday, August 11, 2016

JavaScript - a programmer random thoughts

August 11, 2016

Julia likes to have a small research every day, later she can add some thoughts for the topic. Today the topic is "how to balance coding writing vs reading API documents".  


In order to write good JavaScript code, read a lot of JavaScript code first. She did write JavaScript/ CSS/ Html code 8 hours nonstop at work, she likes to take a break while she was at home enjoying the evening. 

 Julia reviewed the blog about JavaScript while watching interviews. 
Interviews she enjoyed - Vogue 73 questions series: 

1. Serena Williams
Serena offers 1 hour $100 master class - video class - She is really good at teaching, she shows in the interview how to make a hidden drop shot.


2. Iggy Azalea - 7 3 questions 
https://www.youtube.com/watch?v=AMh5f8xRLRE

3. Song writer, singer Swift Taylor
https://www.youtube.com/watch?v=XnbCSboujF4

Random thoughts:
1. How to stay calm, answer questions very well?

2. Airbnb JavaScript Style Guide()  - English Version

https://github.com/airbnb/javascript

Reading while going through JavaScript style guide from Airbnb:

1. JavaScript spread syntax...  - 10 minutes

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator


3. Read JavaScript Array.From - 20 minutes

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from
2. Celebrate the day by learning CSS, working on clipping image etc.:

A. clip techniques - outside - relative, inside, absolute
how to define it and practice it!
http://www.xul.fr/en/css/clip.php

B. Text over the image:
https://css-tricks.com/text-blocks-over-image/

C. Bootstrap 3 Thumbnail Slider / Carousel
http://www.bootply.com/XeZvDD059P#

Monday, August 8, 2016

Designing Fluent APIs in C# - pluralsight.com

August 8, 2016

Plan to work on course - Designing Fluent APIs in C#

http://app.pluralsight.com/author/floyd-may

video to watch:
https://www.youtube.com/watch?v=uKtMwmWv6Q0

Mastering C# 4.0 - pluralsight.com

August 8,  2016

Plan to work on this course - Mastering C# 4.0 - pluralsight.com, 11 hours.

http://app.pluralsight.com/author/jon-skeet

C# Design Strategies - pluralsight.com

August 8, 2016

Plan to work on this course on pluralsight.com - C# design strategies - 3 hours.

http://app.pluralsight.com/author/jon-skeet


.NET distributed system architecture - pluralsight.com

August 8, 2016

Plan to work on the course - .NET distributed system architecture - 5 hour 30 minutes

Lecturer's website:

http://app.pluralsight.com/author/scott-seely

Become a Full-stack .NET Developer - Architecture and Testing - pluralsight.com

August 8, 2016

Plan to study the course:

Become a Full-stack .NET Developer - Architecture and Testing

Lecturer's website:

http://app.pluralsight.com/author/mosh-hamedani

Notes:

1. Remaining use cases

2. Modularize JavaScript Code

3. Refactoring towards the clean architecture

4. Programming against interfaces

5. Test Controllers

6. Test Repositories

7. Adding Integration Tests


Modularizing JavaScript Code - 40m 56s

Introduction
Extracting JavaScript Code
Revealing Module Pattern
Refactoring using Revealing Module Patten
Cleaning the init Method
Applying the DRY Principle
Better Separation of Concerns
Module Dependencies
Physical Separation
Optimization
Exercise
Code Review
Summary

Programming Against Interfaces

Introduction
Dependency Inversion Principles
Extracting Interfaces
Dependency Injection
Adding Ninject
Does Entity Framework Really implement the Repository Pattern?
Package Dependencies
Restructure the Application
Complexity Fallacy
Productivity Fallacy
Exercise
Refactoring Data Annotations
Complexity Fallacy
Productivity Fallacy
Exercise
Refactoring Data Annotations
Summary

Testing Controllers


Introduction
Extracting Queries
Repository pattern
When to use the repository pattern
extracting repositories
extracting queries with eager loading
exercise
code review
clean architecture
decoupling from entity framework
unit of work pattern
implementing the unit of work
consolidating dependencies
summary


Programming Against interfaces
introduction
Dependency inversion principle
extracting interfaces


Repository pattern is already in entity framework - no need to use? it depends.

Design to solve problems - repository pattern

complexity of design - be pragmatic

meidum/ large projects

problems :

complex queries/ fat controllers/ fat services


SQL Injection etc. website common attacks -

SQL injection, XSS, CSRF, preventing CSRF attacks -

http://www.veracode.com/security/xss

C# Extension Methods - pluralsight.com

August 8, 2016

Plan to study the course "C# Extension Methods". 3 hours course.

Lecturer's website:
http://app.pluralsight.com/author/elton-stoneman

August 8, 1 hour, Introduction Extension Methods

Sunday, August 7, 2016

A small research - tennis coaching vs algorithm lecturing

August 7, 2016

  Julia likes to pick up a small topic to do some research and practice her research muscle. Since she was amazed about USATP master professional Rick Macci's teaching video, and amazed how good the presentation is. A lot of technologies are applied on tennis coaching and tennis matches. For example, on the tennis court, on the grand slam matches, there are hundreds of camera on the court, hundreds of technologies on speed measuring, and all other things.

  Here is the link:

 https://www.youtube.com/watch?v=5MHugAF2DiQ

1. Lecture on Roger Federer's tennis forehand stroke, and show 3D technologies how to do analysis
2. Before vs After, two videos are comparing.
3. Statistics: How many views? over half a million views. -
4. Producer: USPTA
    - how good USPTA can utilize the technologies and help the teaching.

Lecture notes: 
Forehand - 7 steps: (P, J, E, T, F, FS, F)
Preparation
Joint angles
Elbow Extension
Tap the dog
The Flip
Forward Swing
The Finish

Goal: Racket Speed, keep the ball in the court


And teaching lectures she spent time to work on this weekend:

Algorithm: count inversion
extended merge sort:

Julia also likes the lecture content about count inversion - merge sort, the examples and discussions.
So, Julia likes to study those lecture notes, take time to enjoy reading.

1. http://www.cs.umd.edu/class/fall2009/cmsc451/lectures/Lec08-inversions.pdf
Julia learns tennis from over 20 top coaches in the world and also actively practice what she learns through lessons:
Here is one of them she learned from the coach - 
https://www.youtube.com/watch?v=n7ApnK3BGcU

Julia started to work on the double alley drill - learning is fun!




one more:

Friday, August 5, 2016

Count inversions - Extended merge sort - 3 Lecture Notes Study

August 5, 2016 

Choose topic: extended merge sort
Algorithm: count inversions

count inversions - extended merge sort
1. http://jane4532.blogspot.ca/2013/06/zz-google-onsite-interview.html
2. http://www.geeksforgeeks.org/counting-inversions/
3. http://www.cs.umd.edu/class/fall2009/cmsc451/lectures/Lec08-inversions.pdf
4. https://www.cp.eng.chula.ac.th/~piak/teaching/algo/algo2008/count-inv.htm
5.  https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/05DivideAndConquerI.pdf
6. http://www.cs.colostate.edu/~cs320/Slides/05_inv.pdf


problem statement:
Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. 
Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j
Example:
The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3).
Lecture Notes -
1. First lecture study:

1. How many inversions at most in the array n?
n(n-1)/2, special case, like {n, n-1, ..., 1}, any two nodes in the array is one inversion pair.

or: What is the maximum number of inversions for a list of length n? 
n(n-1)/2

2. If each inversion is counted once, then the time of the algorithm is O(n^2), n is the number of elements in the array. Not optimal, we should not count each inversion.

3. Ideas to solve the algorithm:
Bubble sort? 
Selection sort?
Insertion sort? 
These are O(n^2)
Bubble and insertion sort count each individual inversion. To do better we must not count each individual inversion. 

So, better algorithm is to beat O(n^2), using merge sort, nlogn - divide and conquer - sort and count inversion in the same time.

In merge sort we do not swap all elements that are out of order with each other, we make larger distance "swaps". 

Questions: Sorting and counting inversion - merge part how to count the inversions.

Keywords in the lecture notes (7):

Collaborative filtering 
inversions 
Meta-search tools
Rank analysis
Recurrence Analysis  - T(n) = 2 T(n/2) + cn 
similarity/ dissimilarity / in the middle 
the number of out of place rankings 

Actionable Items: 
1. Merging part with diagram:   <- Julia, can you draw a diagram as well 
2. Count Inversions: Algorithm pseudo code - write down here: 

2. 2nd Lecture Notes Study: 

Julia, write down favorite notes one sentence a time, on page 16, 17 
------- 
Counting inversions: how to combine two subproblems?
Q. How to count inversions (a,b) with a ∈ A and b ∈ B? 
A. Easy if A and B are sorted!

Warmup algorithm. 
Sort A and B. 
For each element b ∈ B, 
- binary search in A to find how elements in A are greater than b. 

list A                               list B
7    10    18  3  14           17    23    2  11  16

sort A                              sort B
  7    10  14  18              11    16  17  23

binary search to count inversions (a, b) with a ∈ A and b ∈ B

  7    10  14  18              11    16  17  23
                                       5    2      1     1   0
-------






3. 3rd Lecture Notes Study:  (Inversions Count)
http://www.cs.umd.edu/class/fall2009/cmsc451/lectures/Lec08-inversions.pdf


Play to win; stop Recognize when you are using negative self-talks and replace it with positive; when in doubt, remember: Play to win.


Memorize 8 tips to help you to perform to your highest potential in Tennis (? code practice, etc.):
1. Let go of what others think
2. Perform for yourself, not to impress or to "not disappoint" others
3. Accept that you will make mistakes, and let them go
4. Focus on what you can control
5. Recognize when you are using negative self-talk and replace it with positive
6. Rather than performing perfectly, perform to see improvement
7. Be objective about your performance, not subjective
8. Focus on the Journey, not the Destination

Play not to lose or Play to win - Julia plays to win! 

Thursday, August 4, 2016

ITINT5: tree maximum path sum (II)

August 4, 2016

Blog 1: July 6, 2015
http://juliachencoding.blogspot.ca/2015/07/itint5-tree-maximum-path-sum.html

First writing in C# (July 6, 2015)
https://gist.github.com/jianminchen/754d29e47c491cfc271f764fb5dd8a61

Review comments (August 4, 2016, after 13 months):
1. first, the input argument res - variable name - not accurate - res should be maxValueCrossRoot
2. function name: maxTreePathSumRe is confusing, will be better called "maxTreePathSumEndByRoot"
3. line 121, 122 can be merged into one line statement - easy to read 
4. add some design spec for the function - maxTreePathSumRe

Blog 2: August 4, 2016
C# code practice: 2nd writing
https://gist.github.com/jianminchen/c9be400e7bee71734ee7c454635846cf

review comments:
1. Line 138 - 150, function ArrayMaximum
No need, call Array.Max();

3rd writing:
https://gist.github.com/jianminchen/3b2c8e0e84e52cbca2a7ec435b29a2e4

highlight of changes:
1. line 124, use Array.Max(), remove the function: ArrayMaximum(int[])

Use Language Integrated Query (LINQ) - Array.Max(), detail see the blog:
http://juliachencoding.blogspot.ca/2016/06/array-class-c-c-javascript-java.html

LINQ - Enumerable Methods Reference:
https://msdn.microsoft.com/en-us/library/bb342261(v=vs.100).aspx

Blogs to read:
Choose topic: extended merge sort
Algorithm: count inversions

count inversions - extended merge sort
1. http://jane4532.blogspot.ca/2013/06/zz-google-onsite-interview.html
2. http://www.geeksforgeeks.org/counting-inversions/
3. http://www.cs.umd.edu/class/fall2009/cmsc451/lectures/Lec08-inversions.pdf
4. https://www.cp.eng.chula.ac.th/~piak/teaching/algo/algo2008/count-inv.htm


Leetcode 124: Binary Tree Maximum Path Sum - Single Responsibility Principle (SRP)

August 4, 2016

 If you do not have idea how to solve the Leetcode 124, please read the blog first, warm up with ideas to solve the problem:
http://juliachencoding.blogspot.ca/2016/08/leetcode-124-binary-tree-maximum-path.html



The maximum path sum in the above tree is highlighted using red color, node 6->9->-3->2->2. Any two nodes in the tree can form a unique path, and the choice of path is N^2, N is the total nodes in the tree.

Creative way to solve the algorithm problem:

Review S.O.L.I.D. principles, one of principle - Single Responsibility Principle. 

Use SRP to write the function, one task a time. 
1. Work on a simple problem first:
Maximum value end by root in a binary tree - in other words, maximum value from the root node to any node in binary tree

https://gist.github.com/jianminchen/8f3ec942e90bcdca5a1569d1a70e92df

Goal: be able to write the function in 10 minutes, verify code with static analysis.

1. Step 1: write a simple recursive function - preorder traversal. 
A: Pay attention to negative value node. 
(if both left and right child node's value are negative value, maximum value path ending at root node is root node's value itself; value >= root node's value) -> come out formula: line 98, maximum value of 3 values. 
  
B: Avoid if statement, just get minimum value through 3 values, make it one line statement - no if/else discussion of left/right child value > 0.

Only 5 lines of code. Short and concise.




2. Add one more task in the above function -

Usually the function should be designed to work on one task only. Need to add a second task to the function. 

Based on the simple problem - maximum value end by the root node, add one more task to the function:
maxValueCrossRoot calculation. (bottom up solution)

Try to calculate the maximum path sum cross the root node in the tree. 

https://gist.github.com/jianminchen/5eab22189f0fd7a58aa4fbc56b725dd8

Add 2 more lines of code: line 104, 105, add one more input argument - ref int maxCrossRoot, 3 places update

Goal: complete the code change in 10 minutes. 

2. Step 2: add 2 lines code (line 104, line 105), 3 changes - add one more argument (line 96, line 101, line 102):


So, overall, less than 20 minutes code writing. Follow the above 2 steps - write a function to complete the first task, and then, add second task to the function. 

Questions and Answers:

1. How to make this algorithm an easy one? 
A few people complain that the algorithm is too tough to work on through their blogs. Julia also spent hours to work on it in 2015, and then, Feb. 2016. 

In August 2016, Julia spent hours to review the algorithm, wrote 2 blogs.  

For easy to write, try SRP techniques, work on maximum path end by root first, then piggyback the max path cross the root. It will help to ease the stress. 


I learned to stay and work hard every day to get the chance to be the best. - Karolina Pliskova
Julia, can you repeat the sentence word by word?

Leetcode 124: Binary tree maximum path sum - a quick review

August 4, 2016
Come back to review the previous work, but it is still not easy to tell the ideas to solve the problem.

Let us talk about an example first:
In the practice on May 31, 2016, line 60 - 79, test case 3:
https://gist.github.com/jianminchen/578656e1079e8c58b08dd19f5b027e68




The maximum path sum in the above tree is highlighted using red color, node 6->9->-3->2->2. Any two nodes in the tree can form a unique path, and the choice of path is N^2, N is the total nodes in the tree.

Walk through the above example in the diagram and have some more discussion: 

First talk about "maximum value cross root" - variable: maxValueCrossRoot,
each node is the root of its subtree, so the maximum one will be maximum one from the following list:

1. n1: root node (9): need to calculate maximumEndByRoot on right child (-3) first.
2. n2: left child (6):
3. n3: right child (-3):
4. n4: right->right child(-6): -6
5. n5: right->right->right (2): 4
6. n6: right->rigth->right->left(2) : 2
7: n7: right->right->right->left->left(-6): -6
8: n8: right->rigth->right->left->right(-6): -6

It is comparison by values.
Tip: 1.The idea to get the maximum value is to pass a reference int to any recursive function. Any subtree will have one value, and compare with the global variable's value.
2. Use preorder traversal to travel tree once.

And "maximum value end by root" - variable: maximumEndByRoot

the above node n8: -6
n7: -6
n6: 2
n5: 4
n3: +1
n2: 6

So, the root node maxValueCrossRoot = 9 + 6 + 1 = 16
maximumByEnd = 15.

Tip: 1. use recursive function with return value - maxValueEndByRoot, the formula is easy to recall.
2. use preorder traversal to travel tree once.

The above case is coincident, the maxValueCrossRoot is ended at the root node n1 (value 9), which may be anywhere (ni, i is one value from 1 to 8) in the tree.

Monday, August 1, 2016

HackerRank - Prepare to get experience on advanced level algorithms on HackerRank

August 1, 2016

 Choose a small topic to work on, when to choose to work on advanced algorithm and what to learn through the practice.

 Pragmatic ideas:

1. How is the algorithm developed by editors? Best algorithm lecture material to study.

2. Study some code for classical problems through submissions.

Julia spent over 100 hours to work on HackerRank, solved over 50+ algorithms problems, and then, she is getting better to understand the problem statement on HackerRank. But she only chose to work on easy, medium difficult questions.

Last time - 3 hours - really struggling - world code sprint #5 with advanced, difficult questions.  

Some facts on 3 hours activities: 
1. Tried to guess, break down small problems.
2. Wrote down some notes
3. Tried to guess what kind of problem it is - DP, DFS, graph, etc.

Julia likes to come back to review, and if she can write a blog on her 3 hours experience:

1. Spent 30+ minutes to read the problem statement
http://juliachencoding.blogspot.ca/2016/07/build-forest-hackerrank-world.html

2. Spent 30+ minutes to read the problem statement
http://juliachencoding.blogspot.ca/2016/07/build-palindrome-hackerrank-world.html



Actionable Items:

1. Work on suffix array first, learn basics first:
http://www.geeksforgeeks.org/suffix-array-set-1-introduction/

2. Read the article, get all questions related to suffix array in the contest:
(plan to spend 2 hours to study)
http://www.stanford.edu/class/cs97si/suffix-array.pdf

3. Review previous suffix array blog and C# implementation of suffix array:
http://juliachencoding.blogspot.ca/search/label/suffix%20array%20C%23


Productivity Tips for the Busy Tech Professional - pluralsight.com

August 1, 2016

  Lecture website:

http://app.pluralsight.com/author/richard-seroter

One hour talk - great ideas!

Most favorite tips:

1. Decompose big problems - never see big problem, always small problems  (10 out of 10)

2. Learn to say no, and leave buffer for important things to pop up.

3. Establishing a frame of mind - talk about his experience to write books etc.



AWS study - pluaralsight

August 1  2016

 Canadian statutory holiday - civic day, choose some study material from pluralsight.com - learning AWS.

Lecturer's website:

http://app.pluralsight.com/author/richard-seroter


Choose one or two in the following:


1. Amazon Web Service Databases in Depth

2. Architecting Highly Available Systems on AWS

3.
https://app.pluralsight.com/library/courses/aws-auditing-environments-security-best-practices/table-of-contents

Blog reading:
http://jane4532.blogspot.ca/