Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / index.html
Last active Oct 28, 2021
[chrome][android] BarcodeDetector example
View index.html
<!doctype html>
<html>
<head>
<script type="module">
// WICG Shape Detection API
// - https://wicg.github.io/shape-detection-api/
try {
const start = document.getElementById("start");
const video = document.getElementById("video");
const result = document.getElementById("result");
@bellbind
bellbind / bitstream.js
Last active Jun 1, 2020
[JavaScript] QR code generator from scratch
View bitstream.js
// big endian bit stream
export class BitWriter {
constructor(buf = [], byte = 0, pos = 7) {
this.byte = byte;
this.pos = pos;
this.buf = Array.from(buf);
}
writeBit(b) {
this.byte |= (b & 1) << this.pos;
this.pos--;
@bellbind
bellbind / mh.cpp
Last active Mar 25, 2020
[c++]Monty-Hall simulation
View mh.cpp
// clang++ -Wall -Wextra -pedantic -std=c++17 mh.cpp -o mh
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <random>
std::default_random_engine engine;
// utilities
@bellbind
bellbind / bchcode-example.js
Last active Apr 10, 2020
[JavaScript] Programming Polynomial and Galois Field and Implementing Reed-Solomon code
View bchcode-example.js
import {PF} from "./pf.js";
import {GF} from "./gf.js";
import {GF2n} from "./gf2n.js";
import {BCHCode} from "./bchcode.js";
import {Polynomial, PolynomialUtils} from "./polynomial.js";
{
console.log("[BCHCode with GF]");
const gf = GF(PF(2), 4, [1, 1, 0, 0, 1]);
@bellbind
bellbind / find-polynomial.js
Last active Mar 18, 2020
[JavaScript] Programming for Galois Field (and applied to encode/decode Reed-Solomon code)
View find-polynomial.js
const egcd = (a, b) => {
if (a === 0) return [b, 0, 1]; // b = 0*0 + b*1
const r = b % a, d = (b - r) / a; // r = b - a*d
const [g, s, t] = egcd(r, a); // g = r*s + a*t
return [g, t - d * s, s]; // g = (b-a*d)*s + a*t = a*(t-d*s) + b*s
};
//console.log(egcd(13, 5));
//console.log(egcd(5, 13));
@bellbind
bellbind / hello.wat
Created Feb 18, 2020
[wasi][nodejs] WASI hello world on node.js-13.8
View hello.wat
;; Example code from wasmtime WASI tutorial doc:
;;
;; - https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md
;;
;; (with wabt) $ wat2wasm hello.wat
(module
;; import wasi functions
(import "wasi" "fd_write"
(func $fd_write (param i32 i32 i32 i32) (result i32)))
@bellbind
bellbind / index.html
Last active Jan 29, 2020
[ES module] test hash fragment and redirected for import.meta.url
View index.html
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="data:,">
<script type="module">
import "./main.js";
import "./main-redirected.js";
import "./main-identity.js";
import "./main-fetch-url.js";
</script>
@bellbind
bellbind / index.html
Created Jan 15, 2020
[broeswe][openlayers] Example for OpenLayers (with OpenStreetMap tiles)
View index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/css/ol.css" type="text/css">
<style>
.map {
height: 90vh;
width: 90vw;
}
@bellbind
bellbind / index.html
Last active Dec 11, 2019
[IPFS][libp2p][browser] Pubsub example on libp2p peer in IPFS node
View index.html
<!doctype html>
<html>
<head>
<title>Pubsub on libp2p</title>
<script type="module" src="./main.js"></script>
</head>
<body>
<h3 id="myid"></h3>
<div>
id: <input id="id" type="text" size="40"/>
@bellbind
bellbind / index.html
Last active Dec 9, 2019
[IPFS][libp2p][browser] Chat with libp2p peer in IPFS node
View index.html
<!doctype html>
<html>
<head>
<title>Chat on libp2p</title>
<script type="module" src="./main.js"></script>
</head>
<body>
<h3 id="myid"></h3>
<div>
to: <input id="to" type="text" size="40"/>