<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Ramlev.dk]]></title>
  <link href="http://ramlev.dk/atom.xml" rel="self"/>
  <link href="http://ramlev.dk/"/>
  <updated>2012-05-16T19:38:20+02:00</updated>
  <id>http://ramlev.dk/</id>
  <author>
    <name><![CDATA[Hasse R. Hansen]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Getting started with vagrant]]></title>
    <link href="http://ramlev.dk/blog/2012/04/04/getting-started-with-vagrant/"/>
    <updated>2012-04-04T21:58:00+02:00</updated>
    <id>http://ramlev.dk/blog/2012/04/04/getting-started-with-vagrant</id>
    <content type="html"><![CDATA[<p>A Virtual Machine is a nice solution to handle different environments on you local machine. My computer is a Macbook Air, and, yes, i can install and use <a href="http://httpd.apache.org/">Apache</a>, <a href="http://nginx.org/">nginx</a>, <a href="http://php.net">php</a>, <a href="http://mysql.com">MySQL</a> and so on, on that machine, and i often do. But if you want to make sure a project is with php5.2.7 on an <a href="http://httpd.apache.org/">Apache</a> with a special version of MySQL, you don&#8217;t want to mess up you local environment.</p>

<p>I have been using <a href="http://virtualbox.org">VirtualBox</a> for years, mostly for IE testing, but also for a linux playfield. But the whole VirtualBox is a bit too much for me. I fell over <a href="http://vagrantup.com">Vagrant</a>, created by <a href="http://twitter.com/mitchellh">Mitchell Hashimoto</a>, which does it for me, since i can run multiple VM without starting VirtualBox since it&#8217;s running in the background.</p>

<!-- more -->


<p>Vagrant is handeled commandline, and easy access via ssh, shutting down and so on. Check the <a href="documentation">http://vagrantup.com/docs/getting-started/index.html</a>.</p>

<p>And it supports shared folders, so lets say all on your development code is on your local machine, and by configurering your Vagrant VM you can have access to these files across multiple VM&#8217;s.</p>

<blockquote><p><strong>Thats freaking awesome</strong>!!11!one!!.. <a href="http://twitter.com/mitchellh">@mitchellh</a></p></blockquote>

<h2>Installing Vagrant</h2>

<p>To be able to install <a href="http://vagrantup.com">Vagrant</a>, you will need to have <a href="http://www.ruby-lang.org/en/">Ruby</a>, <a href="http://rubygems.org/">RubyGems</a> and most important <a href="https://www.virtualbox.org/">Virtual 4.x+</a>.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>gem install vagrant
</span></code></pre></td></tr></table></div></figure>


<h2>Creating a new VM based on a Ubuntu</h2>

<p>In this guide we&#8217;re going to install the <a href="http://releases.ubuntu.com/lucid/">Ubuntu 10.04 Lucid Lynx</a> the only reason for that is that it&#8217;s a official box on the <a href="http://vagrantup.com">Vagrant</a> website.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>vagrant box add lucid http://files.vagrantup.com/lucid32.box
</span></code></pre></td></tr></table></div></figure>


<p>If you want to go with the official <a href="http://releases.ubuntu.com/11.10/">11.10 Oneiric Ocelot</a> release, witch is the latest stable Ubuntu release right now, you can use this instead.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>vagrant box add oneiric http://timhuegdon.com/vagrant-boxes/ubuntu-11.10.box
</span></code></pre></td></tr></table></div></figure>


<p>Create a subdirectory for your virtual machine.</p>

<p>It&#8217;s so easy to have multiple VM&#8217;s, just add a subdirectory in the ~/servers folder, and execute this command for as many VM&#8217;s you want.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>mkdir -p ~/servers/develop
</span><span class='line'><span class="nv">$ </span><span class="nb">cd</span> ~/servers/develop
</span><span class='line'><span class="nv">$ </span>vagrant init lucid <span class="c"># or &quot;$ vagrant init oneiric&quot; - if you&#39;re going with the 11.10 release from above</span>
</span></code></pre></td></tr></table></div></figure>


<p>After installing the VM we&#8217;re going to configure the VM a bit, just the most simple and most needed configuration.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>vim ~/servers/develop/Vagrantfile
</span></code></pre></td></tr></table></div></figure>


<p>And replace everything with</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="no">Vagrant</span><span class="o">::</span><span class="no">Config</span><span class="o">.</span><span class="n">run</span> <span class="k">do</span> <span class="o">|</span><span class="n">config</span><span class="o">|</span>
</span><span class='line'>  <span class="n">config</span><span class="o">.</span><span class="n">vm</span><span class="o">.</span><span class="n">box</span> <span class="o">=</span> <span class="s2">&quot;oneiric&quot;</span>
</span><span class='line'>
</span><span class='line'>    <span class="n">config</span><span class="o">.</span><span class="n">vm</span><span class="o">.</span><span class="n">forward_port</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">8000</span>
</span><span class='line'>    <span class="n">config</span><span class="o">.</span><span class="n">vm</span><span class="o">.</span><span class="n">forward_port</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">2222</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>It&#8217;s not really rocketscience, but we&#8217;re telling vagrant to forward port 80 to 8000 and 22 to 2222, so from your terminal, yo can access port 80 on the vagrant VM with http://localhost:8000 (when we have installed nginx :o) )</p>

<h2>Starting it up</h2>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>vagrant up
</span></code></pre></td></tr></table></div></figure>


<p>When the box have been loaded, and you have been told a bit about the settings of the server, you can now login, either with a shortcut,</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>&gt; vagrant up
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Importing base box <span class="s1">&#39;ocelot&#39;</span>...
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Matching MAC address <span class="k">for </span>NAT networking...
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Clearing any previously <span class="nb">set </span>forwarded ports...
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> -- <span class="nv">22</span> <span class="o">=</span>&gt; 2200 <span class="o">(</span>adapter 1<span class="o">)</span>
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Creating shared folders metadata...
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Clearing any previously <span class="nb">set </span>network interfaces...
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Booting VM...
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Waiting <span class="k">for </span>VM to boot. This can take a few minutes.
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> VM booted and ready <span class="k">for </span>use!
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> Mounting shared folders...
</span><span class='line'><span class="o">[</span>default<span class="o">]</span> -- v-root: /vagrant
</span></code></pre></td></tr></table></div></figure>


<p>In this case, we&#8217;re told that the port 2222 is used by something else on the system, so it makes an automatic change of port to 2200. Thats not nessessary an issue on your computer. But if you have multiple vagrant boxes loaded at the same time, this could easy be an issue.</p>

<h2>Accessing it</h2>

<p>When a box is created the uses and password is always <code>vagrant</code> / <code>vagrant</code></p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>vagrant ssh
</span></code></pre></td></tr></table></div></figure>


<p>Or with a regular ssh command like you&#8217;re used to</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>ssh vagrant@localhost -p 2200
</span></code></pre></td></tr></table></div></figure>


<h2>Shutdown, suspend &#8230;</h2>

<p>Vagrant comes with a bunch of commands which does the work</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>vagrant up <span class="c"># starts a VM.</span>
</span><span class='line'><span class="nv">$ </span>vagrant status <span class="c"># Status of the current VM.</span>
</span><span class='line'><span class="nv">$ </span>vagrant ssh <span class="c"># Logs you into the current VM.</span>
</span><span class='line'><span class="nv">$ </span>vagrant halt <span class="c"># shuts down.</span>
</span><span class='line'><span class="nv">$ </span>vagrant <span class="nb">suspend</span> <span class="c"># Suspend the box to the current state.</span>
</span><span class='line'><span class="nv">$ </span>vagrant resume <span class="c"># Resumes a suspended box.</span>
</span><span class='line'><span class="nv">$ </span>vagrant destroy <span class="c"># Deletes the VM, everythings gone.</span>
</span></code></pre></td></tr></table></div></figure>


<p>Thats it for the simple use of <code>Vagrant</code>, below i have created a little guide to install the most common tools for a Nginx, MariaDB, PHP and Drupal developing environment.</p>

<h2>Configuring the Linuxbox</h2>

<p>Just to get the linux server up and running with the most needed tools. A more advanced description of how to configure a setup like this, is in <a href="http://ramlev.dk/blog/2011/12/18/setup-osx-as-the-most-awesome-php-developing-environment">this blogpost</a> - but it&#8217;s for Mac OSX, but not really an issue to get converted to linux.</p>

<p>We should make sure the setup it up to date.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>apt-get update
</span><span class='line'><span class="nv">$ </span>apt-get upgrade
</span></code></pre></td></tr></table></div></figure>


<p>This is needed later on.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>apt-get install python-software-properties
</span></code></pre></td></tr></table></div></figure>


<h2>Install and configure MariaDB</h2>

<p>In this guide we&#8217;re going to use MariaDB over the MySQL, have had more stability with this, and less hard on the ressources.</p>

<p>First of all we&#8217;re going to add MariaDB to the apt repository list. So create the file.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>vim /etc/apt/sources.list.d/mariadb.list
</span></code></pre></td></tr></table></div></figure>


<p>And add the following to the file.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="c"># MariaDB repository list - created 2012-02-15 07:42 UTC</span>
</span><span class='line'><span class="c"># http://downloads.askmonty.org/mariadb/repositories/</span>
</span><span class='line'>deb http://ftp.osuosl.org/pub/mariadb/repo/5.3/ubuntu oneiric main
</span><span class='line'>deb-src http://ftp.osuosl.org/pub/mariadb/repo/5.3/ubuntu oneiric main
</span></code></pre></td></tr></table></div></figure>


<p>And you need to fetch the repository key.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
</span></code></pre></td></tr></table></div></figure>


<p>Now it&#8217;s time to update the apt cache, to let apt know we got some new repositories, and ofcourse install MariaDB.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>apt-get update
</span><span class='line'><span class="nv">$ </span>apt-get install mariadb-server
</span></code></pre></td></tr></table></div></figure>


<p>For security reasons and to clean the database run the following, and answer the questions.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>mysql_secure_installation
</span></code></pre></td></tr></table></div></figure>


<h2>Nginx + PHP 5</h2>

<p>Im not going into configuring Nginx or PHP5, just installing the tools. You can take a look at <a href="http://ramlev.dk/blog/2011/12/18/setup-osx-as-the-most-awesome-php-developing-environment">Setup OSX as the Most Awesome PHP Developing Environment</a> if you want my totally awësome dns/nginx automatic vhost setup.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>apt-add-repository ppa:brianmercer/nginx
</span><span class='line'><span class="nv">$ </span>apt-get update
</span></code></pre></td></tr></table></div></figure>




<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>apt-get install nginx-custom php5-cli php5-mysql php5-fpm php5-gd php-pear
</span></code></pre></td></tr></table></div></figure>


<h2>Update Pear</h2>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>pear upgrade --force Console_Getopt
</span><span class='line'><span class="nv">$ </span>pear upgrade --force pear
</span><span class='line'><span class="nv">$ </span>pear upgrade-all
</span></code></pre></td></tr></table></div></figure>


<h2>The other utilities</h2>

<p>To get a development server up and running with the utuilities we use the most, we need the following tools.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install git-core git-doc vim postfix rsync unzip bzr patch curl
</span></code></pre></td></tr></table></div></figure>


<p>We could install drush from apt, but it&#8217;s not in the newest version, so we&#8217;re going to install it with <a href="http://pear.php.net/">Pear</a></p>

<h2>Install Drush</h2>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>pear channel-discover pear.drush.org
</span><span class='line'><span class="nv">$ </span>pearh install drush/drush
</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[create a ctools access plugin]]></title>
    <link href="http://ramlev.dk/blog/2012/03/30/create-a-ctools-access-plugin/"/>
    <updated>2012-03-30T18:19:00+02:00</updated>
    <id>http://ramlev.dk/blog/2012/03/30/create-a-ctools-access-plugin</id>
    <content type="html"><![CDATA[<p>After i <a href="http://drupal.org/node/1487980">saw</a> that my name is a part of the long list of contributors to <a href="http://drupal.org/projects/ctools">ctools 1.0</a> (i know it&#8217;s just a little <a href="http://drupal.org/node/1233424">patch</a>, but everything counts), i think i have to give a little back.</p>

<p>I will try to explain how to create a custom &#8220;visibility rule&#8221; which in <a href="http://drupal.org/projects/ctools">ctools</a> is called an <strong>access plugin</strong> for use for ex. <a href="http://drupal.org/projects/panels">panels</a>). The main reason for this, is that i have seen several times that the quick way to create a custom visibility rule in panels, is to choose the &#8220;PHP Code&#8221; rule, and enter som custom php code, and that&#8217;s in my opinion the worst way ever to handle access rules.</p>

<p>So in this guide i will show how easy it is to create your own custom access rule. Ex. you have an panel pane which only should be visible if a expression is TRUE, that could be if the node visited is of the type of &#8216;Page&#8217;, the authenticated user visiting the page have role &#8216;normal site user&#8217; or a lot of other rules.</p>

<p>A case for me was to create an access rule, so a panel pane only is visible if a custom field on a node have a specified value.</p>

<p>In this example i need a node type with a field named &#8216;field_age_value&#8217;, and will be able to add a field to a panel pane, and create a visibility rule for this pane, so it&#8217;s only visible if the age on the node is 40.</p>

<!-- more -->


<p>First of all you need to tell your custom module that we&#8217;re working with ctools plugins, that&#8217;s done by implementing hook_ctools_plugin_directory() in your .module file, and telling ctools where to look for your plugin.</p>

<figure class='code'><figcaption><span>Filename: custom_module.module  </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="cp">&lt;?php</span>
</span><span class='line'>
</span><span class='line'><span class="sd">/**</span>
</span><span class='line'><span class="sd"> * Implements hook_ctools_plugin_directory().</span>
</span><span class='line'><span class="sd"> *</span>
</span><span class='line'><span class="sd"> * It simply tells panels where to look for the .inc file that</span>
</span><span class='line'><span class="sd"> * defines various args, contexts and content_types.</span>
</span><span class='line'><span class="sd"> */</span>
</span><span class='line'><span class="k">function</span> <span class="nf">custom_module_ctools_plugin_directory</span><span class="p">(</span><span class="nv">$module</span><span class="p">,</span> <span class="nv">$plugin</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="nv">$module</span> <span class="o">==</span> <span class="s1">&#39;ctools&#39;</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">empty</span><span class="p">(</span><span class="nv">$plugin</span><span class="p">))</span> <span class="p">{</span>
</span><span class='line'>   <span class="k">return</span> <span class="s2">&quot;plugins/</span><span class="si">$plugin</span><span class="s2">&quot;</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>This tell&#8217;s ctools to look in plugins/ folder after custom plugins. In this case it&#8217;s looking in plugins/access for an .inc file. Create the access plugin subdirectory.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>mkdir -p plugins/access
</span></code></pre></td></tr></table></div></figure>


<p>In this directory (plugins/access) create the file field_age_value.inc, which contains the plugin, which will handle the access to the panel pane.</p>

<figure class='code'><figcaption><span>Filename: field_age_value.inc  </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="cp">&lt;?php</span>
</span><span class='line'>
</span><span class='line'><span class="sd">/**</span>
</span><span class='line'><span class="sd"> * Plugins are described by creating a $plugin array which will</span>
</span><span class='line'><span class="sd"> * be used by the system that includes the file.</span>
</span><span class='line'><span class="sd"> */</span>
</span><span class='line'><span class="nv">$plugin</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>  <span class="s1">&#39;title&#39;</span> <span class="o">=&gt;</span> <span class="nx">t</span><span class="p">(</span><span class="s1">&#39;Node: field age value&#39;</span><span class="p">),</span>
</span><span class='line'>  <span class="s1">&#39;description&#39;</span> <span class="o">=&gt;</span> <span class="nx">t</span><span class="p">(</span><span class="s1">&#39;Controls access by field_age value&#39;</span><span class="p">),</span>
</span><span class='line'>  <span class="s1">&#39;callback&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;custom_module_field_age_value_ctools_access_check&#39;</span><span class="p">,</span>
</span><span class='line'>  <span class="s1">&#39;default&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;field_age_value&#39;</span> <span class="o">=&gt;</span> <span class="mi">0</span><span class="p">),</span>
</span><span class='line'>  <span class="s1">&#39;settings form&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;custom_module_field_age_value_ctools_settings&#39;</span><span class="p">,</span>
</span><span class='line'>  <span class="s1">&#39;summary&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;custom_module_field_age_value_ctools_summary&#39;</span><span class="p">,</span>
</span><span class='line'>  <span class="s1">&#39;required context&#39;</span> <span class="o">=&gt;</span> <span class="k">new</span> <span class="nx">ctools_context_required</span><span class="p">(</span><span class="nx">t</span><span class="p">(</span><span class="s1">&#39;Node&#39;</span><span class="p">),</span> <span class="s1">&#39;node),</span>
</span><span class='line'><span class="s1">);</span>
</span><span class='line'>
</span><span class='line'><span class="s1">/**</span>
</span><span class='line'><span class="s1"> * Custom callback defined by &#39;</span><span class="nx">callback</span><span class="s1">&#39; in the $plugin array.</span>
</span><span class='line'><span class="s1"> *</span>
</span><span class='line'><span class="s1"> * Check for access.</span>
</span><span class='line'><span class="s1"> */</span>
</span><span class='line'><span class="s1">function custom_module_field_age_value_ctools_access_check($conf, $context) {</span>
</span><span class='line'><span class="s1">  // If for some unknown reason that $context isn&#39;</span><span class="nx">t</span> <span class="nx">set</span><span class="p">,</span> <span class="nx">we</span> <span class="nx">just</span> <span class="nx">want</span> <span class="nx">to</span> <span class="nx">be</span> <span class="nx">sure</span><span class="o">.</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="k">empty</span><span class="p">(</span><span class="nv">$context</span><span class="p">)</span> <span class="o">||</span> <span class="k">empty</span><span class="p">(</span><span class="nv">$context</span><span class="o">-&gt;</span><span class="na">data</span><span class="p">)</span> <span class="o">||</span> <span class="k">empty</span><span class="p">(</span><span class="nv">$context</span><span class="o">-&gt;</span><span class="na">data</span><span class="o">-&gt;</span><span class="na">field_age_value</span><span class="p">))</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="k">FALSE</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1">// If the age set in the panels visibility rule settings is different from the field_age_value</span>
</span><span class='line'>  <span class="c1">// access to the pane is denied.</span>
</span><span class='line'>  <span class="nv">$age</span> <span class="o">=</span> <span class="nv">$context</span><span class="o">-&gt;</span><span class="na">data</span><span class="o">-&gt;</span><span class="na">field_age_value</span><span class="p">;</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="nv">$age</span> <span class="o">!==</span> <span class="nv">$conf</span><span class="p">[</span><span class="s1">&#39;field_age_value&#39;</span><span class="p">][</span><span class="nv">$context</span><span class="o">-&gt;</span><span class="na">data</span><span class="o">-&gt;</span><span class="na">field_age_value</span><span class="p">[</span><span class="nx">field_language</span><span class="p">(</span><span class="s1">&#39;node&#39;</span><span class="p">,</span> <span class="nv">$context</span><span class="o">-&gt;</span><span class="na">data</span><span class="p">,</span> <span class="s1">&#39;field_age_value&#39;</span><span class="p">)][</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">])</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="k">FALSE</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>  <span class="k">return</span> <span class="k">TRUE</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="sd">/**</span>
</span><span class='line'><span class="sd"> * Settings form for the &#39;field_age_value&#39; access plugin.</span>
</span><span class='line'><span class="sd"> */</span>
</span><span class='line'><span class="k">function</span> <span class="nf">custom_module_field_age_value_ctools_settings</span><span class="p">(</span><span class="nv">$form</span><span class="p">,</span> <span class="o">&amp;</span><span class="nv">$form_state</span><span class="p">,</span> <span class="nv">$conf</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;settings&#39;</span><span class="p">][</span><span class="s1">&#39;field_age_value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>    <span class="s1">&#39;#type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;textfield&#39;</span><span class="p">,</span>
</span><span class='line'>    <span class="s1">&#39;#title&#39;</span> <span class="o">=&gt;</span> <span class="nx">t</span><span class="p">(</span><span class="s1">&#39;Age&#39;</span><span class="p">),</span>
</span><span class='line'>    <span class="s1">&#39;#description&#39;</span> <span class="o">=&gt;</span> <span class="nx">t</span><span class="p">(</span><span class="s1">&#39;The pane will only be visible if the age field on the node, is the same as set in this field&#39;</span><span class="p">),</span>
</span><span class='line'>    <span class="s1">&#39;#default_value&#39;</span> <span class="o">=&gt;</span> <span class="nv">$conf</span><span class="p">[</span><span class="s1">&#39;field_age_value&#39;</span><span class="p">],</span>
</span><span class='line'>  <span class="p">);</span>
</span><span class='line'>  <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="sd">/**</span>
</span><span class='line'><span class="sd"> * Provide a summary description based upon the age.</span>
</span><span class='line'><span class="sd"> */</span>
</span><span class='line'><span class="k">function</span> <span class="nf">custom_module_field_age_value_ctools_summary</span><span class="p">(</span><span class="nv">$conf</span><span class="p">,</span> <span class="nv">$context</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">return</span> <span class="nx">t</span><span class="p">(</span><span class="s1">&#39;Nodes with age @age&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;@age&#39;</span> <span class="o">=&gt;</span> <span class="nv">$conf</span><span class="p">[</span><span class="s1">&#39;field_age_value&#39;</span><span class="p">));</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>When this is done and the module is enabled in your installation, you should clear the cache to be sure that ctools will find the plugin.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>drush cc all
</span></code></pre></td></tr></table></div></figure>


<p>You will now be able to find your custom visibility rule in the panels UI, by pressing the settings icon for a given field in ex. a node view panel.</p>

<p><img src="http://ramlev.dk/images/20120330-cy8qsddughiub4g2t6abieg9ya.jpg" alt="Panels UI" /></p>

<p>And select the &#8220;Node: field_age_value&#8221; visibility rule, and press &#8220;next&#8221;.</p>

<p><img src="http://ramlev.dk/images/20120330-ca3wtkcsmidtjn7ugqxaj4kf3p.jpg" alt="Add visibility rule for Node content" /></p>

<p>And finally set the age to 40 in the text field.</p>

<p><img src="http://ramlev.dk/images/20120330-jhjnuj3m3insiy5scq599ice5x.jpg" alt="Configure visibility rule for Node content" /></p>

<p>When the panel pane is updated and saved, when you visit the node you just configured, the pane you have set up the visibility rule for, will only be shown if the field_age_value field on the shown node is 40.</p>

<p>Thats it for this friday night.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Drupal 7 FormAPI #states - A hidden diamond]]></title>
    <link href="http://ramlev.dk/blog/2012/03/09/drupal-7-formapi-number-states-a-hidden-diamond/"/>
    <updated>2012-03-09T22:06:00+01:00</updated>
    <id>http://ramlev.dk/blog/2012/03/09/drupal-7-formapi-number-states-a-hidden-diamond</id>
    <content type="html"><![CDATA[<p>Everyone who have worked as a developer on a Drupal website, sure does know the <a href="http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7">FormAPI</a> but how many does actually know the <a href="http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#states">#states</a> property.</p>

<p>I will try to demo how to use that property. When #states is set on a field, some javascript is attached to the element, to allow it to have different active states.</p>

<p>In Drupal 7, the way to handle states on element, should be done with this property, and not by adding your own javascript code.</p>

<!-- more -->


<p>A check for state, is attached on the element which is changing state, and not on the element which triggers the state change.</p>

<h1>An example.</h1>

<figure class='code'><figcaption><span>Example form alter block  </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="cp">&lt;?php</span>
</span><span class='line'><span class="k">function</span> <span class="nf">example_form_alter</span><span class="p">(</span><span class="o">&amp;</span><span class="nv">$form</span><span class="p">,</span> <span class="o">&amp;</span><span class="nv">$form_state</span><span class="p">,</span> <span class="nv">$form_id</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;dummy_text&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>    <span class="s1">&#39;#type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;textfield&#39;</span><span class="p">,</span>
</span><span class='line'>    <span class="s1">&#39;#title&#39;</span> <span class="o">=&gt;</span> <span class="nx">t</span><span class="p">(</span><span class="s1">&#39;Dummy text&#39;</span><span class="p">),</span>
</span><span class='line'>  <span class="p">);</span>
</span><span class='line'>  <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;conditions&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>    <span class="s1">&#39;#type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;checkbox&#39;</span><span class="p">,</span>
</span><span class='line'>    <span class="s1">&#39;#title&#39;</span> <span class="o">=&gt;</span> <span class="nx">t</span><span class="p">(</span><span class="s1">&#39;Conditions&#39;</span><span class="p">),</span>
</span><span class='line'>  <span class="p">);</span>
</span><span class='line'>  <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;you_sure&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>    <span class="s1">&#39;#type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;radios&#39;</span><span class="p">,</span>
</span><span class='line'>    <span class="s1">&#39;#title&#39;</span> <span class="o">=&gt;</span> <span class="p">(</span><span class="s1">&#39;Are you sure?&#39;</span><span class="p">),</span>
</span><span class='line'>    <span class="s1">&#39;#options&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="mi">0</span> <span class="o">=&gt;</span> <span class="s1">&#39;No&#39;</span><span class="p">,</span> <span class="mi">1</span> <span class="o">=&gt;</span> <span class="s1">&#39;Yes&#39;</span><span class="p">),</span>
</span><span class='line'>    <span class="s1">&#39;#default_value&#39;</span> <span class="o">=&gt;</span> <span class="mi">0</span><span class="p">,</span>
</span><span class='line'>    <span class="s1">&#39;#states&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>      <span class="s1">&#39;visible&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>        <span class="s1">&#39;:input[name=&quot;conditions&quot;]&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;checked&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span><span class="p">),</span>
</span><span class='line'>      <span class="p">),</span>
</span><span class='line'>    <span class="p">),</span>
</span><span class='line'>  <span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'><span class="cp">?&gt;</span><span class="x"></span>
</span></code></pre></td></tr></table></div></figure>


<p>What is going on here, most of it is some pretty simple formAPI elements, but the new property #states attached to the &#8216;you_sure&#8217; element have some conditions defined. Every conditions is key/vaule pair, and the key is a jQuery selector which we&#8217;re checking for the value which is an array of conditions, which must be met on that element. In this example we are checking if the input field named &#8216;conditions&#8217; is checked, if so, the &#8216;you_sure&#8217; is visible ,hidden otherwise.</p>

<p>If we add another row in the &#8216;visible&#8217; array, such as</p>

<figure class='code'><figcaption><span>Example form alter block  </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="x">&#39;:input[name=&quot;dummy_text&quot;]&#39; =&gt; array(&#39;value&#39; =&gt; &#39;test&#39;),</span>
</span></code></pre></td></tr></table></div></figure>


<p>Then both fields, conditions have to be checked and &#8216;dummy_text&#8217; field has to be filled with the value &#8216;test&#8217;, for the &#8216;you_sure&#8217; field to be shown.</p>

<p>The following states may be applied to a #states event.</p>

<p>enabled, disabled, required, optional, visible, invisible, checked, unchecked, expanded, collapsed.</p>

<p>States are handled only by javascript, and all states are applied clientside, so if javascript is disabled, to states will be appliced, and therefore very important to handle validation serverside.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[On track]]></title>
    <link href="http://ramlev.dk/blog/2012/03/06/on-track/"/>
    <updated>2012-03-06T23:05:00+01:00</updated>
    <id>http://ramlev.dk/blog/2012/03/06/on-track</id>
    <content type="html"><![CDATA[<p><img src="http://ramlev.dk/images/on-track.jpg" alt="On-track" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Drush command to show module info]]></title>
    <link href="http://ramlev.dk/blog/2012/03/04/drush-command-to-show-module-info/"/>
    <updated>2012-03-04T14:48:00+01:00</updated>
    <id>http://ramlev.dk/blog/2012/03/04/drush-command-to-show-module-info</id>
    <content type="html"><![CDATA[<p>Was tired everytime i should get info about an installed module, i have do do something like</p>

<pre><code>cat sites/all/modules/contrib/views/views.info
</code></pre>

<p>When i want to show which version is installed.</p>

<!-- more -->


<p>So i made this little module <a href="http://drupal.org/project/drush_moduleinfo">drush_moduleinfo</a>, with this module you will be able to see some info about an installed module.</p>

<p>Is&#8217;t easy done by doing the command below, in a drupal installation.</p>

<pre><code>$ drush moduleinfo views
</code></pre>

<p>And you will get something like</p>

<pre><code>Name               Views
Description        Create customized lists and queries from your database.
Installed version  6.x-2.12
Newest version     6.x-3.0-rc3
Module path        sites/all/modules/contrib/views
Dependencies       None
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[My Vim repository on GitHub.com]]></title>
    <link href="http://ramlev.dk/blog/2012/01/24/my-vim-repository-on-github-dot-com/"/>
    <updated>2012-01-24T16:24:00+01:00</updated>
    <id>http://ramlev.dk/blog/2012/01/24/my-vim-repository-on-github-dot-com</id>
    <content type="html"><![CDATA[<p>Since i have done a few blogposts (<a href="my-vim-configuration-and-plugins.html">1</a>, <a href="vim-and-drupal-code-validation.html">2</a>) about my Vim installation, i think it&#8217;s about time i show you folks my configuration.</p>

<p>The configuration is a part of my <a href="http://github.com/ramlev/dotfiles">dotfiles</a> repository, and quite easy to install.</p>

<p>The project is on <a href="http://github.com/ramlev/dotfiles">GitHub.com</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Vim and drupal code validation]]></title>
    <link href="http://ramlev.dk/blog/2012/01/21/vim-and-drupal-code-validation/"/>
    <updated>2012-01-21T00:00:00+01:00</updated>
    <id>http://ramlev.dk/blog/2012/01/21/vim-and-drupal-code-validation</id>
    <content type="html"><![CDATA[<p>I have been using the <a href="https://github.com/scrooloose/syntastic">Syntastic</a> plugin for vim for a long time. Syntastic does what it have to, in php files it validates the file by in short terms do a</p>

<pre><code>$ php -l FILENAME
</code></pre>

<p>And present the error(s) in the statusbar, and with a little marker at the line(s).</p>

<p>If you install the <a href="http://pear.php.net/package/PHP_CodeSniffer/">PHP_CodeSniffer</a> via the pear installer, Syntastic automatic validates the code against the default code standards setup in php_codesniffer.</p>

<!-- more -->


<p>I found <a href="http://drupal.org/project/drupalcs">DrupalCS</a> module by <a href="http://drupal.org/user/244460">Ericduran</a> which is a PHP code sniffer addon, and tests your active code on-the-fly when saving.</p>

<p>The DrupalCS and phpcs (php code sniffer) is integrated into the Syntastic plugin.</p>

<p><img src="http://ramlev.dk/images/tumblr_ly5b6fI2Bm1qagf85.png" alt="vim editor" /></p>

<p>The installation of PHP Code Sniffer and Drupal CS is quite simple, and it’s nicely documented on the <a href="http://drupal.org/project/drupalcs">DrupalCS</a> module page.</p>

<p>After installing it, you can test if the DrupalCodingStandard work by test if it’s loaded in your terminal</p>

<pre><code>$ phpcs -i
</code></pre>

<p>If you want to test a file from your terminal, you can fire the command</p>

<pre><code>phpcs --standard=DrupalCodingStandard --extensions=php,module,inc,install,test,profile,theme FILENAME.module
</code></pre>

<p>The result will look something like this <a href="https://gist.github.com/1652469">output</a>.</p>

<p>If you execute the phpcs without the Drupal specific validator</p>

<pre><code>$ phpcs --extensions=php,module,inc,install,test,profile,theme FILENAME.module 
</code></pre>

<p>The result <a href="https://gist.github.com/1652460">output</a> is a bit more scary.</p>

<h2>Vim configuration</h2>

<p>The configuration for vim im using to get it working is.</p>

<pre><code>let g:syntastic_enable_signs=1 " Enable markers on the line containing a problem.

let g:syntastic_auto_jump=0 " Dont jump to the first line with a problem

let g:syntastic_phpcs_conf='--standard=DrupalCodingStandard --extensions=php,module,inc,install,test,profile,theme' " Test php,module,inc,install ... files with the DrupalCodingStandard
</code></pre>

<p>The first days after using it on a daily basis, it was quite annoying, but it have made me more aware of how i code.%</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[My Vim configuration and used plugins]]></title>
    <link href="http://ramlev.dk/blog/2012/01/16/my-vim-configuration-and-used-plugins/"/>
    <updated>2012-01-16T22:50:00+01:00</updated>
    <id>http://ramlev.dk/blog/2012/01/16/my-vim-configuration-and-used-plugins</id>
    <content type="html"><![CDATA[<p>My primary editor for PHP/Drupal programming have been MacVim for years, and therefore my editor have been tweaked and customized to my needs, you can see my <a href="https://raw.github.com/ramlev/vim/master/vimrc">.vimrc</a> file. I’m always ready for new plugins, new branches of existing repositories and to learn new.</p>

<p>The installed version of my MacVim is the <a href="https://github.com/downloads/b4winckler/macvim/MacVim-snapshot-64.tbz">snapshot-64</a>. Which is installed with <a href="https://github.com/mxcl/homebrew">Homebrew</a>.</p>

<!-- more -->


<p>First of all the colorscheme is very important, since we’re looking at it for (way too many) hours a day. I toggles between <a href="https://githu.com/telamon/vim-color-github">github</a> and <a href="https://github.com/vim-scripts/Mustang2">Mustang2</a>.</p>

<p>Below theres a list of all the installed plugins im using these days. All plugins, syntax and colorschemes is handled by <a href="https://github.com/tpope/vim-pathogen">pathogen.vim</a> which in short terms makes it very easy to install new plugins, colorshemes and so on.</p>

<p><a href="https://github.com/mileszs/ack.vim">Ack</a> is an alternative grep command, which is more effective and fast. Use this plugin to search recursivly from the current path for a text-string.</p>

<pre><code>:Ack 'function hook_node_info'
</code></pre>

<p>Will look in current path for the written text string.</p>

<p><a href="https://github.com/kien/ctrlp.vim">CTRLP.vim</a> is described in this <a href="ctrlp.html">blogpost</a>.</p>

<p><a href="https://github.com/sjl/gundo.vim">Gundo.vim</a> gives you a little window, where you will se a visualized view of your undo-tree.</p>

<p><a href="https://github.com/vim-scripts/jsbeautify">Jsbeautifier</a> is a little tool, which can format / indent your .js code nice, an online version can be found here <a href="http://jsbeautifier.org/">jsbeautifier</a>.</p>

<p><a href="https://github.com/walm/jshint.vim">JSHint</a> is a little nodeJS tool, so you can test your .js code for code errors.</p>

<pre><code>:JSHint %
</code></pre>

<p>Will run jshint on the current file and open a little scratch window, which describes all errors with linenumbers.</p>

<p><img src="http://ramlev.dk/images/tumblr_lxu0sy7sIv1qagf85.png" alt="vim editor" /></p>

<p><a href="https://github.com/scrooloose/nerdcommenter">NERDCommenter</a> provides a nifty feature to easy change a block of text to a comment block, supports a lot of different filetypes.</p>

<p><a href="https://github.com/scrooloose/nerdtree">NERDTree</a> have been the most important plugin for me, the plugin creates a window where you can explore your filesystem, open files and create/delete files/directories.</p>

<p><img src="http://ramlev.dk/images/tumblr_lxu1f4n7MO1qagf85.png" alt="vim editor" /></p>

<p><a href="https://github.com/vim-scripts/php.vim-for-php5">Php.vim-for-php5</a></p>

<p>Syntax highlight file for php5, which can be configured a bit.</p>

<p><a href="https://github.com/ervandew/supertab">Supertab</a> works when hitting <TAB> when typing a word, it will display a box with text suggestions, and you can browse through suggestions with <TAB> and <S-TAB></p>

<p><img src="http://ramlev.dk/images/tumblr_lxwt3vDxaA1qagf85.png" alt="vim editor" /></p>

<p><a href="https://github.com/scrooloose/syntastic">Syntastic</a> checks your sourcecode for syntax errors. It checks your code through external syntax checkers. You will be notified by a little mark on all lines containing an error. And shows a window where information about the error is shown.</p>

<p>Check this <a href="vim-and-drupal-code-validation.html">blogpost</a> for a lot more info on this subject.</p>

<p><a href="https://github.com/majutsushi/tagbar">Tagbar</a> shows a sidebar with functions, variable definitions generated by ctags. Classes, properties, methods and functions in javascript.</p>

<p><img src="http://ramlev.dk/images/tumblr_lxu1s0h0DW1qagf85.png" alt="vim editor" /></p>

<p><a href="https://github.com/jeetsukumaran/vim-buffergator">vim-buffergator</a> lets you see a window on the left, with all open buffers.</p>

<p><a href="https://github.com/ap/vim-css-color">vim-css-color</a> will highlights color definitions in css-files. a color will be shown with the color as background for the text, #f00 will be shows as white text on red background.</p>

<p><a href="https://github.com/tpope/vim-fugitive">Vim-fugitive</a> Handle various git commands from within vim.</p>

<p><a href="https://github.com/henrik/vim-indexed-search">Vim-indexed-search</a> shows a “Match x of y” when searching in buffers.</p>

<p><img src="http://ramlev.dk/images/tumblr_lxwt6ewFSO1qagf85.png" alt="vim editor" /></p>

<p><a href="httsp://github.com/itspriddle/vim-jquery">Vim-jquery</a> is a syntax file to add some colorations for jQuery keywords and css selectors.</p>

<p><a href="https://github.com/tsaleh/vim-matchit">Vim-matchit</a> - The % in normal vi/vim will jump between matching [ ( {’s, with matchit you will be able to jump between keywords as if, then, else, foreach, you can decide yourself, the configuration goes into the .vimrc file.</p>

<p><a href="https://github.com/jinfield/vim-nginx">Vim-nginx</a> is as simple as syntax colors for nginx configuration files.</p>

<p><a href="https://github.com/Lokaltog/vim-powerline">Powerline</a> is a utility plugin which allows you to create better-looking, more functional vim statuslines.</p>

<p><a href="https://github.com/tpope/vim-surround">Vim-surround</a> is all about “surroundings”: parentheses, brackets, quotes, XML tags, and more. The plugin provides mappings to easily delete, change and add such surroundings in pairs</p>

<p><a href="https://github.com/vim-scripts/ZoomWin">ZoomWin</a> you easy makes your window zoom in/out of full screen with o. This is very useful if you have a split screen going on, and you want to give a window full attention.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[CTRLP.vim]]></title>
    <link href="http://ramlev.dk/blog/2012/01/11/ctrlp-dot-vim/"/>
    <updated>2012-01-11T14:46:00+01:00</updated>
    <id>http://ramlev.dk/blog/2012/01/11/ctrlp-dot-vim</id>
    <content type="html"><![CDATA[<p>A fuzzy file, tag, recently used files finder plugin for the vim editor, which makes my day so more easy.</p>

<!-- more -->


<p>I use to use the <a href="https://github.com/wincent/Command-T">Command-T</a> plugin, but found <a href="http://kien.github.com/ctrlp.vim/">CTRLP.vim</a> on <a href="http://thechangelog.com/post/15573551543/ctrlp-fuzzy-file-buffer-mru-and-tag-finder-for-vim">The Changelog</a>. The <a href="https://github.com/wincent/Command-T">Command-T</a> plugin is a quite more simple than <a href="http://kien.github.com/ctrlp.vim/">CTRLP.vim</a>, and needs ruby to be installed. But the major reason for changing is that <a href="http://kien.github.com/ctrlp.vim/">CTRLP.vim</a> is more advanced, and the features is</p>

<ul>
<li>Full support for Vim’s regexp as search pattern.</li>
<li>Built-in Most Recently Used (MRU) files monitoring and search.</li>
<li>Built-in root directory finder.</li>
<li>Open multiple files at once.</li>
<li>Create new files and directories.</li>
<li>Execute Ex-commands on an opening file (jump to a line, a string or do anything).</li>
<li>Optional cross-sessions caching and history allow for fast initialization.</li>
<li>Mappings and usage conform to Vim’s conventions.</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Setup OSX as the most awesome PHP developing environment]]></title>
    <link href="http://ramlev.dk/blog/2011/12/18/setup-osx-as-the-most-awesome-php-developing-environment/"/>
    <updated>2011-12-18T21:22:00+01:00</updated>
    <id>http://ramlev.dk/blog/2011/12/18/setup-osx-as-the-most-awesome-php-developing-environment</id>
    <content type="html"><![CDATA[<blockquote><p>Make your OSX (snow)Lion a dream of a php development envrionment.</p></blockquote>

<p>I was being driven crazy everytime i should setup an local virtual host for a test site, all the manual tasks to perform (creation of the vhost file, restart apache ect.). Therefore i started to investiage how to get rid of that, and the result is, that i only have to create the directory where the test site stays.</p>

<blockquote><p>No need for restarting your webserver</p></blockquote>

<!-- more -->


<p>A setup with a custom local dns handler, nginx as the webserver, which is custom configured to handle my needs.</p>

<h2>This will be installed and configurered.</h2>

<ul>
<li>Homebrew + Homebrew alternatives</li>
<li>git</li>
<li>Iterm2</li>
<li>zsh + oh-my-zsh</li>
<li>Macvim</li>
<li>named</li>
<li>nginx</li>
<li>Configure nginx for wildcard local domains.</li>
<li>php 5.3.8</li>
<li>mariaDB</li>
<li>Real life example</li>
<li>Another site</li>
<li>Linux note</li>
<li>Homebrew</li>
</ul>


<p><a href="http://mxcl.github.com/homebrew/">Homebrew</a> - as told on the website, <strong>The missing package manager for OSX</strong>, it’s the easiest and most flexisble way to install various tools Apple didn’t include with OSX. The HomebrewAlt is an addon to the normal homebrew, with a lot of new apps to install. We’re using it to get php upgraded to 5.3.8.</p>

<p>There are a few requirements to be able to install Homebrew, and it’s:</p>

<ul>
<li>OSX 10.5+ (which should be fully updated).</li>
<li>Xcode 4.x</li>
</ul>


<p>It’s pretty simple to install Homebrew, it’s done with this oneliner.</p>

<pre><code>$ /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
</code></pre>

<p>If you want to <a href="https://gist.github.com/323731">see</a> the script.</p>

<p>Homebrew it now installed in /usr/local and it’s path is writeable by the user who have installed it, so you can acutally install with homebrew without sudo’ing.</p>

<p>Download and install Homebrew-alt into /usr/local/LibraryAlt</p>

<pre><code>$ git clone https://github.com/adamv/homebrew-alt.git /usr/local/LibraryAlt
</code></pre>

<p>Add /usr/local/bin and /usr/local/sbin to your path.</p>

<pre><code>$ vim ~/.zshrc 
</code></pre>

<p>Paste the following into the very buttom of the file and [esc]:wq</p>

<pre><code>export PATH=$(brew --prefix)/bin:$(brew --prefix)/sbin:$PATH;
</code></pre>

<h2>Git</h2>

<p><a href="http://git-scm.com/">Git</a> is a free &amp; open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.</p>

<p>It’s simply installed with</p>

<pre><code>$ brew install git
</code></pre>

<p>And you’re good to go.</p>

<h2>Iterm2</h2>

<p><a href="http://www.iterm2.com/#/section/home">iTerm2</a> is a replacement for Terminal. iTerm2 has a rich collection of features.</p>

<p>Go to <a href="www.iterm2.com">www.iterm2.com</a> and download and install the app.</p>

<h2>ZSH &amp; Oh-my-zsh</h2>

<p>The <a href="http://www.zsh.org/">ZSH</a> is a shell designed for interactive use, although it is also a powerful scripting language, it will be installed along with [oh-my-zsh)[https://github.com/robbyrussell/oh-my-zsh] which is a framework for managing your ZSH configuration, theres a lot of plugins, which adds tab-completion for ex, git homebrew, and a lot of terminal themes to spice it all up with.</p>

<p>First we need to install wget and a never version of zsh, to download and execute the oh-my-zsg install script, it’s so easy done with homebrew.</p>

<pre><code>$ brew install wget zsh
</code></pre>

<p>Fire this command to install oh-my-zsh</p>

<pre><code>$ wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
</code></pre>

<h2>MacVim</h2>

<p>To get <a href="http://code.google.com/p/macvim/">Macvim</a> installed we again simply use Homebrew, we add a little something to homebrew, to learn a new subcommand.</p>

<p>We want to search the homebrew library to see if MacVim is available to install.</p>

<pre><code>$ brew search macvim
</code></pre>

<p>And we’re getting:</p>

<pre><code>$ brew search macvim
macvim
</code></pre>

<p>Which means that it’s available, and ready for installation</p>

<pre><code>$ brew install macvim
</code></pre>

<p>You can now start MacVim from your terminal with</p>

<pre><code>$ mvim FILE
</code></pre>

<h2>Named</h2>

<p><a href="http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds4/named.htm">Named</a> is a domain name daemon, which can act as a local dns server.</p>

<p>We need to set up named (bind), to handle wildcard DNS for our development TLF (top level domain) and using OpenDNS as secondary DNS lookup for all other requests.</p>

<p>Everything is set up in your terminal as root user.</p>

<pre><code>$ sudo -i
</code></pre>

<p>To be sure, backup the original configuration</p>

<pre><code>$ cp /etc/named.conf /etc/named.conf.orig
</code></pre>

<p>Create a keyfile which is read by named on startup.</p>

<pre><code>$ rndc-confgen -a
</code></pre>

<p>Edit the named.conf file</p>

<pre><code>$ vim /etc/named.conf
</code></pre>

<p>Somewhere inside options {} block, add OpenDNS as DNS forwarder.</p>

<pre><code>forwarders {
    208.67.222.222 // OpenDNS primary
    208.67.220.220 // OpenDNS secondary
}
</code></pre>

<p>Add the following before the “0.0.127.in-addr.arpa” IN { zone</p>

<pre><code>zone "dev" IN {
   type master;
   file "dev.zone";
};
</code></pre>

<p>Save your named.conf file [esc]:wq</p>

<p>Now we need to create the dev.zone file, so bind (named) could read the dns configuration for that tld.</p>

<pre><code>$ vim /var/named/dev.zone
</code></pre>

<p>And paste this block into that file.</p>

<pre><code>dev. 7200    IN       SOA     dev. root.dev. (
              2008031801 ;    Serial
              15      ; Refresh every 15 minutes
              3600    ; Retry every hour
              3000000 ; Expire after a month+
              86400 ) ; Minimum ttl of 1 day
              IN      NS      dev.
              IN      MX      10 dev.

              IN      A       127.0.0.1
*.dev.        IN      A       127.0.0.1
</code></pre>

<p>Save the file, agagin, with [esc]:wq</p>

<p>Run the following commands to ensure configuration is ok</p>

<pre><code>$ named-checkconf /etc/named.conf
</code></pre>

<p>And</p>

<pre><code>$ named-checkzone dev /var/named/dev.zone
</code></pre>

<p>Now set your computer dns to use localhost as primary dns handler, in System Preferences -> Network for both Wireless and Ethernet connections by clicking Advanced and selecting the DNS tab, and add 127.0.0.1.</p>

<p>Set Bind (named) to load when computer starts, and load it now.</p>

<pre><code>$ launchctl load -w /System/Library/LaunchDaemons/org.isc.named.plist
</code></pre>

<p>Let’s flush the internal DNS cache first,</p>

<pre><code>$ sudo dscacheutil -flushcache
</code></pre>

<p>Lets test that everything is working as planned.</p>

<pre><code>$ dig test.dev
</code></pre>

<p>Should return something like</p>

<pre><code>$ dig test.dev

; &lt;&lt;&gt;&gt; DiG 9.7.3-P3 &lt;&lt;&gt;&gt; test.dev
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 4384
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;test.dev.          IN  A

;; ANSWER SECTION:
test.dev.       7200    IN  A   127.0.0.1

;; AUTHORITY SECTION:
dev.            7200    IN  NS  dev.

;; ADDITIONAL SECTION:
dev.            7200    IN  A   127.0.0.1

;; Query time: 2 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Dec 18 10:51:34 2011
;; MSG SIZE  rcvd: 72
</code></pre>

<p>And we can see it’s resolved as a local domain. All ok.</p>

<p>And a ping test, should return</p>

<pre><code>$ ping test.dev                                                                                                  

PING test.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.041 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.110 ms
</code></pre>

<h2>Nginx</h2>

<p><a href="http://wiki.nginx.org/Main">Nginx</a> is an awesome alternative to Apache Web Server, more lightweight, very customizable, and thats for good use with this setup.</p>

<p>This Nginx vhost configuration is mostly for Drupal installations, but works with other frameworks and homemade stuff, almost out-of-the-box, but changes to the vhost.conf file, depending on configration in your .htaccess file used in Apache, can appear.</p>

<p>First of all we need to ensure that Apache wont be started when booting.</p>

<pre><code>$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
</code></pre>

<p>Now we need nginx to be installed via Homebrew.</p>

<pre><code>$ brew install nginx
</code></pre>

<p>When nginx is compiled, we need to backup the original nginx.conf file.</p>

<pre><code>$ cp /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.orig
</code></pre>

<p>Open and configure your nginx.conf file to your needs.</p>

<pre><code>$ vim /usr/local/etc/nginx/nginx.conf
</code></pre>

<p>Look for user in the file, and make it look like</p>

<pre><code>user YOUR_NAME staff;
</code></pre>

<p>Save the file [esc]:wq</p>

<p>Create the nginx log directory, to make it show up in Console.app</p>

<pre><code>$ sudo mkdir /var/log/nginx
</code></pre>

<p>Configure nginx for wildcard local domains.</p>

<p>Edit your nginx.conf</p>

<pre><code>$ vim /usr/local/etc/nginx/nginx.conf
</code></pre>

<p>And add the following line in the http {} section just before the closing }</p>

<pre><code>include /usr/local/etc/nginx/vhosts.conf
</code></pre>

<p>Save and exit the file [esc]:wq</p>

<p>Create the vhosts.conf file, in this example it’s confiugred for drupal development, but will work for the most.</p>

<pre><code>$ vim /usr/local/etc/nginx/vhosts.conf
</code></pre>

<p>And paste the following into the file.</p>

<pre><code>server {
    listen 80 default;
    server_name _;
    index  index.php;

    if ($host ~* "^(.+)+.dev$") {
        set $site $1;
    }

    root   /Users/[USERNAME]/www/$site;

    access_log  /var/log/nginx/$host.access.log combined;
    error_log   /var/log/nginx/$host.error.log crit;

    add_header X-Frame-Options SAMEORIGIN;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location = /backup {
        deny all;
    }

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location / {
        try_files $uri $uri/ @rewrite;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~ \.php$ {
        fastcgi_read_timeout 600;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass   127.0.0.1:9000;
    }

    # Fighting with ImageCache? This little gem is amazing.
    location ~ ^/sites/.*/files/styles/ {
        try_files $uri $uri/ @rewrite;
    }
}
</code></pre>

<p>Create a www folder in your homedir</p>

<pre><code>$ mkdir ~/www
</code></pre>

<p>Restart your nginx</p>

<pre><code>$ sudo nginx -s reload
</code></pre>

<p>And now you should be able to create new local sites without configurering and restarting nginx everytime.</p>

<h2>PHP 5.3.8</h2>

<p>The version of PHP in OSX Lion is upgraded to 5.3.6, but we will install <a href="http://php.net/">PHP 5.3.8</a> with Homebrew, and with that it would be upgradeable, when new and awesome releases appear.</p>

<p>Now for the PHP 5.3.6 -> 5.3.8 upgrade. We will start by backing up the originally installed php.</p>

<pre><code>$ sudo mv /usr/bin/php /usr/bin/php.orig
</code></pre>

<p>Run homebrew installer with the php brew file from the alternative brew directory.</p>

<pre><code>$ brew install /usr/local/LibraryAlt/duplicates/php.rb --with-mysql --with-fpm
</code></pre>

<p>When php is compiled and ready, create your own php-fpm.conf file.</p>

<pre><code>$ cp /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf.default /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf
</code></pre>

<p>Create symbolic link for it in /usr/local/etc/</p>

<pre><code>$ sudo ln -s /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf /usr/local/etc/php-fpm.conf
</code></pre>

<p>Edit the file</p>

<pre><code>$ vim /usr/local/etc/php-fpm.conf
</code></pre>

<p>Add the following line below ;pid = run/php-fpm.pid</p>

<pre><code>pid = /usr/local/var/run/php-fpm.pid
</code></pre>

<p>Update the user and group section as follows</p>

<pre><code>user = _www
group = _www
</code></pre>

<p>Remove the ; from the start of the following lines then save using Ctrl+X then Y</p>

<pre><code>pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 5
pm.max_requests = 500
</code></pre>

<p>Create directory for php-fpm log</p>

<pre><code>$ mkdir /usr/local/Cellar/php/5.3.8/var/log/
</code></pre>

<p>and the file</p>

<pre><code>$ touch /usr/local/Cellar/php/5.3.8/var/log/php-fpm.log
</code></pre>

<p>Make our log file visible in Console app</p>

<pre><code>$ sudo ln -s /usr/local/Cellar/php/5.3.8/var/log/php-fpm.log /var/log/nginx/php-fpm.log
</code></pre>

<p>Set your timezone in php.ini</p>

<pre><code>$ vim /usr/local/etc/php.ini
</code></pre>

<p>Look for ;date.timezone, and add following below</p>

<pre><code>date.timezone = Europe/Copenhagen
</code></pre>

<p>And update the memory_limit</p>

<pre><code>memory_limit = 256M
</code></pre>

<p>Save the file [esc]:wq</p>

<h2>MariaDB</h2>

<p><a href="http://mariadb.org/">MariaDB</a> is an alternative to MySQL, it’s created and maintained by some original authors of MySQL.</p>

<p>Install MariaDB from terminal and with homebrew</p>

<pre><code>$ brew install mariadb
</code></pre>

<p>After installation is done, unset TMPDIR</p>

<pre><code>$ unset TPMDIR
</code></pre>

<p>Then install database</p>

<pre><code>$ mysql_install_db
</code></pre>

<p>Make all of the services (nginx, php-fpm and MariaDB run on boot)</p>

<p>Start iterm2 and become root.</p>

<pre><code>$ sudo -i
</code></pre>

<p>Download the LaunchDaemon to load nginx on boot</p>

<pre><code>$ curl http://realityloop.com/sites/realityloop.com/files/uploads/nginx.plist_.txt &gt; /System/Library/LaunchDaemons/org.homebrew.nginx.plist
</code></pre>

<p>Download LaunchDaemon for php-fpm</p>

<pre><code>$ curl http://realityloop.com/sites/realityloop.com/files/uploads/php-fpm.plist_.txt &gt; /System/Library/LaunchDaemons/org.homebrew.php-fpm.plist
</code></pre>

<p>Copy the LaunchDaemon to load MariaDB on boot into place</p>

<pre><code>$ cp /usr/local/Cellar/mariadb/5.2.8/com.mysql.mysqld.plist /System/Library/LaunchDaemons/com.mysql.mysqld.plist
</code></pre>

<p>Now it’s time to reboot your computer, to make sure everything is working.</p>

<p>After reboot, open iterm and run this command.</p>

<pre><code>$ sudo /usr/local/Cellar/mariadb/5.2.8/bin/mysql_secure_installation
</code></pre>

<p>Answer the prompts as follows, replace [password] with a password of your own chosing</p>

<pre><code>Enter current password for root (enter for none): [Enter]
Set root password? [Y/n] y
New password: [password]
Re-enter new password: [password]
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
</code></pre>

<h2>Real life example</h2>

<p>Now for an example by installing a drupal site with a few tools.</p>

<p>Download <a href="http://drupal.org/project/drush">drush</a> which is a command line tool for Drupal, this will install <a href="http://drupal.org/project/drush_make">drush_make</a> as well.</p>

<pre><code>$ brew install drush
</code></pre>

<p>Go to ~/www</p>

<pre><code>$ cd ~/www
</code></pre>

<p>And download Drupal core.</p>

<pre><code>$ drush dl drupal --drupal-project-rename=drupal7
</code></pre>

<p>Open your favorite browser and go to</p>

<pre><code>http://drupal7.dev
</code></pre>

<p>You should see the installation page of Drupal. Instead we could install drupal with a oneliner.</p>

<pre><code>$ cd ~/www/drupal7
</code></pre>

<p>And we use drush to install with default settings.</p>

<pre><code>$ drush site-install --db-url=mysql://root:PASSWORD@localhost/drupal7
</code></pre>

<p>And if you visit</p>

<pre><code>http://drupal7.dev
</code></pre>

<p>you will see a default installed drupal site, and you will be able to login with user: admin, pass: admin.</p>

<h3>Another site</h3>

<p>We’ll just try another site</p>

<pre><code>$ cd ~/www/
</code></pre>

<p>Install a drupal 6.x site</p>

<pre><code>$ drush dl drupal-6.x --drupal-project-rename=drupal6
</code></pre>

<p>And again use drush site-install to install the site.</p>

<pre><code>$ drush site-install --db-url=mysql://root:PASSWORD@localhost/drupal6
</code></pre>

<p>And visit</p>

<pre><code>http://drupal6.dev
</code></pre>

<p>You will see an installed drupal 6 site.</p>

<p><strong> And everything without reloading Nginx </strong> - MAGIC</p>

<h2>Linux note</h2>

<p>As a little note, it would quite easy install on a unix based platform as well, skip the homebrew parts and install through your preferred install util (apt-get or whatever).</p>

<p>The paths would in most cases deviate a bit from the ones on OSX.</p>

<p>I just tested it on a Ubuntu 10.04, and took me around 10 mins to install from this guide.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Coder tip of the day]]></title>
    <link href="http://ramlev.dk/blog/2011/05/10/coder-tip-of-the-day/"/>
    <updated>2011-05-10T10:33:00+02:00</updated>
    <id>http://ramlev.dk/blog/2011/05/10/coder-tip-of-the-day</id>
    <content type="html"><![CDATA[<p>In the <a href="http://alfredapp.com">Alfred.app</a> 0.9 release it’s now possible to execute shell commands (Thank you). For that i have made a few custom commands which makes my day a lot easier. The most important for now is my Lorem Ipsum fetcher. Which i can execute by accessing Alfred.App and type “lorem” + [Enter] - and a random lorem ipsum paragraph is sent to my clipboard.</p>

<!-- more -->


<p><img src="http://ramlev.dk/images/tumblr_lkzchkBXIB1qagf85.png" alt="alfred app config image" /></p>

<p>The command is</p>

<pre><code>$ curl --silent http://loripsum.net/api/1/medium | pbcopy
</code></pre>

<p>And remember to tick the ‘silent’ then it should be all good.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[F.lux App]]></title>
    <link href="http://ramlev.dk/blog/2011/04/29/f-dot-lux-app/"/>
    <updated>2011-04-29T19:00:00+02:00</updated>
    <id>http://ramlev.dk/blog/2011/04/29/f-dot-lux-app</id>
    <content type="html"><![CDATA[<p>F.lux makes the color of your computer’s display adapt to the time of day, warm at night and like sunlight during the day.</p>

<p>At first, i thought it was pretty annoying, but after have used it for at couple of days, it&#8217;s pretty awesome.</p>

<p><img src="http://ramlev.dk/images/tumblr_lkfits02nw1qagf85.png" alt="F.lux configuration window" /></p>
]]></content>
  </entry>
  
</feed>

