Apache ProxyPass and Cache-Control

website.conf
1
2
3
4
5
6
7
8
9
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule headers_module modules/mod_headers.so
ProxyRequests off

<LocationMatch "/s3/">
ProxyPass http://s3.amazonaws.com/your_bucket/
Header set Cache-Control "max-age=290304000, public"
</LocationMatch>

Keep Your Framerate Out of My Physics - Part I

Never let your physics simulation depend on something as unreliable and capricious as the machine’s framerate.

When I was building Electric Field Hockey I used window.requestAnimationFrame to control the time-step for all the physics calculations.

Simulation Tick Function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Simulation.prototype.tick = function(frame) {
var ts = frame.timeDiff / 1000;
var puck = this.puck;
var force = puck.charge.calcForceFrom( this.charges );
var newPosition = EFH.Physics.calcPosition(puck.charge,
puck.velocity, force, ts);
puck.velocity = EFH.Physics.calcVelocity(puck.velocity,
force, ts);

puck.moveTo(newPosition.x, newPosition.y);

};

var init = function() {
/* SNIP */
self.anim = new Kinetci.Animation(function(frame) {
self.tick( frame );
});
};

It’s easy and straight forward: every time the browser wanted a new frame, we can calculate the forces, apply them to the objects, and figure out the new positions.

But it’s also simplistic.

Read More

Ray Tracing in JavaScript

I wanted to learn a little about ray tracing, and I’m kind of obsessed with javascript at the moment so i cranked out this little gem. I’m planning to add more features to it when I get a chance, but for now you can set the parameters for the sphere and location of the light source. Press ‘Trace’ to get an image on the canvas (which may take a few seconds).

Read More

Optimizations in the Google Analytics tracking snippet

This is not an instructional post on how to use Google Analytics, but a quick teardown to highlight some clever things the script does to optimize page load speed and work around network latency issues.

How does the Google Analytics tracking snippet work? The code they tell you to paste into your site is an opaque mess:

1
2
3
4
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

Lets clean up the function contents a little bit.

Read More

Code Rainbow

Oh the joys of writing CRUD methods. Found this gem in one of the applications I helped maintain. Its been replaced with the much more terse null-coalescing operator by now.

Who doesn’t love 1000 lines of CRUD methods?

?? anyone?

Its crud like this that makes an ORM look so appealing.