Skip to content

Instantly share code, notes, and snippets.

@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 / 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 から取り出す

(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)
(module
(memory 1 1)
(func (export "test1")
(local $i i32)
i32.const 1000000000
set_local $i
loop
i32.const 0
i64.const 1
@ukyo
ukyo / bench.js
Last active May 17, 2016 07:31
quick sort with wasm
// see http://indiegamr.com/generate-repeatable-random-numbers-in-js/
// the initial seed
Math.seed = 6;
// in order to work 'Math.seed' must NOT be undefined,
// so in any case, you HAVE to provide a Math.seed
Math.seededRandom = function(max, min) {
max = max || 1;
min = min || 0;
@ukyo
ukyo / README.md
Last active March 20, 2016 19:08
emscriptenでwabassembly試す
@ukyo
ukyo / .gitignore
Last active December 18, 2018 03:39
ServiceWorker sample fetch with LZ4+MessagePack
node_modules/
@ukyo
ukyo / 20150801win10.js
Last active December 7, 2015 11:11
unzip win10 edge vmware vm with node
var fs = require('fs');
var zlib = require('zlib');
var start;
var end;
function unzipFile(name, start, end) {
var rs = fs.createReadStream('MsEdge.Win10.VMware.zip', {start: start, end: end});
var inflateStream = zlib.createInflateRaw();
var ws = fs.createWriteStream(name);
@ukyo
ukyo / uirouter.coffee
Created August 6, 2014 03:38
ui routerの書き方、模索中
# stateごとに管理すればイイんじゃ無いか説
# 再利用可能だとおもったらdirective使う
angular.module 'foo'
.config ($stateProvider) ->
$stateProvider.state 'home',
url: '/'
template: """
<div>
<div>{{user.name}} {{user.email}}</div>
@ukyo
ukyo / example.php
Created June 10, 2014 09:52
添付メール送る奴 php 5.1.6で動作確認
<?php
require "path/to/mail.php";
echo send_mail("foo@bar.com", "bar@foo.com", "subject", "message", "path/to/file.format");