Skip to content

Instantly share code, notes, and snippets.

@geraldalewis
geraldalewis / ringer.js
Created April 14, 2017 15:38
Smart styled <button> focus ring behavior
function initializeRinger(){
var pressedAt = 0;
document.removeEventListener('DOMContentLoaded', initializeRinger);
function checkRing(target){
if (!target.classList.contains('ringer')) return;
if (target.classList.contains('ringer-no-ring')) return;
target.classList.add('ringer-no-ring');
}
function onpress(event){
@geraldalewis
geraldalewis / gist:3742581
Created September 18, 2012 10:59
Do does
class Frame
constructor: (@elements) ->
methods = ['remove', 'show', 'hide', 'stop']
for method in methods
do (method) ->
Frame::[method] = ->
element[method]() for element in @elements
@geraldalewis
geraldalewis / implicit_this.coffee
Created February 18, 2012 02:08
Implicit `this` in CoffeeScript
class Sprite
@id: 0
id: -1
x: 0
y: 0
width: 0
height: 0
@geraldalewis
geraldalewis / gist:1711902
Created January 31, 2012 18:03
Emulating `let`
var print = console.log;
var header = function(name){print("\n>>"+ name.toUpperCase() +"<<")}
var subheader = function(name){print(" >"+ name +"< ")}
header("iterating arrays");
subheader("emulated let");
(function() {
var callbacks = [];
@geraldalewis
geraldalewis / gist:1608379
Created January 13, 2012 19:55
default arguments order
# non-default params = true arity;
# args <= arity: apply args to non-defaults first, in order
# args > arity: apply args in order
f = (a=0,b,c=2) ->
f() # a = 0 b = undefined c = 2
f(1) # a = 0 b = 1 c = 2
f(1,2) # a = 1 b = 2 c = 2
@geraldalewis
geraldalewis / gist:1142542
Created August 12, 2011 17:42
Full diff of src/ for patch #1590 for issue #1234
diff --git a/src/grammar.coffee b/src/grammar.coffee
index e57ab39..035e168 100644
--- a/src/grammar.coffee
+++ b/src/grammar.coffee
@@ -217,7 +217,7 @@ grammar =
# Variables and properties that can be assigned to.
SimpleAssignable: [
o 'Identifier', -> new Value $1
- o 'Value Accessor', -> $1.push $2
+ o 'Value Accessor', -> $1.add $2
@geraldalewis
geraldalewis / 1002_patches.diff
Created July 25, 2011 16:32
1002_identical_params..1002_identical_params_revised
diff --git a/src/nodes.coffee b/src/nodes.coffee
index 1697c44..cc382d7 100644
--- a/src/nodes.coffee
+++ b/src/nodes.coffee
@@ -1076,19 +1076,23 @@ exports.Code = class Code extends Base
o.scope = new Scope o.scope, @body, this
o.scope.shared = del o, 'sharedScope'
o.indent += TAB
- o.uniqs = {}
delete o.bare
adsf'
asdf
@geraldalewis hello.
@geraldalewis
geraldalewis / debug_mode_for_coffee_script.md
Created May 15, 2011 23:10
Debug mode for running .coffee scripts #558, #987

Debug mode for running .coffee scripts #558, #987

Adds a --debug option for .coffee scripts that outputs more helpful error messages (mapping compiled .js lines of code to the input .coffee file's lines).

This branch should be considered experimental at the moment -- it serves as a proof-of-concept and to expose additional issues with adding debugging support to CoffeeScript

Current output:

TypeError: string is not a function