Skip to content

Instantly share code, notes, and snippets.

View hevi1991's full-sized avatar
👻
career has entered garbage time

Cloud hevi1991

👻
career has entered garbage time
View GitHub Profile
@hevi1991
hevi1991 / reactUseReducer.js
Created April 9, 2024 03:54
React useReducer 示例
import React, { useReducer } from "react";
import ReactDOM from "react-dom";
const initialState = {
items: [],
total: 0
};
const actions = {
ADD_ITEM: "ADD_ITEM",
@hevi1991
hevi1991 / reactUseContext.js
Created April 9, 2024 03:44
React useContext 配合 useState 的示例
import React, { createContext, useContext, useState } from "react";
import ReactDOM from "react-dom";
// 创建一个Context对象
const ExampleContext = createContext();
// 创建一个自定义的Provider组件
function ExampleProvider({ children }) {
// 使用useState Hook创建一个状态
const [value, setValue] = useState("Initial Value");
@hevi1991
hevi1991 / gist:fa5e3c0ba4cb03e0bf0c1feaff59e520
Last active April 9, 2024 03:42
使用【蒙特卡洛模拟】,模拟10000次抛硬币,最容易出现连续出现同一面的连击数
// https://www.zhihu.com/question/650059927
function highestComboTest(target = 12) {
let combo = 0;
let comboArr = [];
let testCount = 10000;
for (let i = 0; i < testCount; i++) {
if (Math.random() >= 0.5) {
@hevi1991
hevi1991 / singleton.js
Last active April 9, 2024 06:28
JavaScript 使用代理来实现单例模式
export function singleton(clazz) {
let instance;
return new Proxy(clazz, {
construct(target, args) {
if (instance) {
return instance;
} else {
instance = new target(...args);
return instance;
@hevi1991
hevi1991 / GLSL-Noise.md
Created September 13, 2021 03:20 — forked from patriciogonzalezvivo/GLSL-Noise.md
GLSL Noise Algorithms

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}
@hevi1991
hevi1991 / perlin.glsl
Created September 13, 2021 03:18 — forked from akella/perlin.glsl
// Classic Perlin 3D Noise
// by Stefan Gustavson
//
vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}
vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}
vec3 fade(vec3 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);}
float cnoise(vec3 P){
vec3 Pi0 = floor(P); // Integer part for indexing
vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1