Skip to content

Instantly share code, notes, and snippets.

View Swivelgames's full-sized avatar

Joseph Dalrymple Swivelgames

View GitHub Profile
@Swivelgames
Swivelgames / ReferencableString.js
Last active August 29, 2015 14:04
Messing around with things and trying to find a good way to make a string reference-able...
var StringReference = function(scope, str) {
if(str===void 0) { str = scope; scope = window; };
Object.defineProperty(scope, "__"+str, {
configurable: true,
enumerable: false,
get: function(){
return scope[str];
},
set: function(val){
@Swivelgames
Swivelgames / ExecutableArray.js
Last active August 29, 2015 14:07
Executable Array (Executable Array of Callbacks)
/**
* @class ExecutableArray
* @extends Array.prototype
* @param {Array} arr Original Array (if any)
* @author Joseph Dalrymple <me@swivel.in>
* @description Implements `call` and `apply` on an Array-like object
*/
var ExtNodeList = (function(){
/**
* Constructor Function
@Swivelgames
Swivelgames / chat.js
Last active August 29, 2015 14:26
100-Line Challenge
var Chat = React.createClass({
getInitialState: function() {
return { messages: {} };
},
getLatestMessages: function() {
if(this.getAjaxReq) this.getAjaxReq.abort();
this.getAjaxReq = new XMLHttpRequest();
this.getAjaxReq.onreadystatechange = function(){
@Swivelgames
Swivelgames / jQueryPluginTemplate.js
Last active September 11, 2015 16:47
jQuery Plugin
;(function($,window,document,undefined) {
var PluginConfig = {
"name": "PluginName",
"defaults": {
"propertyName": "value"
}
};
var Plugin = function(element, options) {
this.settings = $.extend( {}, this._defaults, options );
var os = require('os');
var fs = require('fs');
global.Terminal.emit('echo', "Included OS, FS");
global.Terminal.registerCommand('cat', function (parts, raw, terminal) {
terminal.emit('echo', fs.readFileSync(parts[1]) + os.EOL);
terminal.emit('commandExit');
});
global.Terminal.emit('echo', "Attempted to register command `cat`");
@Swivelgames
Swivelgames / matrix.js
Last active June 9, 2016 20:43
Multiply Matrices
var Matrix; Matrix = (function(){
var Constructor = function(inp) {
if(typeof inp !== "object" || !inp.length) {
throw new TypeError("Matrix required");
}
this.matrix = inp;
this.length = {
y: this.matrix.length,
var Matrix; Matrix = (function(){
var Constructor = function(inp) {
this.length = Matrix.getMatrixDims(inp);
if(!this.length) {
throw new Error("Invalid matrix");
}
this.matrix = inp;
};
@Swivelgames
Swivelgames / example.js
Created July 14, 2016 17:12 — forked from kirbysayshi/LICENSE
Hierarchical Spatial Hash Grid: extremely efficient spatial hashing for collision detection between objects of any size! This is an implementation in JS as described in http://www10.informatik.uni-erlangen.de/~schornbaum/hierarchical_hash_grids.pdf
// The only thing HSHG expects a collidable object to have is a getAABB() method that
// returns an object with two properties, min and max, that should both have a single
// array with two numbers as coordinates. For example, an object at 10, 10 and
// height/width of 100 would return { min: [10, 10], max: [110, 110] }
function Vertex(args /*x, y, radius*/){
var argProp;
for(argProp in args){
if(args.hasOwnProperty(argProp)){
@Swivelgames
Swivelgames / A_Random_Gradient_Generator.js
Last active July 18, 2016 13:05
Random color gradient generator
import RGBAFader from "./RGBAFader.js";
var x = new RGBAFader();
var y = new RGBAFader();
var interval = setInterval( () => {
y.accuate();
x.accuate();
var rgbX = "rgb(";
@Swivelgames
Swivelgames / object-watch.js
Last active November 16, 2016 22:02 — forked from eligrey/object-watch.js
object.watch polyfill in ES5
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Modified by Joseph Dalrymple, http://swivel.in
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/