Tuesday, 25 February 2020

deep learning


1. concepts
  • neuron (input -> output)
  • input, weight, bias      u=∑w*x+b
  • activation function     y = f(u)
  • cost/loss function
  • overfitting: statistically correspond too closely

2. type of activation functions
  • sigmoid
  • relu
  • softmax (convert to probabilities that sum up to 1)

3. tensorflow
  • tensor: n-dimension vector
  • inception v3, a neural network that's pretrained for image classification
  • top layer - right most output layer
  • bottleneck layer - layer just before the top layer


reference
1. 25 must know concepts
2. quickly setup google’s tensorflow image recognition
3. deep Learning with tensorflow: part 2 — image classification

Wednesday, 1 January 2020

useful javascript functions

1. spread operator ...

2. for ... of iterator

3. includes()

4. some()     //if some element in array pass the test

5. every()    //if every element in array pass the test

6. filter()     //filter the array that pass the test

7. map()     //convert the array

8. reduce()    //reduce to array, number, object

9. find()

ref
1. 7-javascript-methods-that-will-boost-your-skills
2. Most Useful JavaScript Array Functions
3. most-useful-javascript-methods

Thursday, 10 October 2019

cypress

1. login programatically without using UI

    cy.request('POST', '/login', {
      username,
      password
    })


2. compared to selenium, cypress is consistent 'cause it's running inside browser

3. assertion
  • should/and

4. auto complete
  • /// <reference types="Cypress" />

5. fixture (it's like property file)

6. cypress has its own locator inspector after navigating to webpage

7. stub
cy.intercept('GET', '/api/users', { fixture: 'users.json' }).as('getUsers');
cy.visit('/users');
cy.wait('@getUsers');       //stub /api/users and wait for it, real api is not called


8. wait
  • cy.visit('/users');                                                                //only wait for page load
  • can add below code to wait for an api call to finish
cy.intercept('GET', '/api/another-resource').as('getAnotherResource');
cy.wait('@getAnotherResource');



Wednesday, 9 January 2019

security

1. public key (certificate) vs private key
  • used in asymmetric cryptography
  • public key and private key are mathematically related
  • what's encrypted with public key can only be decrypted by private key

  • server generate public/private key pair
  • server send public key to client in SSL/TLS certificate (any website with https address use SSL/TLS)
  • client use CA to verify certificate is legit

2. trustStore vs. keyStore
  • trustStore is normally on client  and is used to store public key (certificate) from trusted CA
  • client will encrypt message with pubic key
  • keyStore is normally on server side and stores private key and public key pair
  • server use private key to decrypt client message
  • you can have trustStore and keyStore on both client and server side, if client also need to authenticate itself to server

3. .crt file vs .key file
  • crt file is public key 
  • key file is private key

4. .p12 file vs .jks file
  • p12 file hold both private and public key
  • jks file hold both private and public key
  • jks is for java application and p12 support across different platforms

6. ssl certificate chain
  • end user certificate
  • intermediate certificates
  • root certificate
  • when install end user certificate, you must bundle all intermediate certificates and install them along with end user certificate
  • the list of certificates, from root to end user, represent certificate chain

7. ca bundle
  • ca bundle is a file that contains root and intermediate certificates
  • end user certificate + CA bundle = certificate chain
8. 2-way authentication (see link)

9. get certificate from browser

10. how to add cert file to java truststore

11. cors
  • domain 1 is not allowed to call domain 2 api (access domain 2 asset) unless correct Access-Control-Allow-* header is set in domain 2 api

12. ssh
  • public key is stored in ssh server
  • private key is stored in ssh client

reference

Tuesday, 27 November 2018

microservice


1. api gateway/nginx

  • routes requests to the appropriate microservice
  • invoke multiple microservices and aggregate the results
  • translate between web protocols such as HTTP and web‑unfriendly protocols that are used internally

reference
1. service discovery

Monday, 22 October 2018

use mac

1.short cuts
  • command + option + ESC (ctrl+alt+del)
  • command + DEL (move to trash)
  • command + tab (cycle apps)
  • command + M (minimize current app)
  • command + W (close window)
  • command + shift + 4 or 3 (take screenshot)
  • command + space (spotlight)
  • command + up/down (go to parent/child dir in finder)
  • command + C / command + option + V (cut and paste file)
  • command + ~ (switch between windows of same application)
  • double click (move the relative position of multiple full screen application)
  • double finger swipe left/right (switch between tabs of browser)
  • drag finder file to terminal (copy its path to terminal)
  • command + shift + G (in finder go to folder)
  • right click + option (copy path)
  • right-click -> service -> new terminal at folder (open terminal at finder)
  • command + shift + T (in textedit remove formatting)
  • view -> show path bar
  • view -> show status bar
  • trackpad -> tap to click
  • track -> secondary click -> click in bottom right corner
  • spread thumb and three finger (show desktop)
  • 4 fingers (mission control)
  • close lid (lock screen)

2. intellij
  • set keymap mac OS X 10.5+                  //for better shortcut key
  • command + two fingers                          //zoom font size
  • command + F9 (save and build)
  • command + E                                          //recent files, also show maven project
  • shift + shift                                              //search everything
  • command + G                                         //search next
  • command + shift + F                              //search text in all files
  • command + B                                         //view definition
  • alt + F7                                                    //find usage
  • command + [                                           //navigate back
  • command + shift + backspace                //last edit location
  • fn + cursor left                                        //goto beginning of line
  • fn + cursor right
  • command + option + L                           //auto format
  • shift + command + 8 .                            //toggle column mode
  • shift + command + F8                            //show all breakpoints
  • option + F8                                             //evaluate expression
  • command + F7                                       //smart step into
  • command + space ()
  • don't forget intellij main menu
  • click .pom file to import maven project, search project recursively
  • eclipse workspace is intellij project, eclipse project is intellij module 
  • select autoscrolling to sources in project setting
  • analyze -> analyze data flow to here
  • debug: can use package.json, "node $NODE_DEBUG_OPTION index.js"
  • debug: can use run configuration 'javascript file' - 'index.js', $NODE_DEBUG_OPTION will be added when clicking debug button
  • the name 'step_definitions' has to be used for cucumber step definition folder so that Intellij can find it from feature file
  • https://www.youtube.com/watch?v=pt3uB0sd5kY

3. vscode 
  • command + P                                              //search file by name
  • ctrl+shift+f                                                  //search all
  • f5                                                                 //debug
  • ctrl+f5                                                         //run
  • ctrl+p                                                          //open recent files
  • ctrl + -                                                        //navigate back
  • ctrl + shift + -                                             //navigate forth

4. brew
  • brew uninstall --force nvm
  • brew list [software]                                   //list all(software) packages installed


reference
1. create intellij run configuration from package.json 'script'
2. intellij can not find step definition from feature file
3. share intellij configuration between projects

Friday, 27 July 2018

json & xml

1. json concept
  • number, string, object, array, boolean, null
  • if start with [, it is a json array
  • if start with {, it is a json object
  • JSON.stringify(obj) convert json object to string
  • JSON.parse(string) convert json string to object
  • json is not extensible

2. json object
myObj = { "name":"John", "age":30, "car":null };

myObj = {                          //nested json object
    "name":"John",
    "cars": {
        "car3":"Fiat"
    }
 }


3. json array (of object)
myObj = {
    "name":"John",
    "cars": [
        { "name":"Ford"},
        { "name":"BMW"},
        { "name":"Fiat"}
    ]
 }


4. java json library (objectmapper)
  • jackson (default for resttemplate, restassured etc)
  • jayway jsonpath

5. xml concept
  • prolog, tag, attribute and element
  • DOM tree, root, parent, child, sibling
  • attribute value must be quoted
  • < less than becomes &lt;
  • online xpath editor @http://xmlgrid.net/xpath.html
  • xml is extensible
  • javascript xml parser
      <?xml version="1.0" encoding="UTF-8"?>       //prolog
      <book category="children">                               //book is tag, category is attribute
          <title>harry Potter</title>                               //element
          <year>2005</year>
      </book>

      parser = new DOMParser();
      xmlDoc = parser.parseFromString(text,"text/xml");


6. xml namespace
<root>

<h:table xmlns:h="http://www.w3.org/TR/html4/">
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table xmlns:f="https://www.w3schools.com/furniture">
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>

</root>

<table xmlns="http://www.w3.org/TR/html4/">          //default namespace
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>


7. xpath
  • /                         //select from root
  • //                        //from current node, wherever they are
  • .                         //current node
  • ..                        //parent
  • @                      //select attribute

8. java xml library
  • DOM api (tree model, in memory)
  • SAX api (stream based, event driven, push-parsing model)
  • Stax api (stream based, event driven, pull-parsing model)
  • JAXB api (schema based)

9. jaxb
  • marshall: convert java object to xml
  • unmarshall: convert xml to java object
  • jaxb validation: verify that xml or java object tree meet all constraint in xml schema
  • convert schema to jaxb class in eclipse (right click)
  • convert schema to jaxb class online ()

10. xml schema
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

</xs:schema>