This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get current time when page is first run | |
// (the + prefix is magic that will cast it into a timestamp) | |
var startTimestamp = +new Date(); | |
window.addEventListener('beforeunload', function () { | |
// get current time when the beforeunload event is fired | |
var endTimestamp = +new Date(); | |
// calculate deltas | |
var deltaTimestamp = endTimestamp - startTimestamp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<style> | |
.chart rect { | |
stroke: #FFF; | |
fill: steelblue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Demo</title> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<style type="text/css"> | |
body { | |
font: 14px Helvetica Neue; | |
text-rendering: optimizeLegibility; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var person = (function(){ | |
return new function() { | |
this.name = 'Justin'; | |
} | |
})(); | |
(function(person){ | |
var type = person.type = {}; | |
type['job'] = 'JavaScript Developer'; | |
type['likes'] = ['Closures', 'Anonymous Functions']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code me, yo! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool Nearby(Point enemyLoc, Point playerLoc, int distance, Direction direction) | |
{ | |
//it helps human understanding and debugging to do all your calculations seperately, instead of one massive hard to read switch/if statements | |
bool isNearby = false; | |
//get the deltas | |
int deltaX = playerLoc.X - enemyLoc.X, | |
deltaY = playerLoc.Y - enemyLoc.Y; | |
//determine direction, you may need to flip which one is negative and positive for it to work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script> | |
<style> | |
.chart rect { | |
stroke: #FFF; | |
fill: steelblue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<style> | |
.chart rect { | |
fill: steelblue; | |
stroke: white; | |
} | |
</style> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProtoClass | |
privateData = "sekretCodes" | |
constructor: -> | |
@someData = "i'm a true, blue object!" | |
@someValue = true | |
@someType = "blue" | |
privateMethod = (stuff) -> | |
console.log("i'm a #{this.someValue}, #{this.someType}, private method!") | |
console.log("i was called with #{stuff}, but i can access the private stuff too: #{privateData}") | |
innerMethod: (stuff) -> privateMethod.call(this, stuff) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to extend a class through its prototype | |
// useful for OOP style inheritance | |
// "inspired" by CoffeeScript's extend pattern | |
var extendz = function (child, parent) { | |
// cache the "Object.hasOwnProperty" function | |
// it's going to be called for every key on the parent | |
var hasOwnProp = {}.hasOwnProperty, | |
// CoffeeScript's extend function |
OlderNewer