Skip to content

Instantly share code, notes, and snippets.

@thealscott
thealscott / key_exists_and_equals
Created May 15, 2012 16:49
Returns if the key of an array exists and equals the given value.
function key_exists_and_equals($array, $key, $value)
{
return (isset($array[$key]) && $array[$key] == $value);
}
@thealscott
thealscott / jquery.autolink.js
Created May 29, 2012 15:19
Extension of the handy autolink jQuery plugin, so that it has a method for handling twitter hashtags. Original from http://kawika.org/jquery/index.php
@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;
@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 / 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: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: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: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: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: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);