Skip to content

Instantly share code, notes, and snippets.

@ukyo
ukyo / README.md
Last active June 15, 2019 14:30
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 / pixelmatch.ts
Created April 24, 2019 03:38
wip pixelmatch.ts
export function pixelmatch(img1: u32, img2: u32, width: u32, height: u32): u32 {
let maxDelta = (35215 as f32) * 0.1 * 0.1;
let diff = 0;
for (let y: u32 = 0; y < height; y++) {
for (let x: u32 = 0; x < width; x++) {
let pos = (y * width + x) * 4;
let delta = colorDelta(img1, img2, pos, pos, false);
if (delta > maxDelta) {
diff++;
drawPixel(img1 + img2, pos, 255, 0, 0);
@ukyo
ukyo / bazel-ng-new-schematics.md
Last active December 20, 2018 08:47
bazel ng new schematics Angular 7.2.0-rc.0

インスコ

$ npm install -g @angular/cli@next @angular/bazel@next

ng new する

$ ng new my-bazel-app --collection=@angular/bazel
@ukyo
ukyo / .gitignore
Last active December 18, 2018 03:39
ServiceWorker sample fetch with LZ4+MessagePack
node_modules/
@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 / angular-storybook.md
Last active November 9, 2018 11:57
AngularでStorybook使う

前提

Angular 7, Storybook 4系

環境作る

まずはng newする。

$ ng new hoge --createApplication=false --style=scss
@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
@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 / 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 / file0.txt
Last active February 15, 2018 05:42
javascriptで生成したファイルをローカルに保存する ref: https://qiita.com/ukyo/items/d623209655a003b13add
function download(blob, filename) {
const objectURL = window.URL.createObjectURL(blob),
a = document.createElement('a'),
e = document.createEvent('MouseEvent');
//a要素のdownload属性にファイル名を設定
a.download = filename;
a.href = objectURL;
//clickイベントを着火