Skip to content

Instantly share code, notes, and snippets.

View devnix's full-sized avatar
🐢

Pablo Largo Mohedano devnix

🐢
View GitHub Profile
@devnix
devnix / batman.js
Created October 2, 2014 18:39
Gotham needs a hero...
var string = "abc";
var number = string++;
number = number.toString();
var output = '';
var i = 0;
while (i <= 16) {
output = output + number;
i++;
}
@devnix
devnix / media-queries.css
Last active August 29, 2015 14:19
Bootstrap 3 CSS media queries
/* Reference: http://goo.gl/6ise9j */
/* col-xs */
@media(max-width:767px) {
}
/* col-sm */
@media(min-width:768px) {
@devnix
devnix / README.md
Last active August 29, 2015 14:20
Wordpress 4.2.1 hotfix (put this file inside wp-includes)

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 / index.js
Last active July 20, 2016 21:16
Javascript strict mode
(function() {
'use strict';
// Your code
})();
@devnix
devnix / colormeter.php
Last active May 16, 2020 00:26 — 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
<?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 / prestashop-cart.php
Created November 30, 2016 10:10
Render the Prestashop's blockcart module in Wordpress (or any external script)
<?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 / OptimizedEvent.js
Last active December 13, 2016 16:02
Snippet for easily using requestAnimationFrame with browser events
/**
* @constructor
*/
function OptimizedEvent() {
this.callbacks = [];
this.running = false;
}
@devnix
devnix / Common.js
Created February 7, 2017 17:24
CommonJS DOM-based Routing
(function() {
'use strict'
// Constructor
function Common() {
// Example of calling to a private method from the constructor
_foo();
}
@devnix
devnix / _pagination.html.twig
Last active May 29, 2019 15:37 — forked from maxpou/_pagination.html.twig
Example of pagination with 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 / handling-optional-input-fields-with-type-safe-abstractions.md
Created March 17, 2023 12:06 — forked from Ocramius/handling-optional-input-fields-with-type-safe-abstractions.md
Handling optional input parameters in PHP with `vimeo/psalm` and `azjezz/psl`

Handling optional input parameters in PHP with vimeo/psalm and azjezz/psl

I had an interesting use-case with a customer for which I provide consulting services: they needed multiple fields to be marked as "optional".

Example: updating a user

We will take a CRUD-ish example, for the sake of simplicity.

For example, in the following scenario, does a null $description mean "remove the description",