coffeescript

Fischer Yates shuffle in coffee-script

*爱你&永不变心* 提交于 2019-12-11 12:58:19
问题 Assuming that Math.random() produces evenly distributed random numbers between 0 and 1, is this a correct implementation of the Fischer Yates shuffle? I am looking for a very random, even distribution, where the number of shuffled elements in an input array ( arr ) can be specified (as required ). shuffle = (arr, required)-> rnd = (int) -> r = Math.random() * int Math.round r len = arr.length-1 for i in [len..1] random = rnd(i) temp = arr[random] arr[random] = arr[i] arr[i] = temp break if i

Why doesn't javascript “this” work with “each”?

假如想象 提交于 2019-12-11 12:24:06
问题 I'm trying to assign a class to an element upon detecting that it has a data-voted attribute of "true" , but the simple addClass line is not working. I was using $(this) until I read jQuery's documentation for each() , and then switched to the following: windowReady = -> jQuery -> $voteLinks = $('.vote-button a') $voteLinks.each (i, current) -> if $(current).data('voted') == "true" $(current).addClass('voted') $(window).load(windowReady); $(window).on('page:load', windowReady); $(this)

Pull Entire Module into current scope Node.js

守給你的承諾、 提交于 2019-12-11 11:53:33
问题 I'm trying to pull an entire module into the current scope of another file after a require call. For instance if my module looks like this: exports.chai = require "chai" exports.mocha = require "mocha" exports.Q = require "q" How can I then access the individual variables like they are global variables in the current file? So instead of doing something like requireVar.chai I can just type chai? Thanks for any advice 回答1: Using coffeescript, I recommend you use the destructuring assignment

how to get a model by array params from a collection

天大地大妈咪最大 提交于 2019-12-11 11:44:34
问题 I have a model like this: model = from: "a@b.com" id: 1 to: [c@d.com] and I have a collection containing these kind of models. The collection needs to filter by from . I know _.where an underscore.js function. I am using it like this: fromIds = _.pluck _.where(msgs, from : login), 'msgId' and need to filter by 'to' as well: toIds = _.pluck _.where(msgs, to : login), 'msgId' it does not work, because to is an array. How can I filter by to ? I would be grateful if someone helped me out ! 回答1:

How to highlight the “->” symbol in my coffee.vim syntax file?

纵然是瞬间 提交于 2019-12-11 11:41:49
问题 I just copied javascript.vim into coffee.vim now coffee files are highlighted like js files. Now I would like to make the CoffeScript function arrow "->" the same color as: hi Special guifg=#66D9EF guibg=bg gui=italic I'm not really sure where to start. Any suggestions? syntax/coffee.vim: " Language: CoffeeScript " Maintainer: Mick Koch <kchmck@gmail.com> " URL: http://github.com/kchmck/vim-coffee-script " License: WTFPL if !exists("main_syntax") if version < 600 syntax clear elseif exists("b

webstorm 7/karma server looking for wrong sourcemap file when debugging coffeescript

旧巷老猫 提交于 2019-12-11 11:21:16
问题 I am having a devil of a time trying to get the debugger to work with my coffeescript files when testing with the karma test runner. Supposedly, all I need to do is tell the Webstorm file watcher to generate sourcemaps and the debugger will work with the karma test runner. Unfortunately, the debugger doesn't seem to recognize the map file output by the coffeescript compiler. It looks for file.coffee -> file.js.map. However, despite trying to get some other result the map file is always file

Not able to display Month names on Rickshaw Graph on Coffeescript

倖福魔咒の 提交于 2019-12-11 11:14:47
问题 I am working on a project using Sinatra based framework called Dashing. Part of my project is to create a graph using RickShaw Graph. My problem is that I am not able to display month names and dates on the X-Axis. I am using coffeescript to render these values. Here is the code for the graph: class Dashing.Graph extends Dashing.Widget @accessor 'points', Dashing.AnimatedValue @accessor 'current', -> return @get('displayedValue') if @get('displayedValue') points = @get('points') if points

Adding field in Mongoose plugin gives “TypeError: Invalid value for schema path `CreatedBy.type`”

*爱你&永不变心* 提交于 2019-12-11 11:14:38
问题 I'm trying to make a CreatedBy Mongoose plugin, but when trying to use the ObjectId as the field type it gives me ( "account" is another defined collection already): TypeError: Invalid value for schema path `CreatedBy.type` & here is the plugin code: mongoose = require 'mongoose' module.exports = exports = updatedByPlugin = (schema, options) -> schema.add CreatedBy: type: mongoose.Schema.Types.ObjectId ref: "account" schema.pre "save", (next) -> @CreatedBy = options.accountId next() return

Filter response in jQuery autocomplete

半世苍凉 提交于 2019-12-11 10:54:52
问题 I'm trying to implement jQuery.autocomplete which I use to enter tags (much like here on SO). However, I don't want to show tags that I have already in my list. If I have added foo already I don't want it to show up as a suggestion. The list of tags are fetched from my server. However, I have some issues with altering the ui.content object. I use the response method found here: response: (event, ui)-> # Fetch already added tags current = $('input#photo_tag_list').val().split(',') # Filter out

heroku coffee-rails failure in asset precompile

☆樱花仙子☆ 提交于 2019-12-11 09:47:18
问题 Deploying Rails 3.2.14, Ruby 2.0.0 to heroku git push heroku master Counting objects: 15, done. Delta compression using up to 8 threads. Compressing objects: 100% (9/9), done. Writing objects: 100% (9/9), 895 bytes, done. Total 9 (delta 7), reused 0 (delta 0) -----> Ruby/Rails app detected -----> Using Ruby version: ruby-2.0.0 -----> Installing dependencies using Bundler version 1.3.2 Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -