Skip to content

Instantly share code, notes, and snippets.

View romgrk's full-sized avatar
♥️
hey

Rom Grk romgrk

♥️
hey
View GitHub Profile
COLORS = [
'#3366CC'
, '#DC3912'
, '#FF9900'
, '#109618'
, '#990099'
, '#575acb'
, '#ebdb0c'
, '#ed2467'
, '#66AA00'
@romgrk
romgrk / event-base-reactivity.ts
Last active March 12, 2024 14:12
DataGrid event-based reactivity
//
// Event-based reactivity with events corresponding 1:1 with state properties
// I use "path" and "event" interchangeably.
//
// Example state model
type State = {
virtualization: {
offsetTop: number,
renderContext: {
V8
{
'react:equal:monomorphic': { average: 1206.33, stddev: 59.63406930792349 },
'react:unequal:monomorphic': { average: 1198.67, stddev: 41.51572660517404 },
'hughsk/shallow-equals:equal:monomorphic': { average: 595.33, stddev: 33.47967874530592 },
'hughsk/shallow-equals:unequal:monomorphic': { average: 559.33, stddev: 1.699673171197595 },
'romgrk-fastCompareUnsafe:equal:monomorphic': { average: 510.33, stddev: 1.247219128924647 },
'romgrk-fastCompareUnsafe:unequal:monomorphic': { average: 447.67, stddev: 2.0548046676563256 },
'romgrk-fastCompareStrict:equal:monomorphic': { average: 881.33, stddev: 1.699673171197595 },
'romgrk-fastCompareStrict:unequal:monomorphic': { average: 775.33, stddev: 0.9428090415820634 },
@romgrk
romgrk / patch-redux-toolkit.ts
Last active March 6, 2024 11:04
redux-toolkit reducers without immer
import { AnyAction, Slice } from '@reduxjs/toolkit'
/* The redux-toolkit maintainers refuse to add a way to disable immer.js for
* specific reducers, therefore we need to create an escape hatch by ourselves.
* Immer.js needs to be disabled in certain cases for performance reasons.
* Link: https://github.com/reduxjs/redux-toolkit/issues/242
*/
/** Add reducers without immer.js to a redux-toolkit slice */
export function addRawReducers<S>(
@romgrk
romgrk / tsx.ctags
Created January 24, 2023 07:39
Universal ctags typescript.tsx definitions (requires pcre2 feature)
# Typescript TSX ctags
# Based on https://github.com/romainl/ctags-patterns-for-javascript/blob/d965c4abfd00e438a24f6f828b5a1d00258f330c/ctagsrc
--langdef=tsx
--langmap=tsx:.tsx
# These are the added ctags
--regex-tsx=/^[ \t]*(export[ \t]{1,})?type[ \t]{1,}([A-Za-z0-9_$]{1,})/\2/t,Type,Types/{pcre2}
--regex-tsx=/^[ \t]*(export[ \t]{1,})?interface[ \t]{1,}([A-Za-z0-9_$]{1,})/\2/t,Type,Types/{pcre2}
/*
* Skipping over internal reactivity but this would be the gist of how to build a component that doesn't
* use react but still allows customization via user-supplied react-based render functions.
*
* Why? Because react is way to slow for use-cases like virtualization+scrolling. The whole cycle (state-update
* then re-render then vdom diffing then dom update) has too many unavoidable costs. Being able to go from
* state-update to dom-update directly is unbeatable.
*
* It uses react portals, so even though it manages its own HTML structure, it contains inside itself parts that
* are rendered & managed by react. And portals ensure there is full react compatibility, including the Context API,
@romgrk
romgrk / moonrepl.lua
Last active October 29, 2023 02:35
MoonScript REPL (using luarepl)
#!/usr/bin/env lua
-- This is an example quick-implementation of a MoonScript REPL,
-- using LuaRepl.
--
-- Requires:
-- - moonscript and luarepl, of course
-- - log (https://github.com/romgrk/log.moon)
--
-- The additionnal 'log' is my personnal logging utility.
@romgrk
romgrk / avoiding-nullable-types.md
Last active October 5, 2023 06:20
Avoiding nullable types

I've been seeing this pattern quite a bit:

// inside a component
const dimensions = useRef<DOMRect | null>(null)

useEffect(() => {
  dimensions.current = someRef.current.getBoundingClientRect()
}, []);
body {
--sk_primary_background: 38,38,38 !important;
}
.c-wysiwyg_container--theme_dark,
.c-wysiwyg_container__formatting,
.then {
background-color: #212121 !important;
}
@romgrk
romgrk / github-notifications.user.js
Last active September 20, 2023 10:53
Tampermonkey/UserJS&CSS script to enhance github notifications
// ==UserScript==
// @name github-notifications
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://github.com/notifications
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==