Skip to content

Instantly share code, notes, and snippets.

View benjamincharity's full-sized avatar
🤖

Benjamin Charity benjamincharity

🤖
View GitHub Profile
@benjamincharity
benjamincharity / datauri-test.js
Created May 4, 2013 15:22
Modernizr test for datauri (base64 encoded images).
// data uri test.
// https://github.com/Modernizr/Modernizr/issues/14
// This test is ascynchronous. Watch out.
(function(){
var datauri = new Image();
// define a couple of functions to make things a bit cleaner
var lowercase = function(string){
return isString(string) ? string.toLowerCase() : string;
};
function isString(value){
return typeof value == 'string';
}
// test for the major version of IE
var msie = int((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]);
@benjamincharity
benjamincharity / findUnicodeCharacter.js
Created June 26, 2013 13:03
Get the unicode character with Javascript.
// From http://blog.hull.io/post/46243434040/introducing-sass-getunicode
'☃'.charCodeAt(0).toString(16);
/**
* List Prefix'
*/
html {
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
font-family: Helvetica Neue;
font-weight: 100;
letter-spacing: .1em;
@benjamincharity
benjamincharity / rvm rvmrc
Last active December 20, 2015 01:28
Create, use and trust a .rvmrc file.
# Create and use an rvm gemset
rvm --rvmrc --create ruby-1.9.3@myProject
# Set the rvm as trusted
rvm rvmrc trust .
@benjamincharity
benjamincharity / zepto.smoothScroll.js
Last active October 4, 2019 15:21 — forked from austinpray/zepto.smoothScroll.js
Smooth scrolling with Zepto.js
function smoothScroll(el, to, duration) {
if (duration < 0) {
return;
}
var difference = to - $(window).scrollTop();
var perTick = difference / duration * 10;
this.scrollToTimerCache = setTimeout(function() {
if (!isNaN(parseInt(perTick, 10))) {
window.scrollTo(0, $(window).scrollTop() + perTick);
smoothScroll(el, to, duration - 10);
function testWebP(callback) {
var webP = new Image();
webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
webP.onload = webP.onerror = function () {
callback(webP.height === 2);
};
};
function notify(supported) {
console.log((supported) ? "webP supported!" : "webP not supported.");
@benjamincharity
benjamincharity / createGIF.cli
Created July 24, 2013 18:07
Use ImageMagick to create a gif from the command line.
convert -delay 20 -loop 0 source*.gif final.gif
pre {
white-space: pre; /* CSS 2.0 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3.0 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP Printers */
word-wrap: break-word; /* IE 5+ */
}
/*
An attempt at fixing the dreaded iOS orientationchange zoom bug http://adactio.com/journal/5088/. Seems to work!
Authored by @scottjehl
MIT License.
*/
(function(w){
var doc = w.document;
if( !doc.querySelectorAll ){ return; }