Skip to content

Instantly share code, notes, and snippets.

const Dataloader = require("dataloader")
const fakeAsync = (content, t) => new Promise(res => setTimeout(_ => {
console.log("content:", content)
content = content.map(c => c + 1)
res(content)
}, t))
async function start() {
const testLoader = new Dataloader(async (keys) => {
console.log("batched by dataloader: ", keys)
// 代表非同步操作
let timePromise = (time)=>{return new Promise(res => setTimeout(()=> res(), time))}
let taskA = timePromise(1000)
await taskA
console.log("TaskA done")
// 此處B,C會並行
let taskB = timePromise(2000)
let taskC = timePromise(500)
await taskB
// hello / world 依序執行
async function hello(){ await new Promise((res)=> setTimeout(()=>{console.log("hello"); res();}, 2000) ) }
async function world(){ await new Promise((res)=> setTimeout(()=>{console.log("world"); res();}, 2000) ) }
console.log("start")
await hello()
await world()
console.log("end")
// hello / world 同時執行
return axios.post(
encodeURI(
`https://sheets.googleapis.com/v4/spreadsheets/${local.spreadsheet_id}:batchUpdate`
), {
"requests": [{
"insertRange": {
"range": {
"sheetId": local.sheet,
"startRowIndex": 3,
"endRowIndex": 4
const jwt = require('jsonwebtoken');
// 剛才下載的檔案
const googleServerKey = require("./test-f9099.json")
const token = jwt.sign({
"iss": googleServerKey.client_email,
scope,
"aud": "https://www.googleapis.com/oauth2/v4/token",
"exp": Math.floor(Date.now() / 1000) + (60 * 60),
"iat": Math.floor(Date.now() / 1000)
}, googleServerKey.private_key, {
import numpy as np
import tensorflow as tf
from matplotlib import pyplot as plt
# 產生100筆資料 , 此為簡單的線性關係 (加點noise)
x_data = np.linspace(-10.0, 10.0, num=100)
y_data = 3.21 * x_data + 2 + np.random.uniform(-10.0,10.0,100)
# 產生tf的graph
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
import matplotlib
matplotlib.use('TKAgg')
from matplotlib import pyplot as plt
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WebRTC Offer</title>
<script src="https://webrtc.github.io/adapter/adapter-latest.js" type="application/javascript"></script>
<script src="/socket.io/socket.io.js" type="application/javascript"></script>
</head>
<body>
<h1> Self View </h1>
<video id="selfView" width="320" height="240" autoplay muted></video>
@sj82516
sj82516 / 12-IntegertoRoman.js
Last active November 13, 2016 06:22
LeetCode
/**
* @param {number} num
* @return {string}
*/
var intToRoman = function(num) {
var romanNums = ['I','V','X','L','C','D','M'];
var ans = "";
var nums = [];
for(var v=(num%10); num>0; i++,v=(num%10)){
nums.push(v);
let person = {name: 'John Smith'};
let tpl = `My name is ${person.name}.`;
console.log(tpl);
let x = 5;
let y =3;
let tpl2 = `${x} + ${y} = ${x+y}`;
console.log(tpl2);
// template literal本身不具重用性,除非自己包成函式