Skip to content

Commit b58c79c

Browse files
author
David Brady
committed
Added wanted-recipes and recipe-template
1 parent bbfd6fe commit b58c79c

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

authors-guide.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ h1. Grindy HOWTOs
6161

6262
h2. How to Add a Recipe
6363

64-
Create a new textile page. The filename should be about the problem, e.g. <tt>finding-last-day-of-the-month.textile</tt> or <tt>reversing-arrays.textile</tt>. In your file, start with the following template:
64+
Create a new textile page (or copy the <a href="/recipe-template">Recipe Template</a>. The filename should be about the problem, e.g. <tt>finding-last-day-of-the-month.textile</tt> or <tt>reversing-arrays.textile</tt>. In your file, start with the following template:
6565

6666
{% highlight text %}
6767
---

contributing.textile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Here's the Contribution Recipe:
1313
# Send a pull request to coffeescript-cookbook
1414
# If we merge your pull request, you get commit access. BAM. Go back to step 2 and stay there as long as you want.
1515

16+
17+
h2. Wanted Recipes
18+
19+
Want to help, but don't know where to start? Want a recipe, but don't know how to write it? Check out the <a href="/wanted-recipes">Wanted Recipes</a> page!
20+
1621
h2. Authors
1722

1823
Write recipes! Fork the repository, author some pages, and send us a pull request. For more information read the <a href="/authors-guide">author's guide</a>.

index.textile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Welcome to the CoffeeScript Cookbook! It's a bit of a mess right now, and VERY l
99

1010
Contributions URGENTLY needed NOW:
1111

12+
* +NEW!+ Check out the <a href="/wanted-recipes">Wanted Recipes</a> page!
13+
* +NEW!+ For authors: we've added a <a href="/recipe-template">Recipe Template</a> to help get you started.
1214
* Authors: Write recipes! <a href="/authors-guide">Here's how</a>.
1315
* Developers: Expand the Cookbook site! <a href="/developers-guide">Here's how</a>.
1416
* Designers: Make this place look like not-crap! <a href="/designers-guide">Here's how</a>.

recipe-template.textile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
layout: recipe
3+
title: Title of The Recipe
4+
chapter: Chapter Name
5+
---
6+
7+
h2. Problem
8+
9+
You have a problem.
10+
11+
h2. Solution
12+
13+
Do this about it.
14+
15+
h2. Discussion
16+
17+
Here's why.
18+

wanted-recipes.textile

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
layout: default
3+
title: Wanted Recipes
4+
---
5+
h1. Wanted Recipes
6+
7+
Here's a list of recipes we think we need. Pick one, implement it, and remove it from the page. Alternately, add a quick note here for a recipe you'd like to see so someone else can add it.
8+
9+
In the notes below, "JS" means the recipe is just a simple passthrough to an existing JavaScript method.
10+
11+
h2. Syntax
12+
13+
* loops: for x in [1..10]
14+
* loops: for x in [1..10] then do_one_thing
15+
* list comprehensions: y*3 for y in (x*2 for x in [1,2,3]) # => [6, 12, 18]
16+
* maps: Previous line might be better represented as ([1,2,3].map (x) -> x*2).map (y) -> y*3
17+
* list comp gotcha: y = x for x in [1..3]; y # => 3; but y = (x for x in [1..3]); y # => [ 1, 2, 3 ]
18+
* Ensuring variables are closed over # with "do"
19+
20+
h2. Objects
21+
22+
* cloning an object (see http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object ) -- snag both the generic JS version, port to CS, also snag the jQuery version and port to CS+jQ.
23+
24+
h2. Strings
25+
26+
* Find a substring in a string # not by regex! JS indexOf(), lastIndexOf()
27+
* HTML methods # JS .sup(), .sub(), .blink(), .link(url), etc. May not exist in your JS impl!
28+
* Splitting a string # JS "foo bar baz".split ' ' # => [ 'foo', 'bar', 'baz' ]
29+
* substr # str.substr(x,y) === str[x..x+y-1] === str[x...x+y]
30+
* substring # str.substring(x,y) === str.slice(x,y) === str[x..y-1] === str[x...y]
31+
* Uppercasing a string # JS toUpperCase()
32+
* Lowercasing a string # JS toLowerCase()
33+
* Replacing substrings
34+
35+
h2. Arrays
36+
37+
* Using Arrays to Swap Variables # [x,y] = [y,x]
38+
* Mapping arrays to other arrays with map # [1,2,3].map (x) -> x*2 # => [2, 4, 6]
39+
* Reducing arrays to values (ruby inject) with reduce # [1..10].reduce (a,b) -> a+b # 55
40+
* Reducing arrays in reverse order # JS reduceRight
41+
{% highlight coffeescript %}
42+
["example", "contrived ", "pretty ", "a ", "is ", "here "].reduceRight (x,y) -> x+y
43+
# => 'here is a pretty contrived example'
44+
{% endhighlight %}
45+
* Testing every element in an array
46+
{% highlight coffeescript %}
47+
evens = (x for x in [0..10] by 2)
48+
even = (x) -> x % 2 == 0
49+
evens.every even
50+
# => true
51+
{% endhighlight %}
52+
* Filtering arrays # [1..10.filter (x) -> x % 2 == 0 # => [ 2, 4, 6, 8, 10 ]
53+
* Detecting presence of matching items in an array # [1..10].some (x) -> x % 2 == 0 # => true
54+
* Processing an array item by item # [10..1].forEach (x) -> console.log x # => nothing;, but a countdown is displayed on the console
55+
56+
h2. Dates and Times
57+
58+
* Calculating the phase of the moon
59+
* Holidays: Calculating Easter
60+
* Holidays: Calculating US Thanksgiving
61+
* Holidays: Calculating CA Thanksgiving
62+
63+
h2. Math
64+
65+
* Converting between degrees and radians
66+
* square root # JS Math.sqrt
67+
* Constants # JS Math.PI, Math.E
68+
* floor, ceil, round # JS Math.floor, Math.ceil, Math.round
69+
* Raising a number to a power # JS Math.pow(x, y)
70+
* Logarithms # Math.log
71+
* Finding the base-n log # Math.log(num) / Math.log(base)
72+
* Exponents # Math.exp
73+
74+
h2. Functions
75+
76+
* Nested functions
77+
78+
{% highlight coffeescript %}
79+
hypotenuse = (a, b) ->
80+
square = (x) -> x * x
81+
Math.sqrt(square(a) + square(b))
82+
83+
console.log hypotenuse 3, 4
84+
# => 5
85+
86+
square 5
87+
# ReferenceError: square is not defined
88+
{% endhighlight %}
89+
90+
* Optional Arguments # use arg? to detect presence: if arg=0, arg? == true
91+
92+
{% highlight coffeescript %}
93+
foo = (a, b=42, c) -> if c? then a*b*c else a*b
94+
[Function]
95+
foo 6
96+
# => 252
97+
foo 1, 2
98+
# => 2
99+
foo 1, 2, 3
100+
# => 6
101+
{% endhighlight %}
102+
103+
* Variable arguments with splats
104+
* Recursion of unnamed functions with arguments.callee
105+
106+
{% highlight coffeescript %}
107+
console.log [1,2,3,4,5].map (x) ->
108+
if x <= 1 then return 1
109+
return x * arguments.callee(x-1)
110+
# => [1, 2, 6, 24, 120 ]
111+
{% endhighlight %}
112+
113+
h2. jQuery
114+
115+
* Callback bindings # using => instead of ->
116+
* jQuery AJAX from CS
117+
118+
h2. Regular Expressions
119+
120+
* Searching for substrings # "foo bar baz".match(/ba./) # => [ 'bar', index: 4, input: 'foo bar baz' ]
121+
* Searching for substrings # "foo bar baz".search(/ba./) # => 4
122+
* Replacing substrings # "foo bar baz".replace( /ba./, 'foo') # => "foo foo baz"
123+
* Extended "heregexes"
124+
125+
h2. AJAX
126+
127+
* Getting data from a remote server # using raw XHTTPRequest instead of jQuery's $.ajax
128+
129+
130+

0 commit comments

Comments
 (0)