Skip to content

Instantly share code, notes, and snippets.

View maraisr's full-sized avatar
:fishsticks:

marais maraisr

:fishsticks:
View GitHub Profile
@munrocket
munrocket / wgsl_2d_sdf.md
Last active March 18, 2024 02:38
WGSL 2D SDF Primitives

WGSL 2D SDF Primitives

Revision: 06.08.2023, https://compute.toys/view/398

Circle - exact

fn sdCircle(p: vec2f, r: f32) -> f32 {
  return length(p) - r;
}
@jacob-ebey
jacob-ebey / webpack-access-federated-containers-plugin.js
Created December 8, 2020 05:12
webpack-access-federated-containers-plugin.js
/*
Makes your remote containers low level API accessible via:
import accessFederatedContainer from "access-federated-containers";
accessFederatedContainer("app2")
*/
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Compilation} Compilation */
@n1ru4l
n1ru4l / AsyncIteratorUtilities.ts
Created September 21, 2020 16:05
AsyncIteratorUtilities.ts
export const map = <T, O>(map: (input: T) => Promise<O> | O) =>
async function* mapGenerator(asyncIterable: AsyncIterableIterator<T>) {
for await (const value of asyncIterable) {
yield map(value);
}
};
export const filter = <T, U extends T>(filter: (input: T) => input is U) =>
async function* filterGenerator(asyncIterable: AsyncIterableIterator<T>) {
@AndrewIngram
AndrewIngram / PostDetail.jsx
Last active October 23, 2022 01:56
Updated Next.js with Relay (still using getInitialProps)
import React from "react";
import { graphql } from "react-relay";
import createPageContainer from "../relay/createPageContainer";
import PostLayout from "../components/PostLayout";
import Header from "../components/Header";
import Shell from "../layouts/Shell";
@developit
developit / *polkompress.md
Last active April 13, 2021 22:50
polkompress

Polkompress

A tiny zero-dependency compression middleware for polka (& express!) with native Brotli support.

@sibelius
sibelius / AutocompleteRelay.tsx
Last active March 23, 2024 10:13
@material-ui Autocomplete lab with react-window + infinite-loader for GraphQL/Relay connections
import React, { useRef, useState } from 'react';
import { Typography } from '@material-ui/core';
import TextField from '@material-ui/core/TextField';
import CircularProgress from '@material-ui/core/CircularProgress';
import Autocomplete, {
AutocompleteChangeDetails,
AutocompleteChangeReason,
AutocompleteProps
} from '@material-ui/lab/Autocomplete';
@sidevesh
sidevesh / fetchHandler.js
Last active April 30, 2020 11:54
fetchHandler - handle api calls to your Backend with fetch api in a simple and unified way
const responseParserTypes = {
json: (response) => response.json(),
text: (response) => response.text(),
blob: (response) => response.blob(),
formData: (response) => response.formData(),
arrayBuffer: (response) => response.arrayBuffer(),
};
const parseResponse = (response, type) => {
if (!Object.keys(responseParserTypes).includes(type)) {
@developit
developit / *constant-locals-loader.md
Last active February 4, 2022 17:15
Inline Webpack CSS Modules classNames, reducing bundle size. https://npm.im/constant-locals-loader

constant-locals-loader for Webpack

This loader optimizes the output of mini-css-extract-plugin and/or css-loader, entirely removing the potentially large CSS classname mappings normally inlined into your bundle when using CSS Modules.

Run npm install constant-locals-loader, then make these changes in your Webpack config:

module.exports = {
 module: {
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
// Create a Worker we want to share memory with:
let w = new Worker(`data:text/javascript,
onmessage = ({data: memory}) => {
// Got WebAssembly.Memory once, log same instance forever with no further postMessages:
setInterval(() => console.log('Current buffer in worker:', memory.buffer), 5_000);
}
`);
// Create a shared growable memory:
let m = new WebAssembly.Memory({ initial:1, maximum: 65536, shared: true });
// Send memory to the worker: