Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Ashkenas jashkenas

View GitHub Profile
View main_menu.coffee
class MainMenu
interviewEditor = null
highlight: (menuId) ->
$('#main_menu li').removeClass('active_menu_item')
$("#main_menu li##{menuId}").addClass('active_menu_item')
clearContentArea: ->
$('div#content').children().remove()
View gist:767470
console.log [
foo: 1
,
bar: 2
]
View forCapture.coffee
for f, index in files
extname = path.extname f
fs.lstat f, (err, stats) ->
if !stats.isDirectory() and extname is '.coffee'
fs.readFile f, 'utf8', compileCallback
else if stats.isDirectory()
readDirAfterThisOne = ->
if index is files.length - 1 then clearInterval(h) and processDir(f)
h = setInterval readDirAfterThisOne, 50
View alternative.js
this.set({status: status});
this.trigger("change:status", this, status);
View findPos.coffee
class Utilities
@findPos: (obj) ->
obj = obj.get(0) if obj.html?
left = top = 0
measure = ->
left += obj.offsetLeft
top += obj.offsetTop
measure()
measure() while obj = obj.offsetParent
View gist:669419
getstyles ->
result = {}
for key in arguments
result[key] = this.getStyle(key)
return result
View assets.yml
package_assets: on # (on, off, always)
embed_assets: on # (on, off, datauri)
compress_assets: on # (on, off)
gzip_assets: on # (on, off)
template_function: _.template # (defaults to the built-in micro-templating)
package_path: packages # (defaults to assets)
javascript_compressor: closure # (yui, closure)
compressor_options:
compilation_level: ADVANCED_OPTIMIZATIONS
View object.coffee
assert.deepEqual item, {
x: 1
y: 2
}
# Or:
assert.deepEqual item,
View view_model.coffee
class ViewModel
firstName: ko.observable 'Bob'
lastName: ko.observable 'Smith'
constructor:
names = -> @firstName() + ' ' + @lastName()
@fullName = ko.dependentObservable names, this