Skip to content

Instantly share code, notes, and snippets.

Greg Smith incompl

Block or report user

Report or block incompl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@incompl
incompl / ctor_name_inheritance.js
Created Oct 17, 2011
.name property, constructors, inheritance
View ctor_name_inheritance.js
// A weird bug when you inherit from a constructor. You shouldn't
// inherit from a constructor but when I accidentally did I noticed
// this weirdness.
function Foo() {}
// this should be Object.prototype, or {}, or omitted completely,
// but certainly not the Object constructor. Still, what follows
// isn't exactly what you'd expect...
Foo.prototype = Object;
@incompl
incompl / __proto__ dne constructor.prototype.js
Created Oct 20, 2011
Shows that .__proto__ is not the same as .constructor.prototype
View __proto__ dne constructor.prototype.js
function Parent() {}
var parent = new Parent();
function Child() {}
Child.prototype = parent;
var child = new Child();
// child inherits directly from parent. this makes sense.
console.log(child.__proto__ === parent); // true
console.log(child.__proto__ === Parent.prototype); // false
@incompl
incompl / box2dweb-example.js
Created May 11, 2012
Example of box2dweb with C++ heritage noted in comments
View box2dweb-example.js
// Code from http://lib.ivank.net/?p=demos&d=box2D
// These look like imports, but in JavaScript they are just busy-work.
var
b2Vec2 = Box2D.Common.Math.b2Vec2,
b2BodyDef = Box2D.Dynamics.b2BodyDef,
b2Body = Box2D.Dynamics.b2Body,
b2FixtureDef = Box2D.Dynamics.b2FixtureDef,
b2World = Box2D.Dynamics.b2World,
b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
@incompl
incompl / gist:2925304
Created Jun 13, 2012 — forked from buhrmi/gist:1344659
Sublime Text 2 Git Annotation Colors
View gist:2925304
<dict>
<key>name</key>
<string>Git Modified Line</string>
<key>scope</key>
<string>git.changes.x</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#212340</string>
</dict>
View gist:3091064
<head>
...
<!-- source files for development -->
<!-- <script src="src/setup.js"></script> -->
<!-- <script src="src/player.js"></script> -->
<!-- <script src="src/enemy.js"></script> -->
<!-- <script src="src/bullet.js"></script> -->
<!-- <script src="src/explosion.js"></script> -->
<!-- concatenated / minified source for production -->
View gist:3757477
var state = [{
id: 0,
transform: {
position: {
x: 15.290663048624992,
y: 2.0000000004989023,
z: -24.90756910131313
},
rotation: {
x: 0.32514392007855847,
View gist:3757489
var char = new Int8Array( 1 );
// uchar now shares the same ArrayBuffer as char.
var uchar = new Uint8Array( char.buffer );
char.buffer === uchar.buffer; // true
char[0] = -1;
uchar[0] === 255; // true, same data interpreted differently
var arr = new Float64Array([15.290663048624992]);
View gist:3757491
// Compact the state.
var slimmerState = new Float64Array([
0,
15.290663048624992,
2.0000000004989023,
-24.90756910131313,
0.32514392007855847,
-0.8798439564294107,
0.32514392007855847,
0.12015604357058937,
View gist:3757494
var encodeUint8 = (function() {
var arr = new Uint8Array( 1 );
return function( number ) {
// If we assume that the number passed in
// valid, we can just use it directly.
// return String.fromCharCode( number );
arr[0] = number;
return String.fromCharCode( arr[0] );
};
}());
View gist:3757496
// Shared code
var MsgType = {
"game start": String.fromCharCode(0),
"update state": String.fromCharCode(1),
"private message": String.fromCharCode(2)
};
var MsgTypeLookup = [
"game start",
"update state",
You can’t perform that action at this time.