Skip to content

Instantly share code, notes, and snippets.

@oxyflour
oxyflour / index.js
Created September 19, 2020 17:08
async reduce of array
async function reduce(arr, fn) {
let tasks = arr.map(item => ({ item })),
reqs = []
while (true) {
if (tasks.length === 1) {
return tasks[0].item
}
const toRun = tasks.filter(task => !task.started)
for (let i = 0; i + 1 < toRun.length; i += 2) {
const [a, b] = toRun.slice(i, i + 2)
@oxyflour
oxyflour / index.html
Created August 29, 2020 12:50
async generator react
<html>
<body>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="index.jsx" type="text/babel"></script>
</body>
</html>
@oxyflour
oxyflour / CMakeLists.txt
Created August 12, 2020 14:23
compile node-addon-api (< 3) with cmake-js
cmake_minimum_required(VERSION 3.18)
project(binding)
if(WIN32)
set(CUDA_NVCC_FLAGS -Xcompiler;"/MD /wd 4819")
endif()
find_package(CUDA REQUIRED)
include_directories(${CMAKE_JS_INC} "${CMAKE_SOURCE_DIR}/include")
file(GLOB SOURCE_FILES "src/*.cu")
cuda_add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
@oxyflour
oxyflour / main.js
Created July 29, 2020 15:39
eval in another process
const cluster = require('cluster'),
os = require('os')
class Worker {
destroyed = false
/** @type { { [id: string]: { id: string, func: Function, args: any[], resolve: Function, reject: Function } } } */
calls = { }
/** @type { import('cluster').Worker } */
worker = this.fork()
fork() {
@oxyflour
oxyflour / faces.stl
Last active July 5, 2020 16:27
unfold stl
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@oxyflour
oxyflour / index.html
Last active May 8, 2020 18:21
topo filter demo
<html>
<body>
<style>
svg {
user-select: none;
}
svg polygon {
fill: chocolate;
}
svg circle {
@oxyflour
oxyflour / main.cc
Last active March 21, 2020 10:12
lock free set
#include <stdio.h>
// Reference:
// https://nosferalatu.com/SimpleGPUHashTable.html
// replace the function with cuda implement
unsigned long atomicCAS(unsigned long *addr, unsigned long comp, unsigned long val) {
auto prev = *addr;
if (*addr == comp) {
*addr = val;
@oxyflour
oxyflour / fwd.sh
Created October 8, 2019 13:25
openvpn forwarding
nano /etc/sysctl.conf
# uncomment the following line
# net.ipv4.ip_forward=1
sysctl -p
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
@oxyflour
oxyflour / make-bin.bat
Created October 1, 2019 15:59
use prebuilt magma binary on windows (from PyTorch)
rem update blas dir and cuda version
set BLAS_DIR=D:\Programs\OpenBLAS-0.3.7-x64
set CUDA_PREFIX=cuda100
set OUTPUT_EXE=build\main
set MAGMA_DIR=%~dp0\build\magma
if not exist %MAGMA_DIR% (
rem using static library precompiled for pytorch
rem https://github.com/pytorch/pytorch/blob/master/docs/source/notes/windows.rst
@oxyflour
oxyflour / setup.sh
Created June 21, 2019 11:47
kubeadm offline installation
sudo apt install docker.io
sudo swapoff -a
# then edit /etc/fstab and comment out swap
# https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy
sudo mkdir /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/http-proxy.conf << EOF
[Service]
Environment="HTTP_PROXY=http://nuc7.yff.me:8124/"