Skip to content

Instantly share code, notes, and snippets.

View Atinux's full-sized avatar

Sébastien Chopin Atinux

View GitHub Profile
@Atinux
Atinux / sse.ts
Last active April 22, 2024 20:39
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 April 22, 2024 08:58
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 October 10, 2023 03:04
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: {
@mikeal
mikeal / gist:9242748
Last active June 23, 2020 05:17
Response to Nodejitsu NPM Trademark

I've known people at nodejitsu for years, since before the company even existed. I still consider many of them friends. That said, somebody over there has lost their mind.

Trademarks are an important part of open source. They protect the integrity of the trust that is built by any project. A classic example of why this is the case is Firefox. Suppose that a malware producer takes the Firefox codebase, which is free and open source, packages up their malware with it and then releases it as "Firefox". Then they buy search advertising and suddenly their bad and malicious version of Firefox is the first result on search engines across the web. This is clearly a bad thing for Firefox and open source everywhere, but what can Mozilla do to protect their community of users?

They can't enforce a software license since the use is permitted under the Mozilla Public License. They can, however, enforce on these hypothetical bad actors using their trademark on the word "Fi