Skip to content

Instantly share code, notes, and snippets.

View brysgo's full-sized avatar

Bryan Goldstein brysgo

View GitHub Profile
@brysgo
brysgo / VerboseAsync.js
Last active March 19, 2024 19:53
verbose logging of nodejs async function by converting to generator
async function myAsyncFunction() {
await callToSomethingAsync();
someNonAsyncFunctionCall();
await callToAnotherAsyncThing();
}
function convertAsyncFunctionToGenerator(fn) {
// Convert the function to string
let stringFn = fn.toString();
javascript:(function()%7Bconst%20scrollToBottom%20%3D%20(className)%20%3D%3E%20%7B%0A%20%20%20%20const%20element%20%3D%20document.getElementsByClassName(className)%5B0%5D%3B%0A%20%20%20%20element.scrollTop%20%3D%20element.scrollHeight%3B%0A%7D%0Alet%20shuffle%20%3D%20(array)%20%3D%3E%20%7B%0A%20%20let%20currentIndex%20%3D%20array.length%2C%20%20randomIndex%3B%0A%0A%20%20%2F%2F%20While%20there%20remain%20elements%20to%20shuffle.%0A%20%20while%20(currentIndex%20!%3D%200)%20%7B%0A%0A%20%20%20%20%2F%2F%20Pick%20a%20remaining%20element.%0A%20%20%20%20randomIndex%20%3D%20Math.floor(Math.random()%20*%20currentIndex)%3B%0A%20%20%20%20currentIndex--%3B%0A%0A%20%20%20%20%2F%2F%20And%20swap%20it%20with%20the%20current%20element.%0A%20%20%20%20%5Barray%5BcurrentIndex%5D%2C%20array%5BrandomIndex%5D%5D%20%3D%20%5B%0A%20%20%20%20%20%20array%5BrandomIndex%5D%2C%20array%5BcurrentIndex%5D%5D%3B%0A%20%20%7D%0A%0A%20%20return%20array%3B%0A%7D%0Alet%20shuffledNames%20%3D%20shuffle(Array.from(document.getElementsByClassName(%22c-m
@brysgo
brysgo / usePeekaboo.ts
Created April 27, 2021 16:20
cascading sticky elements (open sourced from a side project of mine)
import useComponentSize from '@rehooks/component-size'
import useWindowScrollPosition, { WindowScrollPosition } from '@rehooks/window-scroll-position'
import { useMemo, useRef, RefObject } from 'react'
interface Props<T extends HTMLElement> {
min?: number
max?: number
ref?: RefObject<T>
}

Keybase proof

I hereby claim:

  • I am brysgo on github.
  • I am brysgo (https://keybase.io/brysgo) on keybase.
  • I have a public key ASDCZLDZgtKM_8KZLwR7VBTsJAvCur4wv3xDSFmZzR3YFQo

To claim this, I am signing this object:

@brysgo
brysgo / .zshrc
Last active September 20, 2019 14:44
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
[
{
"id": "adelphes.android-dev-ext",
"name": "android-dev-ext",
"publisher": "adelphes",
"version": "0.7.1"
},
{
"id": "dbaeumer.vscode-eslint",
"name": "vscode-eslint",
@brysgo
brysgo / linkAll.sh
Created March 14, 2019 20:43
Bash script to link all the packages in a half baked mono repo
#!/bin/bash
for d in ./packages/*/ ; do
echo ""
echo "##################################################"
echo "##"
echo "## Linking in $d"
echo "##"
echo ""
echo
@brysgo
brysgo / convert.js
Last active November 6, 2018 22:53
Convert via region data to yolo format
const fs = require("fs");
const path = require("path");
const sizeOf = require("image-size");
const args = process.argv.slice(2);
const data = require(path.join(path.resolve(args[0]), "/via_region_data.json"));
const imgMetadata = Object.values(data["_via_img_metadata"]);
@brysgo
brysgo / index.html
Last active July 9, 2018 21:09 — forked from darwin/index.html
Dev escalated quickly
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css"/>
<script src="http://cmx.io/v/0.1/cmx.js"></script>
<body>
<scene id="scene1">
<label t="translate(0,346)">
<tspan x="0" y="0em">Dev escalated quickly</tspan>
</label>
<drawing t="translate(130,130)">

Keybase proof

I hereby claim:

  • I am brysgo on github.
  • I am brysgo (https://keybase.io/brysgo) on keybase.
  • I have a public key ASBcK_qRcPereB_XIWFhqbWZQF9G_E1rZUgW3UIw_zJjJQo

To claim this, I am signing this object: