Skip to content

Instantly share code, notes, and snippets.

Avatar
❄️
Winter is coming

Julien Roncaglia vbfox

❄️
Winter is coming
View GitHub Profile
@vbfox
vbfox / runes.ts
Last active Jun 9, 2021
Javascript/Typescript Rune iterators
View runes.ts
/**
* Iterate a string runes. Same as iterating [...str]
*
* Note: This assume that the string is well-formed
*
* WARNING: This is useless, use the string iterator.
*/
export function* runeIterator(s: string) {
const len = s.length;
let highSurrogate: number | undefined;
@vbfox
vbfox / useScrollStartEndEvents.ts
Created Apr 28, 2021
Simulate a 'scrollstart' and 'scrollend' event by listening to scroll and debouncing the calls
View useScrollStartEndEvents.ts
/**
* Simulate a 'scrollstart' and 'scrollend' event by listening to scroll and debouncing the calls.
*
* The proposal to standardize part of this is https://github.com/w3c/csswg-drafts/issues/3744
*/
export function useScrollStartEndEvents(
ref: RefObject<HTMLElement>,
onScrollStart?: () => void,
onScrollEnd?: () => void,
debounceTimeMs: number = 100
View maintainReferentialEquality.ts
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
function deepReferentialEquality(from: any, to: any, path = ''): any {
if (to === undefined || from === undefined || to === null || from === null) {
return to;
}
const objectType = typeof from;
if (objectType !== typeof to) {
// The object changed type
@vbfox
vbfox / keyedPromiseQueue.ts
Created Jun 4, 2020
A queue of promises keyed by a value
View keyedPromiseQueue.ts
import { Queue } from 'src/utils/queue';
import { assertDefined } from 'src/utils/asserts';
interface QueueItem {
readonly generator: () => PromiseLike<any>;
readonly resolve: (value: any) => void;
readonly reject: (error: any) => void;
}
interface PerKeyQueue<TKey> {
@vbfox
vbfox / modifyProxiedResponse.js
Created Nov 25, 2019
Small function for express.js http-proxy-middleware to change response text
View modifyProxiedResponse.js
/* eslint-disable @typescript-eslint/unbound-method */
/* eslint-disable no-param-reassign */
import zlib from 'zlib';
import concatStream from 'concat-stream';
import BufferHelper from 'bufferhelper';
import stream from 'stream';
import { IncomingMessage, ServerResponse } from 'http';
export type Modification = (original: string, proxyRes: IncomingMessage) => string | undefined;
@vbfox
vbfox / Immutable.ts
Created Apr 16, 2019
Simple type immutable.js Map based immutable type with strongly typed keys
View Immutable.ts
import { Iterable, Map } from "immutable";
// tslint:disable:array-type
// tslint:disable:unified-signatures
export interface Immutable<T> {
set<TKey extends keyof T>(key: TKey, value: T[TKey]): Immutable<T>;
/**
* Returns a new Map which excludes this `key`.
*
@vbfox
vbfox / FableReactEquals.fs
Last active Apr 16, 2019
Prototype of Equals function for F# Fable React interop that does the same as the (=) operator except that all functions are equal
View FableReactEquals.fs
// Flawed try, I don't think a deep function ignoring compare is practical
//
// https://fable.io/repl/#?code=PYBwpgdgBAYghgIwDZgHQEkC2JgCcAuqAUgMoCwAUKJLIiqgMJ5pEDO6E+Yuol108ZGia4wlSgG0APFhwEAFACIwARwCucJAEFcuOAE9WAdQCW+ABaKANFEUAzOmAC0SEwj259AegCq+E0ioAFasigCUAHwAupQo+FAguCYAbnBcUKoa2roGxmbmUPIAHgBcUMAIQWGF+mUVVYUAxth1lVBOEeVtHVAIwMBIYWV9A1AAvJRQU1AhAHJpKWIUkjLYePhKjcDYcKIAImlgoTb2ji5uHt5+AcGhkTEUcQlJqelbO-uHrIWlXQ3ytT+QygJk440m0zmC2SSxWAFFMGYlAASAAM4zGUGRAEZwtFYmB4okUocZqw4epNN9ilBWv99LSgYyRkhxmT5v4YeIKNIEUjFGioABCTE4vEPJ7E15gdnAfAUrLUoqM+rVAEqyrVYb9VmYqGc2GPQnPEnpVhwTBgAAq+nAPzpasBqvBFGmsvllKQ3wZEDUSFZADIAxC3VN6qgAEpgOzcSCNMAKqnyEOht0AeUqYEahAA5oSAAo8fBy21gNN2YphAD8WwgrHwuDU2bwVhTqamGaCWdzBaLJfA5YB1dr9cbzdwYW5vMRG0U+FLwDsWNR4oJRJepJCNvAi8KAH0NQ0yqPQTm2frFlOpHzZ4LQfW4BB47uDlxV0b16aZSZWK+ZfIDwdZkdXPVgOUvZYPxBCBXAgGUpVJH8dD0BliiAiZXWmZCDFQJCcgZZUAB9CKgbD9AAITUOwY1wXDWAANRMMAAHcoCKblJQ3dJRC2XAABNCzlfsZQw9NM2zVA83wQTi3nAcKwAbxIzBdgAa24NkGzUGVCIAX0nSCnh4k1pRBVgo14vj7SZUTphMJcQkTL02KgX1-SgCxIDbaYHC9JY3TAPzvKmTih
@vbfox
vbfox / TraceChanges.ts
Created Mar 27, 2019
Trace props or state that changed and made a React PureComponent refresh
View TraceChanges.ts
export class Test extends React.PureComponent<{}, {}> {
UNSAFE_componentWillUpdate(nextProps: any, nextState: any) {
const changedProps = _.reduce(
this.props,
(result: string[], value, key) => value === nextProps[key] ? result : result.concat(key),
[]);
console.log("changedProps: ", changedProps);
const changedStates = _.reduce(
this.state,
(result: string[], value, key) => value === nextState[key] ? result : result.concat(key),
@vbfox
vbfox / MemoReactHelpers.fs
Last active Oct 24, 2018
React 16.6 Fable 1
View MemoReactHelpers.fs
module MemoReactHelpers
/// A special ReactElement that tell React to not render anything
[<Emit("null")>]
let noElement = jsNative<ReactElement>
[<Erase>]
type ComponentClass<'props, 'state> = class end
[<RequireQualifiedAccess>]
@vbfox
vbfox / vswhere.fs
Last active Aug 22, 2018
F# vswhere
View vswhere.fs
// Microsoft.VisualStudio.Setup.Configuration.Interop.dll
module VsInstances =
open System.Runtime.InteropServices
[<Guid("B41463C3-8866-43B5-BC33-2B0676F7F42E")>]
[<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>]
[<ComImport>]
[<AllowNullLiteral>]
type private ISetupInstance =