Code Monkey home page Code Monkey logo

coffeescript-cookbook.github.io's Introduction

CoffeeScript Cookbook

CoffeeScript Cookbook is a community run website for the CoffeeScript language. We want you to write recipes and make the site better!

Contributing

You can find details about contributing on the site. For now here is a simple formula:

  1. Fork the repository at GitHub
  2. Do awesomeness!
  3. Send a pull request to coffeescript-cookbook
  4. If we merge your pull request, you get commit access. BAM. Go back to step 2 and stay there as long as you want.

Here are some relevant links from the site.

Jekyll

CoffeeScript Cookbook is currently implemented as a jekyll site. Jekyll is awesome.

License

This site and all contributions are licensed under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) license. By submitting information to this site you agree to grant this license to all users of the site, and that your editing of the authors page constitutes satisfactory attribution.

coffeescript-cookbook.github.io's People

Contributors

aaronw avatar aididjaafar avatar amsul avatar blowmage avatar cpursley avatar d8uv avatar data-meister avatar dbrady avatar fhemberger avatar fulmicoton avatar jasongiedymin avatar jgaskins avatar jlburkhead avatar joaomoreno avatar krawaller avatar lolmaus avatar markmontymark avatar michaelglass avatar nonsensery avatar oakraven avatar pedrosnk avatar peterhellberg avatar phaedryx avatar phlipper avatar scotterc avatar sebslomski avatar sreid avatar sukima avatar tashemi avatar thirdtruck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coffeescript-cookbook.github.io's Issues

Build process

It seems my build process is borked. I get many maruku errors about odd references (looks like it's trying to parse markdown inside code block) and the {% highlight %} code is being ignored.

Is there missing plugins? What is the procedure for testing a build locally before pushing to the code base?

chinese adition

i want to tranlate this masterpiece to chinese, what folder structrue should i use?

using several git programs simultaneously

I have a question of a basic nature that no tutorial has been able to answer to me. I was working with SourceTree in a local repo pushing to Github.com. At some point I decided to use Github Desktop, so I added the local repo and started to push to Github.com. I did not like this software, so I went back to SourceTree. Opened my project there but changes were not being tracked anymore. I wonder if one can use two git managers for tracking changes or else I don't know what went wrong.

Extension of built-in native objects in recipes

Browsing the recipes, I found one pattern to be quite common: The extension of build-in native objects.
It's totally fine to back-port ECMAScript 5 methods (as long you make sure, you don't overwrite existing implementations by accident), e.g.:

unless String::trim then String::trim = -> @replace /^\s+|\s+$/g, ""

On the other hand, modifying objects you don't own is considered a bad practice in JavaScript (whereas it's quite common in other languages like Ruby):

Personally, I think those examples should either be reworked or have a note in the "Discussion" section, that this should be used with caution, linking the articles above.

What do you think?

Why the ruby comparisons every once and a while?

Some of the articles mention ruby just to underline that some features in [java|coffee]script are similar to ruby. They assume the reader knows and is accustomed to ruby. I don't think we should go down that path, and should have the syntax arguments for coffeescript's own sake.

Some examples are

http://coffeescriptcookbook.com/chapters/strings/interpolation
http://coffeescriptcookbook.com/chapters/arrays/filtering-arrays
http://coffeescriptcookbook.com/chapters/arrays/mapping-arrays

[Discussion] Patterns for monads

In my recent ventures into learning more functional styled programming I'm quite fascinated with monads. Both in terms of compositions and readability (A.K.A chaining). This got me thinking on how to pattern this style.

Sure, there are many libraries out there that attempt to make monads through programmatic means (currying I think it's calls). However, in my research the concept for a monad is simple enough one shouldn't need a library to implement.

What I mean is, couldn't there be a pattern one could use to make monads in their programs? I'll discuss a few examples here in hopes to illicit some discussion on possible patterns suitable for the cookbook. (The example are a rough draft I whipped up while writing this).

Identity

Simplest example although not very useful (I think).

class Identity
  constructor: (@value) ->
    @value = @value.value if @value instanceof Identity
  bind: (fn) ->
    newValue = fn.call(this, @value)
    new Identity(newValue)

Maybe

An example with some practical usage. The Maybe Monad encapsulates a value allowing functions to be composed on it without need for a

class Maybe
  constructor: (@value) ->
    @value = @value.value if @value instanceof Maybe
  bind: (fn) ->
    return this unless @value?
    newValue = fn.call(this, @value)
    new Maybe(newValue)

Immutable Object

This is the heart of the issue here, using OOP style classes in a functional / immutable way.

class MyObject
  constructor: (@value) ->
    @value = @value.value if @value instanceof MyObject
  bind: (fn) ->
    newValue = fn.call(this, @value)
    new MyObject(newValue)
  addTwo: ->
    @bind =>
      @value + 2

This isn't to compete with promises which are much better off being handled via a library but I think there is some advantages to modeling your typical classes as monadic classes providing a chainable and readable way to compose functions on itself and providing immutability to what would otherwise be mutable OOP.

Thoughts? Ideas?

Error when running 'foreman start'

When pulling down a fresh issue from Github, I run bundle install without any errors, but when running foreman start I get the following error message:

15:20:25 jekyll.1 | /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global/gems/commander-4.1.5/lib/commander/runner.rb:365:in `block in require_program': program version required (Commander::Runner::CommandError)
15:20:25 jekyll.1 |     from /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global/gems/commander-4.1.5/lib/commander/runner.rb:364:in `each'
15:20:25 jekyll.1 |     from /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global/gems/commander-4.1.5/lib/commander/runner.rb:364:in `require_program'
15:20:25 jekyll.1 |     from /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global/gems/commander-4.1.5/lib/commander/runner.rb:52:in `run!'
15:20:25 jekyll.1 |     from /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global/gems/commander-4.1.5/lib/commander/delegates.rb:11:in `run!'
15:20:25 jekyll.1 |     from /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global/gems/commander-4.1.5/lib/commander/import.rb:10:in `block in <top (required)>'

Some other terminal commands:

  • which
[coffeescript-cookbook.github.com]  [master*]    which ruby
/Users/mbodmer/.rvm/rubies/ruby-1.9.3-p484/bin/ruby
[coffeescript-cookbook.github.com]  [master*]    which jekyll
/Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@coffeescript-cookbook/bin/jekyll
  • gem env
[coffeescript-cookbook.github.com]  [master*]    gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.2.1
  - RUBY VERSION: 1.9.3 (2013-11-22 patchlevel 484) [x86_64-darwin13.0.0]
  - INSTALLATION DIRECTORY: /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@coffeescript-cookbook
  - RUBY EXECUTABLE: /Users/mbodmer/.rvm/rubies/ruby-1.9.3-p484/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@coffeescript-cookbook/bin
  - SPEC CACHE DIRECTORY: /Users/mbodmer/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-13
  - GEM PATHS:
     - /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@coffeescript-cookbook
     - /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@coffeescript-cookbook/bin
     - /Users/mbodmer/.rvm/gems/ruby-1.9.3-p484@global/bin
     - /Users/mbodmer/.rvm/rubies/ruby-1.9.3-p484/bin
     - /Users/mbodmer/.rvm/bin
     - /usr/local/heroku/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin

I am running Mac OS X 10.9.2, and have previously installed Jekyll for another project.

[Discussion] The ES6 future of CoffeeScript. Looking for a ES6-friendly CoffeeScript replacement.

ES6 is gaining a lot of spread. It introduces a lot of new concepts into JS. Here are nice overviews: short, comprehensive.

And people already use those features! Thanks to the effort from such projects as 6to5, es6-transpiler and Traceur, for a modern JS developer who does not use CoffeeScript, there is simply no reason not to use ES6 nowadays. Many modern JS projects are already being written in ES6. Moreover, popular JS frameworks already demand that their users code in ES6 out of the box (this includes Angular 2 and EmberJS).

CoffeeScript is essentially locked at ES5. Some ES6 features are accessible via backticks, but others directly conflict with the CS syntax, including said backticks. With main contributors having explicitly refused to support ES6, CS is doomed to become a thing of the past.

This worries me a lot. I still use CS for all my projects, but i will doubt using CS in a new project.

My problem is that i absolutely adore CS syntax. I worship it. After getting used to CS, i can't stand vanilla CS anymore.

Here's an extract from React sources i saw today (by the way, React is written in ES6):

for (var key in props) {
  if (!props.hasOwnProperty(key)) {
    continue;
  }

  style[key] = props[key];
}

This can be rewritten in CoffeeScript as:

for own key, value of props
  style[key] = value

JS code is more than 100% larger than CS with zero benefit!

Back to the matter. With CS maintainer having doomed CS to be obsolete, we need a replacement.

I suggest that here we:

  1. Collect references to and discus JS preprocessors that implement CS-like syntax while maintaining ES6 compatibility. I failed to google up any but maybe you're luckier.
  2. Discus starting a new preprocessor project that would implement CS-like syntax while maintaining ES6 compatibility.
    • We should start discussing the new syntax. Some of core CS features conflict with ES6, namely backticks and fat arrows, others become redundant (splats, comprehensions, classes, etc). I suggest we give precedence to ES6 and change CS convensions.
    • Should we start from scratch or fork CS?
    • Anyone feels skilled enough to be a primary maintainer/contributor of the CoffeeScript killer? :D I don't. :(

Unique recipe fails on empty arrays

As defined here: http://coffeescriptcookbook.com/chapters/arrays/removing-duplicate-elements-from-arrays

Array::unique = ->
  output = {}
  output[@[key]] = @[key] for key in [0...@length]
  value for key, value of output

[].unique() evaluates to [null] in the latest version of Chrome.

This can be fixed by using the 'own' keyword to only iterate over output's own properties.

Array::unique = ->
  output = {}
  output[@[key]] = @[key] for key in [0...@length]
  value for own key, value of output

[].unique() evaluates to [] in the latest version of Chrome.

I'm not sure why null is a property of the empty array, but javascript can be weird like that.

New design is harmful to your health

We needed to do something about the website's design, but this is not it.

Code boxes with too much contrast, regular text with too little, links are blue on blue, etc...

I propose to regress it to the original dark text on clear background design. All in favor say 'aye'.

Inconsistent case for recipe names on table of contents.

There is a mix of title-case and sentence-case for the recipe names in the table of contents. They should be made consistent. I have a preference for title-case. For example this:

Math
Faster Fibonacci algorithm [[sentence]]
A random integer function [[sentence]]
Generating Random Numbers [[title]]

should be:

Math
Faster Fibonacci Algorithm [[title]]
A Random Integer Function [[title]]
Generating Random Numbers [[title]]

I will update the existing sentence-cased recipes to title case if others are in agreement on using title-case.

Arrays / Max Array Value / faulty example

The example is wrong at the "Solution" section of "Max Array Value" in chapter "Arrays".

The following does not work:
Math.max [12, 32, 11, 67, 1, 3]

Instead it could be something like:
Math.max.apply null, [12, 32, 11, 67, 1, 3]

Callback bindings

Looking at the following code. According to the recipe on Callback bindings next should be executed. However it is not.

class MyClass:    
   constructor: () =>
       @showCarouselInfo()
       @next() 

   next: () =>
        console.log 'fires'

    showCarouselInfo: =>
      getIndex = (string) =>
        number = parseInt(string.match(/\d+/))

      $('.ball').on 'click', (e) =>
        console.log('fire')
        index = getIndex(e.currentTarget.id)
        info = $('.carousel-wrapper > p')
        @next(info[index])

Testing-every-element has an error

evens = (x for x in [1..10] by 2)

evens.every (x)-> x % 2 == 0

=> true

This is actually false because tha array starts from 1 by 2... So every number in the array it will be an odd number.

I am going to fork the project and correct this issue then make a pull request.

Generator access by interactor support

I attempt use ES6 new feature which is generator function (yield) and read it by for...loop
In javascript i can simple write below :

function* hello(){
    var i = 10;
    for (var j =0 ;j<i;j++){
        yield j
    }
}

for(var i of hello()){
    console.log(i)
}

In coffeescript:

hello = ()->
    for i in [0..10]
        yield i
    return
for i of hello()->
    console.log i

coffee script nothing output.... this is due to compiled js still using for...in instead of for...of, currently i just using embed javascript to solve this problem , could you please fix it ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.