Skip to content

Instantly share code, notes, and snippets.

function createGlobalVar(varName, varValue) {
this[varName] = varValue;
}
createGlobalVar('generatedVar', 10);
@thetallweeks
thetallweeks / web.config
Created March 25, 2014 18:24
Enable BrowserLink for static files
<configuration>
<system.webServer>
<handlers>
<add name="Browser Link for HTML" path="*.html" verb="*"
type="System.Web.StaticFileHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
resourceType="File" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
function getPrevious(n, className) {
var y = n.previousSibling;
// Check if previous node is an element node with a specific class
while (y.nodeType != 1 || !y.classList.contains(className)) {
// If not, move on to previous node
y = y.previousSibling;
}
return y;
}
@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 / github-pygments.css
Created November 14, 2013 16:33
Pygments syntax highlighting from github
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #000000; font-weight: bold } /* Keyword */
.highlight .o { color: #000000; font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold; font-style: italic } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
@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;
}