Skip to content

Instantly share code, notes, and snippets.

(module
(import "js" "print" (func $print (param f64)))
(global $PI f64 (f64.const 3.141592653589793))
(global $SOLAR_MASS f64 (f64.const 39.47841760435743))
(global $DAYS_PER_YEAR f64 (f64.const 365.24))
;; (global $size (mut i32) (i32.const 0))
(memory $mem 1)
(func $createBody (param i32 f64 f64 f64 f64 f64 f64 f64)
(local $offset i32)
@ukyo
ukyo / text.md
Last active November 13, 2018 08:33
mallocとfreeだけ使いたい

wasmのメモリ管理つらい問題

とりあえずmallocとfreeがあればokなんだが・・・。

解決策1 emscripten使う

  • pros: 何も考えなくてもmallocとfreeが手に入る。
  • cons: でかい。

解決策2 https://github.com/dcodeIO/webassembly から取り出す

@ukyo
ukyo / adler32.c
Last active July 3, 2017 10:41
人のぬくもりがあるwasm
// https://ja.wikipedia.org/wiki/Adler-32
#include <webassembly.h>
#define MOD_ADLER 65521
uint32_t adler32(uint8_t *data, size_t len) {
uint32_t a = 1, b = 0;
while (len > 0) {
@ukyo
ukyo / hoge.js
Created July 10, 2017 11:01
対象のブランチの派生元commitかmerge commitのhashを表示する
const gmk = require('git-miru-kun');
(async () => {
const gitDir = await gmk.readGitDir('.git');
const parentHashDict = {};
const targetBranch = await gitDir.readHead();
const { branchName } = targetBranch;
const commits = (await gitDir.readBranches())
@ukyo
ukyo / git-cat-file.js
Last active August 30, 2017 13:18
git cat file
const fs = require('fs');
const zlib = require('zlib');
const path = require('path');
const { parse } = require('./git-object-parser');
const { Packfile } = require('./packfile');
// hashからGitオブジェクトのパスを作る
function getObjectPath(sha1) {
return path.resolve(
process.cwd(),
@ukyo
ukyo / brbr.js
Created October 20, 2017 08:29
brで改行している要素から擬似的なパラグラフ列を生成する
function isBlock(node) {
if (node.nodeType !== Node.ELEMENT_NODE) return false;
return /^(ADDRESS|ARTICLE|ASIDE|BLOCKQUOTE|CANVAS|DD|DIV|DL|DT|FIELDSET|FIGCAPTION|FIGURE|FOOTER|FORM|H1|H2|H3|H4|H5|H6|HEADER|HGROUP|HR|LI|MAIN|NAV|NOSCRIPT|OL|OUTPUT|P|PRE|SECTION|TABLE|TFOOT|UL|VIDEO)$/.test(node.nodeName);
}
function createPseudoParagraph(node) {
return { nodeName: "PSEUDO_PARAGRAPH", childNodes: [node] };
}
function createBrBlock(nodes) {
@ukyo
ukyo / README.md
Last active May 14, 2024 05:55
maincontent取るくん

Install and Build and Screenshot.

git clone https://gist.github.com/906764beb36481301405c586abd81011.git
cd 906764beb36481301405c586abd81011
npm install
npm run build
npm run screenshot https://gist.github.com/ukyo/906764beb36481301405c586abd81011
open out.html
@ukyo
ukyo / text.md
Created February 16, 2018 10:46
jsx or tsxからオレオレvirtual dom作る関数に渡す例

babel使ったときの例

package.json

{
  "name": "my-jsx",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
@ukyo
ukyo / facedetect.html
Created September 9, 2018 08:49
顔認識するやつ
<canvas id="canvas" width="640" height="480"></canvas>
<script>
const img = new Image;
img.src = "lena.png";
let ctx;
let arr;
img.onload = () => {
ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
arr = ctx.getImageData(0, 0, 640, 480).data;
@ukyo
ukyo / index.html
Last active October 23, 2018 07:08
WebAssembly Shared Memory example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
<meta