Languages
2,101 gist results
2,101 gist results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _.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 '.'}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(' ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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' | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "directory" : "source/components" | |
| } | |
| # npm install -g bower | |
| # bower install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _ = 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 |