<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cakebaker</title>
	<atom:link href="http://cakebaker.42dh.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Mon, 24 Jun 2019 11:15:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.7.23</generator>
	<item>
		<title>Bash autocompletion for Git</title>
		<link>http://cakebaker.42dh.com/2011/04/06/bash-autocompletion-for-git/</link>
		<comments>http://cakebaker.42dh.com/2011/04/06/bash-autocompletion-for-git/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 08:36:05 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1514</guid>
		<description><![CDATA[One thing I often wished to have when using Git was the ability to autocomplete Git commands and branch names. As I had to learn this week from Markus Prinz&#8217; article A few of my Git tricks, tips and workflows, Git comes with an autocompletion script for the Bash shell. But to use the autocompletion, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>One thing I often wished to have when using <a href="http://git-scm.com/">Git</a> was the ability to autocomplete Git commands and branch names. As I had to learn this week from Markus Prinz&#8217; article <a href="http://nuclearsquid.com/writings/git-tricks-tips-workflows.html">A few of my Git tricks, tips and workflows</a>, Git comes with an autocompletion script for the <a href="http://en.wikipedia.org/wiki/Bash_(Unix_shell)">Bash</a> shell. </p>
<p>But to use the autocompletion, you have to enable it. To do that, add the following snippet to your <code>~/.bashrc</code> file (if you are using a Mac, see the aforementioned <a href="http://nuclearsquid.com/writings/git-tricks-tips-workflows.html">article</a>):</p>
<pre>
<code>source /etc/bash_completion.d/git</code>
</pre>
<p>You can then either reload the <code>.bashrc</code> file with <code>source ~/.bashrc</code> or open a new shell to see the autocompletion in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2011/04/06/bash-autocompletion-for-git/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Array iteration with JavaScript</title>
		<link>http://cakebaker.42dh.com/2011/04/01/array-iteration-with-javascript/</link>
		<comments>http://cakebaker.42dh.com/2011/04/01/array-iteration-with-javascript/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 14:51:54 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1487</guid>
		<description><![CDATA[Till recently I always used a for-loop when I had to iterate over an array in JavaScript. For example: var myArray = [1, 2, 3, 4]; for (var i = 0; i &#60; myArray.length; i++) { console.log(myArray[i]); } However, with ECMAScript 5 the Array object itself got some methods for iteration purposes. With those methods [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Till recently I always used a for-loop when I had to iterate over an array in JavaScript. For example:</p>
<pre>
<code>var myArray = [1, 2, 3, 4];

for (var i = 0; i &lt; myArray.length; i++) {
    console.log(myArray[i]);
}</code>
</pre>
<p>However, with <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript 5</a> the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array">Array object</a> itself got some methods for iteration purposes. With those methods you often can write cleaner code than by using a for-loop. Let&#8217;s have a (short) look at those methods. For details, please follow the provided links.</p>
<p><strong>forEach</strong></p>
<p>The <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach">forEach()</a> method calls the provided function for each array element. Using forEach(), we can rewrite the example from above to:</p>
<pre>
<code>var myArray = [1, 2, 3, 4];

myArray.forEach(function (element) {
    console.log(element);
});</code>
</pre>
<p><strong>filter</strong></p>
<p>The <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter">filter()</a> method applies the provided filter function to each array element and returns a new array with all elements for which the filter function returned a true value. </p>
<p>For example, to get only the even numbers of an array we could write the following code:</p>
<pre>
<code>var myArray = [1, 2, 3, 4];

var evenNumbers = myArray.filter(function (x) {
    return x % 2 == 0;
});
// evenNumbers is [2, 4]</code>
</pre>
<p><strong>every</strong> &#038; <strong>some</strong></p>
<p>The <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every">every()</a> and <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some">some()</a> methods are similar: whereas the every() method only returns true if the provided testing function returns a true value for each array element, the some() method returns true if there is at least one array element for which the testing function returns a true value. You can see the difference in this example:</p>
<pre>
<code>var oddNumbers = [1, 3, 5, 7];
var mixedNumbers = [1, 2, 3, 4];
var evenNumbers = [2, 4, 6, 8];

oddNumbers.every(isEven); // returns false
oddNumbers.some(isEven); // returns false

mixedNumbers.every(isEven); // returns false
mixedNumbers.some(isEven); // returns true

evenNumbers.every(isEven); // returns true
evenNumbers.some(isEven); // returns true

function isEven(x) {
    return x % 2 == 0;
}</code>
</pre>
<p><strong>map</strong></p>
<p>The <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map">map()</a> method applies the provided function to each array element and returns an array with the results.</p>
<p>For example, to square all values of an array we can do the following:</p>
<pre>
<code>var myArray = [1, 2, 3, 4];

var squared = myArray.map(function (x) {
    return x * x;
});
// squared is [1, 4, 9, 16]</code>
</pre>
<p><strong>reduce</strong> &#038; <strong>reduceRight</strong></p>
<p>The <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce">reduce()</a> and <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ReduceRight">reduceRight()</a> methods reduce an array step-by-step to a single value by using the provided function and an optional initial value. It works in the following way: the first two array elements (or the initial value and the first array element) are passed as parameters to the provided function. The result of this function call plus the next array element are then used as new parameters for the function. And so on, until there are no more array elements left.</p>
<p>The difference between reduce() and reduceRight() is that reduce() iterates over the array from left-to-right whereas reduceRight() iterates in the opposite direction, from right-to-left.</p>
<p>Here is a simple example to calculate the sum of the values of an array:</p>
<pre>
<code>var myArray = [1, 2, 3, 4];
var initialValue = 10;

myArray.reduce(add); // performs 1 + 2 + 3 + 4 and returns 10
myArray.reduceRight(add); // performs 4 + 3 + 2 + 1 and returns 10

myArray.reduce(add, initialValue); // performs 10 + 1 + 2 + 3 + 4 and returns 20
myArray.reduceRight(add, initialValue); // performs 10 + 4 + 3 + 2 + 1 and returns 20

function add(x, y) {
    return x + y;
}</code>
</pre>
<p>That&#8217;s it. I hope I could give you an overview over the available iteration possibilities in JavaScript. Happy coding!</p>
<p>Update 2011-04-02: I found a site by Microsoft where you can test those methods in your browser: <a href="http://ie.microsoft.com/testdrive/HTML5/ECMAScript5Array/Default.html">ECMAScript 5 Arrays</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2011/04/01/array-iteration-with-javascript/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>2-legged vs. 3-legged OAuth</title>
		<link>http://cakebaker.42dh.com/2011/01/10/2-legged-vs-3-legged-oauth/</link>
		<comments>http://cakebaker.42dh.com/2011/01/10/2-legged-vs-3-legged-oauth/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 17:30:25 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[oauth]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1471</guid>
		<description><![CDATA[From emails I receive it seems like there is a bit of confusion about what the terms 2-legged OAuth and 3-legged OAuth mean. I hope I can clear up this confusion with this article (and don&#8217;t contribute more to the confusion&#8230;). In short, they describe two different usage scenarios of OAuth involving two respectively three [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>From emails I receive it seems like there is a bit of confusion about what the terms <strong>2-legged OAuth</strong> and <strong>3-legged OAuth</strong> mean. I hope I can clear up this confusion with this article (and don&#8217;t contribute more to the confusion&#8230;).</p>
<p>In short, they describe two different usage scenarios of <a href="http://oauth.net/">OAuth</a> involving two respectively three parties.</p>
<p><a href="http://tools.ietf.org/html/rfc5849">3-legged OAuth</a> describes the scenario for which OAuth was originally developed: a resource owner wants to give a client access to a server without sharing his credentials (i.e. username/password). A typical example is a user (resource owner) who wants to give a third-party application (client) access to his Twitter account (server). </p>
<p>On a conceptual level it works in the following way:</p>
<ul>
<li>Client has signed up to the server and got his client credentials (also known as &#8220;consumer key and secret&#8221;) ahead of time</li>
<li>User wants to give the client access to his protected resources on the server</li>
<li>Client retrieves the temporary credentials (also known as &#8220;request token&#8221;) from the server</li>
<li>Client redirects the resource owner to the server</li>
<li>Resource owner grants the client access to his protected resources on the server</li>
<li>Server redirects the user back to the client</li>
<li>Client uses the temporary credentials to retrieve the token credentials (also known as &#8220;access token&#8221;) from the server</li>
<li>Client uses the token credentials to access the protected resources on the server</li>
</ul>
<p><a href="http://oauth.googlecode.com/svn/spec/ext/consumer_request/1.0/drafts/2/spec.html">2-legged OAuth</a>, on the other hand, describes a typical client-server scenario, without any user involvement. An example for such a scenario could be a local Twitter client application accessing your Twitter account.</p>
<p>On a conceptual level 2-legged OAuth simply consists of the first and last steps of 3-legged OAuth:</p>
<ul>
<li>Client has signed up to the server and got his client credentials (also known as &#8220;consumer key and secret&#8221;)</li>
<li>Client uses his client credentials (and empty token credentials) to access the protected resources on the server</li>
</ul>
<p>Above I used Twitter as an example, though strictly speaking, they don&#8217;t use 2-legged OAuth, but a variant of it. They not only provide the client credentials but also the token credentials (see also <a href="http://dev.twitter.com/pages/oauth_single_token">Using one access token with OAuth</a>).</p>
<p>As you have seen, 2-legged OAuth is nothing new, it is simply using OAuth in a different scenario than it was designed for. And hence you can use (almost?) all existing OAuth libraries for 2-legged OAuth, too. </p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2011/01/10/2-legged-vs-3-legged-oauth/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Bugfix release v2010-12-08 of the OpenID component</title>
		<link>http://cakebaker.42dh.com/2010/12/08/bugfix-release-v2010-12-08-of-the-openid-component/</link>
		<comments>http://cakebaker.42dh.com/2010/12/08/bugfix-release-v2010-12-08-of-the-openid-component/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 15:53:40 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[openid]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1465</guid>
		<description><![CDATA[There is a new bugfix release of the OpenID component available: https://github.com/cakebaker/openid-component/downloads. This release fixes a bug in the isOpenIDResponse() method. So far this method only recognized OpenID responses from a GET request. But as I had to learn, there are OpenID providers (e.g. Hyves) responding with a POST request&#8230; So, if you use the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>There is a new bugfix release of the OpenID component available: <a href="https://github.com/cakebaker/openid-component/downloads">https://github.com/cakebaker/openid-component/downloads</a>. </p>
<p>This release fixes a bug in the isOpenIDResponse() method. So far this method only recognized OpenID responses from a GET request. But as I had to learn, there are OpenID providers (e.g. <a href="http://hyves.nl">Hyves</a>) responding with a POST request&#8230; So, if you use the isOpenIDResponse() method, please upgrade to the new version. </p>
<p>However, this bug not only affected the component itself but also the <a href="http://code.42dh.com/openid/">examples</a> and the <a href="https://github.com/cakebaker/openid-component-example">example application</a>. They contained code that looked like:</p>
<pre>
<code>if ($this-&gt;RequestHandler-&gt;isPost()) {
    // make OpenID request
} elseif ($this-&gt;Openid-&gt;isOpenIDResponse()) {
    // handle OpenID response
}</code>
</pre>
<p>This snippet will fail if the response from an OpenID provider is a POST request. Instead it should look like:</p>
<pre>
<code>if ($this-&gt;RequestHandler-&gt;isPost() &amp;&amp; !$this-&gt;Openid-&gt;isOpenIDResponse()) {
    // make OpenID request
} elseif ($this-&gt;Openid-&gt;isOpenIDResponse()) {
    // handle OpenID response
}</code>
</pre>
<p>Please fix this in your code if you followed the examples.</p>
<p>Thanks go to Sam Mousa for reporting this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2010/12/08/bugfix-release-v2010-12-08-of-the-openid-component/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Navigation with the &#8220;j&#8221; and &#8220;k&#8221; keys</title>
		<link>http://cakebaker.42dh.com/2010/12/04/navigation-with-the-j-and-k-keys/</link>
		<comments>http://cakebaker.42dh.com/2010/12/04/navigation-with-the-j-and-k-keys/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 09:33:19 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1456</guid>
		<description><![CDATA[If you are using Vim you already know the meaning of the &#8220;j&#8221; and &#8220;k&#8221; keys: they navigate one line downwards resp. upwards. Some websites like The Big Picture adopted this functionality to provide an easy way to navigate, in the case of The Big Picture to jump from photo to photo. As I wanted [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>If you are using <a href="http://www.vim.org/">Vim</a> you already know the meaning of the &#8220;j&#8221; and &#8220;k&#8221; keys: they navigate one line downwards resp. upwards. Some websites like <a href="http://www.boston.com/bigpicture/">The Big Picture</a> adopted this functionality to provide an easy way to navigate, in the case of The Big Picture to jump from photo to photo.</p>
<p>As I wanted to use the same functionality and didn&#8217;t find an existing solution I wrote a simple <a href="http://jquery.com/">jQuery</a> plugin for this purpose: <a href="https://github.com/cakebaker/jquery-jknavigable">jquery-jknavigable</a>. Its usage is pretty simple, to make the posts of a blog navigable with the &#8220;j&#8221; and &#8220;k&#8221; keys you would use the following code:</p>
<pre>
<code>$('.post').jknavigable();</code>
</pre>
<p>By default the active element is marked with the class &#8220;active&#8221; so you can style it differently. If necessary, you can specify your own class name:</p>
<pre>
<code>$('.post').jknavigable({'activeClass': 'someClass'});</code>
</pre>
<p>That&#8217;s it. Feedback is, as always, welcome.</p>
<p>PS: a good starting point for writing your own plugin is jQuery&#8217;s <a href="http://docs.jquery.com/Plugins/Authoring">Plugin Authoring page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2010/12/04/navigation-with-the-j-and-k-keys/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cucumber: Switching from Webrat to Capybara</title>
		<link>http://cakebaker.42dh.com/2010/09/19/cucumber-switching-from-webrat-to-capybara/</link>
		<comments>http://cakebaker.42dh.com/2010/09/19/cucumber-switching-from-webrat-to-capybara/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 14:24:43 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1441</guid>
		<description><![CDATA[My current testing tool of choice is Cucumber. Cucumber itself integrates well with other tools. One of those tools is Webrat, which allows you to access your application without a browser and to perform actions like clicking on a link or filling out forms. It works fine with Rails 2.3.x, but not with Rails 3 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>My current testing tool of choice is <a href="http://cukes.info/">Cucumber</a>. Cucumber itself integrates well with other tools. One of those tools is <a href="http://github.com/brynary/webrat">Webrat</a>, which allows you to access your application without a browser and to perform actions like clicking on a link or filling out forms. It works fine with Rails 2.3.x, but not with Rails 3 (at least I was not able to make it work, and on <a href="http://www.railsplugins.org/plugins/26-webrat">RailsPlugins.org</a> the current version of Webrat, 0.7.2.beta.1, is listed as &#8220;Maybe [working] with Rails 3&#8221;). Fortunately, there is an alternative working with both Rails versions: <a href="http://github.com/jnicklas/capybara">Capybara</a>. And so I decided to make the switch from Webrat to Capybara. </p>
<p>Before making the switch, I recommend to run your Cucumber tests to ensure all tests pass:</p>
<pre>
<code>$ cucumber features</code>
</pre>
<p>As usual when adding new dependencies, you have to modify the Gemfile of your app. Replace the Webrat entry with:</p>
<pre>
<code>gem "capybara", "0.3.9"</code>
</pre>
<p>and run:</p>
<pre>
<code>$ bundle update</code>
</pre>
<p>With Capybara installed, you have to setup Cucumber to use Capybara by running one of the following commands:</p>
<pre>
<code>// Rails 2.3.9
$ script/generate cucumber --rspec --capybara

// Rails 3.0.0
$ rails generate cucumber:install --rspec --capybara</code>
</pre>
<p>Now, you are ready to run the tests again. If you are lucky, all tests pass, which means there is nothing more to do. However, I think it is more likely you will get a bunch of errors and maybe even some failing tests. </p>
<p>The errors I got were &#8220;undefined method&#8221; errors. They are relatively easy to fix by replacing the no longer existing Webrat methods with their Capybara counterparts. In the following code block I list some examples:</p>
<pre>
<code># Webrat
field_with_id('openid_identifier').value.should =~ /invalid OpenID/
# Capybara
find_field('openid_identifier').value.should =~ /invalid OpenID/

# Webrat
response.should contain('Previous')
# Capybara
page.should have_content('Previous')

# Webrat
assert_have_selector('.author', :count =&gt; 1)
# Capybara
page.should have_css('.author', :count =&gt; 1)

# Webrat
assert_have_xpath("//span[@id='#{id}']", :content =&gt; expected_count)
# Capybara
page.should have_xpath("//span[@id='#{id}']", :text =&gt; expected_count)</code>
</pre>
<p>The trickiest part to fix was the failing test. To test some &#8220;remember me&#8221; functionality I manually set a cookie, and this no longer worked with Capybara: </p>
<pre>
<code>cookies[:remember_me_id] = remember_me_id</code>
</pre>
<p>After some searching I found a <a href="http://gist.github.com/484787">Gist</a> from Nicholas Rutherford in which he dealt with cookies. Thanks to his code I could set my cookie with the following snippet:</p>
<pre>
<code>cookies = Capybara.current_session.driver.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
cookies[:remember_me_id] = remember_me_id</code>
</pre>
<p>And with that, my switch to Capybara was complete. Any questions?</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2010/09/19/cucumber-switching-from-webrat-to-capybara/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Bugfix release for the OpenID component &#038; an example application</title>
		<link>http://cakebaker.42dh.com/2010/07/19/bugfix-release-for-the-openid-component-an-example-application/</link>
		<pubDate>Mon, 19 Jul 2010 14:23:38 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[openid]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1435</guid>
		<description><![CDATA[Last week I received a mail from a user of the OpenID component in which he described that it wasn&#8217;t possible to login with OpenIDs from claimID and Blogger. After some debugging I found the reason for this problem: a bug in the isOpenIDResponse() method. The method only recognized responses from providers using OpenID 2.0, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Last week I received a mail from a user of the <a href="http://code.42dh.com/openid/">OpenID component</a> in which he described that it wasn&#8217;t possible to login with OpenIDs from <a href="http://claimid.com/">claimID</a> and <a href="http://blogger.com">Blogger</a>. After some debugging I found the reason for this problem: a bug in the isOpenIDResponse() method. The method only recognized responses from providers using OpenID 2.0, but not from providers still using the older OpenID 1.x&#8230; So, if you are using this method in your code, please <a href="http://github.com/cakebaker/openid-component/downloads">upgrade</a> to the latest version (v2010-07-17).</p>
<p>I also got asked whether there is an example application that shows the usage of the OpenID component. As I already use a very simple application to test the component manually, I pushed this application to <a href="http://github.com/cakebaker/openid-component-example">GitHub</a> (you can see the application in action on <a href="http://openid-example.42dh.com/">http://openid-example.42dh.com/</a>). I hope this will make it easier for some of you to get started with the OpenID component.</p>
]]></content:encoded>
			</item>
		<item>
		<title>Grouping &#8220;constants&#8221; with JavaScript</title>
		<link>http://cakebaker.42dh.com/2010/07/14/grouping-constants-with-javascript/</link>
		<comments>http://cakebaker.42dh.com/2010/07/14/grouping-constants-with-javascript/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 14:10:32 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1427</guid>
		<description><![CDATA[A while ago I wrote about how you can group related constants in PHP5 by using a constants class: class MyConstants { const AA = 'value'; const BB = 'another value'; } echo MyConstants::AA; // output: value Now, while experimenting with JavaScript (or more precisely with Node.js) I got some constants in my code I [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>A while ago I wrote about how you can <a href="http://cakebaker.42dh.com/2008/10/09/grouping-of-constants/">group related constants</a> in PHP5 by using a constants class:</p>
<pre>
<code>class MyConstants {
    const AA = 'value';
    const BB = 'another value';
}

echo MyConstants::AA; // output: value</code>
</pre>
<p>Now, while experimenting with JavaScript (or more precisely with <a href="http://nodejs.org">Node.js</a>) I got some constants in my code I wanted to organize with such a constants class. My first, albeit naive, approach looked like:</p>
<pre>
<code>var sys = require('sys');

function MyConstants() {
    const AA = 'value';
    const BB = 'another value';
}

sys.puts(MyConstants.AA); // output: undefined</code>
</pre>
<p>However, as you can see, this doesn&#8217;t work. One reason is that <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/const">const</a> &#8220;[c]reates a constant that can be global or local to the function in which it is declared.&#8221;. So it isn&#8217;t possible to create a constants class like I imagined&#8230;</p>
<p>This means we have to emulate a constants class by using static properties and relying on the naming convention that names of constants are uppercased (i.e. the &#8220;constants&#8221; are technically not constants and their value can be changed):</p>
<pre>
<code>var sys = require('sys');

function MyConstants() {
}

MyConstants.AA = 'value';
MyConstants.BB = 'another value';

sys.puts(MyConstants.AA); // output: value</code>
</pre>
<p>If there is a better approach, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2010/07/14/grouping-constants-with-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>OpenID component v2010-05-19 released</title>
		<link>http://cakebaker.42dh.com/2010/05/19/openid-component-v2010-05-19-released/</link>
		<comments>http://cakebaker.42dh.com/2010/05/19/openid-component-v2010-05-19-released/#comments</comments>
		<pubDate>Wed, 19 May 2010 07:51:25 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[openid]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1412</guid>
		<description><![CDATA[As mentioned in the title, I released a new version of the OpenID component today. It&#8217;s a maintenance release: the only change is an update of the bundled PHP OpenID library from version 2.1.2 to 2.2.2. With this change you no longer have to patch the OpenID library if you are working with PHP 5.3. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>As mentioned in the title, I released a new version of the OpenID component today. It&#8217;s a maintenance release: the only change is an update of the bundled <a href="http://github.com/openid/php-openid/">PHP OpenID library</a> from version 2.1.2 to 2.2.2. With this change you no longer have to patch the OpenID library if you are working with PHP 5.3.</p>
<p>To update, simply replace the OpenID component and the content of the &#8220;vendors/Auth&#8221; folder (and its subfolders) with the files from the zip archive.</p>
<p>You can <a href="http://github.com/cakebaker/openid-component/downloads">download</a> the new version from Github.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2010/05/19/openid-component-v2010-05-19-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sassy CSS</title>
		<link>http://cakebaker.42dh.com/2010/05/08/sassy-css/</link>
		<comments>http://cakebaker.42dh.com/2010/05/08/sassy-css/#comments</comments>
		<pubDate>Sat, 08 May 2010 13:13:11 +0000</pubDate>
		<dc:creator><![CDATA[cakebaker]]></dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1398</guid>
		<description><![CDATA[Those who follow me on Twitter probably know about my love-hate relationship with CSS. To ease the pain of working with CSS I switched to Compass, a stylesheet authoring framework. With Compass, you write the stylesheets in Sass (Syntactically Awesome Stylesheets) instead of CSS. Sass is basically CSS without brackets and semicolons, as you can [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Those who follow me on Twitter probably know about my love-hate relationship with CSS. To ease the pain of working with CSS I switched to <a href="http://compass-style.org/">Compass</a>, a stylesheet authoring framework. With Compass, you write the stylesheets in <a href="http://sass-lang.com/">Sass</a> (Syntactically Awesome Stylesheets) instead of CSS. Sass is basically CSS without brackets and semicolons, as you can see in this example from the Sass website:</p>
<pre>
<code>h1
  height: 118px
  margin-top: 1em

.tagline
  font-size: 26px
  text-align: right</code>
</pre>
<p>However, with the upcoming Sass 3 (it is planned to be released on May 10, 2010) a new format gets introduced: SCSS (Sassy CSS). It is a superset of CSS, i.e. each CSS file is automatically a SCSS file (you simply have to change the file extension from &#8220;css&#8221; to &#8220;scss&#8221;). So the example from above in SCSS is just plain CSS:</p>
<pre>
<code>h1 {
  height: 118px;
  margin-top: 1em;
}

.tagline {
  font-size: 26px;
  text-align: right;
}</code>
</pre>
<p>Not that exciting, isn&#8217;t it? </p>
<p>Where SCSS shines is when it comes to the integration of the Sass features (nesting, variables, and mixins) into this format. The devs did a very good job to make it feel like those features are native CSS. </p>
<p>Let&#8217;s have a look at some examples.</p>
<p>Nesting:</p>
<pre>
<code>#header {
  background: gray;
  a {
    background: white;
    color: black;
  }
}</code>
</pre>
<p>Variables:</p>
<pre>
<code>$background_color: gray;

#header {
  background: $background_color;
}</code>
</pre>
<p>Mixins:</p>
<pre>
<code>@mixin red_border($border_width) {
  border: $border_width solid red;
}

#box_a {
  @include red_border(5px);
}

#box_b {
  @include red_border(10px);
}</code>
</pre>
<p>Personally I really like the new SCSS format, and I can only recommend to try it out for yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2010/05/08/sassy-css/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
