Skip to content

Instantly share code, notes, and snippets.

View ryanbrubaker's full-sized avatar

Ryan Brubaker ryanbrubaker

View GitHub Profile
@ryanbrubaker
ryanbrubaker / gist:3086157
Created July 10, 2012 20:51
Functional JavaScript inheritance
Function.prototype.method = function(name, func)
{
if (!this.prototype[name])
{
this.prototype[name] = func;
return this;
}
};
Object.method('superior', function(name)
@ryanbrubaker
ryanbrubaker / gist:3086065
Created July 10, 2012 20:32
Generated constructors from CoffeeScript class example
Animal = (function()
{
function Animal(name)
{
this.name = name;
}
Animal.prototype.move = function(meters)
{
return alert(this.name + (" moved " + meters + "m."));
@ryanbrubaker
ryanbrubaker / gist:3085501
Created July 10, 2012 18:54
CoffeeScript class utility functions
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent)
{
for (var key in parent)
{
if (__hasProp.call(parent, key))
child[key] = parent[key];
}
function ctor()
@ryanbrubaker
ryanbrubaker / gist:3085435
Created July 10, 2012 18:41
CoffeeScript class example taken from coffeescript.org
class Animal
constructor: (@name) ->
move: (meters) ->
alert @name + " moved #{meters}m."
class Snake extends Animal
move: ->
alert "Slithering..."
super 5
@ryanbrubaker
ryanbrubaker / gist:2886198
Created June 7, 2012 02:32
Decoder view for morse code demo
class DecoderView extends Backbone.View
initialize: ->
@model.bind('parsedCharacter', @render)
render: (token) =>
messageBox = $('#messageBox')
messageBox.val(messageBox.val() + token)
@ryanbrubaker
ryanbrubaker / gist:2886116
Created June 7, 2012 02:18
Decoder model for morse code demo
class MorseDecoder extends Backbone.Model
initializeKey: =>
"""
Omitting code that initializes the morse code key
dictionary.
"""
initialize: =>
@inputTokens = []
@ryanbrubaker
ryanbrubaker / gist:2886084
Created June 7, 2012 02:07
CommunicationLineView for morse code demo
class CommunicationLineView extends Backbone.View
initialize: ->
@model.bind('hasNewData', @render)
render: (tokens) =>
context = document.getElementById(
"communicationLineCanvas").getContext('2d')
context.clearRect(0, 0, context.canvas.width, 29)
tokenNum = 0
@ryanbrubaker
ryanbrubaker / gist:2872411
Created June 5, 2012 03:19
CommunicationLine model for morse code demo
class CommunicationLine extends Backbone.Model
initialize: (options) =>
@inputQueue = []
@communicationLine =
['', '', '', '', '', '', '', '', '', '']
@decoder = options.decoder
setInterval(@moveDataOneStep, 100)
@ryanbrubaker
ryanbrubaker / gist:2872372
Created June 5, 2012 03:17
StraightKey input view for morse code sample
class StraightKeyInput extends Backbone.View
initialize: ->
@dashTimer = null
@dashFlag = false
@wordStopTimer = null
@wordStopFlag = false
events:
'mousedown #straight-key': 'startTimers',
@ryanbrubaker
ryanbrubaker / gist:2872351
Created June 5, 2012 03:13
Function to draw morse code signal line
drawSignalLine = ->
context = document.getElementById(
"communicationLineCanvas").getContext('2d')
context.clearRect(0, 0,
context.canvas.width, context.canvas.height)
context.moveTo(0, 30)
context.lineTo(500, 30)
context.strokeStyle = "#000"