Skip to content

Instantly share code, notes, and snippets.

View atinux's full-sized avatar

Sébastien Chopin atinux

View GitHub Profile
@regenrek
regenrek / .cursorrules
Last active March 3, 2025 11:59
Cursorrule for Nuxt3 Typescript and Nuxt Ui
You have extensive expertise in Vue 3, Nuxt 3, TypeScript, Node.js, Vite, Vue Router, Pinia, VueUse, Nuxt UI, and Tailwind CSS. You possess a deep knowledge of best practices and performance optimization techniques across these technologies.
Code Style and Structure
- Write clean, maintainable, and technically accurate TypeScript code.
- Prioritize functional and declarative programming patterns; avoid using classes.
- Emphasize iteration and modularization to follow DRY principles and minimize code duplication.
- Prefer Composition API <script setup> style.
- Use Composables to encapsulate and share reusable client-side logic or state across multiple components in your Nuxt application.
Nuxt 3 Specifics
@atinux
atinux / sse.ts
Last active February 1, 2025 19:02
SSE endpoint example with Nuxt 3
// ~/server/api/sse.ts
export default defineEventHandler(async (event) => {
if (!process.dev) return { disabled: true }
// Enable SSE endpoint
setHeader(event, 'cache-control', 'no-cache')
setHeader(event, 'connection', 'keep-alive')
setHeader(event, 'content-type', 'text/event-stream')
setResponseStatus(event, 200)
@wilsonpage
wilsonpage / swr.ts
Last active March 28, 2025 09:35
An implementation of stale-while-revalidate for Cloudflare Workers
export const CACHE_STALE_AT_HEADER = 'x-edge-cache-stale-at';
export const CACHE_STATUS_HEADER = 'x-edge-cache-status';
export const CACHE_CONTROL_HEADER = 'Cache-Control';
export const CLIENT_CACHE_CONTROL_HEADER = 'x-client-cache-control';
export const ORIGIN_CACHE_CONTROL_HEADER = 'x-edge-origin-cache-control';
enum CacheStatus {
HIT = 'HIT',
MISS = 'MISS',
REVALIDATING = 'REVALIDATING',
@Akryum
Akryum / main.backup.js
Last active July 3, 2018 16:16
vue-cli SSR
// Existing imports
import Vue from 'vue'
import router from './router'
import store from './store'
// Other existing code here
// Add 'app' variable
const app = new Vue({
// Existing options
@mattbrailsford
mattbrailsford / .travis.yml
Last active September 12, 2021 13:49
Configuration for deploying a NUXT static site to github pages
language: node_js
node_js:
- "8"
cache:
directories:
- "node_modules"
branches:
only:
@DiederikvandenB
DiederikvandenB / nuxt.config.js
Created October 16, 2017 10:21
NuxtJS Sentry Module
module.exports = {
/* ... */
modules: [
['~/modules/sentry', {
public_key: '',
private_key: '',
project_id: '',
}],
],
/* ... */
@atinux
atinux / async-foreach.js
Last active August 30, 2024 13:03
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@atinux
atinux / last-digit-ean13.js
Last active November 29, 2019 18:07
Get last digit of an EAN/GTIN 13 in JavaScript
function getLastEan13Digit(ean) {
if (!ean || ean.length !== 12) throw new Error('Invalid EAN 13, should have 12 digits')
const multiply = [1, 3]
let total = 0
ean.split('').forEach((letter, index) => {
total += parseInt(letter, 10) * multiply[index % 2]
})
@stevebauman
stevebauman / TextareaUpload.vue
Created July 11, 2017 16:08
Markdown Text Area Upload VueJS 2 Component
<template>
<textarea
:id="id"
:name="name"
:value="value"
:placeholder="placeholder"
:rows="rows"
:cols="cols"
class="form-control"
@dragover.prevent
@mikermcneil
mikermcneil / do-stuff.js
Created June 21, 2015 01:03
example of reporting progress using machines + lamda inputs
// A machine definition
// (e.g. `machines/do-stuff.js`)
module.exports = {
friendlyName: 'Do stuff',
// ...
inputs: {