Skip to content

Instantly share code, notes, and snippets.

View iaincarsberg's full-sized avatar

Iain Carsberg iaincarsberg

View GitHub Profile
@iaincarsberg
iaincarsberg / angleOmatic.js
Created January 4, 2012 13:32
Contains some JS to find the angle between shapes
/**
* Used to create a new Vector2
* @param float x Contains the x coord
* @param float y Contains the y coord
*/
function Vector2(x, y) {
this.x = x;
this.y = y;
}
@iaincarsberg
iaincarsberg / config.js
Created December 15, 2011 09:35
The good parts config for NodeLint.tmbundle
/*
* This is the customized options file for nodelint.js being run through TextMate.
* Properties listed here will override the default properties within nodelint.js options.
* Commented out properties are the same in the default configuration.
* predef handles global variables used throughout different frameworks.
*
* Changes released into the Public Domain by tav <tav@espians.com>
* Options support added by Corey Hart <corey@codenothing.com>
*
*/
@iaincarsberg
iaincarsberg / Flow.js
Created October 17, 2011 15:43
Demos of two possible level loading syntaxes.
// Less pretty syntax, super simple to implement, generic reusable implementation
flow.exec(
function () {
new Entity().addComponent('level', this)
},
function (err, level) {
level.addComponent('level-segment', 'something.json', this)
},
function (err, level) {
level.addComponent('level-segment', 'something-else.json', this)
@iaincarsberg
iaincarsberg / output.txt
Created October 6, 2011 15:59
RequireJS - Compose.js - Chaining Multiple Constructors
Animal - this {}
Animal - debug: [ muppet , bert ]
Hello, my name is bert and I am a muppet
returned: { species: 'muppet', name: 'bert' }
****************************************
Muppet - this {}
Muppet - debug: [ ernie ]
Animal - this {}
Animal - debug: [ muppet , ernie ]
Hello, my name is ernie and I am a muppet
@iaincarsberg
iaincarsberg / main.js
Created October 4, 2011 10:58
RequireJS - Compose.js - Utility/Helper functions
/*global require*/
require('whom', function (Whom) {
if (Whom.allOver18(
new Whom('Iain', 27),
new Whom('Bob', 53),
new Whom('Rob', 19)
)) {
console.log('Drink!');
} else {
console.log('Banned');
@iaincarsberg
iaincarsberg / main.js
Created October 4, 2011 10:50
RequireJS - Compose.js together
/*global require*/
require(['whom'], function (Whom) {
var me = new Whom('Iain', 27);
});
@iaincarsberg
iaincarsberg / lineIntersection.js
Created September 28, 2011 09:30
The lineIntersection function from the thorny/math/poly2.js class file
/**
* Used to find an intersection between two points.
* @param vector2
* @return obj|false if intersection happened returns array of x/y
* otherwise fales.
*/
lineIntersection: function (v1, v2, v3, v4) {
var
bx,
by,
@iaincarsberg
iaincarsberg / app.js
Created September 22, 2011 19:11
RequireJS
/*global define console*/
require.config({
baseUrl: '/src',
packages: [
{
name: 'underscore',
main: 'underscore',
location: '/lib/underscore'
}
],
@iaincarsberg
iaincarsberg / gist:1216206
Created September 14, 2011 09:43
jQuery snippet for accessing a controller implemented using https://github.com/managedit/kohana-api
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="/js/libs/json2.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$.ajax({
url: '/api/login',
type: 'POST',
data: JSON.stringify({id: 123}),
processData: false,
contentType: 'application/json',
@iaincarsberg
iaincarsberg / vector2.spec.js
Created July 12, 2011 09:36
Real world usage of Jasmine compared to Qunit
/*global console window describe xdescribe it expect runs waits*/
(function () {
require.paths.unshift(__dirname + '/../../../');
require('thorny/base')('./config/default.json')(function ($) {
describe('a vector2', function () {
it('should contain the following functions', function () {
var vector2 = $('thorny math vector2');
expect(typeof vector2.factory).toEqual('function');
expect(typeof vector2.centroid).toEqual('function');