Skip to content

Instantly share code, notes, and snippets.

View luckyshot's full-sized avatar
🌍
xaviesteve.com

Xavi Esteve luckyshot

🌍
xaviesteve.com
View GitHub Profile
@luckyshot
luckyshot / gist:4770306
Created February 12, 2013 14:43
Affiliate link tracking in 60 seconds (jQuery)
jQuery('a[href*=".amazon."]').click(function(){
_gaq.push(['_trackPageview', '/aff/'.jQuery(this).html()]);
});
@luckyshot
luckyshot / toc.css
Last active December 12, 2015 12:09
Create table of contents from headings (jQuery)
#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 February 12, 2013 14:45
Add 'first' CSS class to the first paragraph found that doesn't contain an image (jQuery)
// 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 February 12, 2013 14:47
Load PrettyPrint plugin only if needed
// 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 December 12, 2015 12:09
Add target blank and track in Google Analytics to outgoing links
// 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 December 13, 2015 22:48
HTML Elements for theme testing Source: http://wordpress.com
<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 December 13, 2015 23:59
YouTube - Embed video with autoplay and no controls
<!-- 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 February 21, 2013 14:36
Google Analytics - Make full screen
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 October 10, 2019 18:29 — 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…
<?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 December 14, 2015 16:29
Detect if is a touch device
/**
* TOUCH DEVICE
* Detects touch devices
* Usage: if (is_touch_device) { yes! }
*/
var is_touch_device = 'ontouchstart' in document.documentElement;