Skip to content

_.extend Backbone.View::
tagName: "div"
initialize: (@model = new Backbone.Model, @el = @build_element()) -> @delegateEvents()
# :api:private
klass_string: (parts=[]) ->
if @constructor is Backbone.View
parts.push "BackboneView"
".#{parts.join '.'}"
replaceWord: ->
          text = $( '#textarea' ).val().split(' ')
          word = text[text.length-2]
          index = text.length - 2
          ajax =
            url: 'http://words.bighugelabs.com/api/2/d60ba0946e7215aa09a94b94a20b4bbf/' + word + '/json'
            type: 'GET'
            dataType: 'jsonp'
            success: ( data ) ->
              text = $( '#textarea' ).val().split(' ')
@zeekay
zeekay / inject-args.coffee
Created June 26, 2013 20:08
Why would anyone ever want to do this? Reasons...
injectArgs = (func, args...) ->
rawFunc = func.toString()
argNames = (a.trim() for a in (/function \((.*)\)/.exec rawFunc)[1].split(','))
func = rawFunc.replace /function \((.*)\)/, 'function anonymous()'
if args.length != argNames.length
throw new Error 'Function arity must match number of passed arguments'
unless args.length > 0
return new Function func
@RegexHelpers =
# matches colors like #ffffff, #eee, rgb(255,255,255), and rgba(255, 255, 255, 0.25)
cssColorMatchString: '(?:#(?:[0-9a-f]{6}|[0-9a-f]{3}))|(?:rgba?\\((?:\\d+, *){2,3}(?:\\d+(?:\\.\\d+)?)\\))'
makeTagRegex: (tagName, attributeMatch=".*") ->
# matches:
# <tagName attribute>content</tagName>
# [tagName: attribute]content[/tagName]
# <tagName = attribute>content</tagName>
# <tagName>content</tagName>
@Geokoumpa
Geokoumpa / gist:11365481
Created April 28, 2014 08:30
Ember-model findMany implementation
# this calls to a resource collection path adding an 'ids' param with comma separated ids, e.g. /posts?ids="1,2,3"
Ember.RESTAdapter.reopen findMany: (klass, records) ->
url = @buildURL(klass)
params = ids: records._ids.join(",")
@ajax(url, params).then (data) ->
collectionKey = Ember.get(klass, "collectionKey")
dataToLoad = (if collectionKey then Ember.get(data, collectionKey) else data)
@ybiquitous
ybiquitous / test.coffee
Created July 23, 2012 09:27
CoffeeScript+Underscore.js+jQuery
jQuery ($) ->
nums = [20..0]
doms = _.map nums, (e, i, l) -> "<li>[#{i}]=#{e}</li>"
$("<ul>#{doms.join("")}</ul>").appendTo("body")
hoge =
name: "Hoge"
age: 10
@benmccormick
benmccormick / palindrome.coffee
Created April 14, 2013 17:40
Submission for Problem C of google code jam Qualification Round 2013 https://code.google.com/codejam/contest/2270488/dashboard#s=p2
fs = require('fs')
writevalue = (i, val)->
output += "Case #"+i+": "+val+"\n"
# is a palindrome (expects a string)
isPalindrome = (num) ->
reversed = (num).split("").reverse().join("")
num is reversed
@toumorokoshi
toumorokoshi / init.coffee
Last active October 2, 2018 05:43
My Atom Settings
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to make opened Markdown files always be soft wrapped:
#
# path = require 'path'
#
{
"directory" : "source/components"
}
# npm install -g bower
# bower install
_ = require('underscore')
log = console.log
getDistinctSortedSubsequences = (word) ->
# Sort the string
sorted = word.split("").sort().join("")
# Computes powerset of string
# Ref : http://rosettacode.org/wiki/Power_set#JavaScript