Skip to content

Instantly share code, notes, and snippets.

View dan-lee's full-sized avatar
‌‌

Dan dan-lee

‌‌
  • Germany
  • 17:05 (UTC +02:00)
  • X @drlehr
View GitHub Profile
@wontondon
wontondon / LICENSE
Last active August 25, 2022 00:35
ReactRouterV6 Sentry Support
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
@cdaringe
cdaringe / pnpm-patch-package.js
Created April 13, 2022 18:28
pnpm-patch-package.js
/**
* @description
* Support patch-package in pnpm projects.
*
* `pnpm` can be tricky to use with patch-package. To minimize friction creating patches,
* this script helps automate patching by using npm and a temp workspace to generate
* patch files.
*
* @usage
* 0. ensure the dependencies of interest are top level dependencies/devDependencies (no patching transitive deps)
@DavidWells
DavidWells / javascript-proxy-as-rest-client.js
Last active October 6, 2023 18:39
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
@Explosion-Scratch
Explosion-Scratch / Compress string.js
Created November 1, 2021 18:51
Compress string using gzip and native browser APIs
function compress(string, encoding) {
const byteArray = new TextEncoder().encode(string);
const cs = new CompressionStream(encoding);
const writer = cs.writable.getWriter();
writer.write(byteArray);
writer.close();
return new Response(cs.readable).arrayBuffer();
}
function decompress(byteArray, encoding) {
@wilsonpage
wilsonpage / swr.ts
Last active February 20, 2024 05:21
An implementation of stale-while-revalidate for Cloudflare Workers
export const CACHE_STALE_AT_HEADER = 'x-edge-cache-stale-at';
export const CACHE_STATUS_HEADER = 'x-edge-cache-status';
export const CACHE_CONTROL_HEADER = 'Cache-Control';
export const CLIENT_CACHE_CONTROL_HEADER = 'x-client-cache-control';
export const ORIGIN_CACHE_CONTROL_HEADER = 'x-edge-origin-cache-control';
enum CacheStatus {
HIT = 'HIT',
MISS = 'MISS',
REVALIDATING = 'REVALIDATING',
@nzvtrk
nzvtrk / memoizeDebounce.js
Last active October 6, 2022 12:58
Memoized debounce using lodash for async fetching
import { debounce } from 'lodash';
import axios from 'axios';
// or vanilla debounce
// const debounce = (func, timeOut) => {
// let timer
//
// return (...args) => {
// if (timer) clearTimeout(timer)
// timer = setTimeout(func, timeOut)
let NETWORK_PRESETS = {
'GPRS': {
'offline': false,
'downloadThroughput': 50 * 1024 / 8,
'uploadThroughput': 20 * 1024 / 8,
'latency': 500
},
'Regular2G': {
'offline': false,
'downloadThroughput': 250 * 1024 / 8,
@fnky
fnky / ANSI.md
Last active April 18, 2024 09:48
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@SMUsamaShah
SMUsamaShah / List of JavaScript GUI libraries.md
Last active April 4, 2024 07:29
dat.gui alternatives to create GUI from JavaScript object

JavaScript GUI libraries

These libraries can be used to quickly create a GUI for configureable parameters using sliders, checkboxes, colors pickers etc

  1. Tweakpane https://github.com/cocopon/tweakpane Demo: https://cocopon.github.io/tweakpane/
  2. control-panel https://github.com/freeman-lab/control-panel
  3. ControlKit https://github.com/automat/controlkit.js
  4. guify https://github.com/colejd/guify Main site is down, here is the demo https://jons.website/projects/guify/index
  5. oui https://github.com/wearekuva/oui
  6. Palette.js https://github.com/lehni/palette.js
import React, { Component, createContext } from 'react'
function initStore(store) {
const Context = createContext();
class Provider extends React.Component {
constructor() {
super();
this.state = store.initialState;
}