Skip to content

Instantly share code, notes, and snippets.

View surma's full-sized avatar
🍑

Surma surma

🍑
View GitHub Profile
@surma
surma / run-wasm.js
Created June 10, 2019 20:38
Wasm Run Script
/**
* Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@surma
surma / .gitignore
Last active April 5, 2019 09:15
GoWasm
node_modules
package-lock.json
@surma
surma / README.md
Last active March 8, 2024 12:06
webpack-emscripten-wasm

Minimal example making webpack and wasm/Emscripten work together.

Build instructions:

  • Clone this gist
  • npm install
  • npm start
  • Open http://localhost:8080
  • Look at console
@surma
surma / package.json
Created April 18, 2018 15:07
Boilerplate for quick one-off TypeScript projects. Just run `npm start`
{
"name": "tsquickstart",
"version": "1.0.0",
"description": "Boilerplate for quick one-off TypeScript projects. Just run `npm start`",
"scripts": {
"init": "test -f tsconfig.json || (tsc --init -t ESNext -m ESNext && npm install)",
"start": "npm run init && concurrently \"npm run watch\" \"npm run serve\"",
"serve": "http-server",
"watch": "tsc -p . --watch",
"build": "tsc -p ."
@surma
surma / findall_elements_deep.js
Last active October 25, 2020 16:41 — forked from ebidel/findall_elements_deep.js
Finds all elements on the page, including those within shadow dom — iterator version
/**
* Inspired by ebidel@ (https://gist.github.com/ebidel/1b418134837a7dde7d76ed36288c1d16)
* @author surma@
* License Apache-2.0
*/
function* collectAllElementsDeep(selector = '*', root = document.all) {
for (const el of root) {
if (!el.matches(selector))
continue;
@surma
surma / build.sh
Created March 29, 2018 17:25 — forked from anthumchris/build.sh
Emscripten WebAssembly Module.ready() Promise initialization similar to Module.onRuntimeInitialized
#!/bin/bash
docker run --rm -v $(pwd):/src trzeci/emscripten emcc \
-O0 `# leave uncompressed for example` \
-s WASM=1 \
-s EXPORTED_FUNCTIONS="['_hello']" \
-s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap']" \
-o emscripten-module.js \
--post-js module-post.js \
hello.c
function eventTarget(o) {
const {port1} = new MessageChannel();
o.dispatchEvent = port1.dispatchEvent.bind(port1);
o.addEventListener = port1.addEventListener.bind(port1);
}
// Usage:
let myObj = { /* ... */ };
eventTarget(myObj);
@surma
surma / importPolyfill.js
Created May 6, 2017 17:17
Polyfill for dynamic module loading
_registry = {};
importPolyfill = path => {
if(!(path in _registry)) {
const entry = _registry[path] = {};
entry.promise = new Promise(resolve => entry.resolve = resolve);
document.head.appendChild(Object.assign(
document.createElement('script'),
{
type: 'module',
innerText: `import * as X from '${path}'; _registry['${path}'].resolve(X);`,
Promise.settleAll = Promise.settleAll || (ps => Promise.all(ps.map(p => p.catch(_ => {}))));
lol1 lol2
lol3 lol4