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
let cache; | |
const TTL = 1500; | |
const callApi = () => { | |
return new Promise((res, rej) => res('1234')) | |
} | |
async function getData() { | |
if (cache) return cache; | |
try { | |
const newProm = await callApi(); | |
console.log('get new result', newProm); |
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
async function success() { | |
return new Promise((res, rej) => res('Resolved')); | |
} | |
async function error() { | |
return new Promise((res, rej) => rej('Rejected')); | |
} | |
// then, catch syntax | |
function allSettled(promises) { | |
const allPromises = promises.map((p) => { |
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 fs = require('fs'); | |
const path = require('path'); | |
const bytes_100 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mauris augue, vulputate sit amet dolor.\n'; | |
const bytes_400 = bytes_100.repeat(4) | |
const fileName = 'file.txt'; | |
const file = fs.createWriteStream(path.join(__dirname, fileName)); | |
for (let i = 0; i <= 1e6; i++) { | |
file.write(bytes_400); |
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
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"os" | |
"github.com/cherihung/go-server-starter/config" |
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
package config | |
import ( | |
"fmt" | |
"path" | |
"github.com/spf13/viper" | |
) | |
var appConfigs AppConfiguration |
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
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"os" | |
"github.com/gin-gonic/gin" |
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
# 1 choose a compiler OS | |
FROM golang:alpine AS builder | |
# 2 (optional) label the compiler image | |
LABEL stage=builder | |
# 3 (optional) install any compiler-only dependencies | |
RUN apk add --no-cache gcc libc-dev | |
WORKDIR /workspace | |
# 4 copy all the source files | |
COPY . . | |
# 5 build the GO program |
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 compose = (...functions) => x => functions.reduce((acc, fn) => fn(acc), x); | |
// compose(fn1, fn2, fn3) | |
const pipe = functions => data => { | |
return functions.reduce( | |
(value, func) => func(value), | |
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 _generator = i => { | |
return i < 9 ? '0'+(i+1) : (i+1).toString(); | |
}; | |
const UNITS = Array.from({length: 60}, (v, i) => { | |
return _generator(i); | |
}); |
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
{% for item in sorted_items %} | |
{% assign current = nil %} | |
{% if page.id == item.url %} | |
{% assign current = 'currentItem' %} | |
{% endif %} | |
<li class="{{current}}"><a href="{{item.url}}"><img src="{{item.imageId}}.jpg" /></a></li> | |
{% endfor %} |
NewerOlder