Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / erf.js
Last active June 23, 2024 07:03
[javascript] erfinv(x) implementations (and erf(x)/erfc(x) implementations ported from cephes)
// erf(x): error function (see: https://en.wikipedia.org/wiki/Error_function)
// by https://github.com/jeremybarnes/cephes/blob/master/cprob/ndtr.c
const P = [
2.46196981473530512524E-10,
5.64189564831068821977E-1,
7.46321056442269912687E0,
4.86371970985681366614E1,
1.96520832956077098242E2,
5.26445194995477358631E2,
@bellbind
bellbind / binding.gyp
Last active June 20, 2024 18:22
[nodejs]Native module with libuv and v8::Promise on node-4
# -*- mode: python -*-
{
"targets": [
{
"include_dirs": ["<!(node -e \"require('nan')\")"],
"target_name": "TimerAndPromise",
"sources": [
"timer-and-promise.cc"
],
"conditions": [
@bellbind
bellbind / Dockerfile
Last active June 17, 2024 01:23
[docker] ruby-1.8.7 with rails-2.3.18 image
# docker build -t ruby-1.8.7 .
# docker run -it --rm ruby-1.8.7
FROM ubuntu:16.04
WORKDIR /root
RUN apt update
RUN apt upgrade -y
RUN apt install -y ruby-build autoconf subversion bison
RUN apt install -y mecab mecab-ipadic-utf8 wget
@bellbind
bellbind / build.zig
Last active May 5, 2024 06:24
[zig][WebAssembly][c11] FFT
// build all: $ zig build
// clean up: $ zig build dist-clean
const builtin = @import("builtin"); // list-up the content with `zig builtin` command
const Builder = @import("std").build.Builder;
//NOTE: this build code is for zig-0.4.0, maybe incompatible with zig >= 0.5
pub fn build(b: *Builder) void {
{ //[case: WebAssembly wasm] build fft.wasm
const wasmStep = b.step("fft.wasm", "build fft.wasm");
const wasm = b.addExecutable("fft.wasm", "fft.zig");
@bellbind
bellbind / loader.html
Last active May 4, 2024 04:42
[threejs][html5]STL File Viewer with HTML5 File API
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>STL File Viewer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
></script>
<script src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/TrackballControls.js"
></script>
<script src="loader.js"></script>
@bellbind
bellbind / main.js
Last active April 27, 2024 04:12
[electron] Tray launcher example
"use strict";
// [run the app]
// $ npm install electron
// $ ./node_modules/.bin/electron .
const {app, nativeImage, Tray, Menu, BrowserWindow} = require("electron");
let top = {}; // prevent gc to keep windows
@bellbind
bellbind / avxvec.c
Last active March 24, 2024 09:20
[c][avx][simd]example for intel SSE/AVX intrinsic api
// clang -std=c11 -mavx avxvec.c -o avxvec
#include <x86intrin.h>
#include <stdio.h>
// see https://software.intel.com/sites/landingpage/IntrinsicsGuide/#techs=AVX
int main() {
double mem[4] = {1.0, 2.0, 3.0, 4.0};
//__m256d v = _mm256_load_pd(mem);
__m256d v = _mm256_set_pd(1, 2, 3, 4); // (e3, e2, e1, e1)
__m256d sq = _mm256_mul_pd(v, v);
@bellbind
bellbind / bchcode-example.js
Last active March 5, 2024 14:27
[JavaScript] Programming Polynomial and Galois Field and Implementing Reed-Solomon code
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 / CMakeLists.txt
Last active February 28, 2024 20:27
[c] malloc and free implementation on the static memory pool
# How to build and to run
# mkdir build ; cd build/ ; cmake .. ; make ; ./test
# (cleanup: rm -r build/)
set(CMAKE_C_STANDARD 11)
list(APPEND CMAKE_C_FLAGS "-Wall -Wextra -pedantic")
add_library(mymalloc SHARED mymalloc.c)
add_executable(test test.c)
link_directories(.)
target_link_libraries(test mymalloc)
@bellbind
bellbind / fragment.glsl
Last active January 31, 2024 14:56
[webgl2]example for webgl2 (with glsl3)
#version 300 es
precision highp float;
//invariant gl_FragCoord;
uniform Screen {
vec2 wh;
} screen;
uniform Timer {
int count;