Skip to content

Instantly share code, notes, and snippets.

View jinjor's full-sized avatar

Yosuke Torii jinjor

View GitHub Profile
@jinjor
jinjor / reader.ts
Last active February 2, 2024 17:36
export class Reader {
private view: DataView;
private offset: number;
private littleEndian: boolean;
constructor(buffer: ArrayBuffer, offset = 0, littleEndian = false) {
this.view = new DataView(buffer);
this.offset = offset;
this.littleEndian = littleEndian;
}
getOffset(): number {
@jinjor
jinjor / kaleidoscope.html
Last active May 7, 2023 18:31
万華鏡
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.19.0/matter.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/decomp.min.js"></script>
</head>
<body>
<div style="display: flex; gap: 10px">
<div id="world"></div>
@jinjor
jinjor / matter-tone.html
Created May 6, 2023 16:54
上から落ちてきたボールがぶつかったら音が出る的な
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.19.0/matter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.min.js"></script>
</head>
<body>
<script>
document.onclick = () => {
@jinjor
jinjor / go-test.sh
Created January 11, 2021 03:16
とりあえず mac で動いた
#!/bin/bash -euo pipefail
export GREP_OPTIONS='--color=always'
go test "$@" \
| GREP_COLOR='1;31' grep -E '.*FAIL.*|$' \
| GREP_COLOR='1;32' grep -E '.*PASS.*|$'
@jinjor
jinjor / rpc-client.ts
Created February 1, 2020 20:07
Simple RPC Example
export async function rpc(name: string, ...args: any[]): Promise<any> {
const formData = new FormData();
for (const [index, arg] of args.entries()) {
const name = String(index);
if (arg instanceof Blob) {
formData.append(name, arg);
} else if (arg instanceof ArrayBuffer) {
formData.append(name, new Blob([arg]));
} else {
formData.append(name, JSON.stringify(arg));
@jinjor
jinjor / rpc-client.js
Last active December 31, 2019 09:53
RPC between Browser and Node.js
async function exec(name, ...args) {
const res = await fetch(`/rpc/${name}`, {
method: "POST",
headers: {
"content-type": "application/json"
},
body: JSON.stringify(args)
});
const json = await res.json();
return json;
module.exports.mergeCoverageByUrl = function(coverage) {
const merged = {};
for (const entry of coverage) {
if (!merged[entry.url]) {
merged[entry.url] = entry;
}
merged[entry.url].ranges.push(...entry.ranges);
}
Object.values(merged).forEach(entry => {
entry.range = convertToDisjointRanges(entry.ranges);
interface State {
index: number;
name: string;
createdAt: number;
startedAt: number;
stoppedAt: number;
connectedAt: number;
disconnectedAt: number;
}
@jinjor
jinjor / drag.ts
Last active March 19, 2019 22:40
function dragFrom(
el: Element,
callbacks: {
start?: (x: number, y: number) => void;
move?: (x: number, y: number) => void;
end?: (x: number, y: number) => void;
}
): () => void {
function handleMove(e: MouseEvent) {
callbacks.move && callbacks.move(e.clientX, e.clientY);
{-|
import Json.Decode exposing (..)
import Json.Decode.Pipeline exposing (..)
type FooOrBar
= Foo String
| Bar Int