Skip to content

Instantly share code, notes, and snippets.

View mathiasbynens's full-sized avatar

Mathias Bynens mathiasbynens

View GitHub Profile
@mathiasbynens
mathiasbynens / change-favicon.js
Created June 7, 2010 12:41
Dynamically changing favicons with JavaScript
/*!
* Dynamically changing favicons with JavaScript
* Works in all A-grade browsers except Safari and Internet Explorer
* Demo: http://mathiasbynens.be/demo/dynamic-favicons
*/
// HTML5™, baby! http://mathiasbynens.be/notes/document-head
document.head || (document.head = document.getElementsByTagName('head')[0]);
function changeFavicon(src) {
@mathiasbynens
mathiasbynens / Awesomify the Safari Reader UI bookmarklet
Created June 13, 2010 19:29
Awesomify the Safari Reader UI bookmarklet
// This works when used from the console with the Reader document open, but fails when used as a bookmarklet. Any ideas?
// See http://mathiasbynens.be/notes/safari-reader-html
javascript:(function(d){var s=d.createElement('style');s.appendChild(d.createTextNode('#background{background:#f773b5 url(http://i.imgur.com/bB7aD.jpg)}h1.title,.page{font-family:"Comic Sans MS"!important}h1.title{color:#f773b5}.page{background:rgba(255,255,255,.9);-webkit-animation-name:f;-webkit-animation-duration:5s;-webkit-animation-iteration-count:infinite;-webkit-animation-timing-function:linear}@-webkit-keyframes f{0%{-webkit-transform:rotate(0) scale(1)}25%{-webkit-transform:rotate(-4deg) scale(.95)}50%{-webkit-transform:rotate(0) scale(1)}75%{-webkit-transform:rotate(4deg) scale(.95)}100%{-webkit-transform:rotate(0) scale(1)}}'));d.head.appendChild(s)})(document)
@mathiasbynens
mathiasbynens / Slightly optimized version of the ‘Device Scale UI elements in iOS Mobile Safari’ script by 37signals
Created June 16, 2010 06:54 — forked from sstephenson/gist:439777
Slightly optimized version of the ‘Device Scale UI elements in iOS Mobile Safari’ script by 37signals
// Provides a device_scale class on iOS devices for scaling user
// interface elements relative to the current zoom factor.
//
// http://37signals.com/svn/posts/2407-device-scale-user-interface-elements-in-ios-mobile-safari
// Copyright (c) 2010 37signals.
// Slightly optimized by Mathias Bynens <http://mathiasbynens.be/>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
<!-- See http://mathiasbynens.be/notes/async-analytics-snippet -->
<!-- Gisted for P. Ireland -->
<script>var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'))</script>
@mathiasbynens
mathiasbynens / jQuery.classList.js
Created July 16, 2010 07:34 — forked from boazsender/jQuery.classList.js
Fork of boaz’s jQuery.fn.classList() method with some minor improvements
/*
Usages:
$(selector).classList() // returns an array of classnames
$(selector).classList('newclass') // replaces the current element’s classes
$(selector).classList(['new', 'class', 'names']) // replaces the current element’s classes
*/
jQuery.fn.extend({
classList: function(value) {
if (value) {
function relativeDate(str) {
var s = (+new Date() - Date.parse(str)) / 1e3,
m = s / 60,
h = m / 60,
d = h / 24,
w = d / 7,
y = d / 365.242199,
M = y * 12,
R = Math.round;
return s <= 5 ? 'just now'
@mathiasbynens
mathiasbynens / jquery.togglefade.js
Created September 2, 2010 14:56
jQuery toggleFade()
jQuery.fn.toggleFade = function(speed, callback) {
speed = ~~speed || 400;
callback = callback || jQuery.noop;
return this.each(function() {
var $this = jQuery(this);
$this[$this.is(':hidden') ? 'fadeIn' : 'fadeOut'](speed, callback);
});
};
@mathiasbynens
mathiasbynens / setZeroTimeout.js
Created September 14, 2010 22:23
Cross-browser-compatible setZeroTimeout
/*! Cross-browser-compatible setZeroTimeout
*
* I took the original setZeroTimeout and made it cross-browser-compatible, using setTimeout(fn, 0) as a fallback in case postMessage is not supported.
* Mathias Bynens <http://mathiasbynens.be/>
* See <http://mathiasbynens.be/notes/settimeout-onload>
*
* Copyright statement below:
*
* See <http://dbaron.org/log/20100309-faster-timeouts>
* By L. David Baron <dbaron@dbaron.org>, 2010-03-07, 2010-03-09
@mathiasbynens
mathiasbynens / appify
Created November 12, 2010 13:46 — forked from subtleGradient/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
@mathiasbynens
mathiasbynens / nytimes-option-a.user.js
Created March 22, 2011 09:12
Userscript to bypass the badly implemented paywall on nytimes.com. Use the “raw” links to install.
// ==UserScript==
// @name Bypass New York Times paywall (20 article limit)
// @author Mathias Bynens <http://mathiasbynens.be/>
// @link http://mths.be/axa
// @match http://www.nytimes.com/*
// ==/UserScript==
(function(d) {
d.getElementById('overlay').style.display = 'none';
d.getElementById('gatewayCreative').style.display = 'none';