Skip to content

Instantly share code, notes, and snippets.

View jaredatron's full-sized avatar

Jared Grippe jaredatron

View GitHub Profile
@jaredatron
jaredatron / parcel_routes.js
Last active March 9, 2023 17:30
putting parcel server behind development server because parcel's proxy features are inflexible
import Path from 'path'
import express from 'express'
import Router from 'express-promise-router'
import { createProxyMiddleware } from 'http-proxy-middleware'
import env from '../env.js'
let assetsRoutes, indexHtmlFallback
// proxy requests to `parcel serve` process
@jaredatron
jaredatron / router.js
Created January 25, 2023 23:20
Next.js 13 app dir like routing using React Router
import * as React from 'react'
import { createBrowserRouter, RouterProvider, Navigate, useLocation } from 'react-router-dom'
import { getLoginUrl } from '~/client/lib/urls'
import { useCurrentUser } from '~/client/hooks/auth'
import AppError from '~/client/components/AppError'
import FullPageLoading from './components/FullPageLoading'
import routeFiles from './routes/**/{Error,NotFound,Layout,Page}.js'
@jaredatron
jaredatron / add_all.js
Created July 18, 2022 21:19
add all photos to an google photos album
// make new album and go to the add images page then run this script in the console
stopIt = false
;(async () => {
const scrollParent = $('.Purf9b')
const wait = async ms => {
await new Promise((r, rj) => {
setTimeout(() => { r() }, ms)
})
}
@jaredatron
jaredatron / knapsack_amend.rb
Created April 11, 2016 23:19
# Monkey Patch Knapsack to merge reports instead of overwrite
# Monkey Patch Knapsack to merge reports instead of overwrite
begin
class Knapsack::Report
alias_method :save_without_leading_existing_report, :save
def save
Knapsack::Presenter.existing_report = open
save_without_leading_existing_report
end
end
@jaredatron
jaredatron / CropImage.js
Created June 17, 2020 23:27
Example of using ReactCrop react-image-crop
import React, { useRef, useState } from 'react'
import PropTypes from 'prop-types'
import ReactCrop from 'react-image-crop'
import 'react-image-crop/dist/ReactCrop.css'
export default function CropImage({
className = '',
src,
height,
width,
@jaredatron
jaredatron / example.bash
Last active April 16, 2021 20:35
tail a hypercore given its public key
hyperspace-simulator tail_hypercore.js -- 0ce9e824c768daf0564f6f1ec24e04430111b8845476464ffbf60e8e3ef06347
var postMessageRoundTripCounter = 0;
var setTimeoutRoundTripCounter = 0;
startPostMessageLoop = function(){
// var lastPostMessageAt = Date.now()
var receiveMessage = function(message){
if (message.data !== 'postMessageTest') return;
// var delta = Date.now() - lastPostMessageAt;
// console.log('postMessage delta:', delta);
postMessageRoundTripCounter++;
@jaredatron
jaredatron / track_back_and_forward_push_state.js
Last active October 10, 2020 00:50
How to track back and forward capability using history push state
/*
This is an example of how one could track if going back or forward is
an option for the user.
*/
if (!window.history.state || !window.history.state.visitedAt){
window.history.replaceState(
{...history.state, visitedAt: Date.now()},
@jaredatron
jaredatron / bash.sh
Created June 11, 2019 20:18
do this to stop Epic Games Launcher from starting at launch boot
launchctl unload ~/Library/LaunchAgents/com.epicgames.launcher.plist
rm ~/Library/LaunchAgents/com.epicgames.launcher.plist
@jaredatron
jaredatron / RawHTML.js
Last active June 9, 2020 01:02
Rendering raw HTML as Preact components
import { h, Fragment } from 'preact'
import { memo } from 'preact/compat'
import PropTypes from 'prop-types'
import Link from 'components/Link'
const RawHTML = memo(({source = '', ignoreNodes = []}) => {
const parser = new global.DOMParser()
const doc = parser.parseFromString(source, "text/html")
const options = {