Coffeescript is an alternative syntax for Javascript.
3
votes
2answers
61 views
How can I remove DRY violations from this event handling code?
I've got a bunch of event handlers that follow this pattern:
$('.class1').on "click tap", (event) ->
a(event)
stopPropagation(event)
$('.class2').on "click tap", (event) ->
b(event)
...
0
votes
0answers
15 views
Improvements to my binary tree written in CoffeeScript
This is my attempt at a binary tree. I'm using it only for ordering a LDAP user list. My need is for storing multiple objects, so this tree is limited to leaves that are objects (see data = {[..]}.
...
3
votes
0answers
42 views
How to refactor this series of JavaScript promises?
This is part of a class for paginating a Backbone collection.
The paginateTo method is for paginating to a model id. It returns the model if it's already in the collection, otherwise it checks with ...
2
votes
0answers
46 views
Review of the Core class of a Javascript framework for maintainable & scalable Single-Page-Applications
A few years ago I started building a tiny (~300 SLOC) JavaScript framework for scalable and maintainable Single-Page-Applications written in CoffeeScript:
https://github.com/flosse/scaleApp and ...
0
votes
0answers
5 views
Assigning object to instance variable during iteration [migrated]
I'm using this peculiar syntax for assigning an object to an instance variable during a list iteration:
execute: =>
while @canExecute()
for @currentStack in @stacks
@executeNext()
...
2
votes
2answers
53 views
isRTL.coffee - A JavaScript Library to determine if a text is of Right To Left direction
I just wrote this tiny library called isRTL.coffee to determine the direction of the text. Is there any better way of doing this?
original code:
rtlChars = '\u0600-\u06FF' # Arabic - Range
...
2
votes
2answers
78 views
Fibonacci using cache
This is my simple Fibonacci implementation in CoffeeScript. What do you think? Using cache (fibResults), it's very very fast.
fibResults = []
defaultMax = 1000
nrMax = defaultMax
fibonacci = (n) ...
1
vote
0answers
62 views
Handling multiple Mongodb connections in Node.js (using Mongolia)
I have a situation where I have multiple objects that each needs to connect to a different mongodb uri.
I am currently testing this using mongolia but the concept should be the same if I were to use ...
3
votes
2answers
219 views
coffeescript and lodash unelegant
# Get the outliers of both the dates and values
maxDate = []
minDate = []
maxVal = []
minVal = []
for k, v of series
for d, i in v
series[k][i][1] = nearZero if d[1] is 0
...
0
votes
1answer
65 views
Coffeescript Review
class ShareModel
constructor: ->
questionaireView = new QuestionnaireView
@previewImages =
shareCurrent: -> ...
1
vote
1answer
51 views
CoffeeScript: multiple changes of scope and big if/else
I just wrote this, and cleaned it up as much as I could. A couple things worry me.
I change the scope of $(this) twice (and apparently don't know how to use =>)
The big if if/else statement. Is ...
2
votes
1answer
72 views
Coffeescript Operators: use &&, ||, etc., or keyword operators?
I often use js2coffee.heroku.com to help me convert JS to CoffeeScript. Here was a line of JS I was converting.
if ( $this.is(':checked') && radioLabel.data('showif') === 'yes' ){
In ...
2
votes
3answers
243 views
Function Is target String found in an Array of Strings in CoffeeScript
I wrote this simple function in CoffeeScript to see if elements are found in an array.
isFoundIn = (searchTerm, arrayToSearch) ->
returnVal = false
for a in arrayToSearch
returnVal = true ...
0
votes
1answer
197 views
Coffeescript nested if's
y = (if @projectionStyle is 'flat' then 0 else
if d3.event.y < -90
-90
else if d3.event.y > 90
90
else d3.event.y)
This is working now, but I feel it's inelegant.
0
votes
1answer
163 views
Express, blade with connect-assets
I have this CoffeeScript code running here (with TZM-Blade) and would like to have your opinion on how to better optimize it.
express = require "express"
gzippo = require "gzippo"
assets = require ...
1
vote
1answer
210 views
coffeescript and angular directive
I feel this is deeply inelegant, but I really want the option of classical inheritance in the future. How could this be written better. FYI animation here is from GSAP if you are curious.
class Modal
...
1
vote
3answers
94 views
Cleanest way to close over a counter in CoffeeScript
I haven't spent too much time with CoffeeScript and am trying to have a simple counter:
casper.on('step.complete', ( ->
i = 0
return (step) ->
i += 1
...
1
vote
1answer
173 views
JQuery Dynamic Dropdown Update
This is based (somewhat loosely) on the code written in this railscast. I'm planning to re-use it in different places throughout the site, so I made it a bit more generic rather than based on IDs. ...
3
votes
2answers
115 views
Passing Context in CoffeeScript
I'm trying to migrate from JavaScript to CoffeeScript. However I'm not sure about the best way to optimize the code generated by js2coffee.
Below is the original JavaScript source :
var async = ...
0
votes
0answers
268 views
Angular JS photo app for personal cloud
I've been working on my first Angular JS app for the past few days.
It's in a very early stage (no real functionality), but that will only make it easier to review what IS there.
The client side is ...
3
votes
1answer
137 views
Functional Sundaram's sieve
I wrote this Sundaram's sieve in Coffeescript to quickly generate prime numbers up to limit:
sieve_sundaram = (limit) ->
numbers = (n for n in [3...limit+1] by 2)
half = limit / 2
...
2
votes
0answers
78 views
Code review CoffeeScript implementation of A* algorithm
a_star = # returns the goal node (or null if path not found). To reconstruct path follow the node.__src till null
(
start, # starting node
...
2
votes
2answers
213 views
My first real JS project, simple form validation
I would really like to hear how I can improve my form validator.
Next, I want to refactor it into OO and learn a testing framework like Jasmine.
Some things I know I could improve
Don't make it ...
3
votes
2answers
646 views
Better way to do this in coffeescript
I was actually writing this little script:
$ ->
# Alter 'input' Width
inputResize = ->
$('form').each ->
tF = $(this)
formWidth = tF.width()
tF.find('input').each ->
...
1
vote
1answer
216 views
Increasing web load time (coffee script and d3.js) [closed]
I took the Bubble chart visualization from Jim Vallandingham: http://vallandingham.me/vis/gates/ and added a few other features such as: a picture over svg, a click function, option to select only ...
3
votes
2answers
2k views
CoffeeScript date formatting
forceTwoDigits = (val) ->
if val < 10
return "0#{val}"
return val
formatDate = (date) ->
year = date.getFullYear()
month = forceTwoDigits(date.getMonth()+1)
day = ...
2
votes
1answer
106 views
Assign local-variables in constructor
How to make this code in constructor more DRY?
Is there some more concise way to assign variables passed through object?
class Ball
constructor: (args) ->
@name = args.name
@x = ...
3
votes
1answer
91 views
CoffeeScript method refactoring
This method is from Backbone-View. I'd like to refactor it but I don't have much experience with Coffee or JavaScript.
linkStyle: ->
if @model.get('published')
'published'
else
...
2
votes
1answer
207 views
Object Wrapper/Parameter Injection Module for CoffeeScript/JavaScript
I made an object wrapper/parameter injector and I hope it will be useful, I made it for a project I am working on but then decided to try polishing it a bit.
The use case is for wrapping objects such ...
2
votes
2answers
80 views
Is there any way to make this CoffeScript code simpler / smaller
I've just started with coffeescript, and I saw http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html which has a little programming problem, so I figured I'd do it in ...
4
votes
3answers
135 views
Can this coffeescripts method be simplified?
I'm new to coffeescripts. Can the getSum method be simplified more? Thanks
MyObject =
checkCondition: (num) ->
return true if num is 5
getSum: (num) ->
total = 0
total += i for ...
2
votes
1answer
384 views
PageObject implementation (CoffeeScript, CasperJS)
I'm using CasperJS and CoffeeScript for integration testing of a hobby project. Page Objects seem to be a useful abstraction. I had two major requirements:
Support for node.js style callbacks - ...
0
votes
1answer
97 views
looking to make this code cleaner
I need to count non-transparent pixels in a canvas. My code is below. I am pretty sure there is a nice and elegant syntax for doing this. But I am new to coffeescript. Please help. Note that the data ...
5
votes
1answer
264 views
Project Euler question 2 in CoffeeScript
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
fib = (x) ->
return 0 if x == 0
return 1 if x == 1
...
4
votes
1answer
412 views
Where is the memory leak in this scraper?
This is a scraper written in coffee-script for nodeJS. It is run in an interval (set to 5 seconds here to dramtically show the leak). Somewhere this code leaks memory. I already tried nulling a few ...
3
votes
1answer
173 views
Is there a better way to structure this in CoffeeScript?
I have this recursive function that searches an object tree structure:
dataSearcher = (dataElement, identifierToFind) ->
if dataElement.identifier == identifierToFind
...
0
votes
1answer
115 views
Is there any javascript pitfalls with this approach that I might be missing?
I have a model with a number of complex/simple properties that has a corresponding strongly typed view, that calls EditorFor to a custom editor template view for the model.
One of the form's ...
2
votes
2answers
98 views
Similar but slightly different JavaScript functions
I have two very similar functions that exist mainly for syntactic sugar.
deactivate = (el, seek) -> el.find(seek).removeClass("active")
activate = (el, seek) -> el.find(seek).addClass("active")
...
0
votes
1answer
96 views
Writing binding providers in CoffeeScript?
In his KnockoutJs 1.3 beta post, Steve Sanderson has an example of using Binding providers ("5. Binding providers (and hence external bindings)") where he makes a comment in the JSFiddle JavaScript ...
4
votes
3answers
139 views
Adding push to array inside the class that is being pushed
I used to mostly do this:
class Person
constructor : (@parent, @data)->
@index = @parent.length
class People
constructor : ->
people = []
for data in database.people
...
2
votes
1answer
528 views
A library written in CoffeeScript
So, I wrote this small library for fast DOM building with API tailored for CoffeeScript
I feel like the code overall can be made better/smaller/faster.
I am also not particularly happy about a few ...
4
votes
4answers
674 views
Short coffeescript style question
I'm going through the CoffeeScript book by Trevor Burnham, and I was curious as to what the best style is for a function I was writing.
In the book the author writes the function like so:
...
10
votes
3answers
3k views
Coffeescript beautification and refactoring
As much as I try, I cannot seem to get this Coffeescript code to look beautiful (I'd like to think it is possible). I have tried both Javascript and Coffeescript. Just to be clear, this code works ...