Skip to content

Instantly share code, notes, and snippets.

@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;
@bellbind
bellbind / less.py
Created July 6, 2012 07:09
[python]less command with curses
# 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 / index.html
Last active January 17, 2024 14:14
[chrome][android] BarcodeDetector example
<!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 / lambda.swift
Last active January 14, 2024 21:26
[swift] Lambda Calculus on swift-2
// Untyped Lambda Calculus on swift-2
enum Expr {
case Num(Int)
case Ref(String)
indirect case Lam(String, Expr)
indirect case App(Expr, Expr)
func eval(env: Env) -> Val {
switch self {
case let .Num(v): return Val.Number(v)
@bellbind
bellbind / main.js
Last active January 5, 2024 11:29
[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 / .brewrc
Created August 1, 2011 03:06
[mac][homebrew]install homebrew to $HOME/.brew
#[homebrew setting for installing to each user directory]
#[ENV: put them into "$HOME/.bash_profile"]
HOMEBREW=$HOME/.brew
export PATH=$HOMEBREW/bin:$PATH
export LD_LIBRARY_PATH=$HOMEBREW/lib:/usr/lib
export DYLD_FALLBACK_LIBRARY_PATH=$HOMEBREW/lib
export C_INCLUDE_PATH=$HOMEBREW/include
export CPLUS_INCLUDE_PATH=$HOMEBREW/include
@bellbind
bellbind / app.m
Created July 19, 2012 20:32
[macosx][objective-c]Make cocoa app without Xcode
// clang -framework Cocoa app.m -o app
// ./app
#import <Cocoa/Cocoa.h>
int main()
{
[NSAutoreleasePool new];
id app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];