Skip to main content

Questions tagged [coffeescript]

CoffeeScript is a little language that compiles into JavaScript. Underneath all of those embarrassing braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

Filter by
Sorted by
Tagged with
12 votes
3 answers
4k 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 ...
S W's user avatar
  • 131
10 votes
1 answer
239 views

Optimize CoffeeScript comparison function

I've wrote this CoffeScript function to compare values in a table, but it turned out to be a HUGE function. Since the code is really really long, you can find it here as well. Code explanation: The ...
Razvan B.'s user avatar
  • 203
10 votes
1 answer
302 views

Tabbed navigation to hide and show pages

I'm new to jQuery and trying to learn how to refactor my bloated code to make it nicer and better maintainable. I have a tabbed navigation which I'm using jQuery to hide and show pages depending on ...
user1502223's user avatar
8 votes
1 answer
472 views

Simple CoffeeScript navigation menu

I'm using simple script to handle tab menu like this: HTML: ...
Eternal1's user avatar
  • 286
7 votes
5 answers
568 views

Avoiding nested conditionals and comparing strings

I have a web page with a set of icons that are grey by default: If a user clicks one, it toggles green (.toggleClass('green')): If a user clicks a green one, it ...
Ecnalyr's user avatar
  • 413
7 votes
1 answer
266 views

Loading an SVG into the canvas

The code below is loading an svg into the canvas via RaphaelJS. There are mouseover/mouseout events, on click on an element of the svg, and drag/zoom. I would like to know, what are some good ...
Radu Dascălu's user avatar
6 votes
1 answer
194 views

CoffeeScript implementation of A* algorithm

...
pathikrit's user avatar
  • 205
6 votes
1 answer
193 views

English-Russian irregular words tester

Could you please offer some suggestions about my self learning project? It is really hard-coded, but I have no idea what to do next. I'm using angular (only few ...
outoftime's user avatar
  • 1,729
5 votes
2 answers
780 views

isRTL.coffee 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? ...
dhilipsiva's user avatar
5 votes
2 answers
102 views

Mathematical boundaries (audio meter)

I've just been putting together an audio meter by stacking bootstrap progress bars, and thought there was probably a better way, mathematically / logically, of achieving this. ...
gratz's user avatar
  • 153
5 votes
2 answers
565 views

Periodic Table generator

I've been playing around with Jekyll and CoffeeScript the last few days and made a Periodic Table to learn those two. Now, to create the Periodic Table, I take an array of ...
MisterBla's user avatar
  • 151
5 votes
1 answer
73 views

Tick module for the game

I tried to look up and suck in most of the information about optimizing this operation and this is what I came up with. As it's pretty much core of the game, I really would like to have it performant ...
FredyC's user avatar
  • 217
4 votes
2 answers
629 views

Get <TH> texts into a tab separated string

table_with_headers = $(this.dom.table).find("thead tr th").map(-> $(this).text() ).get().join("\t") Can one write it nicer? I especially don't like the inner ...
andilabs's user avatar
  • 143
4 votes
2 answers
2k views

Altering input field width

This gets every form element and calculates its width, then changes the input fields depending on the parent-form width: ...
Rockbot's user avatar
  • 143
4 votes
3 answers
847 views

Converting a string to coordinates

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: ...
Acorn's user avatar
  • 285
4 votes
1 answer
270 views

Ruby on Rails text editor

I'm currently building a text editor using contenteditable and RoR back end. As the editor is WYSIWYG and trying to follow DRY, I used only one file to 3 actions: Show, Edit and New. Edit and new ...
Alexandre Wiechers Vaz's user avatar
4 votes
1 answer
226 views

Searching an object tree structure

I have this recursive function that searches an object tree structure: ...
Matthew Nichols's user avatar
4 votes
1 answer
69 views

Merge values of the objects properties with the same name into array

I have such input: [ { name: 'timezone', value: 'EST' }, { name: 'interval', value: 'day' }, { name: 'metrics[]', value: 1}, { name: 'metrics[]', value: 2} ] ...
eawer's user avatar
  • 207
4 votes
1 answer
10k views

Regex for curly quotes and apostrophes

After years of fear and procrastination I decided to learn regular expressions. This is the result: CoffeScript: ...
wyc's user avatar
  • 555
4 votes
1 answer
159 views

Flood game implementation

There is the implementation of flood game on my GitHub. The app.coffee is the main part of project: ...
kharandziuk's user avatar
4 votes
1 answer
308 views

Resize renderer on browser window size change

For a game, there is some WebGLRenderer object that wraps around canvas element. There is need to update it's size when browser window size changes. Here goes my current code written using BaconJS. ...
FredyC's user avatar
  • 217
4 votes
2 answers
91 views

Initializing events on class

I wrote a simple class that substitutes all file inputs in an HTML for a more complex template and set some actions on it. The code is rather small, but I'm not used to write JavaScript. I wonder if ...
fotanus's user avatar
  • 227
4 votes
2 answers
11k views

CoffeeScript date formatting

...
Vinko Vrsalovic's user avatar
4 votes
3 answers
155 views

Adding push to array inside the class that is being pushed

I used to mostly do this: ...
Pickels's user avatar
  • 143
4 votes
2 answers
745 views

HTML5 Video player

I do HTML5 Video player with some controls. I have a button, where I change classname for make play, pause or replay button. I have a mute/unmute button, volume range slider, timer and fullscreen mode ...
rel1x's user avatar
  • 301
4 votes
1 answer
68 views

Refactor array for loop result

...
WaYdotNET's user avatar
4 votes
1 answer
514 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. ...
crocaduck81's user avatar
4 votes
1 answer
76 views

CoffeeScript 2 + 2 program

I tested this program on Smooth-CoffeeScript I just wanted to have as many eyes on this as I could to learn about coffeescript; Is there anything I should do to improve it? Am I using the tools ...
Shui's user avatar
  • 173
4 votes
0 answers
9k views

An Object-Oriented Programming pattern for AngularJS models using CoffeeScript classes

Over the past week, we tried to make our AngularJS model layer more powerful and reduce complexity in our controllers and template by using the object-oriented programming pattern and the CoffeeScript ...
Blaiz's user avatar
  • 141
4 votes
0 answers
138 views

Core class of a JavaScript framework for 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. GitHub www.scaleapp.org It's inspired by ...
flosse's user avatar
  • 121
3 votes
4 answers
8k views

Determining if a target string is found in an array of strings

I wrote this simple function in CoffeeScript to see if elements are found in an array: ...
JAMESSTONEco's user avatar
3 votes
3 answers
174 views

Can this coffeescripts method be simplified?

I'm new to coffeescripts. Can the getSum method be simplified more? Thanks ...
Kuntau's user avatar
  • 141
3 votes
2 answers
1k views

Getting the outliers of both dates and values

This is working now, but it looks very inelegant. I'm sure there is a nicer way of doing this. ...
Fresheyeball's user avatar
3 votes
2 answers
811 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 : ...
uyetch's user avatar
  • 133
3 votes
1 answer
910 views

Memory leak in a scraper [closed]

This is a scraper written in CoffeeScript 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 ...
Lincoln's user avatar
  • 139
3 votes
1 answer
375 views

Functional Sundaram's sieve

I wrote this Sundaram's sieve in Coffeescript to quickly generate prime numbers up to limit: ...
Mirzhan Irkegulov's user avatar
3 votes
1 answer
328 views

Object wrapper/parameter injection module

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 ...
KGZM's user avatar
  • 133
3 votes
1 answer
770 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 ...
glebm's user avatar
  • 665
3 votes
2 answers
749 views

Fibonacci using cache

This is my simple Fibonacci implementation in CoffeeScript. What do you think? Using cache (fibResults), it's very very fast. ...
Daniele Vrut's user avatar
3 votes
1 answer
1k views

Configuring a DataTable using CoffeeScript

I am working on a simple Rails app. For the Expense resource I use a DataTable. So, in my CoffeeScript for this resource I basically do several things: initialize ...
Alexander Popov's user avatar
3 votes
1 answer
119 views

Automatically gravitate popover towards page center

I've authored a couple of plugins which show popovers on a given element. One of the objectives for both was no specification of plugin direction. So instead of the implementing dev having to specify <...
andrew.carpenter's user avatar
3 votes
1 answer
72 views

Set up event on class and initialize state [closed]

Very similar to this question, I'm curious about common patterns/best practices for handling events in coffeescript classes, particularly when you also need to call the event handlers immediately to ...
Jared's user avatar
  • 176
3 votes
1 answer
155 views

Paginating a Backbone collection

This is part of a class for paginating a Backbone collection. The paginateTo method is for paginating to a model id. It returns ...
meleyal's user avatar
  • 131
3 votes
0 answers
83 views

Hotel Room Problem in CoffeeScript

Question: You're in a hotel and you forgot what room number you were in but remember that the sum of it's divisors is greater than the number, yet there is no subset of those divisors that add up to ...
user avatar
3 votes
0 answers
41 views

Backbone.model based state machine

I have created a class to keep track of some internal states. You can see it as a very simple implementation of a state machine ...
Anthony Kong's user avatar
3 votes
0 answers
52 views

Using Angular directives for connect HTML clicks in buttons and controller actions

I'm trying to improve my Angular directive. I'm pretty new to CoffeeScript, so I think there may be inconsistent code. ...
user98293989823's user avatar
3 votes
0 answers
53 views

Search Class with Static Methods

Most of my programming experience is in PHP, and I have always been a bit wary of JavaScript. I have a JavaScript class to manage executing, caching and displaying search results. ...
James Fenwick's user avatar
3 votes
0 answers
83 views

Multiple select widget in CoffeeScript

I created a widget to handle multiple selections in CoffeeScript. There's a working attached snippet that uses the compiled JavaScript (Stack Snippets don't support CoffeeScript), which is available ...
Mohamad's user avatar
  • 2,034
3 votes
0 answers
680 views

Passing functions using higher order components in React

After reading this, I'm on board, however it doesn't get into passing methods from the parent class. In my mixins right now I have a lot of helper functions that are used across the various components ...
Ben's user avatar
  • 131
3 votes
0 answers
208 views

Create component with select+button

I'm new to ReactJs and trying to figure out the preferred style. I also have tried it enough to realize that I'm not a fan of jsx and prefer how React looks when written in coffeescript. This is a ...
George Mauer's user avatar
  • 1,642