Skip to content

Instantly share code, notes, and snippets.

View imelgrat's full-sized avatar

Iván Melgrati imelgrat

View GitHub Profile
@imelgrat
imelgrat / modifier.calculate_age.php
Created April 1, 2019 18:43
Smarty Modifier - Calculate age from birth date
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
* Place this file inside the smarty/libs/plugins directory and invoke as any other modifier (e.g. {$birth_date|calculate_age} )
*/
/**
@imelgrat
imelgrat / limit-gist-box-size.css
Last active February 15, 2019 18:12
Limit width and height of embedded gists.
/**
* Limit embedded gist window size. Show scrollbars when necessary.
* @link https://imelgrat.me/
*/
/* Limit width. Show scrollbars when exceeding width */
.gist {
max-width:350px;
overflow:auto;
}
@imelgrat
imelgrat / bulk-upload.php
Last active February 15, 2019 17:52
Register a WordPress custom post type and perform a bulk-upload from a MySQL database
<?php
/* Create custom posts in WordPress taking data from a MySQL database.
@link https://imelgrat.me/wordpress/bulk-upload-custom-posts-wordpress/
Load WordPress functions and plug-ins. Put correct path for this file.
This example assumes you're using it from a sub-folder of WordPress.
If you run it from somewhere else, adjust path to wp-load.php accordingly.
*/
require_once('../wp-load.php');
$database['hostname'] = 'SERVER';
@imelgrat
imelgrat / bootstrap-tab-collapse.css
Created February 15, 2019 16:35
Integrate Bootstrap's Tabs and Accordions into a single component
.panel-title {
cursor:pointer;
}
h4.tab-title
{
font-family: "avenirheavy", Helvetica, Arial, "sans-serif";
font-weight: normal;
font-size: 22px;
color: #ffffff;
}
@imelgrat
imelgrat / admob-banner.js
Last active February 15, 2019 15:43
Configure AdMob ads on a Phonegap application
/**
* Create an AdMob banner ad using AdMob Plugin Pro (in Phohegap)
*
* @link https://imelgrat.me/phonegap/admob-effective-monetize-cordova-app/
*
* @link https://goo.gl/yTCAea AdMob Plugin Pro
*
*/
function createSelectedBanner()
{
@imelgrat
imelgrat / find-feeds.php
Created February 15, 2019 14:52
Use an open source PHP class to fetch articles from RSS, ATOM and OPML feeds
<?php
/**
* Retrieve and parse OPML (Outline Processor Markup Language) Parser Class.
* Extracts the properties of content from OPML files using a PHP class
*
* @link https://github.com/imelgrat/opml-parser
*
* @link https://imelgrat.me/php/find-atom-opml-rss-feeds/
*/
require_once('opml-parser.php');
@imelgrat
imelgrat / 404.php
Created February 15, 2019 12:39
Redirect WordPress dead-links to the homepage
<?php
/**
* Redirect missing WordPress URLs .
*
* If you want to redirect the browser every time a page can’t be found while avoiding SEO impact, you can open your 404.php file
* in your theme’s folder and paste this at the top. If it doesn’t exist, then create a blank 404.php file.
*
* @link https://imelgrat.me/wordpress/dead-links-redirect-avoid-seo-impact/
*/
header("HTTP/1.1 301 Moved Permanently");
@imelgrat
imelgrat / convert-date-format.php
Created February 15, 2019 12:33
Date formatting: How to Detect and convert date formats in PHP
<?php
/**
* Convert date format.
*
* Use regular expressions to detect dates and convert the detected dates into a MySQL-compatible DATE format.
*
* @link https://imelgrat.me/php/date-formatting-detect-convert/
*/
function convert_date_format($old_date = '')
{
@imelgrat
imelgrat / collapsible-sets.js
Last active February 15, 2019 12:26
jQuery Mobile collapsible sets. Move content to the top
/**
* Attach a handler to collapsible sets.
*
* Attach a handler to every collapsible (filtered by their jQM’s role) so that,
* every time a collapsible’s header is tapped, it will scroll to the top of the page (both header and content)..
*
* @link https://imelgrat.me/javascript/collapsible-scroll-jquery-mobile/
*/
$(document).on('pagebeforeshow', function()
{
@imelgrat
imelgrat / debouce-resize.js
Created February 15, 2019 12:19
Debouncing JavaScript events to prevent jerky action
/**
* Debounce window-resize events
*
* Debouncing JavaScript events to prevent jerky action during UI changes.
*
* @link https://imelgrat.me/javascript/debouncing-javascript-events/
*/
$(window).bind('resize', function(e)
{
window.resizeEvt;