Skip to content

Instantly share code, notes, and snippets.

Chase ChaseWest

Block or report user

Report or block ChaseWest

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ChaseWest
ChaseWest / react-table-component.js
Created May 24, 2014
React Table Component for creating a very basic html table
View react-table-component.js
var Table = React.createClass({
render: function render() {
var _self = this;
var thead = React.DOM.thead({},
React.DOM.tr({},
this.props.cols.map(function (col) {
return React.DOM.th({}, col);
})));
@ChaseWest
ChaseWest / parse-HTML-without-DOMParser.js
Created May 10, 2014
Parse HTML string without DOMParser API
View parse-HTML-without-DOMParser.js
var HTML = "<div><span>Test</span></div>";
var body = document.querySelector("body");
function parseHTML(htmlString){
var frag = document.createDocumentFragment(),
el = document.createElement( "div" );
el.setAttribute("id", "wrapper");
el.innerHTML = HTML;
frag.appendChild(el);
@ChaseWest
ChaseWest / HTML-parse.js
Created May 10, 2014
Parse HTML string to document object and insert into DOM
View HTML-parse.js
var HTML = "<div></span>Test</span></div>";
var body = document.querySelector("body");
function parseHTML(htmlString){
var parser = new DOMParser();
var fragment = document.createDocumentFragment();
fragment.appendChild(parser.parseFromString(htmlString, "text/html").querySelector("body"));
body.appendChild(fragment);
View is-function.js
function is(val, type){
switch(type){
case "finite":
return typeof val === "number" && Number.isFinite(val);
case "integer":
return typeof val === "number" && Number.isInteger(val);
case "NaN":
return typeof val === "number" && Number.isNaN(val);
case "positive":
@ChaseWest
ChaseWest / random-key.js
Last active Aug 29, 2015
Generate a random string (ex: "5ons00tkwfsnstt9")
View random-key.js
function getRandomKey(){
Math.random().toString(36).slice(2)
}
@ChaseWest
ChaseWest / attach-function.js
Created May 10, 2014
Generic pure js function to attach event listeners to DOM nodes
View attach-function.js
var is_attachEvent = !!document.attachEvent,
is_addEventListener = !!document.addEventListener;
function attach(target, event, fn){
switch(true){
case is_addEventListener:
target.addEventListener(event, fn);
break;
case is_attachEvent:
target.attachEvent("on"+event, fn);
@ChaseWest
ChaseWest / loop-function.js
Last active Aug 29, 2015
Loop function to determine the loop type by the object passed in. Set - (Array/Object), fn - (function to call on each iteration), order - (if order doesn't matter and set is an array, then use a while loop)
View loop-function.js
function loop(set, fn, order){
var is_array = Object.prototype.toString.call(set) === '[object Array]',
i, l;
if(is_array){
l = set.length;
if (!order) {
while(l--){ fn(l); }
}
else {
You can’t perform that action at this time.