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
| class tPromise { | |
| constructor(fn){ | |
| this.status = "pedding" | |
| this._queue = [] | |
| this._catch = ()=>{ console.error("unhandle tPromise error") } | |
| fn.call(this, this.resolve.bind(this), this.reject.bind(this)) | |
| } | |
| resolve(data){ | |
| this.status = "resolved"; |
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 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) |
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 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 |
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
| // 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 同時執行 |
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
| return axios.post( | |
| encodeURI( | |
| `https://sheets.googleapis.com/v4/spreadsheets/${local.spreadsheet_id}:batchUpdate` | |
| ), { | |
| "requests": [{ | |
| "insertRange": { | |
| "range": { | |
| "sheetId": local.sheet, | |
| "startRowIndex": 3, | |
| "endRowIndex": 4 |
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 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, { |
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
| 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 |
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
| 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 |
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
| <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> |
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
| /** | |
| * @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); |