Skip to content

Instantly share code, notes, and snippets.

View lonekorean's full-sized avatar

Will Boyd lonekorean

View GitHub Profile
@lonekorean
lonekorean / gist:8755747
Last active August 29, 2015 13:55
JavaScript function parameters
function f(a, b) {
alert(a);
alert(b);
}
f(1); // a gets 1, while b is undefined
f(1, 2, 3); // the 3 is ignored
@lonekorean
lonekorean / gist:8755767
Last active August 29, 2015 13:55
JavaScript mixing types
var a = '1' + 1;
var b = '1' - 1;
var c = '1' * 1;
var d = '1' / 1;
alert(a === '11'); // is a string
alert(b === 0); // is an integer
alert(c === 1); // is an integer
alert(d === 1); // is an integer
@lonekorean
lonekorean / gist:8755777
Last active August 29, 2015 13:55
JavaScript regex search
var s = 'abc abc abc';
alert(s.replace(/abc/, 'xyz')); // outputs 'xyz abc abc'
alert(s.replace(/abc/g, 'xyz')); // outputs 'xyz xyz xyz'
@lonekorean
lonekorean / gist:8756258
Last active August 29, 2015 13:55
SQL query for column information
SELECT
C.name AS ColumnName,
T.name As DataType,
C.max_length AS Length
FROM sys.columns AS C JOIN sys.types AS T ON C.user_type_id = T.user_type_id
WHERE c.object_id = OBJECT_ID('YOUR_TABLE_NAME_HERE')
ORDER BY c.column_id;
@lonekorean
lonekorean / gist:8756268
Last active August 29, 2015 13:55
SQL query for column information output
ColumnName DataType Length
========== ======== ======
ID int 4
Title varchar 255
Blurb varchar 255
IsActive bit 1
Created datetime 8
@lonekorean
lonekorean / gist:8756461
Last active August 29, 2015 13:55
Bad image preloader
// this is bad
function imageLoaded(i) {
alert(i);
}
for (var i = 0; i < max; i++) {
var image = new Image();
image.onload = imageLoaded(i);
// more irrelevant stuff here
@lonekorean
lonekorean / gist:8756498
Last active August 29, 2015 13:55
Still bad image preloader
// better, but still not good
function imageLoaded(i) {
alert(i);
}
for (var i = 0; i < max; i++) {
var image = new Image();
image.onload = function () { imageLoaded(i) };
// more irrelevant stuff here
@lonekorean
lonekorean / gist:8756562
Last active August 29, 2015 13:55
Decent image preloader
// hooray!
function imageLoaded(i) {
return function () {
alert(i);
}
}
for (var i = 0; i < max; i++) {
var image = new Image();
@lonekorean
lonekorean / gist:8757100
Last active August 29, 2015 13:55
Suckerfish dropdown HTML
<ul id="nav">
<li><a href="#">Home</a></li>
<li>
<a href="#">Shows</a>
<ul>
<li><a href="#">30 Rock</a></li>
<li><a href="#">Doctor Who</a></li>
<li><a href="#">The IT Crowd</a></li>
<li><a href="#">The Office</a></li>
<li><a href="#">Star Trek</a></li>
@lonekorean
lonekorean / gist:8757128
Last active August 29, 2015 13:55
Suckerfish dropdown CSS part 1
#nav {
overflow: auto;
}