Skip to content

Instantly share code, notes, and snippets.

View chenglou's full-sized avatar
💫

Cheng Lou chenglou

💫
View GitHub Profile
@ben-x9
ben-x9 / sig
Last active October 4, 2017 04:44
#!/bin/sh
# Works with merlin version 2.5.4. Using protocol described at
# https://github.com/ocaml/merlin/blob/master/doc/dev/OLD-PROTOCOL.md#type-checking
usage ()
{
echo
echo Generate a signature for a Bucklescript module.
echo
@yawaramin
yawaramin / sig
Last active June 12, 2022 05:03
Bourne Shell script to print out Merlin's inferred signature of an OCaml file (module)
#!/usr/bin/env sh
# Works with merlin version 2.5.4. Using protocol described at
# https://github.com/ocaml/merlin/blob/master/doc/dev/OLD-PROTOCOL.md#type-checking
usage ()
{
echo Usage: either of the following will work:
echo
echo ' sig module.ml'
@haifengkao
haifengkao / open_finder_tab.sh
Last active October 24, 2023 19:04
A shell script function to open a Finder tab from terminal
# open the current folder in Finder's tab
function oft() {
local folder_name=$1
if ! [[ -d $1 ]]; then
# it is a file, get the enclosing folder
folder_name="$(dirname "$1")"
fi
# if no arguments are given, we use the current folder
@unitycoder
unitycoder / if-branchless.shader
Last active April 3, 2024 11:20
Avoiding Branching / Conditionals in Shaders Fast No If
"The common wisdom of "don't use conditionals in shaders" is one of my biggest frustrations with how shaders are taught.
step(y, x) _is_ a conditional! It compiles to identical code as:
float val = (x >= y ? 1.0 : 0.0)
or
float val = 0.0;
if (x >= y) val = 1.0;"
https://twitter.com/bgolus/status/1235254923819802626
// Performing shader divisions without diving *rcp = approximation of 1/x
float myDividedVal = myValToDivide * rcp(myDivider);

architectures and whatnot

  1. plain ol' React
let state = initial
render(view(state), element)
  • view is pure!
@samoht
samoht / opam-sources.sh
Last active May 15, 2016 23:01
Gather the sources to build an opam project
#!/usr/bin/env bash
# Instructions. You need:
# - a working opam environment
# - an opam file in your current directory (to describe your project)
# - possibly some packages path-pinned in the current switch
#
# Run the scripts, and then check the contents of sources/
set -eu
@manigandham
manigandham / rich-text-html-editors.md
Last active April 16, 2025 18:28
Rich text / HTML editors and frameworks

Strictly Frameworks

Abstracted Editors

These use separate document structures instead of HTML, some are more modular libraries than full editors

@paulirish
paulirish / what-forces-layout.md
Last active April 24, 2025 09:45
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
@sebmarkbage
sebmarkbage / QuizAnswer.md
Last active September 30, 2018 17:42
Global Shared [Synchronous] State

setProps - depends on reading the last reconciled props from the current reconciled state of the app, at the time of the call. It also depends on an object that doesn't necessarily need to be there outside reconciliation. This is unlike setState, which is state that needs to be there. setState is queued up and merged at the time of reconciliation. Not at the time of the call. setState has a side-effect but is not a stateful nor mutative API.

isMounted - reads the current state of the tree, which may be stale if you're in a batch or reconciliation.

getDOMNode/findDOMNode - Reads the currently flushed node. This currently relies on the state of the system and that everything has flushed at this time. We could potentially do a forced render but that would still rely on the state of the system allowing us to synchronously being able to force a rerender of the system. Note: in 0.14, refs directly to DOM node will resolve to the DOM node. This allow you to get access to a node at the time of its choos

// lein cljsbuild once release
// d8 node_modules/immutable/dist/immutable.min.js mori.bare.js ./bench/mut_perf.js
// jsc node_modules/immutable/dist/immutable.min.js mori.bare.js ./bench/mut_perf.js
;(function() {
function sum(a,b) {
return a+b;
}