Skip to content

Instantly share code, notes, and snippets.

View romgrk's full-sized avatar
♥️
hey

Rom Grk romgrk

♥️
hey
View GitHub Profile
@romgrk
romgrk / animate.ts
Created April 2, 2023 08:25
Animate using RAF
import BezierEasing from 'bezier-easing'
export type Animation = ReturnType<typeof animate>
export type EasingFn = (t: number) => number
export const Easing = {
LINEAR: (t: number) => t,
EASE_IN_OUT: (t: number) => t * t * (3 - 2 * t),
BEZIER: BezierEasing,
}
@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}
function u0:0() -> i64 system_v {
ss0 = explicit_slot 8
ss1 = explicit_slot 8
block0:
v1 = iconst.i64 0
v2 = iconst.i64 0
stack_store v1, ss0
stack_store v2, ss1
jump block1
const fs = require('fs')
const Benchmark = require('benchmark')
const parseOriginal = require('./lib/parseOriginal')
const parseImproved = require('./lib/parse')
const data = fs.readFileSync(process.argv[2]).toString()
const suite = new Benchmark.Suite
suite
// With immer
export const slice = createSlice({
name: 'report',
initialState: createEmptyStore<StoredReport>(),
reducers: {
setMetric: (state, action) => {
const { id, metricId, metric: newMetric } = action.payload
state.byId[id].metrics =
state.byId[id].metrics?.map(metric =>
metric.id !== metricId ?
@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>(
local ffi = require("ffi")
ffi.cdef[[
typedef int handle_T;
typedef long linenr_T; // line number type
typedef int colnr_T;
typedef struct {
linenr_T lnum; /* line number */
colnr_T col; /* column number */
@romgrk
romgrk / rest-considered-harmful.md
Last active October 11, 2021 22:20
REST considered harmful

REST considered harmful

Albeit the title might (probably) be a bit inflammatory, I've come to feel like REST is a bad solution for the problem that it solves.

The thing with REST, is that at its core, it's basically a RPC (Remote Procedure Call) that we've been trying to cram in the HTTP protocol. There is no good reason to do that. HTTP wasn't made for this, and we should instead be abstracting that layer away instead of trying to use it for purposes it isn't meant to fulfill.

@romgrk
romgrk / inline-styles.md
Last active May 20, 2021 21:05
Why I dislike inline styles

Why I dislike inline styles

  1. It mixes behavior, component layout, and style in the same code section, and makes it harder to work on a single of those issues at a time.
  2. It doesn't promote style re-use, which in turn makes the styling less consistent as a whole because there will likely be differences in the inline styles of one file versus the other.
  3. It's less performant. If your component renders 10 times, the engine needs to allocate 10 objects, and then garbage-collect them 10 times. It's hard to understand what causes a GC pause, but short lived objects are the most direct contributor to it. And that is for
<pre><span style="background-color:#D70000"><font color="#FFFFFF"><b> romgrk </b></font></span><span style="background-color:#585858"><font color="#D70000"></font></span><span style="background-color:#585858"><font color="#FFFF87"> ~  github  bentoV2 </font></span><font color="#585858"></font> <font color="#5DAA11">docker</font> <font color="#C4A000">logs</font> bentov2-wes <font color="#5F0000"></font><span style="background-color:#5F0000"><font color="#FFFFFF"> 1 </font></span><span style="background-color:#5F0000"><font color="#303030"></font></span><span style="background-color:#303030"><font color="#BCBCBC">  update-doc-2 </font></span>
* Environment: development
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 128-993-605
[2021-05-18 15:23:32,263] DEBUG in workflows: Instantiating WorkflowManager