Skip to content

Instantly share code, notes, and snippets.

View generate-jwt.php
<?php
$key = '###############';
$exp = ( new DateTime( "now" ) )->getTimestamp() + 120;
$header = [
'typ' => 'JWT',
'alg' => 'HS256'
];
View init.vim
call plug#begin('~/.vim/plugged')
Plug 'jiangmiao/auto-pairs'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'tpope/vim-surround'
Plug 'kien/ctrlp.vim'
Plug 'tpope/vim-commentary'
Plug 'joshdick/onedark.vim'
Plug 'pangloss/vim-javascript'
Plug 'othree/yajs.vim', {'for': 'javascript'}
View lazy-load.js
/**
* Manage lazy load for entire site
* @link https://developers.google.com/web/fundamentals/performance/lazy-loading-guidance/images-and-video
*/
document.addEventListener("DOMContentLoaded", function() {
let lazyImages = [].slice.call(document.querySelectorAll("img.lazyload"));
let lazyBackgrounds = [].slice.call(document.querySelectorAll(".lazy-background"));
let lazyIframes = [].slice.call(document.querySelectorAll('iframe[data-src]'));
if ("IntersectionObserver" in window) {
@diegosomar
diegosomar / polyfill-firefox-preload.js
Created Mar 18, 2020
Enable Firefox compatibility to link[rel="preload"]
View polyfill-firefox-preload.js
/**
* Firefox has no support to link[rel="preload"]
* This is a workaround to async load non-critical CSS
*/
if ( navigator.userAgent.search("Firefox") > -1 ) {
const link_elements = document.querySelectorAll('link[rel="preload"]');
if ( link_elements.length ){
link_elements.forEach( link => {
if (link.getAttribute('as') == 'style') {
link.setAttribute( 'rel', 'stylesheet' );
@diegosomar
diegosomar / wp-change-uploads-filename.php
Last active Jul 16, 2020
Change filename for Wordpress uploads
View wp-change-uploads-filename.php
<?php
/**
* Change filename for uploads
*
* @param string $filename
* @return string
*/
add_filter( 'sanitize_file_name', function ( $filename ) {