coffeescript

coffeescript return function callback acting strange

允我心安 提交于 2019-12-13 04:55:05
问题 let's say i have a simple function like that: foo -> User.findById someId, (err, user) -> return "hello #{user.name}" coffeescript translate it to that: foo(function() { return User.findById(someId, function(err, user) { return "hello " + user.name; }); }); so there are 2 returns here from some reason, but i just want to return the "hello" after the callback. the only way i found not to return a function when i use it is by closing it with a return (that is a weird workaround). so: foo ->

Q.all doesn't call tasks

流过昼夜 提交于 2019-12-13 04:44:00
问题 So I have this CoffeeScript (simplified to focus on the real problem) Q = require 'q' events = require 'events' class SomeObj extends events.EventEmitter constructor: () -> setTimeout () => @emit 'done' , 3000 class SomeObj2 extends events.EventEmitter constructor: () -> setTimeout () => @emit 'done' , 50000 class Main someObj1: null someObj2: null constructor: () -> Q.all([ => @task1(), => @task2()]) .then (results)-> console.log 'results' console.log results .catch((error)-> console.log

How do I dynamically update socket.io callbacks without restarting the server?

落花浮王杯 提交于 2019-12-13 04:37:57
问题 If I have a directory of files that say are in the following format: module.exports = 'add': (socket, data...) -> console.log 'words:add handler'.rainbow, data... socket.emit 'talkback', 'hahahha' How do I include those files and when they are changed, update all connected socket.io clients to use the new callbacks. If the filename is words.controller.coffee , I'd like the callback to be words:add . So every time a new socket connects, how do I make each file that's already been loaded bind

Node not requiring *.coffee files

半世苍凉 提交于 2019-12-13 04:35:52
问题 According, to https://stackoverflow.com/a/4769079/347915, I should be able to require a .coffee file from a .js file: $ echo 'console.log "works"' > module.coffee $ echo ' > require("coffee-script") > require("./module") > ' > test.js $ node test.js works However, when I do that, I get this message when running test.js: module.js:340 throw err; ^ Error: Cannot find module './module' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module

Using mouse cursor position as a range starting point in CoffeeScript/JavaScript

风流意气都作罢 提交于 2019-12-13 04:34:48
问题 As the title states, I would like to use my cursor's position as the start point to a range. Right now have simple sample like this <html> . . <p>The quick brown fox jumps over the lazy dog</p> . . </html> On the CS/JS side of things I have event listen set to mouse move that attempts to print out the offset for the cursor position, however I am not using the correct method and end up getting either undefined or no method error s. Again, really simple CS for the time being since I really just

how I can get line number with error in coffeescript file

笑着哭i 提交于 2019-12-13 04:31:49
问题 In node.js express app and nodeunit tests I widely use coffeescript without saving resulting javascript files on disk to avoid project clogging by javascript translations. When I got any error in coffeeScript file I see in console: the filename where error was occured and line number (for example 37): /pathTo_File/fileName.coffee:37 . But I dont have 37th line in my coffee file!!! I have two times less lines there. I guess that I got error on 37th row in my output javascript file, but I don't

Three.js camera rotation issue

自古美人都是妖i 提交于 2019-12-13 04:22:22
问题 I want to rotate the camera around the x-axis on the y-z plane while looking at the (0, 0, 0) point. It turns out the lookAt function behaves weird. When after rotating 180°, the geometry jump to another side unexpectedly. Could you please explain why this happens, and how to avoid it? You can see the live demo on jsFiddle: http://jsfiddle.net/ysmood/dryEa/ class Stage constructor: -> window.requestAnimationFrame = window.requestAnimationFrame or window.webkitRequestAnimationFrame or window

Method to obscure URL from bots (similar to tripadvisor.com)

元气小坏坏 提交于 2019-12-13 04:00:00
问题 The URL to the Restaurant's website seems to be encoded in a way that it is not scrapable by a bot, yet when clicked on by a user, the URL loads in a new window: http://www.tripadvisor.com/Restaurant_Review-g57415-d805527-Reviews-Harrison_s_Restaurant_Bar-Stowe_Vermont.html The source for the span tag for the 'Website' link is below. How is tripadvisor obscuring/encoding the URL? Is there a way to replicate this or an existing library with similar functionality available? <span class="taLnk

Atom Editor - Body Keybind for Everything Except Vim Mode Insert

无人久伴 提交于 2019-12-13 04:00:00
问题 I am an avid Vim user who recently decided to give Atom a try. In vim I map ,bn & ,bp to next buffer and previous buffer, respectively. I am trying to imitate the same behavior in Atom for switching between tabs. In my keymap.cson file I have the following: 'body': ', b n': 'pane:show-next-item' ', b p': 'pane:show-previous-item' This will work except if I try to type just the ',' character in Vim mode insert it will not display unless I hit ',' twice. I thought maybe the following would work

Making a calculation for a modal using coffeescript

北战南征 提交于 2019-12-13 03:58:15
问题 I am trying to make it so a user can input 3 numbers and when they click the submit button they will see a modal with the calculations from these 3 numbers within the modal. I am unsure how to accomplish this. I have the calculation in my controller. class WelcomeController < ApplicationController def how_much @price = (params[:amount]) @mortgage = (params[:high_rent]) @rent = (params[:current_rent]) if @price && @mortgage && @rent.present? @monthly_savings = @mortgage - @rent @savings_goal =