Skip to content

Instantly share code, notes, and snippets.

View mathiasbynens's full-sized avatar

Mathias Bynens mathiasbynens

View GitHub Profile
@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 / toggleAttr() jQuery plugin
Created February 8, 2010 21:20
toggleAttr() jQuery plugin
/*!
* toggleAttr() jQuery plugin
* @link http://github.com/mathiasbynens/toggleAttr-jQuery-Plugin
* @description Used to toggle selected="selected", disabled="disabled", checked="checked" etc…
* @author Mathias Bynens <http://mathiasbynens.be/>
*/
jQuery.fn.toggleAttr = function(attr) {
return this.each(function() {
var $this = $(this);
$this.attr(attr) ? $this.removeAttr(attr) : $this.attr(attr, attr);
@mathiasbynens
mathiasbynens / hide-jimmy-wales.user.js
Created November 21, 2011 19:43
Userscript that hides Jimmy Wales on Wikipedia
// ==UserScript==
// @name Hide Jimmy Wales.
// @match http://*.wikipedia.org/*
// ==/UserScript==
(function() {
var banner = document.getElementById('siteNotice');
banner && banner.style.display = 'none';
}());
@mathiasbynens
mathiasbynens / jquery.fluid-youtube-videos-original.js
Created June 8, 2011 13:07
Fluid width YouTube videos of different aspect ratios, by Chris Coyier
// Original code from http://css-tricks.com/examples/FluidWidthYouTube/iframe.php
$(function() {
// find all videos
var allVideos = $("iframe[src^='http://www.youtube.com']"),
// The thing that is fluid width
body = $("body"),
http://AI./
└ IP: 209.59.119.34
http://ARAB./
└ IP: 127.0.53.53
http://BH./
└ IP: 10.10.10.10
http://CM./
└ IP: 195.24.205.60
http://DK./
└ IP: 193.163.102.58
@mathiasbynens
mathiasbynens / jquery.preload.js
Created April 22, 2010 17:11
JavaScript preload() function
/*!
* $.preload() function for jQuery – http://mths.be/preload
* Preload images, CSS and JavaScript files without executing them
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/
* Note that since this script relies on jQuery, the preloading process will not start until jQuery has finished loading.
*/
jQuery.preload = function(array) {
var length = array.length,
<!-- 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 / bf.js
Created July 17, 2015 10:56
How many hex-formatted Unicode code points can be mistaken for a number in scientific notation? Which ones are those? https://twitter.com/tabatkins/status/621440178087960576
'use strict';
const pad = function(string) {
const totalCharacters = 4;
return string.length < totalCharacters ?
(Array(totalCharacters + 1).join('0') + string).slice(-totalCharacters) :
string;
}
const UNICODE_MIN = 0x0;
@mathiasbynens
mathiasbynens / jquery.loadasync.js
Created September 6, 2011 09:44
Use jQuery to load scripts asynchronously
// Load scripts asynchronously
jQuery.loadAsync = function(url, callback) {
// Don't use $.getScript since it disables caching
jQuery.ajax({
'url': url,
'dataType': 'script',
'cache': true,
'success': callback || jQuery.noop
});
};
/*
* See http://mathiasbynens.be/notes/async-analytics-snippet#comment-14
*/
<script>
var f = Function(),
clicky = { log: f, goal: f },
clicky_site_id = XXXXXX;
(function(d, t) {
var c = d.createElement(t),