Skip to content

Instantly share code, notes, and snippets.

<div><!-- 1 -->
<span class="red"><!-- 6 --></span>
</div>
<div><!-- 2 -->
<span class="green"><!-- 4 --><span>
</div>
<div><!-- 3 -->
<span class="blue"><!-- 5 --></span>
</div>
<div><!-- 1 -->
<span class="red"><!-- 1.1 --></span>
</div>
<div><!-- 2 -->
<span class="green"><!-- 4 --><span>
</div>
<div><!-- 3 -->
<span class="blue"><!-- 5 --></span>
</div>
myname = "global"; // global variable
function func() {
alert(myname); // "undefined"
var myname = "local";
alert(myname); // "local"
}
func();
function Waffle() {
if (!(this instanceof Waffle)) {
return new Waffle();
}
this.tastes = "yummy";
}
Waffle.prototype.wantAnother = true;
// testing invocations
var first = new Waffle(),
second = Waffle();
// Immediate function style 1
(function () { // JSLint prefers this one
alert('watch out!');
}());
// Immediate function style 2
(function () {
alert('watch out!');
})();
function () {
alert('watch out!');
}();
/*
* BMP FileHeader
*/
private class FileHeader { // 14 bytes
public String signature;
public int fileSize;
public short reserved1;
public short reserved2;
public int fileOffsetToPixelArray;
// Serialize the pixels
int width = _bmp.getWidth();
int [] pixels = new int[width];
for (int h = _bmp.getHeight() - 1; h >= 0; h--) { // reverse scan line
_bmp.getPixels(pixels, 0, width, 0, h, width, 1);
for (int i = 0; i < width; ++i)
pixels[i] = ByteOrder.reverse(pixels[i]); // reverse ARGB as BGRA
dosl.write(pixels);
}
dosl.close();
private int downSample(float factor, byte [] in, byte [] out) {
int bytes = 4; // one audio sample is 32bits
factor = 1.0f / factor;
int downSampleCount = (int) (((in.length / bytes)) * factor);
int ouputSampleCount = 0;
for (int i = 0; i < downSampleCount; ++i) {
float scaledIndex = i * factor;
int floorIndex = (int)(scaledIndex);
@kswlee
kswlee / technique#1
Created March 7, 2014 16:46
badjs#1
if (x && y) { … } // bad
if (!(!x || !y)) { … } // good