Skip to content

Instantly share code, notes, and snippets.

View shaneriley's full-sized avatar

Shane Riley shaneriley

View GitHub Profile
@shaneriley
shaneriley / spinner.js
Created March 21, 2012 20:15
jQuery Spinner plugin
$.fn.spinner = function(duration) {
var props = {
rotation: 0,
tick: (duration || 1000) / 32,
stop: function() {
clearTimeout(this.timeout);
},
start: function() {
var p = this;
p.timeout = setTimeout(function() {
function selleck(tmpl, obj, chain) {
chain = chain || "";
for (var v in obj) {
if (typeof obj[v] === "object") {
tmpl = selleck(tmpl, obj[v], chain + v + ".");
}
tmpl = tmpl.replace((new RegExp("{{" + chain + v + "}}", "g")), obj[v]);
}
return tmpl;
}
@shaneriley
shaneriley / gist:2302099
Created April 4, 2012 14:50
$.random(*number)
(function($) {
$.fn.random = function(qty) {
var $pool = this,
$picks = $(),
$e;
qty = qty || 1;
while (qty) {
$e = $pool.eq(~~(Math.random() * $pool.length));
$picks = $picks.add($e);
$pool = $pool.not($e);
@shaneriley
shaneriley / gist:2473083
Created April 23, 2012 19:01
jQuery smartToggle
(function($) {
$.fn.smartToggle = function(bool, prop) {
prop = prop || bool;
return this.each(function() {
var $e = $(this);
if (bool === prop) {
$e.is(":visible") ? $e.hide() : $e.css("display", prop);
}
else {
bool ? $e.css("display", prop) : $e.hide();
@shaneriley
shaneriley / gist:2655072
Created May 10, 2012 18:50
Updated Sass gradient mixin
= gradient-bg-horizontal($color1, $color2)
background-color: $color2
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#{ie-hex-str($color1)}, endColorstr=#{ie-hex-str($color2)})
-ms-filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#{ie-hex-str($color1)}, endColorstr=#{ie-hex-str($color2)})
background-image: -moz-linear-gradient(100% 100% 180deg, $color2, $color1)
background-image: -webkit-gradient(linear, left center, right center, from($color1), to($color2))
@shaneriley
shaneriley / gist:3327530
Created August 11, 2012 22:11
Get rid of iframe ads
Array.prototype.forEach.call(document.querySelectorAll("iframe"), function(el) { el.parentNode.removeChild(el); });
@shaneriley
shaneriley / markup.haml
Created August 15, 2012 14:13
Rating stars
.rating
.current.three
- %w(one two three four five).each do |rating|
= link_to rating, "#", class: rating
@shaneriley
shaneriley / AHHHHHHH
Created August 21, 2012 18:00 — forked from lessallan/AHHHHHHH
@for sass function issue
$colors: lighten(#026dbd, 45%), lighten(#fad52c, 20%), lighten(#f17d32, 20%), lighten(#da1c1c, 25%), lighten(#8266ba, 20%), lighten(#7bb545, 17%)
$i: 1
@each $color in $colors
&:nth-child(#{$i})
background-color: $color
$i: $i + 1
@shaneriley
shaneriley / gist:3794514
Created September 27, 2012 15:08
CodeMirror extension: Keep track of markers and clear all
var codemirror_overrides = {
setMarker: function(line, gutter_text, line_class) {
if (!this.markers) { this.markers = []; }
this.markers.indexOf(line) === -1 && this.markers.push(line);
this._setMarker(line, gutter_text, line_class);
},
clearMarkers: function(line) {
var e = this;
if (!e.markers) { return; }
if (line) {
@shaneriley
shaneriley / gist:3798945
Created September 28, 2012 09:56
Storage prototype object getter/setter methods
Storage.prototype.setObject = function(key, value) {
this.setItem(key, JSON.stringify(value));
};
Storage.prototype.getObject = function(key) {
return JSON.parse(this.getItem(key));
};