Skip to content

Instantly share code, notes, and snippets.

View reaktivo's full-sized avatar
👋

Marcel Miranda Ackerman reaktivo

👋
View GitHub Profile
@reaktivo
reaktivo / intercept.ts
Created October 17, 2022 19:42
Intercept property access recursively in javascript
function intercept<T extends {}>(
obj: T,
callback: (path: string) => void,
path: string[] = []
): T {
function isPlainObject(obj: unknown) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
const proxy = new Proxy(obj, {
@reaktivo
reaktivo / transform.js
Last active June 19, 2021 19:19
Example jscodeshift transform
module.exports = function(fileInfo, api, options) {
// transform `fileInfo.source` here
// ...
console.log(fileInfo);
return fileInfo.source;
};
@reaktivo
reaktivo / fetch.js
Created July 19, 2020 21:24
Simple ponyfill for QuickJS
import * as os from 'os';
import * as std from 'std';
function mapToFetchResponse(fullResponse) {
const {
responseHeaders,
status,
response,
} = fullResponse;
@reaktivo
reaktivo / rafaelize.js
Created May 6, 2020 19:12
Rafael Rozendal
[...document.querySelectorAll("*")].forEach((a)=>{a.style.color = a.style.background = color="#"+(~~(Math.random()*(1<<24))).toString(16); (/img|svg|video/i).test(a.tagName) && (a.style.visibility = 'hidden')})
@reaktivo
reaktivo / playground.html
Created April 26, 2020 18:20
Preact Playground
<!doctype html>
<main />
<script type="module">
import { html, render } from 'https://unpkg.com/htm/preact/standalone.module.js';
const App = () => {
return html`<h1>Hello world</h1>`;
}
@reaktivo
reaktivo / ID.js
Last active February 18, 2020 14:25
ID - a unique ID/name generator for JavaScript
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `id`
@reaktivo
reaktivo / cacheFn.ts
Created December 2, 2019 13:29
Naive cache of function with serializable arguments
export function cacheFn<T>(fn: T): T {
const cache = {};
return (...args) => {
const key = JSON.stringify(args);
return (cache[key] = cache[key] || fn(...args));
};
}
@reaktivo
reaktivo / types.ts
Created November 26, 2019 15:22
Typescript Contentful type
import { createClient, EntryCollection, ContentTypeLink, Entry, Sys } from 'contentful';
type FlatEntry<T> = {
id: Sys['id'];
contentType: ContentTypeLink['id'];
} & T;
type ValueOf<T> = T[keyof T];
function flatten<T>(contentfulValue: Entry<T> | ValueOf<T>) {
@reaktivo
reaktivo / keybase.md
Created September 10, 2019 06:37
keybase.md

Keybase proof

I hereby claim:

  • I am reaktivo on github.
  • I am reaktivo (https://keybase.io/reaktivo) on keybase.
  • I have a public key ASD6Xr0LWA8Dlst6eZuQaf75ida3MJemmd4euN5btm7VDAo

To claim this, I am signing this object:

@reaktivo
reaktivo / index.js
Last active February 27, 2019 18:24
Node sorting bug
// Run this with node 8
// npx node@8 ./index.js
const arr = [
{ i: 1 },
{ i: 2 },
{ i: 3 },
{ i: 4 },
{ i: undefined },
{ i: undefined },
{ i: undefined },