Skip to content

Instantly share code, notes, and snippets.

View DavidWells's full-sized avatar
😃

David Wells DavidWells

😃
View GitHub Profile
// UTILS
export const getPaddingFromPrecision = (
floatingPointPrecision: number,
): number => {
return Math.ceil(Math.log2(360 * floatingPointPrecision));
};
export const convertToBinary = (
num: number,
@mikaelvesavuori
mikaelvesavuori / ic-metrics-gh-graphql-api.md
Last active January 14, 2025 07:25
Get Individual Contributor metrics from GitHub's GraphQL API.

Get Individual Contributor metrics from GitHub's GraphQL API

These are some handy snippets to get common metrics for checking how active a software engineer is.

  • How many pushes are made by the IC?
  • How many reviews are made by the IC?
  • How many comments are made by the IC?

Setup

import assert from 'node:assert/strict';
// Extended RegExp mode (flag /x) [1] via a template tag
//
// Quote: “While the x-mode flag can be used in a RegularExpressionLiteral,
// it does not permit the use of LineTerminator in RegularExpressonLiteral.
// For multi-line regular expressions you would need to use the RegExp
// constructor.”
//
// The plan is to include this functionality in re-template-tag [2]. Then
@sukima
sukima / simple-dom.js
Last active May 2, 2024 05:56
Very small DOM micro-lib using Proxy
/*******************************************/
/* Version 1.0.0 */
/* License MIT */
/* Copyright (C) 2022 Devin Weaver */
/* https://tritarget.org/cdn/simple-dom.js */
/*******************************************/
/**
* This micro lib is a compact and simple method to interact with the DOM. It
* facilitates the query mechanisms that querySelector and querySelectorAll use
@gushogg-blake
gushogg-blake / entrypoints.md
Last active May 20, 2022 16:19
A proposal for // ENTRYPOINT comments to indicate where a project connects to the outside world

Entrypoints

This is a proposal to adopt the use of // ENTRYPOINT comments next to a program's top-level entrypoints, such as the main function, event handlers, and network listeners.

The idea is to allow new contributors and curious readers to quickly gain an overview of the project's main functions in a way that's easy to understand, and for the entrypoints to act as sensible starting points (and helpful mental anchor points) for further exploration.

The presence of ENTRYPOINT comments should allow the reader to quickly begin to answer questions like what does this program do? (provided the main function is sufficiently readable); what happens when I press a key?; and how does this program respond to network requests?.

Tooling

@unrevised6419
unrevised6419 / README.md
Last active May 9, 2023 20:10
Instant Markdown editor

Instant Markdown editor in new tab

  1. Create a new bookmark
  2. To the link add data:text/html,
  3. After data:text/html, paste block below
  4. Save bookmark, and open it

First time it may take a while to load the library

@souporserious
souporserious / build.mjs
Created February 24, 2022 02:48
Build script using esbuild and ts-morph to bundle library code.
import glob from 'fast-glob'
import { build } from 'esbuild'
import { Project } from 'ts-morph'
const project = new Project({
compilerOptions: {
outDir: 'dist',
emitDeclarationOnly: true,
},
tsConfigFilePath: './tsconfig.json',
@bennadel
bennadel / api-client.js
Created February 6, 2022 20:09
Using fetch(), AbortSignal, And setTimeout() To Apply Retry Mechanics In JavaScript
// Regular expression patterns for testing content-type response headers.
var RE_CONTENT_TYPE_JSON = new RegExp( "^application/(x-)?json", "i" );
var RE_CONTENT_TYPE_TEXT = new RegExp( "^text/", "i" );
// Static strings.
var UNEXPECTED_ERROR_MESSAGE = "An unexpected error occurred while processing your request.";
export class ApiClient {
/**
* I initialize the API client.
import { useLoaderData, Link, useSearchParams } from 'remix';
import { parseISO, format } from 'date-fns';
import groupBy from 'lodash/groupBy';
let PAGE_SIZE = 5;
function safeParseInt(str) {
let parsed = parseInt(str);
return isNaN(parsed) ? 0 : parsed;
}
@franky47
franky47 / stripe-webhooks.ts
Created December 21, 2021 09:44
Strongly-typed webhook handlers for Stripe (Node.js)
import type { Stripe } from 'stripe'
export type StripeWebhookEventTypes =
Stripe.WebhookEndpointCreateParams.EnabledEvent
export type StripeWebhookEvent<
EventType extends StripeWebhookEventTypes,
Payload
> = {
eventType: EventType