Skip to content

Instantly share code, notes, and snippets.

View imelgrat's full-sized avatar

Iván Melgrati imelgrat

View GitHub Profile
@imelgrat
imelgrat / .htaccess
Last active August 23, 2017 19:42
Deny all access to Wordpress' wp-includes directory using .htaccess. Full article at: http://imelgrat.me/security/wordpress-htaccess-file-protect/
# Block wp-includes folder and files
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>
@imelgrat
imelgrat / prevent-jerky-resize.js
Last active August 23, 2017 19:53
Prevent jerky motion upon resizing browser window by waiting until window resizing stops (no external libraries). Full article at: http://imelgrat.me/javascript/debouncing-javascript-events/
$(window).bind('resize', function(e)
{
window.resizeEvt;
$(window).resize(function()
{
clearTimeout(window.resizeEvt);
window.resizeEvt = setTimeout(function()
{
if($(window).width() != previous_width)
{
@imelgrat
imelgrat / README.md
Last active August 23, 2017 19:55
Move content to the top in jQuery Mobile collapsible sets. Full article at: http://imelgrat.me/javascript/collapsible-scroll-jquery-mobile/

Move content to the top in jQuery Mobile collapsible sets

A simple way to make sure content in jQuery Mobile collapsible sets remains visible when expanding each section by bringing the section being opened to the top. This way, people have to scroll less, improving their user experience on the website.

A Pen by Iván Melgrati on CodePen.

License.

@imelgrat
imelgrat / convert-dates.php
Last active August 23, 2017 20:10
A PHP function to detect and convert dates from different formats into a MySQL-compatible format (YYYY-MM-DD). Full article at: http://imelgrat.me/php/date-formatting-detect-convert/
<?php
/**
* @author Ivan Ariel Melgrati
* @copyright 2015
*/
function convert_date_format($old_date = '')
{
$old_date = trim($old_date);
@imelgrat
imelgrat / redirect.php
Last active August 23, 2017 20:22
Redirecting WordPress to the homepage. Full article at: http://imelgrat.me/wordpress/dead-links-redirect-avoid-seo-impact/
<?php
// 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. If it doesn’t exist, then create a blank .php file. Paste the following code in there:
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . get_bloginfo('url'));
exit();
?>
@imelgrat
imelgrat / admob-intersitial.js
Last active August 23, 2017 21:39
JavaScript code to display an intersitial ad on Cordova Apps using AdMob Plugin Pro. Full articlle at: http://imelgrat.me/phonegap/admob-effective-monetize-cordova-app/
function prepareInterstitial()
{
AdMob.prepareInterstitial({ adId:admobid.interstitial, autoShow:true });
}
@imelgrat
imelgrat / createSelectedBanner.js
Last active August 23, 2017 21:39
Create an AdMob ad using AdMob Plugin Pro. Full articlle at: http://imelgrat.me/phonegap/admob-effective-monetize-cordova-app/
function createSelectedBanner()
{
AdMob.createBanner( { adId:admobid.banner,
bgColor: '#XXYYZZ', overlap:false,
adSize: 'SMART_BANNER',// Available sizes are SMART_BANNER, BANNER,MEDIUM_RECTANGLE,FULL_BANNER,LEADERBOARD and SKYSCRAPER
position:8 //1 => Top Left, 2 => Top Center, 3 => Top Right, 4 => Left, 5 => Center, 6 => Right, 7 => Bottom Left, 8 => Bottom Center, 9 => Bottom Right
@imelgrat
imelgrat / admob.js
Last active August 23, 2017 21:39
JavaScript code to configure Cordova's AdMob Plugin Pro. Full articlle at: http://imelgrat.me/phonegap/admob-effective-monetize-cordova-app/
// select the right Ad ID according to platform
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ){ // for android
admobid = {
banner: 'ca-app-pub-xxx/zzz', // or DFP format "/6253334/dfp_example_ad"
interstitial: 'ca-app-pub-xxx/kkk'
};
}
else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)){ // for ios
admobid = {
@imelgrat
imelgrat / plugins.properties
Last active August 24, 2017 02:49
Cordova configuration file with external repositories. Full article at: http://imelgrat.me/phonegap/apache-cordova-compile-faster-netbeans/
org.apache.cordova.device=https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
org.apache.cordova.network-information=https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
org.apache.cordova.geolocation=https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
org.apache.cordova.splashscreen=https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git
org.apache.cordova.file=https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
org.apache.cordova.dialogs=https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
org.apache.cordova.file-transfer=https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
@imelgrat
imelgrat / plugins.properties
Last active August 24, 2017 02:49
Cordova configuration file with local repositories. Full article at: http://imelgrat.me/phonegap/apache-cordova-compile-faster-netbeans/
org.apache.cordova.device=C:\\git-repos\\cordova-plugin-device
org.apache.cordova.network-information=C:\\git-repos\\cordova-plugin-network-information
org.apache.cordova.geolocation=C:\\git-repos\\cordova-plugin-geolocation
org.apache.cordova.splashscreen=C:\\git-repos\\cordova-plugin-splashscreen
org.apache.cordova.file=C:\\git-repos\\cordova-plugin-file
org.apache.cordova.file-transfer=C:\\git-repos\\cordova-plugin-file-transfer
org.apache.cordova.dialogs=C:\\git-repos\\cordova-plugin-dialogs