Skip to content

Instantly share code, notes, and snippets.

View LinZap's full-sized avatar
🔬
copilot

Zap LinZap

🔬
copilot
View GitHub Profile
@LinZap
LinZap / SagaFlow.js
Last active June 18, 2019 16:27
Pseudocode - Custom Saga Flow
const action = {
succ_get_name : res=>console.log('dispatch: SUCC_GET_MAME',res),
fail_get_name : res=>console.log('dispatch: FAIL_GET_MAME',res),
succ_get_book : res=>console.log('dispatch: SUCC_GET_BOOK',res),
fail_get_book : res=>console.log('dispatch: FAIL_GET_BOOK',res),
}
function api(param,result=true) {
console.log('call api: ', param)
return {body:'im response', result}
@LinZap
LinZap / cmd
Created June 11, 2019 15:55
Node.js - HK11
node ./hk11.js "narto"
@LinZap
LinZap / hk10.js
Created June 11, 2019 01:02
Node.js - HK10
const fs = require('fs')
let dir_path = __dirname + '/storage'
let file_path = dir_path + '/hello.txt'
let str = 'Hello world'
if (!fs.existsSync(dir_path))
fs.mkdirSync(dir_path)
if (fs.existsSync(file_path))
@LinZap
LinZap / hk8.js
Last active June 10, 2019 23:18
Node.js - HK8
const proc_strng = require('./proc-string')
console.log(proc_strng.string_to_array('Hello world'))
console.log(proc_strng.string_to_int('00007777777'))
@LinZap
LinZap / hk9.js
Last active June 10, 2019 23:58
Node.js - HK9
var request = require('request');
request('http://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
})
@LinZap
LinZap / hk7.js
Created June 9, 2019 14:22
Node.js - HK7
async function map(arr, func) {
for (let i = 0; i < arr.length; i++)
arr[i] = await func(arr[i])
return arr
}
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
; (async () => {
let arr = [1, 2, 3, 4]
@LinZap
LinZap / hk6.js
Created June 9, 2019 12:19
Node.js - HK6
function delay(ms) {
return new Promise(resolve => setTimeout(() => {
console.log(new Date())
resolve()
}, ms))
}
let p = delay(1000);
for (let i = 0; i < 4; i++) {
@LinZap
LinZap / hk5.js
Created June 9, 2019 09:39
Node.js - HK5
let width = 200;
function delayPrintWidth(ms) {
let w = width
setTimeout(() => console.log(w), ms)
}
delayPrintWidth(1000); // 預期印 200
width = 300;
delayPrintWidth(2000); // 預期印 300
@LinZap
LinZap / hk4.js
Last active June 9, 2019 07:07
Node.js - HK4
/*
function connect(func1, func2) {
let data = { ...func1(), ...func2() }
return function (element) {
element(data)()
}
}
connect(
function () {
@LinZap
LinZap / hk3.js
Created June 8, 2019 20:41
Node.js -HK3
function map(arr,fun){
for(let i=0;i<arr.length;i++)
arr[i] = fun(arr[i])
return arr;
}
const arr = [1,2,3,4,5]
const new_arr = map(arr,function(n){
return n*100