Skip to content

Instantly share code, notes, and snippets.

@iboss-ptk
iboss-ptk / ListExample.hs
Last active June 29, 2018 23:51
functor
fmap (+1) [1,2,3,4]
-- [2,3,4,5]
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)
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) {
;; 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))
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])
" 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')
# 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
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)
// OthelloBot
def nextMoveByMinEdge(board: Board): Move = {
val possibleMovesWithWeight =
board
.possibleMoves
.map { move =>
val weight = /* calc weight for min edge */
(move, weight)
}