Skip to content

Instantly share code, notes, and snippets.

View yuzhouu's full-sized avatar
🎉

##-- yuzhouu

🎉
View GitHub Profile
@arkatsy
arkatsy / zustand-internals.jsx
Last active June 11, 2024 21:35
How zustand works internally
import { useSyncExternalStore } from "react";
// For more on the useSyncExternalStore hook, see https://react.dev/reference/react/useSyncExternalStore
// The code is almost identical to the source code of zustand, without types and some features stripped out.
// Check the links to see the references in the source code.
// The links are referencing the v5 of the library. If you plan on reading the source code yourself v5 is the best way to start.
// The current v4 version contains lot of deprecated code and extra stuff that makes it hard to reason about if you're new to this.
// https://github.com/pmndrs/zustand/blob/fe47d3e6c6671dbfb9856fda52cb5a3a855d97a6/src/vanilla.ts#L57-L94
function createStore(createState) {
@yuzhouu
yuzhouu / text2image.ts
Created May 31, 2022 02:37
convert text to text-image
interface Options {
fontFamily?: string;
fontSize?: number;
}
export default function text2image(text: string, opts?: Options) {
const { fontFamily = "serif", fontSize = 14 } = opts || {};
// high ratio, high dpi
const ratio = Math.max(window.devicePixelRatio || 4, 4);
const canvas = document.createElement("canvas");
@flare9x
flare9x / general_indicators.jl
Created December 18, 2018 12:10
General Market Indicators
# General indicators
@doc """
William’s Variable Accumulation Distribution (note may hilbert transform the price then apply this indicator)
+++ makes sense: https://www.marketvolume.com/technicalanalysis/williamsaccumulationdistribution.asp / http://www.marketinout.com/technical_analysis.php?t=Williams%27_Accumulation%7CDistribution&id=118
http://www.blastchart.com/Community/IndicatorGuide/Indicators/WilliamsAccumulationDistribution.aspx
WVAD  ( ((C-O) / (H L)) * V )
where
C  the current period’s closing price.
O  the current period’s opening price.
H  the current period’s high price.
@mholt
mholt / macapp.go
Last active July 21, 2024 09:43
Distribute your Go program (or any single binary) as a native macOS application
// Package main is a sample macOS-app-bundling program to demonstrate how to
// automate the process described in this tutorial:
//
// https://medium.com/@mattholt/packaging-a-go-application-for-macos-f7084b00f6b5
//
// Bundling the .app is the first thing it does, and creating the DMG is the
// second. Making the DMG is optional, and is only done if you provide
// the template DMG file, which you have to create beforehand.
//
// Example use:
@paulirish
paulirish / what-forces-layout.md
Last active July 23, 2024 15:12
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@mbostock
mbostock / .block
Last active November 22, 2022 23:32
Line Transition
license: gpl-3.0
@paulirish
paulirish / rAF.js
Last active July 19, 2024 19:50
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
<html>
<head>
<title>Angular Gradient Test</title>
<script type="text/javascript" src="graphics.js"></script>
<script type="text/javascript" src="math.js"></script>
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var halfWidth = canvas.width / 2;