Skip to content

Instantly share code, notes, and snippets.

@pyrobot
pyrobot / app.js
Created November 16, 2012 17:17
empty node.js project
// Code me, yo!
@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
@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 / BackgroundPlane.cs
Created December 23, 2012 14:23
(Unity3D) Attach to a Camera and on runtime, the script creates a background gradient plane and initially fills it with the colors set in the Editor. Other scripts can then change the gradient color by calling: BackgroundPlane.TopLeftColor = new Color(...); // or TopRightColor, BtmLeftColor, BtmRightColor
using UnityEngine;
using System;
using System.Collections;
public class BackgroundPlane : MonoBehaviour {
static BackgroundPlane _this;
public Color topLeftColor, topRightColor, btmRightColor, btmLeftColor;
void spread(Transform area, ref GameObject[] array) {
int l = array.Length;
if (l > 1) {
Vector3 center = area.collider.bounds.center, extents = area.collider.bounds.extents;
float top = center.y + extents.y,
bottom = center.y - extents.y;
bool allSpread;
int tries = 0, maxTries = 5000;
float bumpDist = 1.5f;
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>w
</head>
<body>
</body>
</html>
@pyrobot
pyrobot / example.js
Created May 17, 2013 23:58
"pseudocode" example
/*
app = express()
db = a mongodb with the collection "users"
*/
app.get('/user/:name', function (req, res) {
db.users.find({name: req.params.name}, function (theRecordThatYouAskedFor) {
res.render('mytemplatename', { myTemplateVariableThatHoldsUserInfo: theRecordThatYouAskedFor})
});
@pyrobot
pyrobot / main.coffee
Created May 9, 2013 23:06
impactjs smoke test
ig.module(
'game.main'
).requires(
'impact.game'
'impact.font'
).defines ->
MyGame = ig.Game.extend
font: new ig.Font('media/04b03.font.png')
init: ->
# Initialize your game here; bind keys etc.
table.andys-table {
thead tr {
font-weight: bold;
}
tbody {
tr {
border-right: 1px solid #ddd;
td:first-child {
font-weight: bold;