Skip to content

Instantly share code, notes, and snippets.

View tylerforesthauser's full-sized avatar

Tyler Forest-Hauser tylerforesthauser

View GitHub Profile
export const chaosTestStrings = (): void => {
const textNodes = getAllTextNodes(document.body);
for (const node of textNodes) {
const textNodeLength = node.textContent ? node.textContent.length : 0;
if (node.textContent === null) {
return;
}
if (node.parentElement instanceof Element) {
if (node.parentElement.dataset.originalText === undefined) {
@JacobWeisenburger
JacobWeisenburger / makeSearchParamsObjectSchema.ts
Last active April 19, 2025 19:41
a way to parse URLSearchParams with Zod
import { z } from 'zod'
function safeParseJSON ( string: string ): any {
try { return JSON.parse( string ) }
catch { return string }
}
function searchParamsToValues ( searchParams: URLSearchParams ): Record<string, any> {
return Array.from( searchParams.keys() ).reduce( ( record, key ) => {
const values = searchParams.getAll( key ).map( safeParseJSON )
@justin-schroeder
justin-schroeder / externalRedirect.ts
Created July 12, 2022 19:36
Perform an external redirect in Nuxt 3 router middleware
import { useNuxtApp } from '#app'
import { sendRedirect } from 'h3'
/**
* Performs an external redirect in a Nuxt3 route middleware. Once this Nuxt3
* pull request is merged, this function can be removed in favor of navigateTo:
*
* https://github.com/nuxt/framework/pull/5022
*
* @param url - An external url to redirect to
@EllyLoel
EllyLoel / reset.css
Last active January 24, 2025 09:14
CSS Reset
/*
Made by Elly Loel - https://ellyloel.com/
With inspiration from:
- Josh W Comeau - https://courses.joshwcomeau.com/css-for-js/treasure-trove/010-global-styles/
- Andy Bell - https://piccalil.li/blog/a-modern-css-reset/
- Adam Argyle - https://unpkg.com/[email protected]/normalize.min.css / https://codepen.io/argyleink/pen/KKvRORE
Notes:
- `:where()` is used to lower specificity for easy overriding.
*/
@Stiropor
Stiropor / auth.js
Last active September 8, 2022 14:38
Nuxt3 auth demo
import { nextTick } from 'vue'
export const useProperCookie = () => useCookie('proper_token')
export const useAuthFetch = (url, fetchOptions = {}) => {
return $fetch(url, {
baseURL: 'https://l9.test/api/v1',
...fetchOptions,
headers: {
Authorization: `Bearer ${useProperCookie().value}`,
...fetchOptions.headers,
// Snippet for Directus' custom endpoint (tested on v9.8.0)
// This snippet checks if a role named "Homepage" is present and authenticates with it to execute custom logic
// In this case, it returns an image if the role has sufficient permissions.
// It's pretty barebone, but should get you started.
const { getPermissions } = require('directus/utils/get-permissions');
const { getSchema } = require('directus/utils/get-schema');
module.exports = function registerEndpoint(router, { services, exceptions, database }) {
@cadars
cadars / kbd.js
Last active October 12, 2022 14:14
import { Mark, markInputRule, markPasteRule } from '@tiptap/core';
export const kbdInputRegex = /(?:^|\s)((?:<kbd>)((?:[^*]+))(?:<\/kbd>))$/;
export const kbdPasteRegex = /(?:^|\s)((?:<kbd>)((?:[^*]+))(?:<\/kbd>))/g;
export const Kbd = Mark.create({
name: 'kbd',
excludes: '_',
@wobsoriano
wobsoriano / auth.js
Last active February 29, 2024 07:37
nuxtServerInit like implementation for Pinia
import { defineStore } from 'pinia'
export const useAuthStore = defineStore({
id: 'auth',
state: () => ({
isAuthenticated: false,
user: null
}),
actions: {
async nuxtServerInit() {
@leeroybrun
leeroybrun / deploy-pm2.md
Last active August 6, 2024 03:53 — forked from hoangmirs/deploy-pm2.md
Deploy pm2 guide