Skip to content

Instantly share code, notes, and snippets.

View toniengelhardt's full-sized avatar
🔭

T●NI toniengelhardt

🔭
View GitHub Profile
@toniengelhardt
toniengelhardt / nuxt.config.ts
Last active November 24, 2023 14:07
nuxt-alt/auth config for Django backend w/ simple-jwt
auth: {
globalMiddleware: true,
redirectStrategy: 'query', // IMPORTANT! Otherwise, there will be an infinite logout loop.
watchLoggedIn: true,
cookie: {
prefix: 'auth.',
options: {
path: '/',
secure: process.env.NODE_ENV === 'production', // Enable only in production.
sameSite: 'lax', // IMPORTANT!
/**
* Get absolute xy position of caret in px.
* Time to execute: ~2.5ms on a 2018 MacBook Pro.
* Inpired by: https://medium.com/@jh3y/how-to-where-s-the-caret-getting-the-xy-position-of-the-caret-a24ba372990a
* @param {object} element - the textarea element to obtain coordinates for
*/
export function getCaretXY(element: HTMLTextAreaElement): { x: number, top: number, bottom: number } {
const { top: textElementTop, left: textElementLeft } = element.getBoundingClientRect()
const selectionPoint = element.selectionEnd
// Create a dummy element, copy style and populate with content up to the caret.
@toniengelhardt
toniengelhardt / vue3_timeago.vue
Last active January 25, 2022 00:04
Simple Vue 3 TimeAgo component
<template>
<span class="timeago">{{ timeago }}</span>
</template>
<script setup lang="ts">
interface Props {
datetime: Date
refreshInterval?: number
timeFormat?: string
dateFormat?: any
@toniengelhardt
toniengelhardt / REGEX_european_word.js
Last active July 26, 2020 10:13
Regex pattern matching a word with all European special characters
/([0-9a-zA-ZáàâäãåąāăçćčďđðéèêëęěēėģğíìîïīįıķłļñńňņŋóòôöõőøřśšşťŧþţúùûüůűūýÿźżžßæœÁÀÂÄÃÅĄĀĂÇĆČĎĐÉÈÊËĘĒĖĢĞÍÌÎÏĪĮIĶŁĻÑŃŇŅŊÓÒÔÖÕŐØŘŚŠŞŤŦÞŢÚÙÛÜŰŪÝŸŹŻŽÆŒ_-]+)/gi