Skip to content

Instantly share code, notes, and snippets.

View wonglok's full-sized avatar
🙏
Thank you Jesus for the new life

Wong Lok wonglok

🙏
Thank you Jesus for the new life
View GitHub Profile
const SHA256 = require("crypto-js/sha256");
class CryptoBlock {
constructor(index, timestamp, data, precedingHash = " ") {
this.index = index;
this.timestamp = timestamp;
this.data = data;
this.precedingHash = precedingHash;
this.hash = this.computeHash();
this.nonce = 0;
}
@wonglok
wonglok / refraction-rainbow.js
Created May 5, 2020 21:04
refraction rainbow material
import { WebGLCubeRenderTarget, Camera, Scene, Mesh, PlaneBufferGeometry, ShaderMaterial, CubeRefractionMapping, BackSide, NoBlending, BoxBufferGeometry, CubeCamera } from 'three'
import { Vector2, MeshBasicMaterial, DoubleSide, RGBFormat, LinearFilter, CubeReflectionMapping, WebGLRenderTarget, EquirectangularReflectionMapping } from 'three/build/three.module'
import { cloneUniforms } from 'three/src/renderers/shaders/UniformsUtils.js'
class CustomWebGLCubeRenderTarget extends WebGLCubeRenderTarget {
constructor (width, height, options) {
super(width, height, options)
this.ok = true
}
setup (renderer, texture) {
this.texture.type = texture.type
@wonglok
wonglok / shader-cubemap.js
Last active April 30, 2020 01:14
shader-cubemap.js by loklok
import { WebGLCubeRenderTarget, Camera, Scene, Mesh, PlaneBufferGeometry, ShaderMaterial, CubeRefractionMapping, BackSide, NoBlending, BoxBufferGeometry, CubeCamera } from 'three'
import { Vector2, MeshBasicMaterial, DoubleSide, RGBFormat, LinearFilter, CubeReflectionMapping, WebGLRenderTarget, EquirectangularReflectionMapping } from 'three/build/three.module'
import { cloneUniforms } from 'three/src/renderers/shaders/UniformsUtils.js'
class CustomWebGLCubeRenderTarget extends WebGLCubeRenderTarget {
constructor (width, height, options) {
super(width, height, options)
this.ok = true
}
setup (renderer, texture) {
this.texture.type = texture.type
@wonglok
wonglok / loadExt.js
Created January 28, 2020 00:37 — forked from Aymkdn/loadExt.js
To load JS and CSS files with vanilla JavaScript
// long version
function loadExt(files, after) {
var _this=this;
_this.files = files;
_this.js = [];
_this.head = document.getElementsByTagName("head")[0];
_this.after = after || function(){};
_this.loadStyle = function(file) {
var link = document.createElement("link");
link.rel = "stylesheet";
@wonglok
wonglok / ControlPoint.vue
Last active January 16, 2020 09:24
CubicBezierEditor
<template>
<circle v-if="point" ref="control-point" @mousedown="onMD" class="cursor-move" :cx="point.x" :cy="point.y" r="15" fill="pink" />
</template>
<script>
export default {
props: {
width: {},
height: {},
point: {},
@wonglok
wonglok / functional-utils.js
Created August 1, 2019 01:02 — forked from bendc/functional-utils.js
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@wonglok
wonglok / jwtRS256.sh
Created July 12, 2019 03:15 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@wonglok
wonglok / gist:2431e73283f529b27fcae32ea8852118
Created May 11, 2019 03:46 — forked from lmccart/gist:2273a047874939ad8ad1
p5.js + p5.dom.js + clmtracker.js
<html>
<head>
<script src="clmtrackr.js"></script>
<script src="model_pca_20_svm.js"></script>
<script src="p5.js"></script>
<script src="p5.dom.js"></script>
<script>
var ctracker;
@wonglok
wonglok / gpgpu.js
Created April 12, 2019 21:13
Particle Bally
// please load three js and also this
// https://threejs.org/examples/js/GPUComputationRenderer.js
var particleVelocityShader = `
#include <common>
uniform vec2 mousePos;
float constrain(float val, float min, float max) {
if (val < min) {
@wonglok
wonglok / Index.js
Last active February 11, 2019 20:57
Something similar to Geometry Shader
import * as THREE from 'three'
import 'imports-loader?THREE=three!three/examples/js/postprocessing/EffectComposer.js'
import 'imports-loader?THREE=three!three/examples/js/postprocessing/RenderPass.js'
import 'imports-loader?THREE=three!three/examples/js/postprocessing/MaskPass.js'
import 'imports-loader?THREE=three!three/examples/js/postprocessing/ShaderPass.js'
import 'imports-loader?THREE=three!three/examples/js/shaders/CopyShader.js'
import 'imports-loader?THREE=three!three/examples/js/shaders/FXAAShader.js'
import 'imports-loader?THREE=three!three/examples/js/shaders/ConvolutionShader.js'
import 'imports-loader?THREE=three!three/examples/js/shaders/LuminosityHighPassShader.js'
import 'imports-loader?THREE=three!three/examples/js/postprocessing/UnrealBloomPass.js'