<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Westsworld</title>
	
	<link>http://westsworld.dk</link>
	<description>Programming, Code and much more</description>
	<lastBuildDate>Thu, 17 Mar 2011 19:55:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/westsworld" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="westsworld" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Problems connecting to unix:///var/mysql/mysql.sock</title>
		<link>http://westsworld.dk/blog/2011/03/problems-connecting-to-unixvarmysqlmysql-sock/</link>
		<comments>http://westsworld.dk/blog/2011/03/problems-connecting-to-unixvarmysqlmysql-sock/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 19:55:58 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=290</guid>
		<description><![CDATA[In this post I'll go through fixing the problems with PHP and connecting to your local mysql install, using "localhost".

The problems began a while back, with lots of errors in my apache error log saying:
[error] [client ::1] PHP Warning:  mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in ... <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2011/03/problems-connecting-to-unixvarmysqlmysql-sock/">"Problems connecting to unix:///var/mysql/mysql.sock" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://westsworld.dk/blog/2011/01/mysql-5-5-mac-os-x-and-startup-item-security-error/">previous</a> post I talked about MySQL 5.5 and Mac OSX.</p>
<p>In this post I&#8217;ll go through fixing the problems with PHP and connecting to your local mysql install, using &#8220;localhost&#8221;.</p>
<p>The problems began a while back, with lots of errors in my apache error log saying:</p>
<pre>[error] [client ::1] PHP Warning:  mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in ...</pre>
<p>In the rush I was in, I quickly changed my mysql connection to use: 127.0.0.1, which is the IP of your localhost. So basically the same thing.</p>
<p>Today I&#8217;m doing some freelance work for a customer, who has some problems with his server, after the PHP version was upgraded. I decided to fetch all his php files to my local Mac and then run through his webshop, fixing any errors I might see in the log etc.<br />
When starting the my apache and running the website, I quickly found the MySQL connect error again.</p>
<p>Since this project should be a &#8220;search and fix&#8221; mission, I didn&#8217;t have time to change the <strong>mysql_connect(xxx)</strong> statements in the code (yes yes, not my code, so I didn&#8217;t create the mess&#8230;), so instead, I wanted to fix my local PHP->MySQL connection.</p>
<p>The fix was relatively easy, and only contains 1 to 2 steps:</p>
<h3>Step 1 (if needed)</h3>
<p>If you haven&#8217;t activated php.ini on your local install, open a Terminal and write the following command:</p>
<pre>sudo cp /etc/php.ini.default /etc/php.ini</pre>
<p>This copies the default php settings to the php.ini file, which the apache server uses.</p>
<p>Then restart your apache server. (Using System Preferences->Sharing->Web sharing)</p>
<p>Your PHP is now using the php.ini file.</p>
<h3>Step 2</h3>
<p>Open /etc/php.ini file using your favorite text editor.</p>
<p>Goto line 1216 (or search for &#8220;mysql.default_socket = &#8221; without the quotes) and change <strong>/var/mysql/mysql.sock</strong> to <strong>/tmp/mysql.sock</strong></p>
<p>Restart your apache server and you should now be able to connect to localhost again.</p>
<h3>Still have problems?</h3>
<p>If you still have problems, then try the following:</p>
<p>Open Terminal and write:</p>
<pre>mysqladmin version</pre>
<p>It should print something like this:</p>
<pre>mysqladmin  Ver 8.42 Distrib 5.1.53, for apple-darwin10.3.0 on i386
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version		5.1.53
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/tmp/mysql.sock
Uptime:			2 hours 52 min 6 sec

Threads: 3  Questions: 58  Slow queries: 0  Opens: 16  Flush tables: 1  Open tables: 9  Queries per second avg: 0.5</pre>
<p>The path in the <strong>UNIX socket</strong> is the &#8220;localhost&#8221; connection point. So go back to Step 2 and use that path instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2011/03/problems-connecting-to-unixvarmysqlmysql-sock/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using rails and respond_to to include nested data</title>
		<link>http://westsworld.dk/blog/2011/01/using-rails-and-respond_to-to-include-nested-data/</link>
		<comments>http://westsworld.dk/blog/2011/01/using-rails-and-respond_to-to-include-nested-data/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 10:45:56 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[respond_to]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=240</guid>
		<description><![CDATA[I want to display data from a nested table in my XML output using respond_to. I browsed the docs a bit and it seems <strong>:include</strong> is the way to go. However I had some problems getting this to work properly.

I have two models (customer and user) that are linked together. When I fetch the data for a single user, I want my xml output to include the customer data. <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2011/01/using-rails-and-respond_to-to-include-nested-data/">"Using rails and respond_to to include nested data" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>I want to display data from a nested table in my XML output using respond_to. I searched google a bit and it seems <strong>:include</strong> was the way to go. However I had some problems getting this to work properly.</p>
<p>I have two models (customer and user) that are linked together. When I fetch the data for a single user, I want my xml output to include the customer data.</p>
<p>The Customer model:</p>
<pre>
class Customer < ActiveRecord::Base
  has_many :users
end
</pre>
<p>The User model:</p>
<pre>
class User < ActiveRecord::Base
  belongs_to :customer
end
</pre>
<p>In my UserController I use the respond_to method to respond to html and xml data.<br />
The show action is as follows:</p>
<pre>
# Shows the seleted user
def show
  @user = User.find(params[:id])

  respond_to do |format|
    format.html
    format.xml { render :xml => @user) }
  end
end
</pre>
<p>Calling the show action on the user controller as xml should yield something like:</p>
<pre>
&lt;user>
  ...
  &lt;customer>
    ...
  &lt;/customer>
&lt;/user>
</pre>
<p>But the customer data is <strong>not</strong> included.<br />
This puzzled me a bit.</p>
<p>Searching a bit on google got me the following answer:</p>
<pre>
# Shows the seleted user
def show
  @user = User.find(params[:id])

  respond_to do |format|
    format.html
    format.xml { render :xml => @user.to_xml(:include => @user.customer) }
  end
end
</pre>
<p><em><small>source: <a href="http://rubydoc.info/docs/rails/3.0.0/ActionController/MimeResponds">http://rubydoc.info/docs/rails/3.0.0/ActionController/MimeResponds</a></small></em></p>
<p>(I also tried fetching the customer out separately, that didn't work either)</p>
<p>This gave me the following error:</p>
<pre>
undefined method `macro' for nil:NilClass
</pre>
<h2>The solution</h2>
<p>After a lot more searching I found out, that you shouldn't pass an object, but a symbol. The name of the symbol is the data block you want to show, so in my case it was <strong>:customer</strong></p>
<p>The code to fix it was:</p>
<pre>
# Shows the seleted user
def show
  @user = User.find(params[:id])

  respond_to do |format|
    format.html
    format.xml { render :xml => @user.to_xml(:include => :customer) }
  end
end
</pre>
<p>The data for the customer now returned as well.</p>
<h3>Need more data?</h3>
<p>If you need data from several tables, just use an array of symbols instead.</p>
<pre>
# Shows the seleted user
def show
  @user = User.find(params[:id])

  respond_to do |format|
    format.html
    format.xml { render :xml => @user.to_xml(:include => [:customer, :table2, :table3]) }
  end
end
</pre>
<p>Hope you can use this tip.</p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2011/01/using-rails-and-respond_to-to-include-nested-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handle different environments with PHP</title>
		<link>http://westsworld.dk/blog/2011/01/handle-different-environments-with-php/</link>
		<comments>http://westsworld.dk/blog/2011/01/handle-different-environments-with-php/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 12:45:55 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[unittest]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=221</guid>
		<description><![CDATA[Being both a Rails and PHP developer, I'm often lacking a few things when I'm switching from Rails to PHP.

One of the things I miss the most, is the different environments that Rails has, which makes testing, developing, staging and production environments easy.
However, I found a way to do this in PHP as well, without using frameworks like Zend, CakePHP etc. <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2011/01/handle-different-environments-with-php/">"Handle different environments with PHP" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>Being both a Rails and PHP developer, I&#8217;m often lacking a few things when I&#8217;m switching from Rails to PHP.</p>
<p>One of the things I miss the most, is the different environments that Rails has, which makes testing, developing, staging and production environments easy.<br />
However, I found a way to do this in PHP as well, without using frameworks like Zend, CakePHP etc.</p>
<h2>Getting started</h2>
<p>There are basically two things you need to do, in order to get this setup to work properly.</p>
<h3>Configure your server (apache)</h3>
<p>First we need to configure the apache server (If you are using nginx, look at their documentation for help).</p>
<p>The magic lies in using the <a href="http://httpd.apache.org/docs/current/mod/mod_env.html#setenv">SetEnv</a> function in the apache server.<br />
This functions makes a variable available in the <a href="http://php.net/manual/en/reserved.variables.server.php">$_SERVER</a> object in PHP, which is what we are using to differentiate between the environments.</p>
<h4>Virtual hosts</h4>
<p>If you are using virtual hosts, then simply add it with in the <VirtualHost> section.</p>
<p>An example configuration with a &#8220;test&#8221; environment could be:</p>
<pre>
&lt;VirtualHost *:80>
  ServerName my_site.test.dk
  DocumentRoot /var/www/my_site.test.dk

  SetEnv APPLICATION_ENV test

  &lt;Directory /var/www/my_site.test.dk>
    Options Indexes FollowSymLinks -MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  &lt;/Directory>

  ErrorLog /var/log/apache2/my_site.test.dk.error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog /var/log/apache2/access.log combined
&lt;/VirtualHost>
</pre>
<h4>Using the apache.conf / httpd.conf</h4>
<p>On my mac the file is called <strong>httpd.conf</strong>, but on the ubuntu linux servers I&#8217;m managing it&#8217;s called <strong>apache.conf</strong>.</p>
<p>Anyways, just head to the bottom of the file located here:<br />
Linux: /etc/apache/apache.conf<br />
Mac: /etc/apache/httpd.conf</p>
<p>And add the following line:</p>
<pre>
SetEnv APPLICATION_ENV "development"
</pre>
<p>Exchange &#8220;development&#8221; with the environment you are configuring (In my setup, production = no value)</p>
<h3>Configure your application</h3>
<p>Now we need to use the variable passed to the <a href="http://php.net/manual/en/reserved.variables.server.php">$_SERVER</a> object, in order to see what environment we are &#8220;in&#8221;, and configure the application accordingly.</p>
<p>In most projects I have an <strong>environment.inc.php</strong> file, which has the following structure:</p>
<pre>
&lt;?php

// initializing the configuration array (mostly to avoid null warnings)
$envConfiguration = array();

// the environment configuration for the development environment (local machine)
if(isset($_SERVER['APPLICATION_ENV']) &#038;&#038; $_SERVER['APPLICATION_ENV'] == 'development') {
  $envConfiguration = array(
    'db_password' => '12345',
    'db_user' => 'root',
    'db_host' => '127.0.0.1',
    'db_name' => 'my_dev_db'
  );
}
// the environment configuration for the unit testing environment (local machine)
if(isset($_SERVER['APPLICATION_ENV']) &#038;&#038; $_SERVER['APPLICATION_ENV'] == 'unittest') {
  $envConfiguration = array(
    'db_password' => '12345',
    'db_user' => 'root',
    'db_host' => '127.0.0.1',
    'db_name' => 'my_unittest_db'
  );
}
// add more environments here... E.g. staging, test etc

// Not having the APPLICATION_ENV variable set, forces the application to
// use PRODUCTION settings!
// The reason for this is, that I don't always have control of the production
// servers, while I have control over the staging and test servers.
// (You can of course have a <strong>production</strong> value set
else {
  // production environment settings here.
  $envConfiguration = array(
    'db_password' => 'some_strong_password',
    'db_user' => 'some_production_user',
    'db_host' => '127.0.0.1',
    'db_name' => 'production_database'
  );
}
?>
</pre>
<p>Pretty simple ye?</p>
<p>What we are doing is simply checking if the <strong>APPLICATION_ENV</strong> variable is set in the <a href="http://php.net/manual/en/reserved.variables.server.php">$_SERVER</a> object, and if it is, we test what it is.</p>
<p>The reason I&#8217;m checking if the <strong>APPLICATION_ENV</strong> isset, is because it gives a lot of warnings if the variable is not set (which would be in production for my setup).</p>
<h2>What about unit testing? (phpunit)</h2>
<p>Well, I have an answer there as well.</p>
<p>Since the <strong>$_SERVER</strong> variable is not available in unit tests, we simply create it ourselves and set the APPLICATION_ENV to &#8220;unittest&#8221;.</p>
<p>Here is a sample unittest include file, which should be included at the very top of your unittest.<br />
Let&#8217;s call this file <strong>unitTestConfiguration.inc.php</strong> and put it in a folder called <strong>tests</strong></p>
<pre>
&lt;?php

// includes the phpunit framework
require_once 'PHPUnit/Framework.php';

// constructs the SERVER variable to set the environment to unittest.
$_SERVER = array(
  'APPLICATION_ENV' => 'unittest',
  'SERVER_NAME' => 'localhost',
  'REQUEST_URI' => ''
);
// SERVER_NAME and REQUEST_URI is <strong>not needed</strong>, but nice to have

// includes our environment file (remember to add a unittest section there!
include('config/environment.inc.php');

// includes the database file, which reads the $envConfiguration variable
// (which is set in the environment.inc.php file) and connects to the database
include('config/db.inc.php');

// sets the default timezone (Because strftime will throw a warning in PHP5+)
date_default_timezone_set("Europe/Copenhagen");

?>
</pre>
<p>When creating your unit test, simply do the following:</p>
<pre>
&lt;?php

// includes the unit test configuration (including the PHPUnit framework)
include('tests/unitTestConfiguration.inc.php');

class EnvironmentTest extends PHPUnit_Framework_TestCase {
  /**
   * A small test to see if our environment is actually set.
   * (You don't need this test in your test files, this is
   * just for the scope of this post!)
   */
  function testEnvironment() {
    $this->assertTrue(isset($_SERVER['APPLICATION_ENV']));
    $this->assertTrue($_SERVER['APPLICATION_ENV'] == 'unittest');
  }
}
?>
</pre>
<p>To run the unit test, simply open a terminal / command / cmd (or what ever you are using), and go to the project folder.<br />
There you should run the following command:</p>
<pre>
phpunit tests/environmentTest.php
</pre>
<p>On my machine that gives the following output:</p>
<pre>
$ phpunit tests/environmentTest.php
PHPUnit 3.4.14 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 5.75Mb

OK (1 test, 2 assertions
</pre>
<p>Files for this post: <a href='http://westsworld.dk/wp-content/uploads/2011/01/2011-01-08_php_testing_article.zip'>2011-01-08_php_testing_article</a></p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2011/01/handle-different-environments-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL 5.5, Mac OS X and startup item security error</title>
		<link>http://westsworld.dk/blog/2011/01/mysql-5-5-mac-os-x-and-startup-item-security-error/</link>
		<comments>http://westsworld.dk/blog/2011/01/mysql-5-5-mac-os-x-and-startup-item-security-error/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 10:33:55 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=216</guid>
		<description><![CDATA[A few days ago I got a shiny new macbook at work and I needed to install my dev environment again.

I came across a few problems when installing the new MySQL community server package though, which had been upgraded to 5.5 instead of the 5.1 release I had on my old Mac. <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2011/01/mysql-5-5-mac-os-x-and-startup-item-security-error/">"MySQL 5.5, Mac OS X and startup item security error" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>A few days ago I got a shiny new macbook at work and I needed to install my dev environment again.</p>
<p>I came across a few problems when installing the new MySQL community server package though, which had been upgraded to 5.5 instead of the 5.1 release I had on my old Mac.</p>
<h2>Fixing MySQL server startup</h2>
<p>The first problem I came across was that the server would not start properly, using the prefpane item.</p>
<p>This is easily fixed by editing the file <strong>/usr/local/mysql/support-files/mysql.server</strong> and going to line 46 + 47 and replacing the lines there with this:</p>
<pre>
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
</pre>
<p>You can now use the prefpane item to start your MySQL server.</p>
<p><small><em>source: <a href="http://forums.mysql.com/read.php?11,399397,399606#msg-399606">http://forums.mysql.com/read.php?11,399397,399606#msg-399606</a></em></small></p>
<h2>Fixing the autostart</h2>
<p>If you are like me, you like it when all the services start at boot, since you don&#8217;t have to start &#8216;em by hand.<br />
However, there is a problem with getting MySQL server 5.5 to start using the prefpane.</p>
<p>In order to get the autostart up and running you need to fix the privileges on the startup item.<br />
Open a terminal and do the following:</p>
<pre>
sudo chown :wheel /Library/StartupItems/MySQLCOM/MySQLCOM
sudo chown :wheel /Library/StartupItems/MySQLCOM/StartupParameters.plist
</pre>
<p>After that you need to restart the computer. Logging out and back ind will <u>not</u> do the job.</p>
<p><small><em>source: <a href="http://bugs.mysql.com/bug.php?id=57790#c350454">http://bugs.mysql.com/bug.php?id=57790#c350454</a></em></small></p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2011/01/mysql-5-5-mac-os-x-and-startup-item-security-error/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails plugin development using WebMock</title>
		<link>http://westsworld.dk/blog/2011/01/rails-plugin-development-using-webmock/</link>
		<comments>http://westsworld.dk/blog/2011/01/rails-plugin-development-using-webmock/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 13:11:08 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[webmock]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=211</guid>
		<description><![CDATA[I had a few problems getting WebMock working with my rails 3 setup.

When I used webmock in my rails 3 app, the tests ran and all was nice.
But when I wanted to create a plugin using the exact same code as I just tested inside my rails app, I went into some problems.

To start, I created a new plugin using
<pre>
rails generate plugin myclient
</pre>

The files were generated and all seemed fine. <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2011/01/rails-plugin-development-using-webmock/">"Rails plugin development using WebMock" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>I had a few problems getting WebMock working with my rails 3 setup.</p>
<p>When I used webmock in my rails 3 app, the tests ran and all was nice.<br />
But when I wanted to create a plugin using the exact same code as I just tested inside my rails app, I went into some problems.</p>
<p>To start, I created a new plugin using</p>
<pre>
rails generate plugin myclient
</pre>
<p>The files were generated and all seemed fine.<br />
I then wanted to use the webmock plugin, since my client relied on some external services. (Which a test really shouldn&#8217;t do)</p>
<p>I had a really simple test case, just to get started:</p>
<pre>
require 'test_helper'
require 'webmock/test_unit'
require 'curb'

class MyClientTest < ActiveSupport::TestCase
  # Replace this with your real tests.
  test "the truth" do
    assert true
  end

  test 'webmock testing' do
    WebMock.stub_request(:any, 'www.example.com').to_return(:body => 'tester')
    data = Curl::Easy.perform("www.example.com")
    p data.body_str
    assert data.body_str == 'tester'
  end
end
</pre>
<p>When I ran &#8220;rake test&#8221; the test failed and the body that was returned, was the body of the actual page at www.example.com.<br />
After bashing at the problem for a long time, I found out, that webmock doesn&#8217;t work if <strong>webmock</strong> is required <u>before</u> <strong>curb</strong>.</p>
<p>So&#8230; This was just a note about something that really took up too much of my time, and&#8230; yes, I should have know that <strong>webmock</strong> couldn&#8217;t &#8220;overwrite&#8221; the <strong>curb</strong> methods, if it was loaded in first.</p>
<p>Anyways, the final code that works!</p>
<pre>
require 'test_helper'
require 'curb'
require 'webmock/test_unit'

class MyClientTest < ActiveSupport::TestCase
  # Replace this with your real tests.
  test "the truth" do
    assert true
  end

  test 'webmock testing' do
    WebMock.stub_request(:any, 'www.example.com').to_return(:body => 'tester')
    data = Curl::Easy.perform("www.example.com")
    p data.body_str
    assert data.body_str == 'tester'
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2011/01/rails-plugin-development-using-webmock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Read more, continue reading, and how to easily fix it using WP</title>
		<link>http://westsworld.dk/blog/2010/12/read-more-continue-reading-and-how-to-fix-it-using-wp/</link>
		<comments>http://westsworld.dk/blog/2010/12/read-more-continue-reading-and-how-to-fix-it-using-wp/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 23:14:26 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=192</guid>
		<description><![CDATA[<a href="http://twitter.com/jimmiwest/status/19895586870267904">Yesterday</a> I updated my grayish blog theme to a new blue and white theme, with more whitespace and less constraints.
While the new theme is isn't perfect, I shined my website up a bit and it seems nice.

However, scrolling through my twitter list today, I read a blog post by Karan over at <a href="http://mardahl.dk">mardahl.dk</a>, where she discusses the usage of "<strong>Read more</strong>" and "<strong>Click here</strong>" links on webpages. (Direct link to the blog post <a href="http://www.mardahl.dk/2010/11/22/i-dont-want-to-read-more-or-click-here/">here</a>).

This made me investigate what my own website was doing, and while the wording was a bit different, I had the same usability problem she describes in the blog post (you should really read it). People tend to overlook the wording, since lots and lots of advertisements use it. So when I use excerpts on my blog front page, and use the wording "Continue reading", I'm actually scaring the user off, because my message will be misunderstood. <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2010/12/read-more-continue-reading-and-how-to-fix-it-using-wp/">"Read more, continue reading, and how to easily fix it using WP" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/jimmiwest/status/19895586870267904">Yesterday</a> I updated my grayish blog theme to a new blue and white theme, with more whitespace and less constraints.<br />
While the new theme is isn&#8217;t perfect, I shined my website up a bit and it seems nice.</p>
<p>However, scrolling through my twitter list today, I read a blog post by Karan over at <a href="http://mardahl.dk">mardahl.dk</a>, where she discusses the usage of &#8220;<strong>Read more</strong>&#8221; and &#8220;<strong>Click here</strong>&#8221; links on webpages. (Direct link to the blog post <a href="http://www.mardahl.dk/2010/11/22/i-dont-want-to-read-more-or-click-here/">here</a>).</p>
<p>This made me investigate what my own website was doing, and while the wording was a bit different, I had the same usability problem she describes in the blog post (you should really read it). People tend to overlook the wording, since lots and lots of advertisements use it. So when I use excerpts on my blog front page, and use the wording &#8220;Continue reading&#8221;, I&#8217;m actually scaring the user off, because my message will be misunderstood.</p>
<h2>How I fixed it</h2>
<p>When I made my new theme, I simply copied the twentyten theme supplied with wordpress 3, gave it a new name, fixed the style.css file to have my details in it and started to change the stylesheet to make it fit what I wanted.</p>
<p>Karan suggests using a different wording on the links, so it has the &#8220;Read more&#8221; wording, but includes the title of what it actually is, you are reading about.</p>
<p>She suggests the following:</p>
<p><strong>Read more about Education<br />
Read more about our Picture Archive<br />
Read more about meeting the museum around town</strong></p>
<p>And that&#8217;s the approach I&#8217;m going to use as well. However, I will be using the wordpress wording of &#8220;Continue reading&#8221;, since it was there to begin with and because it sounds more like a continuation instead of a whole new beginning to me.</p>
<p><em>Another thing to consider is, that my blog post&#8217;s link will be auto generated, so it&#8217;s easier to do something a bit more generic.</em></p>
<p>This means, that I will be using the following convention:</p>
<p><strong>Continue reading &#8220;my blog post title&#8221;</strong></p>
<p>To do this using the twentyten theme, open up the <strong>functions.php</strong> file that you copied with the theme.</p>
<p>If this is the first time you are altering the file, simply go to line 240, else search for the function named: &#8220;twentyten_continue_reading_link()&#8221;.</p>
<p>The function is defined as follows:</p>
<pre>
/**
 * Returns a "Continue Reading" link for excerpts
 *
 * @since Twenty Ten 1.0
 * @return string "Continue Reading" link
 */
function twentyten_continue_reading_link() {
  return ' &lt;a href="'. get_permalink() . '">' . __( 'Continue reading &lt;span class="meta-nav">&amp;rarr;&lt;/span>', 'twentyten' ) . '&lt;/a>';
}
</pre>
<p>After browsing a bit of documentation in the <em>&#8220;original&#8221; functions.php</em> that wordpress core provides, it seems using globals is that way to go, if you want access to the current post object.</p>
<p>This will make the code look like this:</p>
<pre>
function twentyten_continue_reading_link() {
  global $post;

  return ' &lt;a href="'. get_permalink() . '">' . __( 'Continue reading &lt;span class="meta-nav">&amp;rarr;&lt;/span>', 'twentyten' ) . '&lt;/a>';
}
</pre>
<p>We now have access to the post object and can get the post title from the title from it.<br />
This is done using the variable <strong>post_title</strong> from the <strong>$post</strong> object.</p>
<p>The finished code looks like this:</p>
<pre>
function twentyten_continue_reading_link() {
  global $post;

  return ' &lt;div class="read_more"> '. __('Continue reading', 'twentyten') .' &lt;a href="'. get_permalink() . '">"'. $post->post_title .'" &amp;raquo;&lt;/a> &lt;/div>';
}
</pre>
<p>I added a <strong>div</strong> with a class of &#8220;<strong>read_more</strong>&#8221; around the link, so it would make it easier to style.</p>
<p>After the div there is the wording <strong>Continue reading</strong> and then the link to the blog post, using the title of the post.</p>
<p>What&#8217;s your approach ?</p>
<p>And do you agree with Karan that this will make it more usable or is it the same or even worse ?</p>
<p>All I can say is, that I have already changed it on my blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2010/12/read-more-continue-reading-and-how-to-fix-it-using-wp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows clients with CUPS and Samba</title>
		<link>http://westsworld.dk/blog/2010/12/windows-clients-with-cups-and-samba/</link>
		<comments>http://westsworld.dk/blog/2010/12/windows-clients-with-cups-and-samba/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 10:27:40 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[cups]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[samba]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=169</guid>
		<description><![CDATA[After starting my new job, I battled a bit with getting a printer/scanner working on the local network. The fileserver was a mess as well&#8230; a real mess. My boss gave me permission to install linux on it (since I &#8230; <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2010/12/windows-clients-with-cups-and-samba/">"Windows clients with CUPS and Samba" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>After starting my new job, I battled a bit with getting a printer/scanner working on the local network.<br />
The fileserver was a mess as well&#8230; a real mess.</p>
<p>My boss gave me permission to install linux on it (since I haven&#8217;t really used windows for a long time now) and fix the filesharing and printing on it.<br />
I jumped into the task, knowing in the back of my head, that printing always is a bloody mess to fix, when you have WINDOWS clients on the network.</p>
<p>Anyways, without looking back, I grabbed the new <a href="http://www.ubuntu.com/server">Ubuntu 10.04 server</a> and installed the system. Didn&#8217;t take long, not even for the old machine we have.</p>
<p>After the system was installed, I setup a shared folder and some user shares. I even added our printer (Some old HP CM1015 printer, with a scanner).<br />
No worries!&#8230; well.. on my Mac at least.<br />
The windows clients kept having problems connecting to the printer, but the file shares worked perfectly.</p>
<p>After 2 months of hearing complaints on and off, I finally did some more work with the server and found that this samba -> cups configuration works:</p>
<pre>load printers = yes
printing = cups
printcap name = cups

[printers]
  browsable = yes
  printable = yes
  public = yes
  create mode = 0700
  guest ok = yes
  use client driver = yes
  guest account = smbprint
  path = /var/spool/samba</pre>
<p>As you can see I added a guest account as well.</p>
<pre>/usr/sbin/adduser --system --disabled-password smbprint</pre>
<p>The printer can now be discovered on the network simply by choosing Networks->SERVER_NAME, the shared folders and printers are now displayed.<br />
Just right click on the printer and choose connect.</p>
<p>A special thanks to this guide: <a href="http://tldp.org/HOWTO/Debian-and-Windows-Shared-Printing/sharing_with_windows.html">http://tldp.org/HOWTO/Debian-and-Windows-Shared-Printing/sharing_with_windows.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2010/12/windows-clients-with-cups-and-samba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a Cafe Latté without a “do it all” machine</title>
		<link>http://westsworld.dk/blog/2010/11/making-a-cafe-latte-without-a-do-it-all-machine/</link>
		<comments>http://westsworld.dk/blog/2010/11/making-a-cafe-latte-without-a-do-it-all-machine/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 13:52:42 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[coffee]]></category>
		<category><![CDATA[non-tech]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=145</guid>
		<description><![CDATA[As you properly know, if you know me in real life, "I love coffee".
<em>(I also like tea though, but that's a whole different story.)</em>

Today when I wanted to make me a Latté, I thought to myself:
Why not tell other people how it's done, so they also can enjoy a Cafe Latté without buying an expensive espresso machine. <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2010/11/making-a-cafe-latte-without-a-do-it-all-machine/">"Making a Cafe Latté without a "do it all" machine" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>As you properly know, if you know me in real life, &#8220;I love coffee&#8221;.<br />
<em>(I also like tea though, but that&#8217;s a whole different story.)</em></p>
<p>Today when I wanted to make me a Latté, I thought to myself:<br />
Why not tell other people how it&#8217;s done, so they also can enjoy a Cafe Latté without buying an expensive espresso machine.</p>
<h2>What you need</h2>
<p>For my Latté setup I use the following equipment:<br />
1x Cooking pot<br />
1x Whisk (google translated this one for me)<br />
1x Coffee press<br />
Some hot water<br />
3x tea spoons of grinded coffe (roughly 14-21grams)<br />
Half a cup of milk (I&#8217;m using light milk)<br />
And 10 minutes to spare&#8230;</p>
<p>Here is a picture of the setup:<br />
<a href="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0099.jpg"><img src="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0099-300x225.jpg" alt="My setup" title="IMG_0099" width="300" height="225" class="alignnone size-medium wp-image-149" /></a><br />
<em>(Yep, lots of things to wash up afterwards&#8230;)</em></p>
<h2>Ready, Set, GO!</h2>
<p>First things first. Start by putting on a kettle of with water.<br />
Then grind your coffee beans. (Freshly grinded is always best!)<br />
<a href="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0100.jpg"><img src="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0100-300x225.jpg" alt="Grinded coffee beans" title="IMG_0100" width="300" height="225" class="alignnone size-medium wp-image-150" /></a></p>
<p>Put the grinded coffee beans in the coffee press.<br />
When the water is boiled, wait roughly 30seconds and pour it over the coffee beans.<br />
<a href="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0101.jpg"><img src="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0101-300x225.jpg" alt="Pouring hot water over beans" title="IMG_0101" width="225" height="300" class="alignnone size-medium wp-image-151" /></a></p>
<p>Set a timer between 3mins 30secs and 4minutes, to let the water get the taste of the grinded coffee beans.<br />
<a href="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0102.jpg"><img src="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0102-300x225.jpg" alt="Set a timer" title="IMG_0102" width="225" height="300" class="alignnone size-medium wp-image-152" /></a></p>
<p>And then we need to start making the Latté milk foam.<br />
Since I don&#8217;t have any kind of steamer, i&#8217;m simply pouring half a cup of milk in the pot and whiskering it for the duration the coffee needs to &#8220;drag&#8221;. (The amount of time we set on the timer)</p>
<p>After the milk is done, it will look something like this (all puffy and nice):<br />
<a href="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0104.jpg"><img src="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0104-300x225.jpg" alt="Puffed milk" title="IMG_0104" width="225" height="300" class="alignnone size-medium wp-image-154" /></a></p>
<p>Fill the cup with half coffee and half milk.<br />
I normally pour in the coffee first, then the milk on top. Remember to get lots of the puffed milk at the top, to give it that Cafe-like look.<br />
<a href="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0106.jpg"><img src="http://westsworld.dk/wp-content/uploads/2010/11/IMG_0106-300x225.jpg" alt="Latte is done" title="IMG_0106" width="225" height="300" class="alignnone size-medium wp-image-156" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2010/11/making-a-cafe-latte-without-a-do-it-all-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using form_tag and collection_select with Rails3</title>
		<link>http://westsworld.dk/blog/2010/11/using-form_tag-and-collection_select-with-rails3/</link>
		<comments>http://westsworld.dk/blog/2010/11/using-form_tag-and-collection_select-with-rails3/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 22:06:19 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ror]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=134</guid>
		<description><![CDATA[After being away from rails for a while, i'm coming back en version 3 to check it all out again.

I had a problem with how to create a simple select, using the FormHelper.

I had two models, a user and a customer. They are defined as follows:
<pre>class User &#60; ActiveRecord::Base
  belongs_to :customer
end
</pre>
<pre>class Customer &#60; ActiveRecord::Base
  has_many :users
end
</pre> <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2010/11/using-form_tag-and-collection_select-with-rails3/">"Using form_tag and collection_select with Rails3" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>After being away from rails for a while, i&#8217;m coming back en version 3 to check it all out again.</p>
<p>I had a problem with how to create a simple select, using the FormHelper.</p>
<p>I had two models, a user and a customer. They are defined as follows:</p>
<pre>class User &lt; ActiveRecord::Base
  belongs_to :customer
end
</pre>
<pre>class Customer &lt; ActiveRecord::Base
  has_many :users
end
</pre>
<p>In my UserController I have an action called new, where I initialize a new user object and fetch all the customers from the database:</p>
<pre>class UsersController < ApplicationController
  # Opens the new user view.
  def new
    @user = User.new
    # fetches all the customers, ordered by their name
    @customers = Customer.order(:name)
  end
end
</pre>
<p>However, when I wanted to associate the new user and a customer I couldn't remember how this was done. Then I headed over to api.rubyonrails.com and found the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html">FormHelper</a>, which didn't help me much though...<br />
Then I looked at the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html">FormOptionsHelper</a>, which has the method:<br />
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})</p>
<p>In order to use this in my view, I had the following code:</p>
<pre>&lt;% form_for @user do |f| %>
&lt;ul>
  &lt;li>
    &lt;%= f.label :customer %>
    &lt;!-- select element here!-->
  &lt;/li>
  &lt;li>
    &lt;%= f.label :name %>:
    &lt;%= f.text_field :name %>
  &lt;/li>
  &lt;li>
    &lt;%= f.label :email %>:
    &lt;%= f.text_field :email %>
  &lt;/li>
  &lt;li>
    &lt;%= f.submit %>
  &lt;/li>
&lt;/ul>
&lt;% end %>
</pre>
<p>The method states that it needs an object, a method, a collection, value, text. This resulted in the first try:</p>
<pre>&lt;li>
  &lt;%= f.label :customer %>
  &lt;% f.collection_select :user, :customer_id, @customers, :id, :name %>
&lt;/li></pre>
<p>Which gave a nice error...</p>
<p>This worked however:</p>
<pre>&lt;li>
  &lt;%= f.label :customer %>
  &lt;%= f.collection_select :customer_id, @customers, :id, :name %>
&lt;/li></pre>
<p>Why?<br />
Well the form_tag was being done on the user object already, so the first object could be skipped.</p>
<p>Hope you can use it!</p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2010/11/using-form_tag-and-collection_select-with-rails3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Switching coffee and PHP testing</title>
		<link>http://westsworld.dk/blog/2010/10/switching-coffee/</link>
		<comments>http://westsworld.dk/blog/2010/10/switching-coffee/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 20:52:40 +0000</pubDate>
		<dc:creator>Jimmi Westerberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[job]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[quick tip]]></category>

		<guid isPermaLink="false">http://westsworld.dk/?p=121</guid>
		<description><![CDATA[Whoa, long time since my last post.

Anyways, what has happened recently?

I've switched jobs and are now working at a small IR firm in Denmark, which is located on Amager.
We do webcasts / Quarterly reports for firms in Denmark.

Saying "We do" is a bit off though.
I don't, that is. I help out if we are missing a technician, else i'm creating webapps to help the business complete daily tasks faster. <div class="read_more"> Continue reading <a href="http://westsworld.dk/blog/2010/10/switching-coffee/">"Switching coffee and PHP testing" &#187;</a> </div>]]></description>
			<content:encoded><![CDATA[<p>Whoa, long time since my last post.</p>
<p>Anyways, what has happened recently?</p>
<p>I&#8217;ve switched jobs and are now working at a small IR firm in Denmark, which is located on Amager.<br />
We do webcasts / Quarterly reports for firms in Denmark.</p>
<p>Saying &#8220;We do&#8221; is a bit off though.<br />
I don&#8217;t, that is. I help out if we are missing a technician, else i&#8217;m creating webapps to help the business complete daily tasks faster.</p>
<p>And how is that going?<br />
Well, I&#8217;ve completed a few systems already, and within one month the first system was deployed to the wild. It was fun to create a whole new system, especially because I am on my own.<br />
Roughly speaking, i&#8217;m the only developer there, so I don&#8217;t get a lot of sparing on the code i&#8217;m writing. Only the designs and the general &#8220;look and feel&#8221; of an app.<br />
It&#8217;s fun, it&#8217;s different and I like the pace.</p>
<p>An other thing i&#8217;ve been working on, is moving the old and new sites to new virtualized servers.<br />
I&#8217;ve been managing a few servers for the last 6 years, but not anything on this scale. But it&#8217;s fun. It takes a little time from the programming though, but after it&#8217;s configured, it mostly runs smoothly.</p>
<p>I developed an SSO system and deployed it to the wild a few months ago. So far i&#8217;ve only had minor problems with it, and all things are running great.</p>
<p>And yes, I code in PHP. It was by choice actually. On my last jobs I&#8217;ve coded Bash, Perl, C, C++, then Java and then Ruby on Rails and on the new job I was given a free choice.</p>
<p>So I chose <strong>PHP</strong>.</p>
<p>&#8220;Why?&#8221; you might ask, when there&#8217;s soo much hype about Ruby on Rails these past few years. Without starting a flame wall in the comments, let&#8217;s just say, that while Ruby is a beautiful language, I just couldn&#8217;t get accustomed to the Rails frame work. So many rules, so many conventions. So little time. (The testing was nice though.. but meh)<br />
I might return to Rails someday, but for now, it&#8217;s PHP controlling the battle.</p>
<p>The webapps i&#8217;ve created at my new job are all created using my small github project called php-mvc-base, which basically is just a structure I use to get started on a PHP project. It gives me &#8220;nice urls&#8221;, but other than that, the rules are pretty basic.</p>
<p>The structure outlines as follows:</p>
<pre>/app
/app/controllers
/app/models
/app/views
/public/images
/public/javascripts
/public/stylesheets</pre>
<p>And all controllers (ofc) go in the app/controllers folder.<br />
So let&#8217;s say, that we want a new controller at the URL http://localhost/my_projects/ there is basically two things that can be done:<br />
* Create a folder in the app/controllers folder, called my_projects. Place an index.php file there, do the controller code.<br />
* Create a my_projects.php file in the app/controllers folder. Do the controller code.<br />
Both options give the same path.</p>
<p>Simple and clean (well, at least in my world. And I use the folder approach btw, if you wanted to know).</p>
<p>(You can find the project at <a href="http://github.com/jimmiw/php-mvc-base">http://github.com/jimmiw/php-mvc-base</a> along with a simple example.)</p>
<p>I&#8217;ve also released a few javascripts to CodeCanyon and I&#8217;ve had a few purchases already. It&#8217;s nice knowing people can use your stuff. I mostly coded them because I had a problem they could solve, but releasing them there, made the code so much better. This was mostly due to the javascript approval team on CodeCanyon (Thanks Jeremy McPeak for the patience and help).</p>
<p>You can see my profile on CodeCanyon here: <a href="http://codecanyon.net/user/jimmiw">http://codecanyon.net/user/jimmiw</a></p>
<p>I&#8217;ve also taken over a small project with a designer friend of mine called Janus C.<br />
The project is <a href="http://familielivet.dk">familielivet</a> and is a danish page the centers around the family. It&#8217;s free to use and hopefully easy to understand and use for all ages.<br />
I&#8217;ve not actually released any code to the system yet, but we a doing some design changes and a total rewrite of the codebase, and it will hopefully be released soon.</p>
<p>After switching from Ruby to PHP I missed the easy testing that Ruby offered. Thank god for <a href="http://phpunit.de">phpunit</a> btw, this lovely tool simply makes testing fun again. Be sure to check it out when you are writing tests for your webapps (As you should be!).</p>
<p>On an interesting side note, Rails offers the ease of different environments for you to use.<br />
E.g. Test, Staging and Production.<br />
I actually found a simple way of doing this with PHP as well, but it requires that you have access to the apache configuration files (which you at least have on your development machine).</p>
<p>Roughly speaking, all you need to do, is to add a variable to your apache config, and then use the $_SERVER variable in PHP to test what environment your are currently working on.<br />
Nice and simple.<br />
A small example is this (taken from my development machine):<br />
Just add the following piece of code to the bottom of your httpd.conf file<br />
<code>SetEnv APPLICATION_ENV "development"</code></p>
<p>And in PHP you can do the following when initializing the database connection:</p>
<pre>&lt;?php
  // development machine
  if($_SERVER['APPLICATION_ENV'] == "development") {
    mysql_connect(HOST, USER, PASSWORD);
    mysql_select_db(DATABASENAME);
  }
  // add as many environments as you want
  // the ELSE part is used for production. On shared hosts you cannot edit the
  // httpd.conf file, so if nothing is set, assume it's Production ;)
  else {
    mysql_connect(PRODUCTION_HOST, PRODUCTION_USER, PRODUCTION_PASSWORD);
    mysql_select_db(PRODUCTION_DATABASENAME);
  }
?></pre>
<p>I have a &#8220;unit&#8221; environment as well, which I use when testing database models using phpunit tests. This makes it easier to wipe database tables when starting tests.</p>
<p>And I switched from black coffee to Lattes.<br />
No idea why, but after drinking black coffee for about 10years, they suddenly seem a bit boring&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://westsworld.dk/blog/2010/10/switching-coffee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

