Skip to content

Instantly share code, notes, and snippets.

View jcutrell's full-sized avatar

Jonathan Cutrell jcutrell

View GitHub Profile
@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]
}
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 / 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);
@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 / uniqrand.js
Last active October 4, 2015 21:38
Unique Random Number
function uniqRand(notThis, range){
var maybe = Math.floor(Math.random() * range);
if (maybe !== notThis){
return maybe;
} else {
return uniqRand(notThis, range);
}
}
@jcutrell
jcutrell / gist:2881523
Created June 6, 2012 12:13
Relative Time (for Twitter)
// $.relativeTime - returns a string that tells how long ago the passed in string happened. For Twitter.
$.relativeTime = function(dateString) {
var rightNow = new Date();
var then = new Date(dateString);
if ($.browser.msie) {
// IE can't parse these crazy Ruby dates
then = Date.parse(dateString.replace(/( \+)/, ' UTC$1'));
}
@jcutrell
jcutrell / gist:3144098
Created July 19, 2012 13:57
Centered text with letter-spacing fix
// requires jQuery
$("h2").each(function(){
var h2 = $(this);
var t = h2.text();
var last = t.split("")[t.length-1];
var newtext = t.substring(0,t.length-1) + "<span style='letter-spacing:0px;'>" + last + "</span>";
h2.html(newtext);
});
@jcutrell
jcutrell / index.html
Created August 26, 2012 19:06
Article About The Fridge
<doctype html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container">
<h1>The Fridge: A Startup Cultural Catalyst</h1>
<p>At Whiteboard, we are about culture. We're about family. We're about living <em>with</em> one another, as opposed to simply beside one another. For that reason, we recently took some time to create an internal tool.</p>
// From the 140bytes wishlist here: https://github.com/jed/140bytes/wiki/Wishlist
// TASK:
// Create a function which can create a DOM structure from this:
//
domBuilder(
[/HTML/],
[/HEAD/],
[/TITLE/],
"Wouldn't this be cool?",
[],
@jcutrell
jcutrell / index.html
Created February 8, 2013 21:06
A CodePen by Jonathan Cutrell. Where's Waldo? - A little bit of webkit filter exploration, and a few little tricks here and there.
<div id="imageholder">
<img src="http://3.bp.blogspot.com/-JlYXI_mJn7U/UFIJ7_8iLJI/AAAAAAAAAWY/ClZoftC59Uc/s1600/TheGobblingGluttons.jpg">
<div id="glass"></div>
</div>