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;
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;
@pyrobot
pyrobot / code.coffee
Last active December 16, 2015 22:19
coffeescript is awesome
class View
class @Pieces
@keys = ['floor', 'ceiling', 'side', 'front']
@floorPieces = document.getElementsByClassName('floor')[0].children
@ceilingPieces = document.getElementsByClassName('ceiling')[0].children
@sidePieces = document.getElementsByClassName('side')[0].children
@frontPieces = document.getElementsByClassName('front')[0].children
@allPieces = floor: @floorPieces, ceiling: @ceilingPieces, side: @sidePieces, front: @frontPieces
class @Utils
@hide = (e) -> e.style.display = 'none'
@pyrobot
pyrobot / index.html
Last active December 16, 2015 19:30
injecting angular elements from strings of html
<!DOCTYPE html>
<html ng-app>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.1/angular.min.js"></script>
</head>
<body>
<script>
var
domString = '<div>{{1+2}}</div>',
injector = angular.injector(['ng']),
# get container
container = document.getElementById "container"
# create renderer and add to container
renderer = new THREE.WebGLRenderer
renderer.setSize container.offsetWidth, container.offsetHeight
container.appendChild renderer.domElement
# create the scene and camera
scene = new THREE.Scene