Skip to content

Instantly share code, notes, and snippets.

@thetallweeks
thetallweeks / loopElementsByClass.js
Created January 17, 2014 20:26
After document.getElementsByClassName, loop through the list of elements.
for (var i = 0, j = $elements.length; i < j; i++) {
element = elements[i];
// Bind events, do whatever here
}
@thetallweeks
thetallweeks / ie-specific-classes.html
Last active January 2, 2016 17:49
This provides ie classes on the html tag in case of ie-specific styling. Note: Modernizr replaces "no-js" with "js" when it loads. If you are not using Modernizr, don't include "no-js"
<!DOCTYPE html>
<!--[if IEMobile 7 ]> <html dir="ltr" lang="en-US"class="no-js iem7"> <![endif]-->
<!--[if lt IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie6 lt-ie7 lt-ie8 lt-ie9 lt-ie10"> <![endif]-->
<!--[if IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie7 lt-ie8 lt-ie9 lt-ie10"> <![endif]-->
<!--[if IE 8 ]> <html dir="ltr" lang="en-US" class="no-js ie8 lt-ie9 lt-ie10"> <![endif]-->
<!--[if IE 9 ]> <html dir="ltr" lang="en-US" class="no-js ie9 lt-ie10"> <![endif]-->
<!--[if IE 10 ]> <html dir="ltr" lang="en-US" class="no-js ie10"> <![endif]-->
<!--[if (gte IE 9)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html dir="ltr" lang="en-US" class="no-js"><!--<![endif]-->
@thetallweeks
thetallweeks / 0_reuse_code.js
Created December 31, 2015 19:44
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
@thetallweeks
thetallweeks / better-for-loop.js
Last active December 28, 2015 03:09
This is a better way to do a for loop. It stores the array length in a variable so the javascript doesn't have to get the array length every iteration.
var names = ['George',
'Ringo',
'Paul',
'John'];
for(var i = 0, j = names.length; i < j; i++) {
doSomethingWith(names[i]);
}
.hide-text {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
function CheckNums(num1,num2) {
if(num2 > num1) {
return true;
} else if(num1 === num2) {
return -1;
} else {
return false
}
}
function SimpleAdding(num) {
var total = 0;
for(i = 1; i <= num; i++) {
total += i;
}
// code goes here
return total;
}
@thetallweeks
thetallweeks / 3-LongestWord.js
Last active December 26, 2015 12:19
Coderbyte Longest Word in a string
function LongestWord(sen) {
longest = "";
// code goes here
var words = sen.split(" ");
for(i = 0; i < words.length; i++) {
if(words[i].length > longest.length) {
longest = words[i];
}
}
return longest;
@thetallweeks
thetallweeks / 2-FirstFactorial.js
Last active December 26, 2015 12:19
Coderbyte Factorial function
function FirstFactorial(num) {
var factorial = 1;
// code goes here
for(i = 2; i <= num; i++) {
factorial *= i;
}
return factorial;
}
@thetallweeks
thetallweeks / 1-FirstReverse.js
Last active December 26, 2015 09:48
Coderbyte Reverse string Challenge
// http://coderbyte.com/CodingArea/GuestEditor.php?ct=First%20Reverse&lan=JavaScript
function FirstReverse(str) {
var string = [];
for(i = 0; i <= str.length; i++) {
string[i] = str[str.length - i];
}
// code goes here
return string.join("");
}