Skip to content

Instantly share code, notes, and snippets.

@wizard04wsu
wizard04wsu / isType.js
Last active August 27, 2021 17:13
Improved JavaScript type testing - Future revisions will be at https://github.com/wizard04wsu/javascript-type-testing
/**
* A more robust 'typeof'.
* https://gist.github.com/wizard04wsu/8055356
*
*
* For each of the type testing methods, the only parameter is the item to be tested. These methods do not perform coercion.
*
* is(o) - Returns the item's type.
* - NaN is considered its own type (instead of a number), since it essentially represents something that cannot be converted to a number.
* - For objects, the type of the object is given instead of just 'object' (e.g., 'Array').
@wizard04wsu
wizard04wsu / javascript_resources.md
Created February 4, 2014 21:20 — forked from jookyboi/javascript_resources.md
Here is a set of libraries, plugins and guides which may be useful to your JavaScript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@wizard04wsu
wizard04wsu / css_resources.md
Created February 4, 2014 21:20 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@wizard04wsu
wizard04wsu / getPrototypeOf.js
Last active August 29, 2015 13:56
Cross-browser Object.getPrototypeOf()
//add Object.getPrototypeOf() if it's not supported
// - if the __proto__ property is not supported either, this may break if anything in the object's prototype chain has been tampered with
// - see http://ejohn.org/blog/objectgetprototypeof/
(function (){
"use strict";
function isPrimitive(o){ var t; return o===t || o===null || (t = typeof o)==="number" || t==="string" || t==="boolean"; }
if(!Object.getPrototypeOf){
if(typeof("".__proto__) === "object"){
Object.getPrototypeOf = function getPrototypeOf(object){
@wizard04wsu
wizard04wsu / arrayPrune.js
Last active September 10, 2017 18:02
Array.prototype.prune() is the opposite of Array.prototype.slice(). It removes the specified portion of the array and returns what's left, without modifying the original array.
//returns a copy of an array with a portion removed
//(essentially the opposite of `slice`)
//the `end` argument is optional
//arr.prune(begin[, end])
if(!Array.prototype.prune){
Array.prototype.prune = function prune(begin, end){
"use strict";
var newArr = this.slice(0); //make a copy of the array
@wizard04wsu
wizard04wsu / arrayMaxMin.js
Created February 5, 2014 15:56
Get the maximum and minimum values in an array.
//get max value in an array
//got this from http://addictedtonew.com/archives/482/javascript-array-max-and-equal-height-columns/
if(!Array.prototype.max) Array.prototype.max = function max(){ return Math.max.apply({}, this); };
//get minimum value in an array
if(!Array.prototype.min) Array.prototype.min = function min(){ return Math.min.apply({}, this); };
@wizard04wsu
wizard04wsu / VBArray.vbs
Last active July 1, 2020 17:57
VBScript or VBA array functions
Function getUBound(arr)
getUBound = -1
On Error Resume Next
getUBound = UBound(arr)
On Error GoTo 0
End Function
Function getLength(arr)
getLength = getUBound(arr) + 1
End Function
@wizard04wsu
wizard04wsu / changeBase.js
Last active July 30, 2022 19:45
Convert a number to a different base (e.g., from hex to decimal)
//Convert a number to a different base (e.g., from hex to decimal).
//Returns a string representation of the number, or NaN if `num` does not represent a number of the specified base.
function changeBase(num, fromRadix, toRadix){
if(!(1*fromRadix) || fromRadix%1 !== 0 || fromRadix < 2 || fromRadix > 36){
throw new RangeError(`'fromRadix' must be an integer between 2 and 36, inclusive.`);
}
if(!(1*toRadix) || toRadix%1 !== 0 || toRadix < 2 || toRadix > 36){
throw new RangeError(`'toRadix' must be an integer between 2 and 36, inclusive.`);
}
@wizard04wsu
wizard04wsu / logToBase.js
Last active August 29, 2015 13:56
Get the logarithm of a number to a specified base.
//returns the logarithm of `num` to base `base`
if(!Math.logB){
Math.logB = function logB(num, base){
return Math.log(num)/Math.log(base);
};
}
@wizard04wsu
wizard04wsu / rounding.js
Last active August 30, 2019 15:00
Functions to round a number to a specified precision (i.e., a specified number of decimal places).
function roundToPrecision(num, precision){
var shifter;
precision = new Number(precision || 0);
if(precision%1 !== 0) throw new RangeError("precision must be an integer");
shifter = Math.pow(10, precision);
return Math.round(num*shifter)/shifter;
}
function floorToPrecision(num, precision){
var shifter;