Skip to content

Instantly share code, notes, and snippets.

👨‍👩‍👧
Working from home

Justin Lin JustinSDK

👨‍👩‍👧
Working from home
Block or report user

Report or block JustinSDK

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View es8-for-await.js
// 透過非同步產生器函式
const vertex2 = {
x: 1,
y: 2,
z: 3,
[Symbol.asyncIterator]: async function* () {
for (let key in this) {
yield this[key];
}
}
View es8-async-generator.js
// ES8 非同步產生器
async function* range(start, end) {
for(let i = start; i < end; i++) {
yield i;
}
}
// 與上頭類似的效果
function* range2(start, end) {
function* range_inner() {
View es7-iterator-async-await.js
// 自行實作迭代器
const vertex1 = {
x: 1,
y: 2,
z: 3,
[Symbol.iterator]() {
const keys = Object.keys(this);
let i = 0;
return {
next: () => {
View es6-iterator-promise.js
// 自行實作迭代器
const vertex1 = {
x: 1,
y: 2,
z: 3,
[Symbol.iterator]() {
const keys = Object.keys(this);
let i = 0;
return {
next: () => {
View first_three_js.html
<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/96/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script>
// 場景
const scene = new THREE.Scene();
@JustinSDK
JustinSDK / array.wat
Last active Sep 20, 2018
Wasm Array
View array.wat
;; 說明:https://openhome.cc/Gossip/WebAssembly/Array.html
(module
(import "env" "log" (func $log (param i32)))
(memory 1)
;; 建立新陣列
(func $arr (param $len i32) (result i32)
(local $offset i32) ;; 記錄陣列偏移量
(set_local $offset (i32.load (i32.const 0))) ;; 取得偏移量
@JustinSDK
JustinSDK / bytecode_abc_2.py
Last active Aug 25, 2018
Byte Code ABC - 2
View bytecode_abc_2.py
class Num:
def __init__(self, value):
self.value = value
def bc_instructn(self, bytecodes):
bytecodes.append(f'push {self.value}')
return bytecodes
class Add:
def __init__(self, left, right):
@JustinSDK
JustinSDK / bytecode_abc_1.py
Last active Aug 25, 2018
Byte Code ABC - 1
View bytecode_abc_1.py
class Num:
def __init__(self, value):
self.value = value
def evaluate(self, stack):
push(stack, self.value)
return stack
class Add:
def __init__(self, left, right):
View download.py
from urllib.request import urlopen
def download(url, file):
with urlopen(url) as url, open(file, 'wb') as f:
f.write(url.read())
urls = [
'http://openhome.cc/Gossip/Encoding/',
'http://openhome.cc/Gossip/Scala/',
'http://openhome.cc/Gossip/JavaScript/',
@JustinSDK
JustinSDK / async_demo.py
Last active Aug 14, 2018
async_demo.py
View async_demo.py
from concurrent.futures import ThreadPoolExecutor
import time
import random
def doAsync(task):
g = task()
future = next(g)
while True:
try:
future = g.send(future.result())
You can’t perform that action at this time.