Skip to content

Instantly share code, notes, and snippets.

@thealscott
thealscott / gist:9845518
Last active February 14, 2016 11:17
Spotify URI generator bookmarklet
javascript:{var%20pathArray=window.location.pathname.split('/');var%20newPathname="spotify";for(i=1;i<pathArray.length;i++){newPathname+=":";newPathname+=pathArray[i];}window.location.replace(newPathname);};void(0);
@thealscott
thealscott / gist:9618452
Created March 18, 2014 11:42
Keyframe sprite animation technique
@include create-keyframe(sprite_animation) {
$frames:20;
$step:100%/$frames;
$pre_step:$step - 0.0001%;
@for $i from 0 through $frames {
$n: ($i * $step);
$n2: ($n + $pre_step);
#{$n}, #{$n2} { @include get-sprite($animations_sprite, sequence_#{$i}) }
}
@thealscott
thealscott / gist:8560049
Created January 22, 2014 14:53
XHR ajax snippet (via Remy)
function request(type, url, opts, callback) {
var xhr = new XMLHttpRequest(),
fd;
if (typeof opts === 'function') {
callback = opts;
opts = null;
}
xhr.open(type, url);
@thealscott
thealscott / gist:8559974
Created January 22, 2014 14:48
Cutting the mustard snippet (via BBC)
if ('querySelector' in document &&
'localStorage' in window &&
'addEventListener' in window) {
// bootstrap the JavaScript application
}
@thealscott
thealscott / gist:6434599
Created September 4, 2013 09:10
Safe console snippet
// make it safe to use console.log always
(function(b){
function c(){}
for(var d="assert,clear,count,debug,dir,dirxml,error,exception,firebug,group,groupCollapsed,groupEnd,info,log,memoryProfile,memoryProfileEnd,profile,profileEnd,table,time,timeEnd,timeStamp,trace,warn".split(","),a;a=d.pop();){
b[a]=b[a]||c
}
})((function(){
try
{
@thealscott
thealscott / gist:5797009
Last active December 18, 2015 14:28
Simple asset preloader example
var preloadImageArray = [
'/path/to/images_1.jpg',
'/path/to/images_2.jpg',
'/path/to/images_3.jpg',
'/path/to/images_4.jpg'
];
function preloadImages (preloadImageArray) {
var images = preloadImageArray;
var count = images.length;
@thealscott
thealscott / gist:ebadb841e8f5be4645c0
Last active December 17, 2015 07:39
Some ghetto UA based feature blacklisting, supplement for Modernizr (for shit that it can't reliably feature detect)
var userAgentNaughtyList = {
positionFixed : [
'Android 2',
'Android 3',
'Android 4.0',
'iPhone OS 4',
'iPhone OS 5',
'Windows Phone OS 7'
],
vimeo : [
@thealscott
thealscott / gist:e2d11731e6eec91c4f8a
Last active December 17, 2015 04:59
Center a fullscreen image of any aspect ratio
function centerImage() {
$img = $('img');
var newimage = new Image();
var originalImageWidth;
var originalImageHeight;
newimage.src = $img.attr('src');
newimage.onload = function()
{
// resize/reposition image based on aspect ratio relative to viewport aspect to make sure it is always fullscreen and centered
@thealscott
thealscott / gist:3349897
Created August 14, 2012 14:41 — forked from corydorning/Cross-Browser ::before and ::after pseudo-class polyfill
Cross-Browser ::before and ::after pseudo-class polyfill - adapted into mixins for SCSS using modernizr
@mixin after-polyfill(){
.ie7 & {
/* creates <span class="ie-after"></span> */
zoom: expression( this.runtimeStyle.zoom="1", this.appendChild( document.createElement("span") ).className="ie-after" );
}
}
@mixin before-polyfill(){
.ie7 & {
/* creates <span class="ie-before"></span> */
@thealscott
thealscott / scss-mixins-part-1
Created July 9, 2012 14:12
SCSS utility mixins; includes custom font, box-sizing, opacity, border-radius and box-shadow mixins with prefixes and polyfills.
@mixin custom-font($name, $weight, $font_type) {
$fallbacks:Helvetica, Arial, sans-serif;
@if $font_type == serif {
$fallbacks:Georgia, "Times New Roman", serif;
}
font-family: '#{$name} #{$weight}', $fallbacks;
font-weight:$weight;