Skip to content

Instantly share code, notes, and snippets.

View displaynone's full-sized avatar

Luis Sacristán displaynone

View GitHub Profile
@displaynone
displaynone / change_content_svg.js
Last active February 11, 2017 22:39
Modify SVG into CSS content for inline CSS
// Suppose we have a CSS element with a SVG into the content property
// .class:before {
// content: url('imagen.svg');
// }
//
// This script replaces the SVG in the CSS for the inline CSS so you can access via JS or CSS later
jQuery(document).ready(function() {
var replaceWithSVG = function(selector, url) {
jQuery('').appendTo('head');
// Gets the SVG file
@displaynone
displaynone / wordpress_geo_searchs.sql
Created February 15, 2017 18:49
Geolocalization for WordPress queries
CREATE PROCEDURE geodist (IN mylat decimal(18,12), IN mylon decimal(18,12), IN dist float)
BEGIN
declare lon1 float;
declare lon2 float;
declare lat1 float;
declare lat2 float;
set lon1 = mylon-dist/abs(cos(radians(mylat))*69);
set lon2 = mylon+dist/abs(cos(radians(mylat))*69);
set lat1 = mylat-(dist/69);
set lat2 = mylat+(dist/69);
@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>';
});
// Not valid for IE8 or older (I don't mind)
document.addEventListener("DOMContentLoaded", () => {
// Some code
});
var parent = document.getElementById('myid').parentNode
var elem = document.getElementById('myid');
var w = window.getComputedStyle(elem).width;
@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)
@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 / 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 / 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);
}