Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Guillermo de la Iglesia zguillez

🏠
Working from home
View GitHub Profile
@zguillez
zguillez / Debug.php
Created March 1, 2023 11:33
Display errors and warnings in PHP
View Debug.php
/**
* require_once __DIR__ . '/inc/debug.php';
* $debugger = new Debug(true);
*/
class Debug
{
public function __construct($debug)
{
if ($debug) {
ini_set('display_startup_errors', 1);
@zguillez
zguillez / cors.php
Created March 1, 2023 11:28
Allow cors in PHP
View cors.php
header("Content-Type: application/json;charset=utf-8");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Allow: POST, OPTIONS");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
die();
}
@zguillez
zguillez / wp-code-snippet-gtm
Created February 22, 2023 12:24
Add GTM in code snipped wordpress plugin
View wp-code-snippet-gtm
add_action( 'wp_head', function () { ?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
<?php } );
@zguillez
zguillez / dataLayer-event-variable
Created February 22, 2023 11:13
Get variable from dataLayer event
View dataLayer-event-variable
function() {
for (var i=0; i<dataLayer.length; i++) {
if (dataLayer[i][0]==='event' && dataLayer[i][1]==='view_item') {
return dataLayer[i][2].items[0].id;
}
}
}
@zguillez
zguillez / .zshrc
Created February 12, 2023 15:39
bash alias
View .zshrc
alias c="clear"
alias zls="clear; ls -lash"
alias zgit="clear; git log --oneline --all --graph; git branch -vva; git status"
alias zpull="git pull origin"
alias zcommit="git add --all; git commit -am"
alias zpush="git push origin"
alias zupdate="git add --all; git commit -am update; git push origin --tags"
alias zdocs="clear; cd $HOME/Documentos"
alias zdown="clear; cd $HOME/Downloads"
alias zrepos="clear; cd $HOME/Documentos/Repositorios"