Skip to content

Instantly share code, notes, and snippets.

(function () {
var a=1,
b=2,
c=3
d=4,
e=5,
f=6;
}());
console.log(d,e,f); // 4,5,6
var i = 27 // 27
var j = 027 // 23
function foo (x) {
if (x=true) {
// no matter what value is
// passed in for x, this
// will always execute
}
}
foo(false);
Math.floor(.5 + ((Math.cos(val)*.5)))
if (!val) { … }
var foo = function (person) {
// stuff happens
// perhaps a breakpoint is added here
// or they attempt to log the object
console.log(person);
}
var person = {};
person[‘\t’] = ‘Nicholas’;
@kswlee
kswlee / technique#1
Created March 7, 2014 16:46
badjs#1
if (x && y) { … } // bad
if (!(!x || !y)) { … } // good
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);
// 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();
/*
* BMP FileHeader
*/
private class FileHeader { // 14 bytes
public String signature;
public int fileSize;
public short reserved1;
public short reserved2;
public int fileOffsetToPixelArray;