Skip to content

Instantly share code, notes, and snippets.

@diegosomar
diegosomar / wp-change-uploads-filename.php
Last active October 19, 2023 12:53
Change filename for Wordpress uploads
<?php
/**
* Change filename for uploads
*
* @param string $file
*/
add_filter( 'wp_handle_upload_prefilter', function($file){
$hash1 = sha1(mt_rand(10000000,99999999));
$hash2 = substr(md5(rand()), 0, 7);
<?php
$key = '###############';
$exp = ( new DateTime( "now" ) )->getTimestamp() + 120;
$header = [
'typ' => 'JWT',
'alg' => 'HS256'
];
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'}
/**
* 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 March 18, 2020 14:10
Enable Firefox compatibility to link[rel="preload"]
/**
* 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' );