Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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())