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
| fmap (+1) [1,2,3,4] | |
| -- [2,3,4,5] |
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
| Number.prototype.times = function (fn) { | |
| const n = this.valueOf() | |
| const range = [...Array(n).keys()].map(n => n + 1) | |
| for (const i of range) { | |
| fn(i) | |
| } | |
| } | |
| // notice the () around number. without () it will be a syntax error | |
| (10).times(console.log) |
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
| buildAction = perform => query => new Promise((resolve, reject) => { | |
| const elem = document.querySelector(query) | |
| let count = 0 | |
| const checkExist = setInterval(() => { | |
| if(count >= 1000) { | |
| return reject('timeout') | |
| } | |
| if(elem) { |
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
| ;; if using keyword (:whatever) as key | |
| ;; -- { :amphoe "x" :tambol "y" } | |
| ;; then this is enough | |
| (defn sort-data [keys data] | |
| (sort-by (apply juxt keys) data)) |
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 [lessThan, equal, greaterThan] = [-1, 0, 1] | |
| const compareString = (s1, s2) => { | |
| if (s1 === s2) { return equal } | |
| if (s1 < s2) { return lessThan } | |
| if (s1 > s2) { return greaterThan } | |
| } | |
| const compareObjectBy = ([head, ...tail]) => (o1, o2) => { | |
| const compareStringResult = compareString(o1[head], o2[head]) |
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
| " Dark powered mode of SpaceVim, generated by SpaceVim automatically. | |
| let g:spacevim_enable_debug = 1 | |
| let g:spacevim_realtime_leader_guide = 1 | |
| call SpaceVim#layers#load('incsearch') | |
| call SpaceVim#layers#load('lang#c') | |
| call SpaceVim#layers#load('lang#elixir') | |
| call SpaceVim#layers#load('lang#go') | |
| call SpaceVim#layers#load('lang#haskell') | |
| call SpaceVim#layers#load('lang#java') | |
| call SpaceVim#layers#load('lang#javascript') |
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
| # remap prefix to Control + f | |
| set -g prefix C-f | |
| unbind C-b | |
| bind C-a send-prefix | |
| # set vi key binding | |
| set-window-option -g mode-keys vi | |
| bind-key -T copy-mode-vi 'v' send -X begin-selection | |
| bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel |
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 roundNum = (i, j) => Math.max(Math.abs(i), Math.abs(j)) | |
| const sumRange = n => (n * (n + 1)) / 2 | |
| const accumulateBy = f => n => f(sumRange(n)) | |
| const roundCircumference = n => 8 * n | |
| const accumulateDistanceUpToRound = accumulateBy(roundCircumference) | |
| const distanceOnOuterRound = (i, j) => { | |
| const n = roundNum(i, j) |
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
| // OthelloBot | |
| def nextMoveByMinEdge(board: Board): Move = { | |
| val possibleMovesWithWeight = | |
| board | |
| .possibleMoves | |
| .map { move => | |
| val weight = /* calc weight for min edge */ | |
| (move, weight) | |
| } |