Skip to content

Instantly share code, notes, and snippets.

View gfcarvalho's full-sized avatar

Gustavo Carvalho gfcarvalho

View GitHub Profile

Zip excluding specific directories

Exclude .git file and node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/\*

Exclude .git file and files in node_modules directory, but keep node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/**\*
@gfcarvalho
gfcarvalho / WC_Variable_Product_Price_Range
Created April 18, 2019 01:51 — forked from maion11/WC_Variable_Product_Price_Range
Changing WooCommerce Variable Products Price Range
function wc_varb_price_range( $wcv_price, $product ) {
$prefix = sprintf('%s: ', __('From', 'wcvp_range'));
$wcv_reg_min_price = $product->get_variation_regular_price( 'min', true );
$wcv_min_sale_price = $product->get_variation_sale_price( 'min', true );
$wcv_max_price = $product->get_variation_price( 'max', true );
$wcv_min_price = $product->get_variation_price( 'min', true );
$wcv_price = ( $wcv_min_sale_price == $wcv_reg_min_price ) ?
@gfcarvalho
gfcarvalho / external_database.php
Created February 26, 2019 13:36 — forked from MrSaints/external_database.php
A custom database class to demonstrate how WordPress' wpdb class can be instantiated and extended to allow you to connect to another / an external or secondary database. The global $wpdb object is only capable of communicating with the WordPress database. Refer to http://codex.wordpress.org/Class_Reference/wpdb for more information.
<?php
/*
The MIT License (MIT)
Copyright © 2014 Ian Lai
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
/**
* Converts an image to
* a base64 string.
*
* If you want to use the
* outputFormat or quality param
* I strongly recommend you read the docs
* @ mozilla for `canvas.toDataURL()`
*
* @param {String} url
// relies on Date.now() which has been supported everywhere modern for years.
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values
// if you want values similar to what you'd get with real perf.now, place this towards the head of the page
// but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed
(function(){
// prepare base perf object
(function(w){
var perfNow;
var perfNowNames = ['now', 'webkitNow', 'msNow', 'mozNow'];
if(!!w['performance']) for(var i = 0; i < perfNowNames.length; ++i)
{
var n = perfNowNames[i];
if(!!w['performance'][n])
{
perfNow = function(){return w['performance'][n]()};
break;
@gfcarvalho
gfcarvalho / rAF.js
Created March 12, 2014 03:49 — forked from paulirish/rAF.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];