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 / trimtext.php
Last active August 29, 2015 13:55
Trim Text nicely
/**
* Trimtext
* This function will trim text without cutting it in
* the middle of the word and adding … if longer
*/
public function trimText($text, $length) {
$words = explode(" ", $text);
$text = "";
foreach ($words as $word) {
if (strlen($text." ".$word) <= $length) {
@luckyshot
luckyshot / niceenum.php
Last active August 29, 2015 13:57
Enumerate list with commas and the last one with "and"
<?php
$array = (1,2,3);
$last = array_pop($array);
echo strtolower(implode(', ', $array)." and ".$last);
@luckyshot
luckyshot / index.html
Last active August 29, 2015 13:57
Bootstrap starter HTML page including CSS and JS from CDNs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
@luckyshot
luckyshot / timeago.js
Last active August 29, 2015 14:07
Nice relative time (ago) (multilanguage)
/*
Returns a MySQL date as: '2 days ago', 'right now', '14 hours ago'...
If date is older than 7 days then it displays it as 'September 1'
// Example
console.log( nice_time('2014-09-01 13:12:01') );
// Spanish config
var options = {
@luckyshot
luckyshot / gender.php
Created January 28, 2015 14:40
Detects the gender (male or female) of a name
<?php
/**
* returns positive if male, negative if female
*/
function gender( $s )
{
$gender = 0; // female - , + male
$letters = array(
@luckyshot
luckyshot / responsive.css
Created January 30, 2015 12:14
CSS Responsive code example
@media all and (max-width: 300px) {
}
@luckyshot
luckyshot / style.css
Created May 28, 2015 21:02
Readability CSS
html {
color: #444;
background: #FDFDFF;
font-family: 'Helvetica Neue', HelveticaNeue, sans-serif;
font-size: 16px;
line-height: 1.618em;
margin: 0 auto;
max-width: 50em;
text-rendering: optimizeLegibility;
}
@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');