Skip to content

Instantly share code, notes, and snippets.

View innocenzi's full-sized avatar
🦋

Enzo Innocenzi innocenzi

🦋
View GitHub Profile
@innocenzi
innocenzi / Flashes.vue
Created August 20, 2020 14:34
Inertia flashes component
<template>
<section
:class="[
'mb-16 mx-16',
'absolute inset-x-0 bottom-0 z-50',
'flex justify-center',
'transition-opacity duration-1000',
!hasFlashes && 'opacity-0',
]"
>
@innocenzi
innocenzi / upload.sh
Last active September 22, 2020 14:30
Clipboard to Imgur
#!/usr/bin/env bash
errors=false
screenshot_path=/tmp/screenshot.jpeg
default_client_id=c9a6efb3d7932fd
client_id="${IMGUR_CLIENT_ID:=$default_client_id}"
# Save as a file
xclip -se c -t image/jpeg -o > $screenshot_path 2>/dev/null
@innocenzi
innocenzi / .php_cs
Created September 23, 2020 08:59
Configurations pour Prettier et CS Fixer
<?php
$finder = PhpCsFixer\Finder::create()
->notPath('bootstrap/cache')
->notPath('storage')
->notPath('vendor')
->in(__DIR__)
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
@innocenzi
innocenzi / sort.js
Created November 4, 2020 19:05
Sort Google search result per domain
const priority = ['mozilla.org'];
const blocklist = ['w3schools'];
const resultNode = document.getElementById('rso');
// Sort results
const sorted = [...resultNode.children]
.filter((child) => {
const href = child.querySelectorAll('a')?.[0]?.href;
@innocenzi
innocenzi / test.ts
Last active April 15, 2021 13:58
TypeScript or JavaScript?
// If this code is transpiled by the TypeScript compiler, it will echo "You are using TypeScript"
// If this code is ran as-is, it will echo "You are using JavaScript"
console.log(new Set<String>('1') ? 'You are using TypeScript' : 'You are using JavaScript')
// This is actually valid JavaScript code: properly formatted, it looks like that:
// (new Set) < (String) > ('1')
// In TypeScript, the angle brackets after Set are interpreted as generic types, which is why the result is different.
@innocenzi
innocenzi / vite.config.ts
Created August 4, 2021 12:45
vite-hmr-error
import { defineConfig, Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
// TODO: should be taken from environment
const certificates = {
key: 'D:\\Programmes\\Laragon\\etc\\ssl\\laragon.key',
crt: 'D:\\Programmes\\Laragon\\etc\\ssl\\laragon.crt',
}
export default defineConfig(({ command }) => ({
import path from 'path'
import vue from '@vitejs/plugin-vue'
import icons from 'vite-plugin-svg-icons'
import inspect from 'vite-plugin-inspect'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import createDebugger from 'debug'
import { defineConfig } from 'laravel-vite'
export default defineConfig()
@innocenzi
innocenzi / GenerateI18n.php
Last active July 18, 2022 18:18
VITL translations
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
/**
* Generates a JSON file with all translations.
@innocenzi
innocenzi / README.md
Last active November 21, 2022 13:41
Vite + Inertia SSR

package.json:

{
  "scripts": {
    "dev": "vite",
    "dev:server": "node public/build/server/server.js",
    "build": "vite build",
    "build:server": "vite build --outDir ./public/build/server --ssr ./resources/scripts/inertia/server.ts"
  }
}
import { Plugin } from 'vite'
const PLUGIN_NAME = 'vite:inertia:layout'
const TEMPLATE_LAYOUT_REGEX = /<template +layout(?: *= *['"](?:(?:(\w+):)?(\w+))['"] *)?>/
export default (layouts: string = '@/views/layouts/'): Plugin => ({
name: PLUGIN_NAME,
transform: (code: string) => {
if (!TEMPLATE_LAYOUT_REGEX.test(code)) {
return