-
+
-
diff --git a/authors-guide.md b/authors-guide.md
index 54c1b26..2504368 100644
--- a/authors-guide.md
+++ b/authors-guide.md
@@ -6,7 +6,7 @@ title: Author's Guide
## tl;dr: Look at Other Recipes, and Blend In
-Look at the source of other recipe pages and follow that page structure. Start with the [Developer's Guide](/developers-guide) to get a test version of the cookbook up and running on your machine, and get to work!
+Look at the source of other recipe pages and follow that page structure. Start with the [Developer's Guide]({{ site.baseurl }}/developers-guide) to get a test version of the cookbook up and running on your machine, and get to work!
## General Guidelines
@@ -26,7 +26,7 @@ A typical cookbook page will have three sections (four if you count the title):
## Copyright Issues
-Do not post code that is copyrighted by another user, unless you have permission to use that code AND to relicense that code under the [CC BY 3.0](/license) license. If you DO have permission and the author would like credit, please add them to the [authors](/authors) page.
+Do not post code that is copyrighted by another user, unless you have permission to use that code AND to relicense that code under the [CC BY 3.0]({{ site.baseurl }}/license) license. If you DO have permission and the author would like credit, please add them to the [authors]({{ site.baseurl }}/authors) page.
Also, just a stylistic note, please do not yank code directly from [http://coffeescript.org/](http://coffeescript.org/) and post it with little or no discussion. The CoffeeScript Cookbook is not affiliated with them. We think they're awesome and want them to like us, too! Make sure that anything taken from [http://coffeescript.org/](http://coffeescript.org/) is permissible use and that it stands alone as a valid recipe. If the recipe is too terse, consider adding more examples and discussion.
@@ -99,7 +99,7 @@ When in doubt about what output to show, try evaluating your snippet in the coff
## How to Add a Recipe
-Create a new markdown page (or copy the [Recipe Template](/recipe-template). The filename should be about the problem, e.g. `finding-last-day-of-the-month.md` or `reversing-arrays.md`. In your file, start with the following template:
+Create a new markdown page (or copy the [Recipe Template]({{ site.baseurl }}/recipe-template). The filename should be about the problem, e.g. `finding-last-day-of-the-month.md` or `reversing-arrays.md`. In your file, start with the following template:
{% highlight text %}
---
@@ -175,7 +175,7 @@ See the "Weird Recipe" note above. Do real people in the real world ever hit the
## I Have A Problem/Solution, But It's Basically Just JavaScript. Should I Add It?
-Yes! CoffeeScript compiles to JavaScript, and that means that some of its functionality comes straight from JavaScript. (For example, see [Reversing Arrays](/chapters/arrays/reversing-arrays).) But if you're programming in CoffeeScript and you need to reverse an array, this Cookbook should stand ready to tell you it's available to you in CoffeeScript -- even if it's just a straight call into a JavaScript library.
+Yes! CoffeeScript compiles to JavaScript, and that means that some of its functionality comes straight from JavaScript. (For example, see [Reversing Arrays]({{ site.baseurl }}/chapters/arrays/reversing-arrays).) But if you're programming in CoffeeScript and you need to reverse an array, this Cookbook should stand ready to tell you it's available to you in CoffeeScript -- even if it's just a straight call into a JavaScript library.
## I Found a Typo. Is That Enough of a Fix? Does That Count?
diff --git a/authors.md b/authors.md
index fe612ef..d5181f6 100644
--- a/authors.md
+++ b/authors.md
@@ -24,7 +24,7 @@ The following people are totally rad and awesome because they have contributed r
* Calum Robertson *http://github.com/randusr836*
* Jake Burkhead *https://github.com/jlburkhead*
* [Alex Johnson](https://github.com/nonsensery)
-* ...You! What are you waiting for? Check out the [contributing](/contributing) section and get cracking!
+* ...You! What are you waiting for? Check out the [contributing]({{ site.baseurl }}/contributing) section and get cracking!
# Developers
@@ -34,11 +34,13 @@ The following people are totally rad and awesome because they have contributed r
* Mike Moore *mike@blowmage.com*
* Peter Hellberg *peter@c7.se*
* Jamie Gaskins *jgaskins@gmail.com*
-* ...You! What are you waiting for? Check out the [contributing](/contributing) section and get cracking!
+* Sami Pussinen *me@samipussinen.com*
+* [Devin Weaver (@sukima)](https://github.com/sukima)
+* ...You! What are you waiting for? Check out the [contributing]({{ site.baseurl }}/contributing) section and get cracking!
# Designers
The following people are astonishingly rad and awesome because they did great design for the site!
* [Amsul](http://github.com/amsul) reach@amsul.ca
-* ...You! Check out the [contributing](/contributing) section and get cracking!
+* ...You! Check out the [contributing]({{ site.baseurl }}/contributing) section and get cracking!
diff --git a/chapters/ajax/index.html b/chapters/ajax/index.html
index 5ca402b..0dfcd24 100644
--- a/chapters/ajax/index.html
+++ b/chapters/ajax/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/arrays/list-comprehensions.md b/chapters/arrays/list-comprehensions.md
index 68e7c88..3ab2700 100644
--- a/chapters/arrays/list-comprehensions.md
+++ b/chapters/arrays/list-comprehensions.md
@@ -9,7 +9,7 @@ You have an array of objects and want to map them to another array, similar to P
## Solution
-Use a list comprehension, but don't forget about [mapping arrays](/chapters/arrays/mapping-arrays).
+Use a list comprehension, but don't forget about [mapping arrays]({{ site.baseurl }}/chapters/arrays/mapping-arrays).
{% highlight coffeescript %}
electric_mayhem = [ { name: "Doctor Teeth", instrument: "piano" },
@@ -25,4 +25,4 @@ names = (muppet.name for muppet in electric_mayhem)
## Discussion
-Because CoffeeScript directly support list comprehensions, they work pretty much as advertised wherever you would use one in Python. For simple mappings, list comprehensions are much more readable. For complicated transformations or for chained mappings, [mapping arrays](/chapters/arrays/mapping-arrays) might be more elegant.
+Because CoffeeScript directly support list comprehensions, they work pretty much as advertised wherever you would use one in Python. For simple mappings, list comprehensions are much more readable. For complicated transformations or for chained mappings, [mapping arrays]({{ site.baseurl }}/chapters/arrays/mapping-arrays) might be more elegant.
diff --git a/chapters/arrays/mapping-arrays.md b/chapters/arrays/mapping-arrays.md
index 6a54964..1be0e65 100644
--- a/chapters/arrays/mapping-arrays.md
+++ b/chapters/arrays/mapping-arrays.md
@@ -9,7 +9,7 @@ You have an array of objects and want to map them to another array, similar to R
## Solution
-Use map() with an anonymous function, but don't forget about list comprehensions.
+Use map() with an anonymous function, but don't forget about list comprehensions.
{% highlight coffeescript %}
electric_mayhem = [ { name: "Doctor Teeth", instrument: "piano" },
@@ -27,4 +27,4 @@ names = electric_mayhem.map (muppet) -> muppet.name
Because CoffeeScript has clean support for anonymous functions, mapping an array in CoffeeScript is nearly as easy as it is in Ruby.
-Maps are are good way to handle complicated transforms and chained mappings in CoffeeScript. If your transformation is as simple as the one above, however, it may read more cleanly as a list comprehension.
+Maps are are good way to handle complicated transforms and chained mappings in CoffeeScript. If your transformation is as simple as the one above, however, it may read more cleanly as a list comprehension.
diff --git a/chapters/arrays/reducing-arrays.md b/chapters/arrays/reducing-arrays.md
index 37d5e98..6b52690 100644
--- a/chapters/arrays/reducing-arrays.md
+++ b/chapters/arrays/reducing-arrays.md
@@ -24,10 +24,11 @@ You can simply use Array's `reduce()` and `reduceRight()` methods along with an
Or it may be something more complex such as aggregating elements from a list into a combined object.
{% highlight coffeescript %}
-people =
+people = [
{ name: 'alec', age: 10 }
{ name: 'bert', age: 16 }
{ name: 'chad', age: 17 }
+]
people.reduce (x, y) ->
x[y.name]= y.age
diff --git a/chapters/classes_and_objects/chaining.md b/chapters/classes_and_objects/chaining.md
index be19212..d8d099e 100644
--- a/chapters/classes_and_objects/chaining.md
+++ b/chapters/classes_and_objects/chaining.md
@@ -66,9 +66,9 @@ class TeaCup
cream: false
addChainedAttributeAccessor(this, 'properties', attr) for attr of @properties
-earlgrey = new TeaCup().size('small').type('Earl Grey').sugar('false')
+earlgrey = new TeaCup().size('small').type('Earl Grey').sugar(false)
-earlgrey.properties # => { size: 'small', type: 'Earl Grey', sugar: false }
+earlgrey.properties # => { size: 'small', type: 'Earl Grey', sugar: false, cream: false }
earlgrey.sugar true
diff --git a/chapters/classes_and_objects/index.html b/chapters/classes_and_objects/index.html
index 082c0a3..013fd47 100644
--- a/chapters/classes_and_objects/index.html
+++ b/chapters/classes_and_objects/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/classes_and_objects/object-literal.md b/chapters/classes_and_objects/object-literal.md
index 7d9d2f0..602ccf3 100644
--- a/chapters/classes_and_objects/object-literal.md
+++ b/chapters/classes_and_objects/object-literal.md
@@ -20,7 +20,29 @@ window.MY_NAMESPACE ?= {}
This is equivalent to the following JavaScript:
{% highlight javascript %}
-window.MY_NAMESPACE = window.MY_NAMESPACE || {};
+if(window.MY_NAMESPACE === null || window.MY_NAMESPACE === undefined) {
+ window.MY_NAMESPACE = {};
+}
{% endhighlight %}
-Common JavaScript technique, using object literal to define a namespace. This saves us from clobbering the namespace if it already exists.
+## Problem
+
+You want to make a conditonal assignment if it does not exists or if it is falsy (empty, 0, null, false)
+
+## Solution
+
+Use the Conditional assignment operator
+
+{% highlight coffeescript %}
+window.my_variable ||= {}
+{% endhighlight %}
+
+## Discussion
+
+This is equivalent to the following JavaScript:
+
+{% highlight javascript %}
+window.my_variable = window.my_variable || {};
+{% endhighlight %}
+
+Common JavaScript technique, using conditional assignment to ensure that we have an object that is not falsy
diff --git a/chapters/databases/index.html b/chapters/databases/index.html
index 6100569..abf1318 100644
--- a/chapters/databases/index.html
+++ b/chapters/databases/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/dates_and_times/days-between-two-dates.md b/chapters/dates_and_times/days-between-two-dates.md
index 11f6894..b6a94e9 100644
--- a/chapters/dates_and_times/days-between-two-dates.md
+++ b/chapters/dates_and_times/days-between-two-dates.md
@@ -5,11 +5,11 @@ chapter: Dates and Times
---
## Problem
-You need to find how much seconds minutes, hours, days, months or years has passed between two dates.
+You need to find how many seconds, minutes, hours, days, months or years have passed between two dates.
## Solution
-Use JavaScript's Date function getTime(). Which provides how much time in milliseconds has passed since 01/01/1970:
+Use JavaScript's Date function getTime(). Which provides how much time in milliseconds have passed since 01/01/1970:
{% highlight coffeescript %}
DAY = 1000 * 60 * 60 * 24
@@ -22,12 +22,10 @@ days_passed = Math.round((d2.getTime() - d1.getTime()) / DAY)
## Discussion
-Using milliseconds makes the life easier to avoid overflow mistakes with Dates. So we first calculate how much milliseconds has a day.
-Then, given two distinct dates, just get the difference in milliseconds between two dates and then divide by how much milliseconds has a
-day. It will get you the days between two distinct dates.
+Using milliseconds makes the life easier to avoid overflow mistakes with Dates. So we first calculate how many milliseconds are in a day.
+Then, given two distinct dates, get the difference in milliseconds between two dates and then divide by how many milliseconds are in a day. It will return the days between two distinct dates.
-If you'd like to calculate the hours between two date objects, you can do that just by dividing the difference in milliseconds by the
-conversion of milliseconds to hours. The same goes for minutes and seconds.
+If you'd like to calculate the hours between two date objects, you can do that by dividing the difference in milliseconds by the conversion of milliseconds to hours. The same goes for minutes and seconds.
{% highlight coffeescript %}
HOUR = 1000 * 60 * 60
diff --git a/chapters/dates_and_times/index.html b/chapters/dates_and_times/index.html
index 969aee4..3009762 100644
--- a/chapters/dates_and_times/index.html
+++ b/chapters/dates_and_times/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/design_patterns/adapter.md b/chapters/design_patterns/adapter.md
index bcf4544..e82d19b 100644
--- a/chapters/design_patterns/adapter.md
+++ b/chapters/design_patterns/adapter.md
@@ -10,7 +10,7 @@ Luckily, you remembered you've brought your power adapter with you.
It will connect your power cord socket on one side and wall socket on the other side, allowing for communication between them.
The same situation may arise in code, when 2 (or more) instances (of classes, modules, etc.) want to talk to each other, but whose communication protocol (e.i. the language they use to communicate) is different from each other.
-In such a situation, the [Adapter Pattern](//en.wikipedia.org/wiki/Adapter_pattern) comes in handy. It will do the translation, from one side to the other.
+In such a situation, the [Adapter Pattern]({{ site.baseurl }}//en.wikipedia.org/wiki/Adapter_pattern) comes in handy. It will do the translation, from one side to the other.
## Solution
diff --git a/chapters/design_patterns/index.html b/chapters/design_patterns/index.html
index e488a5d..a548aad 100644
--- a/chapters/design_patterns/index.html
+++ b/chapters/design_patterns/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/design_patterns/interpreter.md b/chapters/design_patterns/interpreter.md
index 0f6ba9d..e3fa133 100644
--- a/chapters/design_patterns/interpreter.md
+++ b/chapters/design_patterns/interpreter.md
@@ -140,4 +140,4 @@ send toasted ham turkey sandwich to 'Rachel' # => "Rachel requested a toasted, w
send toasted turkey ham swiss sandwich to 'Matt' # => "Matt requested a toasted, white bread sandwich with swiss, ham and turkey"
{% endhighlight %}
-This example allows for layers of functions by how it returns the modified object so that outer functions can modify it in turn. By borrowing a very and the particle _to_, the example lends natural grammar to the construction and ends up reading like an actual sentence when used correctly. This way, both your CoffeeScript skills and your existing language skills can help catch code problems.
+This example allows for layers of functions by how it returns the modified object so that outer functions can modify it in turn. By borrowing a verb and the preposition _to_, the example lends natural grammar to the construction and ends up reading like an actual sentence when used correctly. This way, both your CoffeeScript skills and your existing language skills can help catch code problems.
diff --git a/chapters/functions/index.html b/chapters/functions/index.html
index be9a60a..eb3b4e9 100644
--- a/chapters/functions/index.html
+++ b/chapters/functions/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
-
\ No newline at end of file
+
diff --git a/chapters/jquery/ajax.md b/chapters/jquery/ajax.md
index 97d0769..54d89a5 100644
--- a/chapters/jquery/ajax.md
+++ b/chapters/jquery/ajax.md
@@ -43,4 +43,4 @@ jQuery 1.5 and later have added a new, supplemental API for handling different c
## Discussion
-The jQuery and $ variables can be used interchangeably. See also [Callback bindings](/chapters/jquery/callback-bindings-jquery).
+The jQuery and $ variables can be used interchangeably. See also [Callback bindings]({{ site.baseurl }}/chapters/jquery/callback-bindings-jquery).
diff --git a/chapters/jquery/index.html b/chapters/jquery/index.html
index 278cdbe..770dd77 100644
--- a/chapters/jquery/index.html
+++ b/chapters/jquery/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/math/constants.md b/chapters/math/constants.md
index 989012a..d3d25c7 100644
--- a/chapters/math/constants.md
+++ b/chapters/math/constants.md
@@ -45,4 +45,4 @@ Math.LOG10E
## Discussion
-For another example of how a math constant is used in a real world problem, refer to the [Converting Radians and Degrees](/chapters/math/radians-degrees) section of this Math chapter.
+For another example of how a math constant is used in a real world problem, refer to the [Converting Radians and Degrees]({{ site.baseurl }}/chapters/math/radians-degrees) section of this Math chapter.
diff --git a/chapters/math/generating-random-numbers.md b/chapters/math/generating-random-numbers.md
index e795652..e1b3a44 100644
--- a/chapters/math/generating-random-numbers.md
+++ b/chapters/math/generating-random-numbers.md
@@ -36,6 +36,6 @@ range = Math.random() * (max - min) + min
This is a straight lift from JavaScript.
-Note that JavaScript's Math.random() does not allow you to seed the random number generator to force certain values. See [Generating Predictable Random Numbers](/chapters/math/generating-predictable-random-numbers) for that.
+Note that JavaScript's Math.random() does not allow you to seed the random number generator to force certain values. See [Generating Predictable Random Numbers]({{ site.baseurl }}/chapters/math/generating-predictable-random-numbers) for that.
To generate a number from 0 up to (but not including) n, multiply by n. To generate a number from 1 to n (inclusive), multiply by n and add 1.
diff --git a/chapters/math/index.html b/chapters/math/index.html
index 5ad24b7..32eafac 100644
--- a/chapters/math/index.html
+++ b/chapters/math/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/math/working-with-exponents-and-logarithms.md b/chapters/math/working-with-exponents-and-logarithms.md
index c8e7c49..13aedaf 100644
--- a/chapters/math/working-with-exponents-and-logarithms.md
+++ b/chapters/math/working-with-exponents-and-logarithms.md
@@ -34,4 +34,4 @@ Math.log(100) / Math.log(10)
## Discussion
-For more information on the Math object see the documentation on the [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). Also refer to [Math Constants](/chapters/math/constants) for discussion of the various constants in the Math object.
+For more information on the Math object see the documentation on the [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). Also refer to [Math Constants]({{ site.baseurl }}/chapters/math/constants) for discussion of the various constants in the Math object.
diff --git a/chapters/metaprogramming/index.html b/chapters/metaprogramming/index.html
index 7287ee9..4a53a21 100644
--- a/chapters/metaprogramming/index.html
+++ b/chapters/metaprogramming/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/networking/basic-client.md b/chapters/networking/basic-client.md
index 64b3452..e9556db 100644
--- a/chapters/networking/basic-client.md
+++ b/chapters/networking/basic-client.md
@@ -31,7 +31,7 @@ connection.on 'data', (data) ->
### Example Usage
-Accessing the [Basic Server](/chapters/networking/basic-server):
+Accessing the [Basic Server]({{ site.baseurl }}/chapters/networking/basic-server):
{% highlight console %}
$ coffee basic-client.coffee
@@ -43,7 +43,7 @@ Received: Hello, World!
The most important work takes place in the _connection.on 'data'_ handler, where the client receives its response from the server and would most likely arrange for responses to it.
-See also the [Basic Server](/chapters/networking/basic-server), [Bi-Directional Client](/chapters/networking/bi-directional-client), and [Bi-Directional Server](/chapters/networking/bi-directional-server) recipes.
+See also the [Basic Server]({{ site.baseurl }}/chapters/networking/basic-server), [Bi-Directional Client]({{ site.baseurl }}/chapters/networking/bi-directional-client), and [Bi-Directional Server]({{ site.baseurl }}/chapters/networking/bi-directional-server) recipes.
### Exercises
diff --git a/chapters/networking/basic-server.md b/chapters/networking/basic-server.md
index 9dd55c9..90bb381 100644
--- a/chapters/networking/basic-server.md
+++ b/chapters/networking/basic-server.md
@@ -30,7 +30,7 @@ server.listen port, domain
### Example Usage
-Accessed by the [Basic Client](/chapters/networking/basic-client):
+Accessed by the [Basic Client]({{ site.baseurl }}/chapters/networking/basic-client):
{% highlight console %}
$ coffee basic-server.coffee
@@ -44,7 +44,7 @@ Received connection from 127.0.0.1
The function passed to @net.createServer@ receives the new socket provided for each new connection to a client. This basic server simply socializes with its visitors but a hard-working server would pass this socket along to a dedicated handler and then return to the task of waiting for the next client.
-See also the [Basic Client](/chapters/networking/basic-client), [Bi-Directional Server](/chapters/networking/bi-directional-server), and [Bi-Directional Client](/chapters/networking/bi-directional-client) recipes.
+See also the [Basic Client]({{ site.baseurl }}/chapters/networking/basic-client), [Bi-Directional Server]({{ site.baseurl }}/chapters/networking/bi-directional-server), and [Bi-Directional Client]({{ site.baseurl }}/chapters/networking/bi-directional-client) recipes.
### Exercises
diff --git a/chapters/networking/bi-directional-client.md b/chapters/networking/bi-directional-client.md
index b7e020e..99953d7 100644
--- a/chapters/networking/bi-directional-client.md
+++ b/chapters/networking/bi-directional-client.md
@@ -41,7 +41,7 @@ connection.on 'end', (data) ->
### Example Usage
-Accessing the [Bi-Directional Server](/chapters/networking/bi-directional-server):
+Accessing the [Bi-Directional Server]({{ site.baseurl }}/chapters/networking/bi-directional-server):
{% highlight console %}
$ coffee bi-directional-client.coffee
@@ -60,7 +60,7 @@ Connection closed
This particular example initiates contact with the server and starts the conversation in the @connection.on 'connect'@ handler. The bulk of the work in a real client, however, will lie in the @connection.on 'data'@ handler, which processes output from the server. The @ping@ function only recurses in order to illustrate continuous communication with the server and can be removed from a real client.
-See also the [Bi-Directional Server](/chapters/networking/bi-directional-server), [Basic Client](/chapters/networking/basic-client), and [Basic Server](/chapters/networking/basic-server) recipes.
+See also the [Bi-Directional Server]({{ site.baseurl }}/chapters/networking/bi-directional-server), [Basic Client]({{ site.baseurl }}/chapters/networking/basic-client), and [Basic Server]({{ site.baseurl }}/chapters/networking/basic-server) recipes.
### Exercises
diff --git a/chapters/networking/bi-directional-server.md b/chapters/networking/bi-directional-server.md
index d187f92..cb1b982 100644
--- a/chapters/networking/bi-directional-server.md
+++ b/chapters/networking/bi-directional-server.md
@@ -33,7 +33,7 @@ server.listen port, domain
### Example Usage
-Accessed by the [Bi-Directional Client](/chapters/networking/bi-directional-client):
+Accessed by the [Bi-Directional Client]({{ site.baseurl }}/chapters/networking/bi-directional-client):
{% highlight console %}
$ coffee bi-directional-server.coffee
@@ -49,7 +49,7 @@ New connection from 127.0.0.1
The bulk of the work lies in the @socket.on 'data'@ handler, which processes all of the input from the client. A real server would likely pass the data onto another function to process it and generate any responses so that the original handler.
-See also the [Bi-Directional Client](/chapters/networking/bi-directional-client), [Basic Client](/chapters/networking/basic-client), and [Basic Server](/chapters/networking/basic-server) recipes.
+See also the [Bi-Directional Client]({{ site.baseurl }}/chapters/networking/bi-directional-client), [Basic Client]({{ site.baseurl }}/chapters/networking/basic-client), and [Basic Server]({{ site.baseurl }}/chapters/networking/basic-server) recipes.
### Exercises
diff --git a/chapters/networking/index.html b/chapters/networking/index.html
index 5cc875e..27de60d 100644
--- a/chapters/networking/index.html
+++ b/chapters/networking/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/strings/capitalizing-words.md b/chapters/strings/capitalizing-words.md
index 17854d6..28ac74d 100644
--- a/chapters/strings/capitalizing-words.md
+++ b/chapters/strings/capitalizing-words.md
@@ -25,7 +25,7 @@ Or do the same thing using a list comprehension:
## Discussion
-Split, map, join is a common scripting pattern dating back to Perl. This function may benefit from being placed directly onto the String class by [Extending Classes](/chapters/objects/extending-classes).
+Split, map, join is a common scripting pattern dating back to Perl. This function may benefit from being placed directly onto the String class by [Extending Classes]({{ site.baseurl }}/chapters/objects/extending-classes).
Be aware that two wrinkles can appear in the split, map, join pattern. The first is that the split text works best when it is constant. If the source string has multiple spaces in it, the split will need to take this into account to prevent getting extra, empty words. One way to do this is with a regular expression to split on runs of whitespace instead of a single space:
diff --git a/chapters/strings/finding-substrings.md b/chapters/strings/finding-substrings.md
index a33af8c..ee81e89 100644
--- a/chapters/strings/finding-substrings.md
+++ b/chapters/strings/finding-substrings.md
@@ -24,8 +24,8 @@ message.indexOf "This", 5
message.lastIndexOf "This"
# => 49
-{% endhighlight %}
-
-## Discussion
+# Count occurrences of a given string
+message.split(" a ").length - 1
+# => 3
-Still need recipe to count occurrences of a given string within a message.
+{% endhighlight %}
diff --git a/chapters/strings/index.html b/chapters/strings/index.html
index 50a3d9f..b74efe3 100644
--- a/chapters/strings/index.html
+++ b/chapters/strings/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/chapters/strings/replacing-sub-strings.md b/chapters/strings/replacing-sub-strings.md
new file mode 100644
index 0000000..add9945
--- /dev/null
+++ b/chapters/strings/replacing-sub-strings.md
@@ -0,0 +1,29 @@
+---
+layout: recipe
+title: Replacing Sub-Strings Within a String
+chapter: Strings
+---
+## Problem
+
+You want to replace a sub-string with a new sub-string.
+
+## Solution
+
+Split the string using the sub-string you want to remove as a delimiter. Then re-join using the new sub-string as the delimiter.
+
+{% highlight coffeescript %}
+"Orange is the new Black".split("Orange").join("Pink")
+# => "Pink is the new Black"
+
+"I am so sad. I cannot believe how sad I am today!".split("sad").join("happy")
+# => "I am so happy. I cannot believe how happy I am today!"
+
+"I am not a crook.".split("not ").join("")
+# => "I am a crook."
+{% endhighlight %}
+
+## Discussion
+
+You can also use regexes. If you're matching an exact string, this way is simpler and 10x faster.
+
+If you use regexes, remember that you must escape certain characters.
diff --git a/chapters/syntax/code_reuse_on_client_and_server.md b/chapters/syntax/code_reuse_on_client_and_server.md
index f7a1aca..92e706b 100644
--- a/chapters/syntax/code_reuse_on_client_and_server.md
+++ b/chapters/syntax/code_reuse_on_client_and_server.md
@@ -57,7 +57,7 @@ undefined
{% endhighlight %}
-In our web page, we can include our module using by including it as a script.
+In our web page, we can include our module by including it as a script.
{% highlight html %}
diff --git a/chapters/syntax/index.html b/chapters/syntax/index.html
index deb6165..03ab758 100644
--- a/chapters/syntax/index.html
+++ b/chapters/syntax/index.html
@@ -11,7 +11,7 @@
{% for page in site.pages %}
{% if page.url contains url %}
{% unless page.url == indexurl %}
-
{% endunless %}
{% endif %}
{% endfor %}
diff --git a/contributing.md b/contributing.md
index e51cdee..f1f14a7 100644
--- a/contributing.md
+++ b/contributing.md
@@ -15,16 +15,16 @@ Here's the Contribution Recipe:
## Wanted Recipes
-Want to help, but don't know where to start? Want a recipe, but don't know how to write it? Check out the [Wanted Recipes](/wanted-recipes) page!
+Want to help, but don't know where to start? Want a recipe, but don't know how to write it? Check out the [Wanted Recipes]({{ site.baseurl }}/wanted-recipes) page!
## Authors
-Write recipes! Fork the repository, author some pages, and send us a pull request. For more information read the [Author's Guide](/authors-guide).
+Write recipes! Fork the repository, author some pages, and send us a pull request. For more information read the [Author's Guide]({{ site.baseurl }}/authors-guide).
## Developers
-Improve the code! Fork the repository, extend or improve the site coded, and send a pull request. For more information read the [Developer's Guide](/developers-guide).
+Improve the code! Fork the repository, extend or improve the site coded, and send a pull request. For more information read the [Developer's Guide]({{ site.baseurl }}/developers-guide).
## Designers
-Make this site look pretty! Fork the repository, extend, improve or update the design, and send a pull request. For more information read the [Designer's Guide](/designers-guide).
+Make this site look pretty! Fork the repository, extend, improve or update the design, and send a pull request. For more information read the [Designer's Guide]({{ site.baseurl }}/designers-guide).
diff --git a/designers-guide.md b/designers-guide.md
index 3a510a0..df6381c 100644
--- a/designers-guide.md
+++ b/designers-guide.md
@@ -5,7 +5,7 @@ title: Designer's Guide
# Designer's Guide
-Start with the [Developer's Guide](/developers-guide) to get a test version of the cookbook up and running on your machine, and get started!
+Start with the [Developer's Guide]({{ site.baseurl }}/developers-guide) to get a test version of the cookbook up and running on your machine, and get started!
If you have been waiting for your chance to literally _write the designer's guide_ for a website that is also a cookbook about CoffeeScript...
diff --git a/index.html b/index.html
index 98947f9..cd3f572 100644
--- a/index.html
+++ b/index.html
@@ -5,7 +5,7 @@
Welcome to the CoffeeScript Cookbook!
-
CoffeeScript recipes for the community by the community. Head over to the Contribute page and see what you can do to help out!
+
CoffeeScript recipes for the community by the community. Head over to the Contribute page and see what you can do to help out!
diff --git a/license.md b/license.md
index f4a9905..2c473db 100644
--- a/license.md
+++ b/license.md
@@ -3,6 +3,6 @@ layout: default
title: License
---
-coffeescriptcookbook.com is licensed under the [Creative Commons Attribution 3.0 Unported (CC BY 3.0)](http://creativecommons.org/licenses/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 is licensed under the [Creative Commons Attribution 3.0 Unported (CC BY 3.0)](http://creativecommons.org/licenses/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.
-[LICENSE](/LICENSE-CC-BY)
+[LICENSE]({{ site.baseurl }}/LICENSE-CC-BY)