Skip to content

Instantly share code, notes, and snippets.

@pyrobot
pyrobot / gist:9a0cae16b391d458b189
Created December 2, 2014 19:16
track page view time
// 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;
@pyrobot
pyrobot / index.html
Created November 9, 2012 18:46
bars demo
<!doctype html>
<html>
<head>
<script src="http://d3js.org/d3.v2.js"></script>
<style>
.chart rect {
stroke: #FFF;
fill: steelblue;
}
@pyrobot
pyrobot / index.html
Created November 9, 2012 19:24
d3 circles!
<!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;
@pyrobot
pyrobot / life.js
Created November 16, 2012 14:05
me in a nutshell
var person = (function(){
return new function() {
this.name = 'Justin';
}
})();
(function(person){
var type = person.type = {};
type['job'] = 'JavaScript Developer';
type['likes'] = ['Closures', 'Anonymous Functions'];
@pyrobot
pyrobot / app.coffee
Created November 16, 2012 17:20
empty node.js project (Coffee flavored)
# Code me, yo!
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
@pyrobot
pyrobot / index.html
Created November 21, 2012 03:39
start / end graph
<!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;
}
@pyrobot
pyrobot / index.html
Created November 21, 2012 13:09
visualization of reading data from a stream
<html>
<head>
<script src="http://d3js.org/d3.v2.js"></script>
<style>
.chart rect {
fill: steelblue;
stroke: white;
}
</style>
</head>
@pyrobot
pyrobot / coffeeObject.coffee
Created November 23, 2012 03:25
example of an object in coffeescript
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)
@pyrobot
pyrobot / extendz.js
Created November 24, 2012 15:48
JavaScript Object inheritance
// 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