Skip to content

Instantly share code, notes, and snippets.

View tzkmx's full-sized avatar
🎉
estrenando repositorios privados

Jesus Franco tzkmx

🎉
estrenando repositorios privados
View GitHub Profile
@tzkmx
tzkmx / validate_amp_collection.bat
Created February 27, 2017 20:20
Windows batch file to validate list of URLs with AMP errors
@ECHO OFF
FOR /F "usebackq tokens=1 delims=," %%A IN (`grep -v "URL" elsemanario-com__etiqueta_HTML_prohibida.csv`) DO (
FOR /F "usebackq" %%B IN (`amphtml-validator --format=json %%A`) DO (
echo %%B|findstr /C:"PASS" >NUL 2>&1
IF not errorlevel 1 (
echo %%A | tee -a valid_urls.txt
) ELSE (
echo %%A | tee -a nonvalid_urls.txt
)
)
@tzkmx
tzkmx / path_opcache_invalidation.php
Created July 4, 2017 16:44
OpCache path invalidation script
<?php
// Untested, retrieved and reformatted from:
// https://ihaveabackup.net/article/invalidating-the-opcache-in-php-5-5#comment-19
if (!function_exists('opcache_get_configuration')) {
die('OPCache is not installed/running');
}
$data = opcache_get_status(); $expired = array();
@tzkmx
tzkmx / lazyload-fixorder-enqueuing.php
Created July 21, 2017 16:22
Force footer registration of scripts for lazyload when assetsminify plugin present
<?php
/** After registering scripts, A3 Lazy Load plugin fires action
* we use to fix registration, adding data to load it
* in footer, because assetsminify mangles the order of files */
add_action('after_a3_lazy_load_xt_script', function() {
$plugins = get_option('active_plugins');
if( in_array('assetsminify/plugin.php', $plugins) ) {
$scripts = wp_scripts();
foreach($scripts->registered as $handle => $dep) {
if( false !== strpos( $handle, 'lazyloadxt' ) ) {
@tzkmx
tzkmx / author_profile_ogimage.php
Created July 21, 2017 23:07
Complex query to make the og:image set by Yoast SEO,a custom profile thumb_id set in a custom post type
<?php
add_filter('option_wpseo_social', function( $opt ) {
if(is_author() ) {
$userid = get_queried_object_id();
$profile_thumb = get_profile_og_image_id( $userid );
if( $profile_thumb ) {
$timb = new \TimberImage( $profile_thumb );
$img_profile = \Timber\ImageHelper::resize($timb->src, 200, 200);
$opt['og_default_image'] = $img_profile;
@tzkmx
tzkmx / custom-waypoints.js
Last active August 5, 2017 17:04
Waypoints to detect element just coming to viewport
(function($, w){
$(document).ready(function(){
w.waypoints = Array();
function printCoordinates(direction, waypoint) {
return function(scrollDirection) {
if(scrollDirection === direction) {
var c = waypoint.element.getBoundingClientRect();
console.log(i, d, 'top ' + c.top, 'bottom ' + c.bottom);
@tzkmx
tzkmx / .babelrc
Last active August 14, 2017 20:34 — forked from developit/testing-stateful-components.js
test stateful components with chai
{
"presets": ["env"],
"plugins": [
["transform-react-jsx", { "pragma":"h" }]
]
}
@tzkmx
tzkmx / a_scraper_script.php
Last active August 18, 2017 23:36
GraphQL Query to get "Hoy no Circula" from SEMOVI
<?php
require __DIR__ . '/vendor/autoload.php';
function strip_of($subject, $to_strip) {
$search = [ $to_strip, ' ', "\t", "\n" ];
return str_replace($search, ['','','',''], $subject);
}
use Goutte\Client;
@tzkmx
tzkmx / myserverhost.conf
Created October 9, 2017 20:16
Proxy and cache POST request queries to remote GraphQL server
upstream my_graphql_server {
server launchpad.example.host:443 ;
}
server {
listen 192.168.1.20:443 ssl http2;
server_name myserverhost.lan;
ssl_certificate /usr/local/certificates/cert-wCa2Ie;
@tzkmx
tzkmx / fix_fpm_pool.sh
Created October 10, 2017 05:30
SystemD Units to watch and fix PHP FPM pool definition files
#! /bin/bash
sed -i -e '/catch_workers_output/d; /pm.max_children = 5/s/.*/pm.max_children = 10\npm.max_requests = 50/;' $1
@tzkmx
tzkmx / fix_media_vhosts.sh
Created October 10, 2017 05:34
SystemD Units to watch and force aliases to server_name in NginX, disallowing Plesk bloat
#! /bin/bash
filename=/var/www/vhosts/system/$1/conf/nginx.conf
sed -i -e "/media[0-9]\.$1/d" $filename
for index in 4 3 2 1 ; do \
sed -i -e "s@server_name $1;@\0\n\tserver_name media$index.$1;@" $filename ;
done