Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢

Pablo Largo Mohedano devnix

🐢
View GitHub Profile
@devnix
devnix / _pagination.html.twig
Last active May 29, 2019 — forked from maxpou/_pagination.html.twig
Example of pagination with Twig
View _pagination.html.twig
{#
Parameters:
* total (int): number of pages
* current (int): current pages
* url (string): route name & query (string): route parameter
ex: list/page-5?q=myFilter (5 = page and query = myFilter)
* nearbyPagesLimit (int) optional: limit of pages around the current page
#}
{% macro pagination(total, current, url, nearbyPagesLimit = 4) %}
@devnix
devnix / Common.js
Created Feb 7, 2017
CommonJS DOM-based Routing
View Common.js
(function() {
'use strict'
// Constructor
function Common() {
// Example of calling to a private method from the constructor
_foo();
}
@devnix
devnix / OptimizedEvent.js
Last active Dec 13, 2016
Snippet for easily using requestAnimationFrame with browser events
View OptimizedEvent.js
/**
* @constructor
*/
function OptimizedEvent() {
this.callbacks = [];
this.running = false;
}
@devnix
devnix / prestashop-cart.php
Created Nov 30, 2016
Render the Prestashop's blockcart module in Wordpress (or any external script)
View prestashop-cart.php
<?php
// Prestashop's root folder, in my example Prestashop is installed in the root folder, and Wordpress is installed in /blog
define('PRESTASHOP_ROOT', ABSPATH.'..');
// Still don't know if necessary
// require PRESTASHOP_ROOT.'/config/settings.inc.php';
// require PRESTASHOP_ROOT.'/config/defines.inc.php';
@devnix
devnix / colormeter.php
Last active May 16, 2020 — forked from mailtruck/colormeter.js
Calculate difference in percentage between 2 hex colors. Port from Javascript to PHP. For calculating the perception difference, may would be better https://github.com/renasboy/php-color-difference
View colormeter.php
<?php
function color_meter($cwith, $ccolor) {
if (empty($cwith) || empty($ccolor)) return false;
$_cwith = ($cwith[0] === '#') ? substr($cwith, 1, 7) : $cwith;
$_ccolor = ($ccolor[0] === '#') ? substr($ccolor, 1, 7) : $ccolor;
$_r = intval(substr($_cwith, 0, 2), 16);
$_g = intval(substr($_cwith, 2, 2), 16);
@devnix
devnix / index.js
Last active Jul 20, 2016
Javascript strict mode
View index.js
(function() {
'use strict';
// Your code
})();
@devnix
devnix / README.md
Last active Aug 29, 2015
Wordpress 4.2.1 hotfix (put this file inside wp-includes)
View README.md

Wordpress 4.2.1 hotfix

Overwrite your bad ol' wp-includes/formatting.php with this file to avoid that annoying PHP warning. If you prefer to fix it yourself instead downloading a 4.3k php file (which is pretty logical), go to the line 4144 of your local Wordpress installation, and replace this:

if ( SCRIPT_DEBUG ) {

with this:

@devnix
devnix / media-queries.css
Last active Aug 29, 2015
Bootstrap 3 CSS media queries
View media-queries.css
/* Reference: http://goo.gl/6ise9j */
/* col-xs */
@media(max-width:767px) {
}
/* col-sm */
@media(min-width:768px) {
@devnix
devnix / batman.js
Created Oct 2, 2014
Gotham needs a hero...
View batman.js
var string = "abc";
var number = string++;
number = number.toString();
var output = '';
var i = 0;
while (i <= 16) {
output = output + number;
i++;
}