Skip to content

Instantly share code, notes, and snippets.

View gahabeen's full-sized avatar

Gabin Desserprit gahabeen

View GitHub Profile
@thelinuxlich
thelinuxlich / zod_deep_pick.ts
Created October 19, 2023 15:28
Zod Deep Pick
function isZodObject(schema: z.ZodTypeAny): schema is z.AnyZodObject {
if (schema._def.typeName === "ZodObject") return true;
return false;
}
function isZodArray(schema: z.ZodTypeAny): schema is z.ZodArray<any> {
if (schema._def.typeName === "ZodArray") return true;
return false;
@srph
srph / throttle.manual.ts
Last active August 28, 2024 08:27
throttle: Guarantee an async functions only resolves after X ms
import { delay } from '../time'
import { throttle } from './throttle'
// @TODO: In the future, let's write some tests. It's proving to be challenging
// because vitest has no means of flushing promises, and it causes some tests
// to fail (ergo, we expect callback to resolve faster, but it doesn't).
//
// Manual test for throttle function. To run:
// $ npm i -g ts-node && ts-node throttle.manual.ts
const tests = {
@PierBover
PierBover / index.js
Last active April 30, 2024 09:08
Micro router for Cloudflare Workers
const router = require('./router');
router.setRoutes([
{
path: '/ping',
method: 'GET',
handler: ping
},
{
path: '/hello/:name',
@slava-vishnyakov
slava-vishnyakov / readme.md
Last active March 28, 2025 07:52
How to upload images with TipTap editor
  1. Create a file Image.js from the source below (it is almost a copy of Image.js from tiptap-extensions except that it has a constructor that accepts uploadFunc (function to be called with image being uploaded) and additional logic if(upload) { ... } else { ... previous base64 logic .. } in the new Plugin section.
import {Node, Plugin} from 'tiptap'
import {nodeInputRule} from 'tiptap-commands'

/**
 * Matches following attributes in Markdown-typed image: [, alt, src, title]
 *
@anonyco
anonyco / Undo And Redo Mutation Observer Records.js
Last active August 23, 2024 12:18
This sample code snippet demonstrates how to undo and redo a MutationRecord observed by a MutationObserver
//(function(){"use strict";
var Object_freeze = Object.freeze;
/**
* @param {!Array<MutationRecord>} mutationRecords
* @return {undefined}
*/
function redoMutations(undidMutations) {
if (undidMutations) for (var i=undidMutations.length|0, record, type, target, addedNodes, removedNodes, nextSibling, value; i; ) {
@pocesar
pocesar / apify.d.ts
Last active February 4, 2022 07:36
apify typescript typings (non-official, but should help you get going)
declare module 'apify' {
import { IncomingMessage } from 'http'
import { EventEmitter } from 'events'
import {
Page,
Response as PuppeteerResponse,
ResourceType,
LaunchOptions,
HttpMethod,
Request as PuppeteerRequest,
@jonjack
jonjack / add-update-refresh-github-access-token-on-mac.md
Last active April 16, 2025 02:39
Adding & Updating GitHub Access Token on Mac

Using an Access Token for the first time

Follow the instructions on Github to Create an Access Token in Github

Configure Git to use the osxkeychain

By default, git credentials are not cached so you need to tell Git if you want to avoid having to provide them each time Github requires you to authenticate. On Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account.

You can tell Git you want to store credentials in the osxkeychain by running the following:-