Skip to content

Instantly share code, notes, and snippets.

@joshuaalpuerto
joshuaalpuerto / Signal.js
Last active June 12, 2024 23:00
This gist contains a simple implementation of the Signal and Effect pattern in JavaScript. The Signal pattern is a behavioral design pattern that allows communication between objects in a decoupled way, while the Effect pattern is a pattern that allows for the separation of side effects from the main logic of an application.
let currentListener = undefined;
function createSignal(initialValue) {
let value = initialValue;
const subscribers = new Set();
const read = () => {
if (currentListener !== undefined) {
subscribers.add(currentListener);
@joshuaalpuerto
joshuaalpuerto / toRawValue.js
Created April 2, 2022 08:40
Getting raw type
function toRawType (value) {
let _toString = Object.prototype.toString;
let str = _toString.call(value)
return str.slice(8, -1)
}
toRawType('test') === 'String'
@joshuaalpuerto
joshuaalpuerto / aggregateBuilder.js
Last active January 10, 2023 16:04
Mongodb simple aggregate builder using Proxy
function generatePipeline(pipelines = []) {
const callable = () => {};
callable.pipelines = pipelines;
return new Proxy(callable, {
get(callable, propKey) {
return (props) => {
if (propKey === 'run') {
return callable.pipelines;
}
callable.pipelines.push({ [`$${propKey}`]: props });
@DavidWells
DavidWells / github-proxy-client.js
Last active March 3, 2025 17:47
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
@DavidWells
DavidWells / javascript-proxy-as-rest-client.js
Last active July 31, 2025 20:51
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) {
@thameera
thameera / action.js
Last active November 12, 2025 11:03
Actions redirect example
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
// Craft a signed session token
const token = api.redirect.encodeToken({
secret: 'keyboardcat', // IMPORTANT: Read this from event.secrets
@csandman
csandman / README.md
Last active October 11, 2023 10:23
Chakra UI React Select

Chakra React Select

UPDATE: I finally made an NPM package for this component! It is made with TypeScript, and now has a fully customizable styling system. It is also far ahead of this wrapper at this point. Check it out here if you'd like: https://github.com/csandman/chakra-react-select

In order to use this component, you can implement it and use it like you would normally use react-select. It should accept all of the props that the original takes, however customizing the theme or the components could break this implementation. There are also a few extra things you can do with this wrapper that pull from the chakra library.

  • You can pass the size prop with either sm, md, or lg. These will reflect the sizes available on the Chakra <Input /> component (with the exception of xs because it's too small to work).
  • In your options objects, you can add the key isFixed to emulate the exa
@baumandm
baumandm / Chakra-UI x React-datepicker.md
Last active May 29, 2024 05:29
Chakra-UI x React-datepicker

⚠️ I'd recommend using this fork by @igoro00 which has better theme support.


Tiny wrapper component for React-Datepicker to stylistically fit with Chakra-UI 1.x.

<DatePicker selectedDate={myDate} onChange={(d) => console.log(d)} />
@tomhicks
tomhicks / plink-plonk.js
Last active October 15, 2025 13:41
Listen to your web pages
@bvaughn
bvaughn / index.md
Last active September 8, 2025 00:55
How to use profiling in production mode for react-dom

React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.

Table of Contents

Profiling in production

React DOM automatically supports profiling in development mode for v16.5+, but since profiling adds some small additional overhead it is opt-in for production mode. This gist explains how to opt-in.