Skip to content

Instantly share code, notes, and snippets.

@gwa
gwa / gist:5364271
Last active December 16, 2015 02:39
Get the number of bits set in a binary number.
function getNumBitsSet(binary) {
var numbits = 0;
for (var v=binary; v; v>>=1) {
numbits += v&1;
}
return numbits;
}
@gwa
gwa / gist:5364360
Created April 11, 2013 15:31
Custom selected text background color
/* Custom text-selection colors (remove any text shadows: twitter.com/miketaylr/status/12228805301) */
::-moz-selection { background: #fcd700; color: #fff; text-shadow: none; }
::selection { background: #fcd700; color: #fff; text-shadow: none; }
@gwa
gwa / gist:5404020
Last active December 16, 2015 08:09
get set bits in a base 10 number
/**
* Returns an array of set bits in a base 10 number.
* @param int base10
* @return Array
*/
var getSetBits = function ( base10 )
{
if (!base10) {
return;
}
@gwa
gwa / gist:5419893
Last active December 16, 2015 10:28
jQuery Plugin Template
// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;(function ( $, window, document, undefined ) {
// undefined is used here as the undefined global variable in ECMAScript 3 is
// mutable (ie. it can be changed by someone else). undefined isn't really being
// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
// can no longer be modified.
// window and document are passed through as local variable rather than global
@gwa
gwa / mobile-checkboxes.css
Last active December 22, 2015 04:58
Scale up HTML checkboxes on webkit mobile.
input[type=checkbox] {
-webkit-transform: scale(1.3, 1.3);
margin-left: 5px;
}
@gwa
gwa / gist:6463686
Created September 6, 2013 13:19
Get hash portion of URL, without #
var locationhash = window.location.hash.replace('#', '');
@gwa
gwa / gist:6606490
Created September 18, 2013 08:58
javascript string to boolean function.
function stringToBoolean( value ) {
switch (typeof value) {
case "object":
case "string": return (/(true|1)/i).test(value);
case "number": return !!value;
case "boolean": return value;
case "undefined": return null;
default: return false;
}
};
@gwa
gwa / pure-12-column-grid.css
Created September 26, 2013 15:07
pure css responsive 12 column grid
.pure-g {
letter-spacing: -0.31em;
*letter-spacing: normal;
*word-spacing: -0.43em;
text-rendering: optimizespeed;
}
.opera-only :-o-prefocus,
.pure-g {
word-spacing: -0.43em;
@gwa
gwa / 0_reuse_code.js
Created October 17, 2013 11:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@gwa
gwa / gist:7332694
Last active December 27, 2015 13:19
iframe height change listener
// in parent document
// no jQuery required
(function () {
var
ifr = document.getElementById('iframeid'),
vpadding = 50;
window.addEventListener(
"message",
function (ev) {
var d=ev.data.split(':'), k=d[0], v=d[1];