Skip to content

Instantly share code, notes, and snippets.

View displaynone's full-sized avatar

Luis Sacristán displaynone

View GitHub Profile
@displaynone
displaynone / video2gif.sh
Last active August 13, 2021 15:19
Convert video to GIF
$ more /usr/local/bin/video2gif.sh
#!/bin/bash
# https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/
echo "Video file: "
read video_file
echo "Video start position (HH:MM:SS): "
read start_seek
@displaynone
displaynone / error_log_color.php
Last active May 20, 2021 07:58
PHP error log color
<?php
// https://stackoverflow.com/a/13101631
$colorFormats = array(
// styles
// italic and blink may not work depending of your terminal
'bold' => "\033[1m%s\033[0m",
'dark' => "\033[2m%s\033[0m",
'italic' => "\033[3m%s\033[0m",
@displaynone
displaynone / picsum.php
Created March 23, 2020 11:03
Download 10 images from picsum.photos with different sizes
<?php
for ( $i = 0; $i<10; $i++) {
$width = rand(600, 1200);
$height = rand(600, 1200);
file_put_contents( uniqid(rand(), true) . '.jpg', file_get_contents( 'https://picsum.photos/'.$width.'/'.$height));
sleep(2);
}
@displaynone
displaynone / phpcs-git.sh
Created December 17, 2018 09:49
Run PHPCS in uncommit files
for i in $(git status -s | sed 's/^\s//' | cut -d " " -f2 | grep '.php'); do ./vendor/bin/phpcs "$i"; done
@displaynone
displaynone / attributes_regex.js
Created October 30, 2018 15:28
Matching attributes with quotes inside quoutes
//
const regex = /[\w_-]+=(['"])((?!\1).)+\1/gu;
`<div data-slogan="Don't do it" data-warning='Use double quotes (")'>`.match( regex)
@displaynone
displaynone / Find debug traces before git push
Last active June 5, 2018 07:35
Find error_log or console.log in files modified or added before git commit
grep 'error_log\|console' $(git status -s | sed 's/^\s//' | cut -d " " -f2)
var elem = document.getElementById('myid');
var w = window.getComputedStyle(elem).width;
var parent = document.getElementById('myid').parentNode
// Not valid for IE8 or older (I don't mind)
document.addEventListener("DOMContentLoaded", () => {
// Some code
});
@displaynone
displaynone / wrap.js
Last active March 11, 2017 11:03
jQuery wrap in Vanilla JS
// https://codepen.io/luissacristan/pen/vxmKoP
document.querySelectorAll( 'div' ).forEach( elem => {
elem.outerHTML = '<div>' + elem.outerHTML + '</div>';
});