Skip to content

Instantly share code, notes, and snippets.

@haintwork
haintwork / react-basic-tutotial.md
Last active September 14, 2017 00:57
[ReactJs Basic Tutorial 01] #reactjs

React Basic Tutorial

Các khái niệm cơ bản trong React

Component

  1. Giới thiệu Component
  • Compoment là những thành phần UI cơ bản, cho phép chia UI thành những thành phần nhỏ và có thể sử dụng lại.
  • Component nhận tham số property truyền vào tương tự như tag trong HTML, sau đó render lên UI.
  1. Cách viết Component
  • Sử dụng function
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
button {
padding: 1em 2em;
border-radius: 5px;
@haintwork
haintwork / how-to-avoid-many-if-blocks-when-validate-object.md
Last active August 11, 2017 08:01
How to avoid many if blocks when validate object?

Problems

In web development we may face the case that we have to write code to validate the parameter sent from client is satisfied all conditions we defined for that parameter. One strait forward solution that we may think is as example below:

public void register(String email, String name, int age) {
  String EMAIL_PATTERN = 
  "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
  + "+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
  Pattern pattern = Pattern.compile(EMAIL_PATTERN);
  List<String> forbiddenDomains = Arrays.asList("domain1", "domain2");
  if ( email == null || email.trim().equals("")){
@haintwork
haintwork / js-hoisting-issue.md
Last active August 11, 2017 04:24
What is Hoisting issue and how to prevent that

What is Hoisting

  • Puspose: allow to use function before declaring it just like below sample:
catName("Chloe");

function catName(name) {
  console.log("My cat's name is " + name);
}
/*
The result of the code above is: "My cat's name is Chloe"
@haintwork
haintwork / Validation.java
Created August 10, 2017 10:07
Interceptor Example
@Inherited
@InterceptorBinding
@Retention(RUNTIME)
@Target({METHOD, TYPE})
public @interface Validation {
}
@haintwork
haintwork / notes.md
Last active August 10, 2017 04:40
Mockito notes
  • Cannot mock equals() or hash() method of mock object.
@haintwork
haintwork / input-label.md
Created August 5, 2017 14:58
Using input radio with label in React
<label><input type="radio" name="filterTodo" value={FilterType.FILTER_ALL} checked={this.state.option === FilterType.FILTER_ALL} onChange={(e)=>this.filterSelected(e)}/>All</label>
@haintwork
haintwork / redux-initialize.md
Last active August 5, 2017 07:56
Redux Initialize

ActionType constant

const ActionType = {
  ADD_TODO: 'ADD_TODO',
  DELETE_TODO: 'DELETE_TODO'
}

export default ActionType;

App.js

@haintwork
haintwork / javascript-deep-copy.md
Created August 5, 2017 03:48
Deep copy objectin Javascript

Deep copy JSON object:

mObj=JSON.parse(JSON.stringify(jsonObject));