Skip to content

Instantly share code, notes, and snippets.

Avatar

Josantonius Josantonius

View GitHub Profile
@Josantonius
Josantonius / calculate-2x1-promotions.php
Created Nov 25, 2017
Calculate price for 2x1 promotions with PHP
View calculate-2x1-promotions.php
$price = 100;
$products = 9;
echo $price * $products/2 + ($products&1 ? $price/2 : 0); // 500
@Josantonius
Josantonius / calculate-2x1-promotions.php
Created Nov 25, 2017
Calculate price for 2x1 promotions with PHP
View calculate-2x1-promotions.php
$price = 100;
$products = 9;
echo $price * $products/2 + ($products&1 ? $price/2 : 0); // 500
@Josantonius
Josantonius / custom-post-link-category.php
Created Nov 21, 2017
Only first child category from WordPress permalinks.
View custom-post-link-category.php
function only_first_child_category_from_wp_permalinks($cat, $cats) {
foreach ($cats as $category) {
if ($category->parent !== 0) {
$category->parent = 0;
return $category;
}
}
return $cat;
}
add_filter('post_link_category', 'only_first_child_category_from_wp_permalinks', 8, 2);
@Josantonius
Josantonius / languageCodes.json
Last active Sep 2, 2020
List of 217 language codes: ISO 639-1
View languageCodes.json
{
"_comments": {
"_title": "List of 217 language codes: ISO 639-1.",
"_author": "Josantonius - hello@josantonius.com",
"_copyright": "Copyright (c) 2016 - 2017",
"_license": "http://opensource.org/licenses/MIT - The MIT License (MIT)",
"_link": "http://github.com/josantonius/PHP-LanguageCode",
"_since": "1.0.0",
"_comment": "Compiled from https://wikipedia.org/wiki/List_of_ISO_639-1_codes"
},
@Josantonius
Josantonius / http-status-code.json
Created Oct 30, 2017
Full list of HTTP status codes (Español | English)
View http-status-code.json
{
"_comments": {
"_title": "Full list of HTTP status codes",
"_author": "Josantonius - hello@josantonius.com",
"_copyright": "Copyright (c) 2016 - 2017",
"_license": "http://opensource.org/licenses/MIT - The MIT License (MIT)",
"_link": "http://github.com/josantonius/PHP-HTTPStatusCode",
"_since": "1.0.0",
"_comment": "Compiled from wikipedia.org/wiki/List_of_HTTP_status_codes"
},
@Josantonius
Josantonius / get-methods.sh
Last active Sep 27, 2017
BASH - Get methods from PHP classes
View get-methods.sh
/**
* Get methods from PHP classes. (https://asciinema.org/a/139944)
*
* @author Josantonius - hello@josantonius.com
* @copyright Copyright (c) 2017
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
*
* $ sudo nano ~/.bashrc # Add function
* $ . ~/.bashrc
* $ get-methods filename.php
@Josantonius
Josantonius / phantom.js
Last active Sep 24, 2017
PhantomJS - Get web content from url
View phantom.js
/**
* Get web content from url. (https://asciinema.org/a/139259)
*
* $ sudo apt install phantomjs
*
* $ phantomjs phantom.js
*/
var page = require('webpage').create(),
system = require('system'),
args = system.args,
@Josantonius
Josantonius / gulpfile.js
Last active Sep 25, 2017
Gulp configuration file
View gulpfile.js
/**
* Gulp configuration file for Extensions For Grifus plugin.
*
* $ npm init && npm install --save-dev gulp gulp-concat gulp-uglify gulp-sass gulp-plumber gulp-rename gulp-clean-css gulp-notify gulp-sourcemaps gulp-autoprefixer
*
* $ touch gulpfile.js
*
* $ gulp
*/
@Josantonius
Josantonius / IPv4-to-CIDR-and-CIDR-to-IPv4.php
Last active Sep 23, 2017
IPv4 to CIDR and CIDR to IPv4
View IPv4-to-CIDR-and-CIDR-to-IPv4.php
/**
* IPv4 to CIDR.
*
* @author Phptuts
* @copyright Copyright (c) 2012
* @link http://tutorialspots.com/
*
* @return array
*/
function ip2cidr($fromIp, $ToIp) {
You can’t perform that action at this time.