Skip to content

Instantly share code, notes, and snippets.

Avatar

Sébastien Chopin Atinux

View GitHub Profile
View [component].vue
<template>
<UCard v-if="component" class="relative flex flex-col lg:h-[calc(100vh-10rem)]" body-class="px-4 py-5 sm:p-6 relative" footer-class="flex flex-col flex-1 overflow-hidden">
<div class="flex justify-center">
<component :is="`U${defaultProps[params.component].component.name}`" v-if="defaultProps[params.component] && defaultProps[params.component].component" v-bind="defaultProps[params.component].component.props" />
<component :is="is" v-bind="{ ...boundProps, ...eventProps }">
<template v-for="[key, slot] of Object.entries(defaultProps[params.component]?.slots || {}) || []" #[key]>
<template v-if="Array.isArray(slot)">
<div :key="key">
<component
View timeago.vue
<template>
<time :datetime="date" :title="date">{{ timeago }}</time>
</template>
<script>
const units = [
{ max: 2760000, value: 60000, name: 'minute', short: 'm', past: 'a minute ago', future: 'in a minute' },
{ max: 72000000, value: 3600000, name: 'hour', short: 'h', past: 'an hour ago', future: 'in an hour' },
{ max: 518400000, value: 86400000, name: 'day', short: 'd', past: 'yesterday', future: 'tomorrow' },
{ max: 2419200000, value: 604800000, name: 'week', short: 'w', past: 'last week', future: 'in a week' },
@Atinux
Atinux / keybindings.json
Last active January 16, 2022 05:43
VS Code Terminal Shortcuts
View keybindings.json
[
{
"key": "ctrl+shift+n",
"command": "workbench.action.terminal.new"
},
{
"key": "ctrl+shift+right",
"command": "workbench.action.terminal.focusNext"
},
{
View login-url
https://github.com/login/oauth/authorize?client_id=55440d3936ba0961241e
View workshop-token
?access_token=5f73077695f6d2b1d5d0ae4f2277919639838932
@Atinux
Atinux / async-foreach.js
Last active December 9, 2022 22:44
JavaScript: async/await with forEach()
View async-foreach.js
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
View last-digit-ean13.js
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]
})
@Atinux
Atinux / forEach.proto.js
Last active October 4, 2017 09:25
Simple prototype of forEach
View forEach.proto.js
Array.prototype.forEach = function (callback) {
// this represents our array
for (let index = 0; index < this.length; i++) {
// We call the callback for each entry
callback(this[index], index, this)
}
}
@Atinux
Atinux / forEach.js
Created October 3, 2017 13:13
forEach example with async/await (fail)
View forEach.js
const waitFor = (ms) => new Promise((resolve) => setTimeout(resolve, (ms || 0)))
[1, 2, 3].forEach(async (num) => {
await waitFor(50)
console.log(num)
})
console.log('Done')
@Atinux
Atinux / index.vue
Created July 4, 2017 10:25
Dynamic image nuxt
View index.vue
<template>
<div>
<h1>Welcome!</h1>
<nuxt-link to="/about">About page</nuxt-link>
<img :src="flagUrl"/>
<button @click="nextFlag">Next flag</button>
</div>
</template>
<script>