Skip to content

Instantly share code, notes, and snippets.

View happylinks's full-sized avatar

Michiel Westerbeek happylinks

View GitHub Profile
@happylinks
happylinks / Object.res
Created May 16, 2024 08:40
Testing MaybeUndefined in rescript with spice
let omitMaybeUndefined: Js.Json.t => Js.Json.t = %raw(
"function(obj) {Object.keys(obj).forEach(key => obj[key] === 'UNDEFINED' ? delete obj[key] : {}); return obj;}"
)
%%raw(`
let _omitMaybeUndefinedRecursive = (obj) => {
let newObj = {};
Object.keys(obj).forEach((key) => {
if (obj[key] === Object(obj[key])) newObj[key] = _omitMaybeUndefinedRecursive(obj[key]);
@happylinks
happylinks / chatgpt interrupt arc boost.js
Created April 17, 2024 13:14
Interrupt ChatGPT when it's typing and you just want to send something else without clicking stop first
document.addEventListener("DOMContentLoaded", (event) => {
function handleElementAppeared(textarea) {
console.log(textarea);
textarea.addEventListener("keydown", e => {
if (e.key === "Enter") {
var stopButton = document.querySelector('[aria-label="Stop generating"]');
if (stopButton) {
stopButton.click();
textarea.submit();
}
@happylinks
happylinks / RoomServiceV2.re
Created December 13, 2020 13:00
RoomService V2 ReasonML bindings
type key = string;
type rs;
type options = {auth: string};
[@bs.module "@roomservice/browser"] [@bs.new]
external make: options => rs = "RoomService";
type room;
[@bs.send] external room: (rs, string) => Js.Promise.t(room) = "room";
@happylinks
happylinks / gist:0443f283cc4f1c05988608425b2426b0
Last active November 30, 2020 08:45
react-google-picker
// original source code at https://github.com/sdoomz/react-google-picker/blob/master/src/react-google-picker.js
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import loadScript from "load-script";
const GOOGLE_SDK_URL = "https://apis.google.com/js/client.js";
let scriptLoadingStarted = false;
export const request = (url) => {
/* Global settings */
[@bs.deriving abstract]
type pixiSettings = {
[@bs.as "ROUND_PIXELS"]
mutable roundPixels: bool,
[@bs.as "MIPMAP_TEXTURES"]
mutable mipMapTextures: int,
[@bs.as "PRECISION_FRAGMENT"]
mutable precisionFragment: string,
};
@happylinks
happylinks / Reach.re
Created January 10, 2020 10:56
Reach reasonml bindings
module Menu = {
[@bs.module "@reach/menu-button"] [@react.component]
external make:
(~className: string=?, ~children: React.element) => React.element =
"Menu";
module Button = {
[@bs.module "@reach/menu-button"] [@react.component]
external make: (~children: React.element) => React.element = "MenuButton";
};
/* Hooks.re */
let useMachine = (initialState, initialContext, decisionTree) => {
let (state, setState) = React.useState(_ => initialState);
let (context, setContext) = React.useState(_ => initialContext);
let transition = event =>
setState(state => decisionTree(event, state, setContext));
(state, context, transition);
};
@happylinks
happylinks / machine.js
Last active December 3, 2019 10:26
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@happylinks
happylinks / machine.js
Last active December 2, 2019 12:08
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@happylinks
happylinks / machine.js
Created December 2, 2019 12:00
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions