Skip to content

Instantly share code, notes, and snippets.

@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 / beautify.coffee
Created November 10, 2012 04:07
CoffeeScript beautify function
beautify: (string, indent = 0) ->
switch ch = string[0] || ''
when '' then ""
when '{' or '[' then "#{ch}\n#{Array(++indent+1).join('\t')}#{@beautify(string[1..], indent)}"
when '}' or ']' then "\n#{Array(--indent+1).join('\t')}#{ch}#{@beautify(string[1..], indent)}"
when ',' then "#{ch}\n#{Array(indent+1).join('\t')}#{@beautify(string[1..], indent)}"
when ':' then " : #{@beautify(string[1..], indent)}"
else "#{ch}#{@beautify(string[1..], indent)}"
@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.js
Created November 16, 2012 17:17
empty node.js project
// Code me, yo!
@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 / proto.js
Created November 22, 2012 14:49
JavaScript OOP Example
// knowing three things is essential for JavaScript OOP
// ---
// #1 the concept of "closures" (and functional scoping in general)
// #2 knowing how the keyword "this" works, and how to use it.
// #3 knowing when to use the keyword "new"
// example of an OOP style JavaScript class implementation
var ProtoClass = (function(){
// these would be your "private" variables, (in the sense that it can no longer be modified from the outside)
// if you send any of this stuff to the client, its clearly visible with any decent browser Developer Tools