Skip to content

Instantly share code, notes, and snippets.

View tubalmartin's full-sized avatar

Túbal Martín tubalmartin

  • Expedia Group
  • Madrid, SPAIN
  • 23:00 (UTC +02:00)
View GitHub Profile
@tubalmartin
tubalmartin / mobile_detector.php
Created January 3, 2012 15:06
Lightweight detector of mobile devices, OSs & browsers (PHP)
<?php
/*
* Lightweight detector of mobile devices, OSs & browsers
* Copyright 2012 Túbal Martín (email: tubalmartin@gmail.com)
* License: GPL2
*/
if ( ! function_exists('mobile_detector') )
{
@tubalmartin
tubalmartin / pubsub.md
Created February 13, 2012 18:56 — forked from addyosmani/pubsub.md
Four ways to do Pub/Sub with jQuery 1.7 and jQuery UI (in the future)

#Four Ways To Do Pub/Sub With jQuery 1.7 and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

@tubalmartin
tubalmartin / ms.js
Created March 8, 2012 00:25 — forked from rauchg/ms.md
Milliseconds conversion utility.
/**
# ms.js
No more painful `setTimeout(fn, 60 * 4 * 3 * 2 * 1 * Infinity * NaN * '☃')`.
ms('2d') // 172800000
ms('1.5h') // 5400000
ms('1h') // 3600000
ms('1m') // 60000
@tubalmartin
tubalmartin / wuffo-async-rewrite.html
Created March 10, 2012 16:02
Wufoo async snippet: optimized version
<div id="wufoo-z7w3m7">
Fill out my <a href="http://examples.wufoo.com/forms/z7w3m7">online form</a>.
</div>
<script type="text/javascript">
var z7w3m7;
!function(d, t) {
var s = d.createElement(t)
, options = {
'userName':'examples',
'formHash':'z7w3m7',
@tubalmartin
tubalmartin / gist:2658948
Created May 11, 2012 10:52
A tinier stapes.js - 406 bytes smaller when compressed with UglifyJS - It can be further reduced in size
//
// ____ _ _
// / ___|| |_ __ _ _ __ ___ ___ (_)___ (*)
// \___ \| __/ _` | '_ \ / _ \/ __| | / __|
// ___) | || (_| | |_) | __/\__ \_ | \__ \
// |____/ \__\__,_| .__/ \___||___(_)/ |___/
// |_| |__/
//
// (*) a (really) tiny Javascript MVC microframework
//
@tubalmartin
tubalmartin / print_image.php
Created May 13, 2012 17:27
PHP function that prints an image to be used by Riloadr
<?php
function print_image($data_src, $noscript_src, $group_class = "responsive", $classes = "", $alt = "", $data_base = "")
{
echo '<img alt="'.$alt.'" class="'.$group_class.' '.$classes.'" data-src="'.$data_src.'"'.(!empty($data_base) ? ' data-base="'.$data_base.'"' : "").'>'.
'<noscript>'.
'<img alt="'.$alt.'" class="'.$classes.'" src="'.$noscript_src.'">'.
'</noscript>';
}
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
//
// the regular expression composed & commented
// could be easily tweaked for RFC compliance,
// it was expressly modified to fit & satisfy
// these test for an URL shortener:
@tubalmartin
tubalmartin / gist:4270292
Created December 12, 2012 18:28
Facebook FQL result
USERINFO
Array
(
[data] => Array
(
[0] => Array
(
[name] => user
[fql_result_set] => Array
<?php if (!defined('BASEPATH')) exit('No direct access allowed.');
class Profiles extends Auth_Controller
{
protected $_view_path = 'profiles/';
public function __construct()
{
parent::__construct();
@tubalmartin
tubalmartin / gist:4345529
Created December 20, 2012 14:17
Validación NIF de personas jurídicas y entidades en general (ESPAÑA)
<?php
/**
* Valida NIF de personas jurídicas y entidades en general
*
* @param string $nif NIF to check
*
* @return bool returns true on success false otherwise
*/
function nifEntity($nif)