-
Clojure is homophonic language, it means the program structure is similar to its syntax
-
Every statement evaluate to one value ex (+ 1 2) => 3
-
( ) is a list
-
Lists are call, first element is operator the rest is arguments
-
No call expression use infix or postfix position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const actionRequest = actionName + '_REQUEST' | |
| const actionSuccess = actionName + '_SUCCESS' | |
| const actionFailure = actionName + '_FAILURE' | |
| const initialState = { | |
| data: null, | |
| loading: false, | |
| error: null | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // we are not using arrow function, because there no arguments binding | |
| // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions | |
| function action() { | |
| const args = arguments | |
| return dispatch => { | |
| dispatch({ | |
| type: actionRequest | |
| }) | |
| try { | |
| const result = fn.apply(this, args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function middleware({dispatch}) { | |
| return next => action => { | |
| if (typeof action === 'function') { | |
| return action(dispatch) | |
| } | |
| return next(action) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const { loginAction, loginActionTypes, loginReducer } = reduxHelper('login', function(username, password) { | |
| return api.login('username', 'password') | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import loginReducer from './login' | |
| import registerReducer from './register' | |
| import productReducer from './product' | |
| import { combineReducers } from 'redux' | |
| export default combineReducers ({ | |
| login: loginReducer, | |
| register: registerReducer, | |
| product: productReducer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createStore, applyMiddleware } from 'redux' | |
| import reducers from './reducers' | |
| import myMiddleware from './middleware' | |
| const store = createStore(reducers, applyMiddleware(myMiddleware)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Merge multiple objects | |
| function deepMerges(...objs) { | |
| return objs.reduce((a, b) => deepMerge(a,b), {}) | |
| } | |
| // Merge two objects | |
| function deepMerge (one, two) { | |
| if (Array.isArray(one) && Array.isArray(two)) { | |
| return one.concat(two) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # FOR DEBUG | |
| # print all env var | |
| env | |
| ELB_LISTENER_ARN=arn:...... | |
| ACME_PATH=~/.acme.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io, sys, itertools | |
| def tail(file, line_count): | |
| BUFFER_SIZE = 1024 | |
| pos = -BUFFER_SIZE | |
| offset = 0 | |
| result_lines = [] | |
| result_line_count = 0 | |
| while result_line_count < line_count: | |
| file.seek(pos, io.SEEK_END) |