Skip to content

Instantly share code, notes, and snippets.

View Victa's full-sized avatar
🏠
Working from home

Victor Victa

🏠
Working from home
View GitHub Profile
@Victa
Victa / gist:1087834
Created July 17, 2011 17:31
Javascript trim
// remove space at the front and the end.
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
@Victa
Victa / gist:1087836
Created July 17, 2011 17:31
Parsing URLs as Links
String.prototype.parseURL = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
return url.link(url);
});
};
// src : http://www.simonwhatley.co.uk/parsing-twitter-usernames-hashtags-and-urls-with-javascript
@Victa
Victa / gist:1087837
Created July 17, 2011 17:32
Parsing Usernames as Links to Twitter
String.prototype.parseUsername = function() {
return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
var username = u.replace("@","")
return u.link("http://twitter.com/"+username);
});
};
// src : http://www.simonwhatley.co.uk/parsing-twitter-usernames-hashtags-and-urls-with-javascript
@Victa
Victa / gist:1087839
Created July 17, 2011 17:32
Parsing Hashtags as Links to Twitter’s Search
String.prototype.parseHashtag = function() {
return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) {
var tag = t.replace("#","%23")
return t.link("http://search.twitter.com/search?q="+tag);
});
};
// src : http://www.simonwhatley.co.uk/parsing-twitter-usernames-hashtags-and-urls-with-javascript
@Victa
Victa / gist:1094639
Created July 20, 2011 09:20
Target Blank Links
$('a[@rel$='external']').click(function(){
 this.target = "_blank";
});
 
/*
Usage:
<a href="http://www.lepinskidesign.com.br/" rel="external">lepinskidesign.com.br</a>
*/
@Victa
Victa / gist:1094641
Created July 20, 2011 09:20
jQuery preloadImages
jQuery.preloadImages = function()
{
 for(var i = 0; i ").attr("src", arguments[i]);
 }
};
 
// Usage
$.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg");
@Victa
Victa / gist:1094644
Created July 20, 2011 09:21
Target Blank Links
$('a[@rel$='external']').click(function(){
 this.target = "_blank";
});
 
/*
Usage:
<a href="http://www.lepinskidesign.com.br/" rel="external">lepinskidesign.com.br</a>
*/
@Victa
Victa / gist:1112404
Created July 28, 2011 19:56
date is valid ?
function isDateValid(y,m,d){
var x=new Date(y,--m,d);
return !isNaN(+x) && x.getFullYear() == y && x.getMonth() == m && x.getDate() == d;
}
@Victa
Victa / gist:1152681
Created August 17, 2011 21:25
iPhone Calling and Texting Links
<a href="tel:1-408-555-5555">1-408-555-5555</a>
<a href="sms:1-408-555-1212">New SMS Message</a>
@Victa
Victa / index.html
Created August 17, 2011 21:34
Stack of Paper
<div class="papers"></div>
// Source : http://jsfiddle.net/chriscoyier/8jmLY/2/