Skip to content

Instantly share code, notes, and snippets.

View aztack's full-sized avatar
🎯
Focusing

Wang Weihua aztack

🎯
Focusing
View GitHub Profile
@aztack
aztack / Advanced-Types_Type-inference-in-conditional-types.md
Last active June 28, 2021 04:00
Distributive Conditional Types & Co-variant, Contro-variant

https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types

Type inference in conditional types Within the extends clause of a conditional type, it is now possible to have infer declarations that introduce a type variable to be inferred. Such inferred type variables may be referenced in the true branch of the conditional type. It is possible to have multiple infer locations for the same type variable.

For example, the following extracts the return type of a function type:

type ReturnType<T> = T extends (...args: any[]) => infer R ? R : any;
@aztack
aztack / launch.json
Created May 23, 2021 09:13 — forked from cecilemuller/launch.json
Run ts-node in VSCode Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
@aztack
aztack / cancelable-async-seq.js
Created January 22, 2021 03:53
Execute cancelable promises one by one
var u = 2000
function cancableDelay(delay, callback, before) {
return () => {
let timer;
const promise = new Promise((rs, rj) => {
let ret = true
if (typeof before === 'function') {
ret = before(rs, rj) !== false;
}
@aztack
aztack / supplant.js
Created January 5, 2021 03:31 — forked from pbroschwitz/supplant.js
supplant - Crockford
/**
* supplant() does variable substitution on the string. It scans through the string looking for
* expressions enclosed in { } braces. If an expression is found, use it as a key on the object,
* and if the key has a string value or number value, it is substituted for the bracket expression
* and it repeats.
*
* Written by Douglas Crockford
* http://www.crockford.com/
*/
String.prototype.supplant = function (o) {
@aztack
aztack / WebGL-WebGPU-frameworks-libraries.md
Created August 10, 2020 11:26 — forked from dmnsgn/WebGL-WebGPU-frameworks-libraries.md
A collection of WebGL and WebGPU frameworks and libraries

A non-exhaustive list of WebGL and WebGPU frameworks and libraries. It is mostly for learning purposes as some of the libraries listed are wip/outdated/not maintained anymore.

Engines and libraries

  • three.js: JavaScript 3D library
  • stack.gl: an open software ecosystem for WebGL, built on top of browserify and npm.
  • PixiJS: Super fast HTML 5 2D rendering engine that uses webGL with canvas fallback
  • Pex: Pex is a javascript 3d library / engine allowing for seamless development between Plask and WebGL in the browser.
  • Babylon.js: a complete JavaScript framework for building 3D games with HTML 5 and WebGL
  • Filament: Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS and WASM/WebGL
  • ClayGL: A WebGL graphic library
@aztack
aztack / jsc.swift
Created August 4, 2020 11:01 — forked from bellbind/jsc.swift
[swift4][macos] commandline REPL for JavaScriptCore with toplevel await
#!/usr/bin/env swift
// REPL for JavaScriptCore (for arrow keys, use rlwrap command)
import JavaScriptCore
class Timeout: NSObject, JSExport {
let item: DispatchWorkItem
init(_ item: DispatchWorkItem) {self.item = item}
}
func installBuiltins(_ ctx: JSContext) {
@aztack
aztack / promise-is-resolved.js
Created July 13, 2020 04:44 — forked from tyru/promise-is-resolved.js
Check whether a promise is finished / resolved / rejected
function delay(msec, value) {
return new Promise(done => window.setTimeout((() => done(value)), msec));
}
function isResolved(promise) {
  return Promise.race([delay(0, false), promise.then(() => true, () => false)]);
}
function isRejected(promise) {
  return Promise.race([delay(0, false), promise.then(() => false, () => true)]);
@aztack
aztack / Equal.ts
Created July 2, 2020 15:34
Equal.ts
// https://stackoverflow.com/questions/53807517/how-to-test-if-two-types-are-exactly-the-same
// https://github.com/Microsoft/TypeScript/issues/27024
// https://github.com/microsoft/TypeScript/issues/37314#issuecomment-598459316
/*
type Equals<X,Y> =
(<T>() => T extends X ? true : false) extends
(<T>() => T extends Y ? true : false) ? true : false;
*/
type Equal<T, S> = [T] extends [S] ? ([S] extends [T] ? true : false) : false
@aztack
aztack / createQr-nezha-jenkins.js
Last active June 18, 2020 10:23
createQr-nezha-jenkins.js
//---------------------------------------------------------------------
//
// QR Code Generator for JavaScript
//
// Copyright (c) 2009 Kazuhiko Arase
//
// URL: http://www.d-project.com/
//
// Licensed under the MIT license:
@aztack
aztack / createQr-nezha-jenkins.js
Created June 18, 2020 06:52
createQr-nezha-jenkins.js
//---------------------------------------------------------------------
//
// QR Code Generator for JavaScript
//
// Copyright (c) 2009 Kazuhiko Arase
//
// URL: http://www.d-project.com/
//
// Licensed under the MIT license: