Skip to content

Instantly share code, notes, and snippets.

View adamdehaven's full-sized avatar

Adam DeHaven adamdehaven

View GitHub Profile
/** Pre-compiled regex for stripping .md extension (case-insensitive) */
const MD_SUFFIX_REGEX = /\.md$/i
/**
* Server-side plugin that strips `.md` extensions from Vue Router params during SSR.
*
* When a request like `/public-page.md` is received, the Nitro layer sets
* `event.context.markdownRequested` to signal markdown output preference. However,
* Vue Router still sees the `.md` suffix in route params, which breaks data fetching
@adamdehaven
adamdehaven / nuxt.config.ts
Created January 7, 2026 17:23
Nuxt config componentMeta
{
componentMeta: {
globalsOnly: true,
componentDirs: [
join(currentDir, './app/components/global'),
],
exclude: [
'@nuxtjs/mdc',
'@kong/kongponents',
'nuxt/dist',
@adamdehaven
adamdehaven / ProseSvg.vue
Created December 11, 2024 18:39
Prose component for native SVG elements that handles transforming any child nodes (e.g. `path`) to lowercase so they are evaluated as native HTML
<template>
<component
:is="render"
v-bind="attrs"
:id="componentId"
class="prose-svg"
>
<slot />
</component>
</template>
@adamdehaven
adamdehaven / bgimage.css
Last active September 19, 2024 13:29
Bootstrap full-width hero section with text and image
.bgimage {
width:100%;
height:500px;
background: url('https://images.unsplash.com/photo-1438109491414-7198515b166b?q=80&fm=jpg&s=cbdabf7a79c087a0b060670a6d79726c');
background-repeat: no-repeat;
background-position: center;
background-size:cover;
background-attachment: fixed;
}
.bgimage h5 {
@adamdehaven
adamdehaven / vs-code-custom-font.md
Created February 7, 2020 19:06
VS Code Custom Font without Font Install Privileges

VS Code Custom Font without Font Install Admin Privileges

  1. Open Help -> Toggle Developer Tools in the menu (Ctrl + Shift + I)
  2. Paste JavaScript code below into the Console and execute.
    var styleNode = document.createElement('style'); 
    styleNode.type = "text/css"; 
    var styleText = document.createTextNode(`
        @font-face {
            font-family: "Fira Code";
@adamdehaven
adamdehaven / esmodule-can-not-be-stubbed.md
Last active June 16, 2022 14:00
ESModules cannot be stubbed

Utilizing Vite + Vue and Cypress Component Test Runner, how would you stub a composable function since you can't stub the default export?

I can't find a decent example that doesn't utilize Babel, and the only solution we have come up with is exporting an object with methods that can be stubbed, which, to be honest, would be a large refactor.

// Composable function
import { ref } from 'vue'

export default function useToggle (initialValue = false) {
 const enabled = ref(initialValue)
@adamdehaven
adamdehaven / 1-before.json
Created March 22, 2022 22:37
JSON Patch before/after
{
"viewer": {
"name": "Viewer",
"description": "Read only access to all users",
"entity_instances": [
{
"id": "UUID-A"
},
{
"id": "UUID-B"
#!/usr/bin/env bash
mapfile -t words < <(grep -x '[a-z]\{5\}' "${WORDLIST:-/usr/share/dict/words}")
word=${words[RANDOM % ${#words[@]}]} pool=abcdefghijklmnopqrstuvwxyz
for ((round=1; round <= ${ROUNDS:=6}; round++)); do
while chars="" && read -rp "$round/$ROUNDS: " guess || exit 1; do
case " ${words[@]} " in *" ${guess,,} "*) guess=${guess,,}; break; esac
done; for ((i=0; i < ${#word}; i++)); do
[[ ${word:i:1} != ${guess:i:1} ]] && chars+=${word:i:1}
done; i=0; while char=${guess:i:1} && ((i < ${#guess})) ; do
{ [[ ${word:i++:1} == $char ]] && color=2; } ||
@adamdehaven
adamdehaven / Login.spec.ts
Last active January 27, 2022 00:32
Cypress component tests: stub window methods (only relevant code)
import Login from 'Login.vue'
import win from 'window.ts'
it('pre-populates the email input from search params', () => {
// Stub search params
cy.stub(win, 'getLocationSearch').returns(`?email=${encodeURIComponent(user.email)}`)
mount(Login)
// Email input should be pre-populated