Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / index.html
Last active March 30, 2023 22:25
[threejs] simplified gltf2 loader example
View index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://unpkg.com/three"></script>
<script
src="https://unpkg.com/three/examples/js/loaders/GLTF2Loader.js"
></script>
<script src="script.js" defer="defer"></script>
</head>
@bellbind
bellbind / complex.py
Last active March 10, 2023 19:14
[python3] Calc Riemann Zeta function
View complex.py
# complex arith for programming with other languages
# - required functions: exp(f), log(f), sin(f), cos(f), atan2(f), pow(f1, f2)
import math
# [equality for complex]
def ceq(a, b):
return a.real == b.real and a.imag == b.imag
# [add, sub, mul for complex]
@bellbind
bellbind / less.py
Created July 6, 2012 07:09
[python]less command with curses
View less.py
# example of curses: less command
import locale
import sys
import curses
def load():
filename = sys.argv[1]
with open(filename) as f:
return f.readlines(), filename
return [], ""
@bellbind
bellbind / DisplayMode.swift
Last active January 11, 2023 16:55
[macos][c]commandline for display and switch display mode
View DisplayMode.swift
#!/usr/bin/env swift
// swiftc displaymode1.swift
import Foundation
import CoreGraphics
let display = CGMainDisplayID()
guard let dmodes = CGDisplayCopyAllDisplayModes(display, nil) as? [CGDisplayMode] else {exit(1)}
let argv = CommandLine.arguments
if argv.count == 2 {
@bellbind
bellbind / capture.c
Last active December 15, 2022 02:18
[linux][v4l2][libjpeg][c99]example for capturing from UVC webcam (on beaglebone black)
View capture.c
/*
* capturing from UVC cam
* requires: libjpeg-dev
* build: gcc -std=c99 capture.c -ljpeg -o capture
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@bellbind
bellbind / pem.js
Last active December 13, 2022 02:55
[nodejs]Example of RSA usages with node-forge
View pem.js
// RSA with node-forge
"use strict";
// npm install node-forge
const forge = require("node-forge");
new Promise((f, r) => forge.pki.rsa.generateKeyPair(
2048, (err, pair) => err ? r(err) : f(pair)))
.then(keypair => {
const priv = keypair.privateKey;
@bellbind
bellbind / closable-stream.js
Last active December 11, 2022 14:46
[js-ipfs/libp2p] dial to read events from infinite sending from handler, then close read
View closable-stream.js
// wrapping libp2p stream (mplex/stream)
// - stream.source: AsyncIterable<Uint8Array>
// - stream.sink: (Iterable<Uint8Array> | AsyncIterable<Uint8Array>) => Promise<undefined>
// - stream.close, stream.closeRead, stream.closeWrite, stream.abort, stream.reset
const newQueue = () => {
const [gets, polls] = [[], []];
const next = () => new Promise(
get => polls.length > 0 ? polls.shift()(get) : gets.push(get));
const poll = () => new Promise(
poll => gets.length > 0 ? poll(gets.shift()) : polls.push(poll));
@bellbind
bellbind / cache-method.js
Last active November 19, 2022 14:46
[Web Cache API][browser][deno] Web Cache API basic examples
View cache-method.js
await caches.delete("tmp");
const cache = await caches.open("tmp");
const req1 = new Request("http://example.com/");
const req2 = new Request("http://example.com/", {method: "head"});
const req3 = new Request("http://example.com/", {method: "post"});
const res1 = new Response("hello en-US", {headers: {"Content-Type": "text/plain;charset=utf-8"}});
const res2 = new Response("", {headers: {}});
await cache.put(req1, res1); // cache "http://example.com/ with res1
@bellbind
bellbind / example-relay-http2p.mjs
Created November 17, 2022 13:51
[ipfs][nodejs] HTTP like messaging for PeerID via libp2p in IPFS node
View example-relay-http2p.mjs
#!/usr/bin/env node
import * as fs from "node:fs";
// IPFS
import * as IPFS from "ipfs-core";
// WebRTCStar
import wrtc from "@koush/wrtc";
import {sigServer} from "@libp2p/webrtc-star-signalling-server";
import {webRTCStar} from "@libp2p/webrtc-star";
// pubsub peerDiscovery
//import {floodsub} from "@libp2p/floodsub";
@bellbind
bellbind / index.html
Last active November 12, 2022 14:30
[javascript][browser] Simple Turing Pattern simulator
View index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="script.js" defer="defer"></script>
</head>
<body>
</body>
</html>