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.
93 questions
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 ...
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 ...
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 ...
1
vote
1
answer
624
views
Converting Date object in CoffeeScript to string (with a weird format)
I'm trying to convert a Date object into a weird format, like so:
03/30/2017 11:37:14:082 -0500
The issue that really trips me up is the timezone offset. There's ...
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 ...
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 ...
0
votes
1
answer
723
views
Displaying job status in a jQuery Datatable
I was wondering if there was a better way to write this:
...
0
votes
1
answer
42
views
Abstracting out two lines of code in Coffeescript
I am currently working on refactoring two methods that exist in directives into a service.
This is method one:
...
2
votes
0
answers
66
views
jQuery Mobile Menu plugin
I would like some opinions on this Mobile Menu plugin I wrote for work. We develop custom WordPress themes, nothing too advanced or anything. I would like if anyone could just take a look and provide ...
0
votes
1
answer
44
views
Multiple string interpolation
Mostly robocop and hound give "line is too long" for such code statements. I just wanted to know which one is better and preferable way.
This one is a way to avoid making the message long so just do ...
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
...
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:
...
8
votes
1
answer
472
views
Simple CoffeeScript navigation menu
I'm using simple script to handle tab menu like this:
HTML:
...
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 ...
2
votes
1
answer
380
views
Refactor jquery (coffescript) code with checkboxes
I have two different set of checkboxes. With the coffescript code below I set the maximum amount of checkable items at 3. I would like to refactor this code, to be cleaner and compact, but I can't get ...
1
vote
1
answer
165
views
Operating on a list of files using recursion
I'm starting just now with CoffeeScript and I found out that I can't solve problems like looping and recursives with just one line. I would like to improve the code that I just wrote using built-in ...
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 ...
2
votes
0
answers
53
views
Recursively merge objects with corresponding property names
I have such objects that I need to merge:
...
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 ...
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 ...
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 ...
2
votes
3
answers
111
views
Prim's algorithm in CoffeeScript
I'm just starting to learn CoffeeScript and am trying to work through simple examples, this one being Prim's algorithm. I'd like feedback on everything but especially on making this script take ...
1
vote
1
answer
99
views
Kruskal's algorithm
I'm working through Coffeescript implementing simple algorithms (started with Prim's as reviewed in this previous post) and wrote out Kruskal's algorithm as below, with a few helper functions. I'd ...
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.
...
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 ...
2
votes
2
answers
1k
views
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 ...
1
vote
1
answer
722
views
Dynamic dropdown update for site reuse
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
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 ...
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} ]
...
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.
...
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?
...
0
votes
1
answer
160
views
Model with complex/simple properties
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 ...
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.
...
2
votes
1
answer
444
views
Multiple search filter like the one in freshdesk
I have requirement to apply multiple filters on database. I will have multiple conditions in the front end where the user can select the conditions he wants to filter with and then see the output. ...
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 ...
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 ...
1
vote
1
answer
263
views
Conditionally replacing an input field when submitting a form
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 ...
1
vote
1
answer
35
views
Extracting a list of hyperlinks [closed]
I need to produce a list objCollector with some results:
...
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 ...
2
votes
0
answers
67
views
Correcting a quiz
I wrote this code that's supposed to correct quizzes on a webpage, but it feels bloated and I'm sure there's tons of ways to improve it. Any thoughts?
...
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 ...
2
votes
0
answers
883
views
Click interceptor directive
I needed a simple way to add this test to certain click events:
if isUser then fireClickEvent else openSignInModal
So I made this directive:
...
2
votes
0
answers
386
views
Resource that use two different services and query with pagination when resolved
I'm learning Angular and I don't like my current approach. The current controller uses first Geolocation service and when ...
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:
...
2
votes
1
answer
151
views
Wait for all resources to be loaded
In my application I need some resources to be loaded and I have services to load each of them and then I need some point to know that all requests finished. First thought was to use $q.all with array ...
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:
...
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:
...
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:
...
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 ...
1
vote
1
answer
1k
views
AngularJS Login Check
I have states that have a requiredlogin object set as true, then I have Angular listen on ...