Skip to content

Instantly share code, notes, and snippets.

View jcutrell's full-sized avatar

Jonathan Cutrell jcutrell

View GitHub Profile
@jcutrell
jcutrell / gist:2039271
Created March 14, 2012 20:27
Replace Links
//utility for detecting links in text string
detectLinks(string, newtab){
newtab = (newtab == undefined) ? true : newtab;
var regexp = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i;
return newtab ? string.replace(regexp, "<a href='$1' target='_blank'>$1</a>") : string.replace(regexp, "<a href='$1'>$1</a>");
}
@jcutrell
jcutrell / gist:2007042
Created March 9, 2012 15:33
Paul Irish's random color in JS. Pretty fast.
'#'+('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6);
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.4.4",function($,L){$("<div class='vert'></div><div class='horz'></div>").appendTo("body");$(".vert").css({width:"1px",height:"100%",position:"fixed",top:"0px",left:"0px","background-color":"#232323"});$(".horz").css({height:"1px",width:"100%",top:"0px",left:"0px",position:"fixed","background-color":"#232323"});$("html").mousemove(function(a){$(".vert").css({left:a.pageX-$(window).scrollLeft()});$(".horz").css({top:a.pageY-$(window).scrollTop()})});});
@jcutrell
jcutrell / locationlock.js
Created June 22, 2010 21:16
Add current class to links
//works only with static urls, like /home.html, etc
function lockit(someActiveClass){
var href = window.location.href
var split = href.split('/');
if (split[split.length-1] == "") {
var urlend = split[split.length-2]
} else {
var urlend = split[split.length-1]
}