Skip to content

Instantly share code, notes, and snippets.

View masiorama's full-sized avatar
🏠
Working from home

masiorama

🏠
Working from home
View GitHub Profile
@masiorama
masiorama / functions.php
Created January 13, 2018 11:36
Wordpress Woocommerce WCDPD_Product_Pricing customize output
function get_discounted_price_custom( $product = null ) {
if ( $product == null ) {
return false;
}
if ( $product->is_type( 'variable' ) ) {
$default_attributes = $product->get_variation_default_attributes();
$variation_id = iconic_find_matching_product_variation( $product, $default_attributes );
$product = wc_get_product( $variation_id );
@masiorama
masiorama / craft-cms-entries-by-category-group.twig
Created February 9, 2016 17:21
Craft CMS: Getting entries grouped by category in order of the category type drag & drop order.
{# Get the categories related to my "entrySection" entries in structure order #}
{% set entries = craft.entries.section('entrySection') %}
{% set relatedCats = craft.categories.relatedTo(entries) %}
{# Loop the categories #}
{% for category in relatedCats %}
{{ category.title }}
{# Get and loop through entries related to this cat #}
@masiorama
masiorama / gist:a8e841a4f325818dc022
Created May 17, 2015 09:38
rsync backup to user folder excluding itself
#from root dir
rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/home/usamba","/lost+found"} /* /home/usamba/backup_folder
@masiorama
masiorama / Yii: extend-inherit child model's methods
Last active August 29, 2015 14:08
Yii: extend child model with parent's methods like rules, attributeLabel, etc... example
function attributeLabels() {
$labels = array(
'placeOfBirth' => 'Place Of Birth',
'notes' => 'Notes',
'status' => 'Status',
'studentID' => 'Student',
'entryYear' => 'Entry Year',
);
return array_merge($labels, parent::attributeLabels());
@masiorama
masiorama / newappyii.bat
Created July 23, 2013 15:32
CMD: Yii create app script
::set PATH=%PATH%;C:\wamp\bin\php\php5.3.13 ::not necessary if php is set on environment variables
::set FRAMEWORKS=C:\frameworks ::not necessary if frameworks is set on environment variables
@echo off
setlocal enabledelayedexpansion
set /a counter=0
echo Please enter your choice:
for /f %%i in ('dir /b %FRAMEWORKS%"\yii*"') do (
set /a counter+=1
set option=!counter! %%i
@masiorama
masiorama / gist:6052197
Created July 22, 2013 08:21
PHP: Drupal 6 Rules unpublish date/email notification
/* Drupal 6 Rules
* Unpublish of content with Date field (identity check date-based)
* Send auto email with Datetime field (identity check date-based)
*/
//removes all the headers, this comment included
array (
'rules' =>
array (
'rules_send_auto_email' =>
@masiorama
masiorama / gist:5928284
Created July 4, 2013 14:32
Drupal workflow rules example
/**
* DRUPAL
* Use of the rules
* Example of unpublishing a node on a date with rules scheduler
*/
Create the Rule set first...then the Rule.
at /admin/config/workflow/rules/components/add
Create a ruleset (name it "Unpublish Content")
@masiorama
masiorama / gist:5126205
Created March 9, 2013 23:11
Js: track event wrapper for google analytics
// Add in Google Analytics tracking; just in case ga.js isn't correctly loaded
var track = function(category, name, value) {
if (window._gaq) {
window._gaq.push(["_trackEvent", category, name, value]);
}
};
track("Source", "Visit", this.href);
@masiorama
masiorama / gist:5126058
Created March 9, 2013 22:32 — forked from donovan-duplessis/gist:3245252
HTML: load js from CDN with local fallback
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write("<script src='js/libs/jquery-1.7.2.min.js'>\x3C/script>")</script>
@masiorama
masiorama / gist:5037840
Created February 26, 2013 11:34
PHP: Yii Netbeans completion feature
#Tools->Options->Miscellaneous->Files->Ignored Files Pattern
^(yiilite\.php|CVS|SCCS.....
#Create new php file in your project /protected directory named yii.php with this content:
class Yii extends YiiBase
{
/**
* Returns the application singleton or null if the singleton has not been created yet.
* @return CWebApplication the application singleton, null if the singleton has not been created yet.
*/