Skip to content

Instantly share code, notes, and snippets.

Avatar
🌍
xaviesteve.com

Xavi Esteve luckyshot

🌍
xaviesteve.com
View GitHub Profile
@luckyshot
luckyshot / gist:4770306
Created Feb 12, 2013
Affiliate link tracking in 60 seconds (jQuery)
View gist:4770306
jQuery('a[href*=".amazon."]').click(function(){
_gaq.push(['_trackPageview', '/aff/'.jQuery(this).html()]);
});
@luckyshot
luckyshot / toc.css
Last active Dec 12, 2015
Create table of contents from headings (jQuery)
View toc.css
#toc li {
font-size: 80%;
line-height: 1;
}
#toc .h2 {
font-size: 90%;
}
#toc .h3 {
font-size: 70%;
margin-left: 1em;
@luckyshot
luckyshot / gist:4770325
Created Feb 12, 2013
Add 'first' CSS class to the first paragraph found that doesn't contain an image (jQuery)
View gist:4770325
// Add 'first' class to intro text in #post-content container
$('#post-content>p:not(:has(img))').eq(0).addClass('first');
@luckyshot
luckyshot / gist:4770332
Created Feb 12, 2013
Load PrettyPrint plugin only if needed
View gist:4770332
// Load Prettyprint only if needed
if ($('.content pre').length > 0) {
$('.content pre').addClass('prettyprint');
$('head').append('<link href="/prettify.css" type="text/css" rel="stylesheet" /><script type="text/javascript" src="prettify.js"></script>');
prettyPrint();
}
@luckyshot
luckyshot / gist:4770337
Last active Dec 12, 2015
Add target blank and track in Google Analytics to outgoing links
View gist:4770337
// Add target blank and track outgoing links in Google Analytics
// Method 1 (recommended): Event delegation. Track as Event.
// 'click'
// element and class names (i.e. a.button)
// href value clicked
$('body').on('click', function( e ) {
var target = $(e.target);
if ( target.tag == 'A' )
{
@luckyshot
luckyshot / gist:4987211
Last active Dec 13, 2015
HTML Elements for theme testing Source: http://wordpress.com
View gist:4987211
<p>Below is just about every <abbr title="HyperText Markup Language">HTML</abbr> element you might want to use in your blog posts. Check the source code to see the many embedded elements within paragraphs.</p>
<hr />
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
@luckyshot
luckyshot / gist:4995633
Last active Dec 13, 2015
YouTube - Embed video with autoplay and no controls
View gist:4995633
<!-- Deprecated -->
<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/GUL8B3CPmmc&autoplay=1&controls=0&rel=0&showinfo=0&iv_load_policy=3&theme=light&modestbranding=1" width="601" height="338" id="player" style="visibility: visible;"></object>
<!-- New -->
<iframe width="560" height="315" src="https://www.youtube.com/embed/FV7wx01BGQk?controls=2&modestbranding=1&rel=0&showinfo=0&hl={{ config.lang }}" frameborder="0" allowfullscreen></iframe>
<!--
Documentation: https://developers.google.com/youtube/player_parameters
@luckyshot
luckyshot / gist:5005111
Created Feb 21, 2013
Google Analytics - Make full screen
View gist:5005111
document.getElementById('ID-headerPanel').style.display='none';
document.getElementById('ID-headerTabPanel').style.display='none';
document.getElementsByClassName('uI')[0].style.marginTop=0;
document.getElementById('ID-navToggle').click();
if (document.getElementsByClassName('ACTION-remove')[0]) {document.getElementsByClassName('ACTION-remove')[0].click();}
document.getElementById('ID-reportHeader-toolbarSection').style.display='none';
document.getElementById('ID-reportHeader-titleSection').style.display='none';
@luckyshot
luckyshot / lemon_mysql.php
Last active Oct 10, 2019 — forked from AngeloR/lemon_mysql.php
A tiny function to interact with a MySQL database, can be used as a standalone PHP function or inside Limonade-php framework. Returns data in a multi-dimensional associative array. When working with Limonade-php a full-fledged MySQL wrapper seems like overkill. This method instead accepts any mysql statement and if it works returns either the re…
View lemon_mysql.php
<?php
/**
* A quick little function to interact with a MySQL database.
* Updated by Xavi Esteve to use mysqli, original by AngeloR (https://gist.github.com/AngeloR/919695)
*
* When working with Limonade-php a full-fledged MySQL wrapper seems like
* overkill. This method instead accepts any mysql statement and if it works
* returns either the result or the number of rows affected. If neither worked,
* then it returns false
*
@luckyshot
luckyshot / is-touch.js
Last active Dec 14, 2015
Detect if is a touch device
View is-touch.js
/**
* TOUCH DEVICE
* Detects touch devices
* Usage: if (is_touch_device) { yes! }
*/
var is_touch_device = 'ontouchstart' in document.documentElement;