Chris Sedlmayr2022-11-11T12:28:18+00:00http://chris.sedlmayr.co.uk/Chris Sedlmayrchris@sedlmayr.co.ukFixing Keyboard Type on macOS2020-06-30T00:00:00+00:00http://chris.sedlmayr.co.uk/2020-06-30/fixing-keyboard-type-macos<h2 id="everything-was-rosy">Everything was rosy</h2>
<p>I recently purchased a new keyboard to use in all scenarios, both across windows
(gaming), and macOS, work (inc. programming).</p>
<p>Everything was great for the weeks that followed getting it, fantastic
keyboard, lovely to type on, nice click-clack sounds (<3 cherry mx blue).</p>
<p><img src="/images/corsair-k95-rgb-platinum-xt.jpg" alt="Corsair K95 RGB Platinum XT" /></p>
<p>However on macOS one day last week the tilde <code class="language-plaintext highlighter-rouge">~</code> had <em>suddenly</em> moved from being to
the right of <code class="language-plaintext highlighter-rouge">left-shift</code>, to being below <code class="language-plaintext highlighter-rouge"><esc></code>.<br />
This made things tricky given my use of that key for switching between panes,
and also general dir access etc.</p>
<p>The generally documented fix for this is to update the keyboard type using
the keyboard prefs pane, however the button that’s documented was not present
for me :(</p>
<h2 id="the-fix-for-me">The Fix (for me)</h2>
<p>The fix was indeed to change the keyboard type, but the way to do that was
different here.</p>
<p>It looks like macOS was no longer seeing my external keyboard as external,
therefore was taking it’s config/mapping from the built-in KB (even though they
were listed separately in kb prefs).</p>
<p>Also, macOS thought it was ANSI layout, where I wanted ISO.</p>
<p>In order to get the Mac to see it as external again so I could change the type,
I had to remove the plist file for KB prefs</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">rm</span> /Library/Preferences/com.apple.keyboardtype.plist
</code></pre></div></div>
<p>And then reboot, this gave me the normal external keyboard type prompt and
allowed me to select the ISO type.</p>
<h2 id="i-have-my-tilde-back-where-it-belongsi-">I have my tilde back where it belongsi 🍾</h2>
<p>Documenting this so that <em>when</em> it happens again, I don’t have to remember or go
on a hunt again, hope it can help someone else too though.</p>
New Symfony2 Bundle for Logging of Console Exceptions2014-04-22T00:00:00+00:00http://chris.sedlmayr.co.uk/2014-04-22/new-symfony2-bundle-for-logging-of-console-exceptions<p>I’ve just released a new bundle for Symfony2 that quite simply; adds logging of exceptions thrown in console commands.</p>
<p>Get all the info on installation and usage <a href="https://github.com/catchamonkey/CatchamonkeyConsoleLoggerBundle" title="CatchamonkeyConsoleLoggerBundle over at GitHub">over at GitHub</a></p>
<p><em>Tested by Travis and SensioLabsInsight</em></p>
<p><a href="https://travis-ci.org/catchamonkey/CatchamonkeyConsoleLoggerBundle"><img src="https://travis-ci.org/catchamonkey/CatchamonkeyConsoleLoggerBundle.svg?branch=master" alt="Build Status" /></a><br />
<a href="https://insight.sensiolabs.com/projects/fccaa6b6-75d7-4f08-afea-311384d78f8a"><img src="https://insight.sensiolabs.com/projects/fccaa6b6-75d7-4f08-afea-311384d78f8a/mini.png" alt="SensioLabsInsight" /></a></p>
Deploying Symfony2 apps using RPMs2014-04-22T00:00:00+00:00http://chris.sedlmayr.co.uk/2014-04-22/deploying-symfony2-apps-using-rpms<h2 id="note">Note</h2>
<p>This does assume at least a basic undersatnding of RPMs and spec files, but all of the Symfony2 specific work is outlined here for your enjoyment. If you would like to know more about RPMs and .spec files, then <a href="http://www.rpm.org/max-rpm/" title="Maximum RPM">Maximum RPM</a> is a good resource.</p>
<h2 id="tldr">tl;dr</h2>
<p>The <a href="https://gist.github.com/catchamonkey/8575619f450fe4c94acd">spec file can be found over at GitHub gist</a>.
You will of course need to update the top section realting to name, and requirements etc, the ones I have left in there are real world though so should give you a good prompt to get going.</p>
<h2 id="the-spec-file">The .spec file</h2>
<p>I’ll explain the sections one by one below, the steps that happen prior to those detailed below are simply pulling down the main repo source.</p>
<p>To achieve this, we use a homegrown script that pulls from a Git repo, to a specific tagged version.</p>
<h3 id="prep">%prep</h3>
<p>This section is pretty straight forward, we use composer to pull down the dependencies of the repo, with the usual flags, but we also disable the scripts at this point.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>composer <span class="nb">install</span> <span class="nt">--prefer-dist</span> <span class="nt">-o</span> <span class="nt">-n</span> <span class="nt">--no-dev</span> <span class="nt">--no-progress</span> <span class="nt">--no-scripts</span>
</code></pre></div></div>
<h3 id="build">%build</h3>
<h4 id="run-the-post-install-cmd-scripts-cache-clear-install-assets-etc">Run the post-install-cmd scripts (cache clear, install assets etc)</h4>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>composer run-script post-install-cmd <span class="nt">--no-dev</span> <span class="nt">--no-interaction</span>
</code></pre></div></div>
<h4 id="update-the-version-used-in-the-asset-output-scheme">Update the version used in the asset output scheme</h4>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sed</span> <span class="nt">-i</span> <span class="nt">-e</span> <span class="s1">'s/\(assets_version: v=[ ]*\)\([a-zA-Z0-9_]*\)\(.*\)$/\1%{version}\3/g'</span> app/config/config.yml
</code></pre></div></div>
<h4 id="dump-the-assets-not-done-via-any-registered-scripthandler">Dump the assets (not done via any registered ScriptHandler)</h4>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>app/console assetic:dump <span class="nt">--env</span><span class="o">=</span>prod
</code></pre></div></div>
<h4 id="remove-some-files-not-needed-in-production">Remove some files not needed in production</h4>
<p>Apart from the removal of non-production controllers (<code class="language-plaintext highlighter-rouge">rm web/app_*.php</code>), you could skip this part.</p>
<p>The parameters.yml file is needed in order to warm the cache and run the post-install-cmd scripts, but the real one is centrally managed on our servers via puppet so we remove it here, you may be managing your config files differently so you may need to mofidy this part.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">rm </span>web/app_<span class="k">*</span>.php composer.<span class="k">*</span> behat.yml phpspec.yml .travis.yml app/config/parameters.yml
</code></pre></div></div>
<h4 id="move-the-generated-cache-into-a-non-standard-location">Move the generated cache into a non-standard location</h4>
<p>This is one of the most important things you must do when deploying an application that has cached data relating to the application within it.</p>
<p>When you install an RPM, the new version of code is put in place, but old files that are not in the new version are only removed if you use the %files section to list all files individually. That isn’t really feasible when the files are generated and the names change between runs (twig template cache etc).</p>
<p>This gets around that issue by putting these files into a cache/build directory, and after install (more later), mv’ing them over the cache/prod directory, which is a full OS level dir replace, and is also atomic, this means that you have an (almost) full cache put in place at the right moment, rather than generating the cache in place on your production servers.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mv </span>app/cache/prod app/cache/build
</code></pre></div></div>
<h4 id="modify-the-paths-written-in-the-cache-files">Modify the paths written in the cache files</h4>
<p>When Symfony warms the cache, it uses the current directory as the basis for the cache directory. This is of course a problem when you are warming as we are here in a different directory.</p>
<p>We therefore use the package name, and the version being built (which is part of the current dir) and modify all the files in app/cache to have the directory that will be used once installed.</p>
<p>(I’m delimiting with a # for readability within path replacement.)</p>
<p>The directory during build for us is <code class="language-plaintext highlighter-rouge">/home/rpm.private/BUILD/%{name}-%{version}</code>, and the directory we install into on production is <code class="language-plaintext highlighter-rouge">/home/sites/%{name}</code></p>
<p>Find all the files in cache, then edit them using sed.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>find app/cache/ <span class="nt">-type</span> f | xargs <span class="nb">sed</span> <span class="nt">-i</span> <span class="s2">"s#%{_builddir}/%{name}-%{version}#/home/sites/%{name}#ig"</span>
</code></pre></div></div>
<h3 id="install">%install</h3>
<p>This is a standard install section, nothing unique needs to happen here. We install the vhost and then copy the files into place</p>
<h3 id="post">%post</h3>
<p>Here we do something a bit different.</p>
<p>If this is the first installation of this package, then we change ownership of the cache directory to apache as there are still some cache files that are generated during the first request.
We then move the cache/build directory into it’s rightful place in cache/prod</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="o">[</span> <span class="nv">$1</span> <span class="nt">-eq</span> 1 <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
<span class="c"># Grant apache access to it so remaining items can be cached (doctrine annotations)</span>
<span class="nb">chown</span> <span class="nt">-R</span> apache:apache /home/sites/%<span class="o">{</span>name<span class="o">}</span>/app/cache/build
<span class="c"># move the built cache into place</span>
<span class="nb">mv</span> /home/sites/%<span class="o">{</span>name<span class="o">}</span>/app/cache/build /home/sites/%<span class="o">{</span>name<span class="o">}</span>/app/cache/prod
<span class="k">fi</span>
</code></pre></div></div>
<p><strong>Note:</strong> I am looking at removing this writable requirement by warming the rest using the built in PHP web server, and curl during %build. I have already made the code compatible, with this PR on doctrine/annotations. https://github.com/doctrine/annotations/pull/30</p>
<h3 id="triggerpostun">%triggerpostun</h3>
<p>We do the same as in %post here, but the triggerpostun is only run after a successful uninstall (when you upgrade the old package is uninstalled).</p>
<p>Only moved the created cache into place if at least 1 version will be left behind from the uninstall</p>
<p>$2 is the number of versions left after an uninstall of %{name} has been performed</p>
<p><code class="language-plaintext highlighter-rouge">>=1</code> means this is an upgrade, anything smaller means a complete removal</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="o">[</span> <span class="nv">$2</span> <span class="nt">-ge</span> 1 <span class="o">]</span><span class="p">;</span> <span class="k">then
</span><span class="nb">chown</span> <span class="nt">-R</span> apache:apache /home/sites/%<span class="o">{</span>name<span class="o">}</span>/app/cache/build
<span class="nb">mv</span> /home/sites/%<span class="o">{</span>name<span class="o">}</span>/app/cache/build /home/sites/%<span class="o">{</span>name<span class="o">}</span>/app/cache/prod
<span class="k">fi</span>
</code></pre></div></div>
<h3 id="post-and-triggerpostun">%post and %triggerpostun</h3>
<p>We have the checks in these sections for number of versions for a very good reason. When you are upgrading, you only want to move the cache in place once the old version has been uninstalled. That way you can be sure that requests coming in are hitting new code, and new cache. Otherwise you may have a request hit old code and new cache or vice versa, either way, bad things happen for your users, and your error logs.</p>
<h2 id="clean-files-and-more">%clean, %files and more</h2>
<p>I’ve left out the other parts of the .spec file here as they are pretty much standard, but <a href="https://gist.github.com/catchamonkey/8575619f450fe4c94acd">the full file is on GitHub gist</a> so you can check it out.</p>
<h2 id="questions">Questions?</h2>
<p>If you have any questions, then i’d be happy to try and answer them, you can find me in most places as catchamonkey, <a href="https://github.com/catchamonkey">GitHub</a>, <a href="https://twitter.com/catchamonkey">Twitter</a>, <a href="https://connect.sensiolabs.com/profile/catchamonkey">Sensio Connect</a> etc, or just ask in the comments.</p>
New Atom package for syntax highlighting of .spec files2014-04-07T00:00:00+00:00http://chris.sedlmayr.co.uk/2014-04-07/atom-package-syntax-highlighting-spec-files<p>I’ve just published my first package for Atom, which provides syntax highlighting for RPM .spec files.</p>
<p>You can install it using the built in package manager, just search for Spec, and the package is called “Language Spec”.</p>
<p><img src="/images/language-spec-package.png" alt="Language Spec package in Atom.io" /></p>
<p>Or you can use the apm cli</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>apm <span class="nb">install </span>language-spec
</code></pre></div></div>
<h3 id="why-atom">Why Atom?</h3>
<p>I’m not going into a big SublimeText2 vs Atom vs X debate here, I’m playing with it, and I like it.<br />
Trying new things is part of what I like about being a developer, and Atom has some nice features built it.</p>
Homebrew wins me over second time around2014-03-25T00:00:00+00:00http://chris.sedlmayr.co.uk/2014-03-25/homebrew-wins-me-over-second-time-around<p>tl;dr. I’m a <a href="http://brew.sh/" title="check out homebrew">homebrew</a> convert.</p>
<p>I’ve been a Mac user for personal projects for about 5/6 years, but my work environments have generally enforced Windows.<br />
I used FreeBSD VMs (that I set up) in a previous company, and currently we use CentOS in OpenVZ.</p>
<p>I gave homebrew a try when I first got my Macbook Pro, but had mixed results, the version of PHP wasn’t available with the extensions I needed, and other things.<br />
I ended up building all my requirements from source. Apache, PHP, libxml2 etc, and it was fine, all worked well, but maintaining updates for one machine always felt like overkill.</p>
<p>Last year, I won over the company/boss, with the idea of having the machine to develop on that you wanted, (given the choice between Windows, Fedora or OSX). So I now use a Macbook Air and Thunderbolt display, yay!</p>
<p>Despite us still using VMs of CentOS (which of course makes sense, so it matches our live environment, same packages etc), I still wanted to have the Mac setup so I could develop when offline, and play around without the overhead of a remote connection.</p>
<p>The maintainers there have done a great job in the past few years, From my POV, it’s much more robust now, and handles many more of the cases a PHP dev needs, even when living on the cutting edge of versions.</p>
<p>I would have no hesitation in recommending it to anyone looking for a decent package manager for OSX, in lieu of the ports tree!</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>brew <span class="nb">install </span>wget
</code></pre></div></div>
Opening Symfony2 Error page file links in Sublime Text 2 on Windows2012-12-07T00:00:00+00:00http://chris.sedlmayr.co.uk/2012-12-07/opening-symfony2-error-page-file-links-in-sublime-text2-on-windows<p>During my day job, I work on a Windows 7 Machine, with mapped drives to my
CentOS development environment.</p>
<p>Sublime Text 2 and Putty give me the file and shell access to work as if I were
not using a desktop OS that sucks (albeit one that still has some annoying missing features).</p>
<p>I’ve wanted to map the framework: ide: setting in Symfony2 (also works in Symfony 1)
so I could open the file links in error pages straight to Sublime at the right file and line,
but I’ve never quite pursued it… until now!</p>
<p>There is a Sublime package that adds the protocol handler, and from there
it’s actually very easy, once I worked out the file path format required.</p>
<h2 id="step-1">Step 1)</h2>
<p>Add the bitbucket URL as a repo in Sublime Text 2</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ctrl+shift+p
https://bitbucket.org/sublimator/sublimeprotocol
</code></pre></div></div>
<h2 id="step-2">Step 2)</h2>
<p>Then install the package</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ctrl+shift+p
</code></pre></div></div>
<p>Choose SublimeProtocol and press enter.</p>
<p>Note, for this step I had to launch Sublime Text 2 as an administrator due
to the windows domain rules in the office.</p>
<h2 id="step-3">Step 3)</h2>
<p>Configure the ide: setting in Symfony2</p>
<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#app/config/config.yml</span>
<span class="na">framework</span><span class="pi">:</span>
<span class="na">ide</span><span class="pi">:</span> <span class="s2">"</span><span class="s">sblm:///R/%%f:%%1"</span>
</code></pre></div></div>
<p>In my case, the R drive is mapped to the root of my Dev environment.</p>
<p>%%f is the filepath and %%1 is the line number</p>
<p>So when you see a Symfony2 error page, the links will be mapped using this protocol</p>
<p>e.g.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sblm:///R//home/sites/SymfonySite/vendor/symfony/etc.php:139
</code></pre></div></div>
<p>Just make sure your mapping of drive or folder location is correct.</p>
Phighcharts, A PHP wrapper for Highcharts2012-06-08T00:00:00+00:00http://chris.sedlmayr.co.uk/2012-06-08/phighcharts-a-php-wrapper-for-highcharts<p>This is a work in progress, and I have just finished writing the core structure, which offers Pie and Line charting now, and will soon provide stacked etc.<br />
Rather than repeat myself, you can read more, including usage examples over at the project page <a href="http://chris.sedlmayr.co.uk/phighcharts/" title="Project Page on Github">http://chris.sedlmayr.co.uk/phighcharts/</a></p>
<p>The code is hosted on <a href="https://github.com/catchamonkey/phighcharts" title="View the code on Github">Github</a>
is also installable using <a href="http://packagist.org/packages/catchamonkey/phighcharts" title="Install via Composer & Packagist">composer/packagist</a>
and is continuously integrated by <a href="http://travis-ci.org/#!/catchamonkey/phighcharts" title="See the unit tests on Travis CI">Travis</a> <a href="http://travis-ci.org/catchamonkey/phighcharts"><img src="https://secure.travis-ci.org/catchamonkey/phighcharts.png?branch=master" alt="Build Status" /></a></p>
Symfony Live 20122012-02-18T00:00:00+00:00http://chris.sedlmayr.co.uk/2012-02-18/symfony-live-2012<p>Good news everybody, <a href="http://paris2012.live.symfony.com/">Symfony Live 2012</a> has been announced and tickets are now available.<br />
Last year was a great conference with some very memorable and useful talks given.</p>
<p>I’m fortunate enough to be going again this year and am already looking forward to it.</p>
<p>Usually there is a dinner the night before (I think) for the speakers to get together, and I thought it may be a nice idea to
have a similar meetup the night before for attendees, and of course any speakers that want to come along.</p>
<p>I know there are some of you that attend on your own (as I did last year)
and having a group of people to meet up with before it all starts is a good way to kick it all off and break some ice.</p>
<p>I was lucky enough to meet a couple of guys there last year that I hung around with which I really appreciated and made
a big difference to my enjoyment, and can’t help feeling that the whole thing may be more fun if we did something like this,
could be a dinner or just meeting in a pub somewhere near the venue.</p>
<p>So let me know what you think of the idea and I’ll work something out, if there is any interest I may put a sticky up in Google Groups too.</p>
<p>For now just leave me a comment here and we’ll see where it goes.</p>
Essential JavaScript and jQuery design patterns, free kindle book2011-10-10T00:00:00+00:00http://chris.sedlmayr.co.uk/2011-10-10/essential-javascript-and-jquery-design-patterns-free-kindle-book<p>For those of you familiar with the book, quite simply here is a Kindle compatible version.<br />
For those of you unfamiliar, It’s an excellent JavaScript and jQuery Design Patterns book written by Addy Osmani and provided for free.<br />
You can read all about the book over at <a href="http://addyosmani.com/blog/essentialjsdesignpatterns/">addyosmani.com</a></p>
<p>I’ve converted it for Kindle compatibility, and it’s provided here as a download (with permission from Addy of course).</p>
<p><a href="/downloads/Essential JavaScript Design Patterns For Beginners - Addy Osmani.mobi" onclick="_gaq.push(['_trackEvent','PDF','Download','AddyOsmaniJavaScriptKindleEBook']); _ictt.push(['_customTrigger', 'DOWNLOAD', {'t':'Addy Osmani JavaScript Kindle eBook'}]);" target="_blank">Download Essential JavaScript and jQuery design patterns for Kindle</a></p>
<p>It’s always worth keeping an eye on Addy’s site as the book is frequently updated there, also it’s usually a good source of information anyway
and Addy has published some interesting article of late.<br />
As Addy releases new versions of the book i’ll endeavour to keep the kindle version up to date here.</p>
<p>Kindle Version Last Updated: 18th July 2011 (1.0)</p>
Auto persistent url params in symfony 1.42011-07-18T00:00:00+00:00http://chris.sedlmayr.co.uk/2011-07-18/auto-persistent-url-params-in-symfony-1-4<p>Imagine you have various pages and routes within your application, maybe you are displaying
data based on some URL parameters (filters for example).</p>
<p>If you want to persist your filters between pages then you have a few choices.</p>
<p>You could store the filters in the user’s session making it easy, but they are not visible as a URL parameter.<br />
You could modify or create a new link_to/url_for function then modify your templates to use the new function.</p>
<p>Neither of these appealed to me, I wanted the filters to be in the URL, and I didn’t want to modify each link_to usage.</p>
<p>What I have done is created a new custom routing class.<br />
The class is invoked by configuring a route to use it, and you also tell it which URL params you want to persist.</p>
<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">dashboard</span><span class="pi">:</span>
<span class="na">url</span><span class="pi">:</span> <span class="s">/dashboard</span>
<span class="na">class</span><span class="pi">:</span> <span class="s">ictPersistentParamRoute</span>
<span class="na">options</span><span class="pi">:</span>
<span class="na">persist</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">param1</span><span class="pi">,</span> <span class="nv">param2</span><span class="pi">]</span>
<span class="na">param</span><span class="pi">:</span> <span class="pi">{</span> <span class="nv">module</span><span class="pi">:</span> <span class="nv">dashboard</span><span class="pi">,</span> <span class="nv">action</span><span class="pi">:</span> <span class="nv">show</span> <span class="pi">}</span>
</code></pre></div></div>
<p>The class extends sfRoute and overrides the generate() method.<br />
At URL generation time (usage of url_for/link_to etc) the class checks if the route
has persist options defined, and looks at sfWebRequest to see if these parameters are present.
If they are it will retrieve their values and merge the values to those defined in the (link_to) params.</p>
<p>This makes it very easy to add persistent params to your application without much effort!</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?php</span>
<span class="kd">class</span> <span class="nc">ictPersistentParamRoute</span> <span class="kd">extends</span> <span class="nc">sfRoute</span>
<span class="p">{</span>
<span class="k">public</span> <span class="k">function</span> <span class="n">generate</span><span class="p">(</span><span class="nv">$params</span><span class="p">,</span> <span class="nv">$context</span> <span class="o">=</span> <span class="k">array</span><span class="p">(),</span> <span class="nv">$absolute</span> <span class="o">=</span> <span class="kc">false</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">// our work happens here</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
New sfNavBuilderPlugin for symfony 1.42011-06-07T00:00:00+00:00http://chris.sedlmayr.co.uk/2011-06-07/new-sfNavBuilderPlugin-for-symfony-1-4<p>I released this plugin yesterday, which offers a simple interface with which to define and render your symfony 1.4 menu’s</p>
<p>The plugin allows you to create a hierarchical menu, with each item having it’s active state defined by;</p>
<ul>
<li>Current module</li>
<li>Current action</li>
<li>Parameter=value</li>
</ul>
<p>This therefore allows you to say you want an item to be active if;</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>module = blogPost
action = show
a paramName of post_id = a paramValue of 1
</code></pre></div></div>
<h3 id="basic-usage-example">Basic usage example</h3>
<p>One main menu item, with 2 child items</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="cp"><?php</span>
<span class="c1">// create a menu item for the main about page</span>
<span class="nv">$homepage</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">sfNavBuilderItem</span><span class="p">();</span>
<span class="nv">$homepage</span>
<span class="o">-></span><span class="nf">setDisplayName</span><span class="p">(</span><span class="s1">'About Us'</span><span class="p">)</span>
<span class="o">-></span><span class="nf">setUrl</span><span class="p">(</span><span class="nf">url_for</span><span class="p">(</span><span class="s1">'about'</span><span class="p">))</span>
<span class="o">-></span><span class="nf">addActivateWhen</span><span class="p">(</span><span class="k">array</span><span class="p">(</span>
<span class="s1">'module'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="s1">'about'</span><span class="p">),</span>
<span class="s1">'action'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="s1">'index'</span><span class="p">)</span>
<span class="p">));</span>
<span class="c1">// create a menu item for the about the team page and define the parent</span>
<span class="nv">$team</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">sfNavBuilderItem</span><span class="p">();</span>
<span class="nv">$team</span>
<span class="o">-></span><span class="nf">setDisplayName</span><span class="p">(</span><span class="s1">'About the Team'</span><span class="p">)</span>
<span class="o">-></span><span class="nf">setUrl</span><span class="p">(</span><span class="nf">url_for</span><span class="p">(</span><span class="s1">'aboutTeam'</span><span class="p">))</span>
<span class="o">-></span><span class="nf">addActivateWhen</span><span class="p">(</span><span class="k">array</span><span class="p">(</span>
<span class="s1">'module'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="s1">'about'</span><span class="p">),</span>
<span class="s1">'action'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="s1">'team'</span><span class="p">)</span>
<span class="p">))</span>
<span class="o">-></span><span class="nf">setParent</span><span class="p">(</span><span class="nv">$homepage</span><span class="p">);</span>
<span class="c1">// create a menu item for the about the company page and define the parent</span>
<span class="nv">$company</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">sfNavBuilderItem</span><span class="p">();</span>
<span class="nv">$company</span>
<span class="o">-></span><span class="nf">setDisplayName</span><span class="p">(</span><span class="s1">'About the Company'</span><span class="p">)</span>
<span class="o">-></span><span class="nf">setUrl</span><span class="p">(</span><span class="nf">url_for</span><span class="p">(</span><span class="s1">'aboutCompany'</span><span class="p">))</span>
<span class="o">-></span><span class="nf">addActivateWhen</span><span class="p">(</span><span class="k">array</span><span class="p">(</span>
<span class="s1">'module'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="s1">'about'</span><span class="p">),</span>
<span class="s1">'action'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="s1">'company'</span><span class="p">)</span>
<span class="p">))</span>
<span class="o">-></span><span class="nf">setParent</span><span class="p">(</span><span class="nv">$homepage</span><span class="p">);</span>
<span class="c1">// put the items into a menu instance and provide the required info</span>
<span class="nv">$this</span><span class="o">-></span><span class="n">menu</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">sfNavBuilder</span><span class="p">();</span>
<span class="nv">$this</span><span class="o">-></span><span class="n">menu</span>
<span class="o">-></span><span class="nf">setRequest</span><span class="p">(</span><span class="nv">$request</span><span class="p">)</span>
<span class="o">-></span><span class="nf">setModule</span><span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="nf">getContext</span><span class="p">()</span><span class="o">-></span><span class="nf">getModuleName</span><span class="p">())</span>
<span class="o">-></span><span class="nf">setAction</span><span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="nf">getContext</span><span class="p">()</span><span class="o">-></span><span class="nf">getActionName</span><span class="p">())</span>
<span class="o">-></span><span class="nf">addItem</span><span class="p">(</span><span class="nv">$homepage</span><span class="p">);</span>
<span class="c1">// in your template you can then call the renderer</span>
<span class="o"><?</span><span class="n">php</span> <span class="k">echo</span> <span class="nv">$menu</span><span class="o">-></span><span class="nf">render</span><span class="p">();</span> <span class="cp">?></span>
// check out the sfNavBuilderRenderer class to see what this does
</code></pre></div></div>
<p>I have included some fuller examples of use within the readme of the project, but am happy to answer question you have when using it.</p>
<p><a href="https://github.com/catchamonkey/sfNavBuilderPlugin" title="Project page on github">Project page on github</a><br />
<a href="http://catchamonkey.github.com/sfNavBuilderPlugin" title="sfNavBuilderPlugin Project site">sfNavBuilderPlugin Project site</a></p>
<p>Hope you find it useful!</p>
Curl and xmllint play nicely together2011-05-05T00:00:00+00:00http://chris.sedlmayr.co.uk/2011-05-05/curl-and-xmllint-play-nicely-together<p>If you work a lot with XML API’s (writing or consuming), and have ever called one directly using curl to test/debug some output, you may find that the output isn’t very friendly, and for larger responses it’s almost unreadable.</p>
<p>By using curl and xmllint together you can have your response nicely formatted.</p>
<p>To do so, invoke curl, and parse the response through xmllint, giving xmllint the –format option and the - option which tells it to read from stdin</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl <span class="nt">-sL</span> <span class="s2">"http://api.example.com/assets.xml"</span> | xmllint <span class="nt">--format</span> -
</code></pre></div></div>
<p>The curl options used here are -s to invoke silent mode, and -L so it follows redirects.</p>
<p><a href="http://xmlsoft.org/xmllint.html" title="Read more about xmllint here">Read more about xmllint here</a> or view the man pages directly if you have it installed.</p>
Textmate tip, Automatic PHP spl_autoload class name from file path2010-06-30T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-06-30/textmate-tip-automatic-php-spl_autoload-class-name-from-file-path<p>The title says it all so i’ll just get on with it.</p>
<p>Create a new textmate command, and set the output to ‘Insert as snippet’<br />
Paste in the following.</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#!/usr/bin/php
<span class="cp"><?php</span>
<span class="nv">$path</span> <span class="o">=</span> <span class="nv">$_ENV</span><span class="p">[</span><span class="s1">'TM_FILEPATH'</span><span class="p">];</span>
<span class="nv">$path</span> <span class="o">=</span> <span class="nb">trim</span><span class="p">(</span><span class="nv">$path</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">);</span>
<span class="nv">$path</span> <span class="o">=</span> <span class="nb">trim</span><span class="p">(</span><span class="nv">$path</span><span class="p">,</span> <span class="s1">'.php'</span><span class="p">);</span>
<span class="nv">$parts</span> <span class="o">=</span> <span class="nb">explode</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="nv">$path</span><span class="p">);</span>
<span class="nv">$lastPart</span> <span class="o">=</span> <span class="nb">end</span><span class="p">(</span><span class="nv">$parts</span><span class="p">);</span>
<span class="k">echo</span> <span class="s1">'class '</span><span class="p">;</span>
<span class="k">foreach</span> <span class="p">(</span><span class="nv">$parts</span> <span class="k">as</span> <span class="nv">$id</span> <span class="o">=></span> <span class="nv">$part</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// textmate placeholders start at 1</span>
<span class="nv">$id</span> <span class="o">=</span> <span class="nv">$id</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$lastPart</span> <span class="o">==</span> <span class="nv">$part</span><span class="p">)</span> <span class="p">{</span>
<span class="k">echo</span> <span class="s1">'${'</span><span class="mf">.</span><span class="nv">$id</span><span class="mf">.</span><span class="s1">':'</span><span class="mf">.</span><span class="nv">$part</span><span class="mf">.</span><span class="s1">'}'</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="k">echo</span> <span class="s1">'${'</span><span class="mf">.</span><span class="nv">$id</span><span class="mf">.</span><span class="s1">':'</span><span class="mf">.</span><span class="nv">$part</span><span class="mf">.</span><span class="s1">'_}'</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="cp">?></span>
</code></pre></div></div>
<p>And bind to a tab trigger.<br />
When you execute from within a file it performs the following.</p>
<p>Retrieves the full path of the file you are in.<br />
Removes any forward slashes from the beginning and end of the path.<br />
Removes the .php extension from the end of the file.<br />
Explodes each part of the path, seperated by a slash (/) into an array.<br />
Gets the pointer for the last item in the array.<br />
echo’s ‘class’<br />
Then iterates through the array, creating a textmate snippet placeholder for each one, all of which have the required underscore (_) apart from the last one.</p>
<p>So for a file that is in the path /The/Full/Path/Filename.php<br />
We end up with the resulting snippet of</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="err">$</span><span class="p">{</span><span class="mi">1</span><span class="o">:</span><span class="n">The_</span><span class="p">}</span><span class="err">$</span><span class="p">{</span><span class="mi">2</span><span class="o">:</span><span class="n">Full_</span><span class="p">}</span><span class="err">$</span><span class="p">{</span><span class="mi">3</span><span class="o">:</span><span class="n">Path_</span><span class="p">}</span><span class="err">$</span><span class="p">{</span><span class="mi">4</span><span class="o">:</span><span class="nc">Filename</span><span class="p">}</span>
</code></pre></div></div>
<p>Which then enables you to tab through them and remove those from the start that you don’t need.<br />
You could go a step further and only spit out the last 3 parts as that is generally how many are needed for a class name. But it really depends on your app structure so I’ve left it as is for now.</p>
<p>Check out the image for the options<br />
<a href="/images/textmateCommand.jpg"><img src="/images/textmateCommand-300x205.jpg" alt="Textmate Command Options" /></a></p>
<h3 id="update">Update:</h3>
<p>I’ve made a version that gives you just the last 3 parts of the path as mentioned above.<br />
I have both running on the ‘class’ tab command so can choose between them as required.</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#!/usr/bin/php
<span class="cp"><?php</span>
<span class="nv">$path</span> <span class="o">=</span> <span class="nv">$_ENV</span><span class="p">[</span><span class="s1">'TM_FILEPATH'</span><span class="p">];</span>
<span class="nv">$path</span> <span class="o">=</span> <span class="nb">trim</span><span class="p">(</span><span class="nv">$path</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">);</span>
<span class="nv">$path</span> <span class="o">=</span> <span class="nb">trim</span><span class="p">(</span><span class="nv">$path</span><span class="p">,</span> <span class="s1">'.php'</span><span class="p">);</span>
<span class="nv">$parts</span> <span class="o">=</span> <span class="nb">explode</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="nv">$path</span><span class="p">);</span>
<span class="k">echo</span> <span class="s1">'class '</span><span class="p">;</span>
<span class="c1">// do this 3 times</span>
<span class="k">for</span><span class="p">(</span><span class="nv">$i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="nv">$i</span> <span class="o"><=</span> <span class="mi">3</span><span class="p">;</span> <span class="nv">$i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nv">$varName</span> <span class="o">=</span> <span class="s1">'part_'</span><span class="mf">.</span><span class="nv">$i</span><span class="p">;</span>
<span class="nv">$part</span> <span class="o">=</span> <span class="nb">array_pop</span><span class="p">(</span><span class="nv">$parts</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$i</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="nv">$$varName</span> <span class="o">=</span> <span class="s1">'${'</span><span class="mf">.</span><span class="nv">$i</span><span class="mf">.</span><span class="s1">':'</span><span class="mf">.</span><span class="nv">$part</span><span class="mf">.</span><span class="s1">'}'</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="nv">$$varName</span> <span class="o">=</span> <span class="s1">'${'</span><span class="mf">.</span><span class="nv">$i</span><span class="mf">.</span><span class="s1">':'</span><span class="mf">.</span><span class="nv">$part</span><span class="mf">.</span><span class="s1">'_}'</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="c1">// pass the snippet to the file</span>
<span class="k">echo</span> <span class="nv">$part_3</span><span class="mf">.</span><span class="nv">$part_2</span><span class="mf">.</span><span class="nv">$part_1</span><span class="p">;</span>
<span class="cp">?></span>
</code></pre></div></div>
Automatically renaming multiple files by rule2010-05-16T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-05-16/automatically-renaming-multiple-files-by-rule<p>I recently had the need to rename a bunch of files according to a simple rule.<br />
In the directory, any files that had a prefix of “Gee_” should have the prefix changed to “Kif_”<br />
After a little digging I found a simple but quite tasty solution.<br />
Simply run this at your command line.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for </span>f <span class="k">in </span>Gee_<span class="k">*</span><span class="p">;</span> <span class="k">do </span><span class="nb">mv</span> <span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span> <span class="s2">"Kif_</span><span class="k">${</span><span class="nv">f</span><span class="p">#Gee_</span><span class="k">}</span><span class="s2">"</span><span class="p">;</span> <span class="k">done</span>
</code></pre></div></div>
<p>Job done. It finds files matching the pattern supplied, then loops through renaming them appropriately.</p>
<p>It’s worth noting this isn’t recursive so will only complete for files in your current directory.</p>
Git pull and git merge between developers2010-04-15T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-04-15/git-pull-and-git-merge-between-developers<p>I use git locally, but the main upstream repo is an SVN one, there are also a couple of other devs that also use git locally.<br />
We are using git svn as the bridge between these 2.</p>
<p>If we want to share code or update each other it was generally the case that we would have to commit everything back to svn (git svn dcommit), then the others would have to rebase.<br />
It felt like I was abusing git and not making the most of it.</p>
<h3 id="enter-git-pull">Enter git pull</h3>
<p>Git pull allows you to grab code from another git repo and store it in your local repo.</p>
<h3 id="git-pull">Git pull</h3>
<p>I’ll presume you already have a git repo locally, and that there is another git repo somewhere you have access to.</p>
<p>First of all we add the remote location.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git remote add mp git.user@mpdevbox:/www/cm/
</code></pre></div></div>
<p>Let me break that command down</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git remote add <span class="o">=</span> The git <span class="nb">command
</span>mp <span class="o">=</span> A friendly name you use <span class="k">for </span>this remote location
git.user@mpdevbox <span class="o">=</span> the remote user and the remote location
:/www/cm <span class="o">=</span> The path to the remote git repo, <span class="o">(</span>note the colon<span class="o">)</span>
</code></pre></div></div>
<p>Having completed that command you now have a reference to a remote git repo, If you want to pull the code down from it, it’s simple (you may want to create and checkout a branch before you do so, depending on your needs. I won’t so will just pull)</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git pull mp master
</code></pre></div></div>
<p>Where master is the name of your local branch you want to pull into.</p>
<p>This will pull down the code from the remote branch and merge it into your branch, if that all goes OK it will then perform a commit, if you don’t wan the commit then just add –no-commit to the end of the pull command</p>
<p>If there are conflicts that git fails to resolve automatically then you will need to resolve them manually.<br />
This can be easily done using mergetool</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git mergetool
</code></pre></div></div>
<p>and follow the instructions.</p>
<p>On Mac this will open a merge/diff client which lets you easily choose from your local and the pulled down repo. Once done you can commit if you want, there is even a pre-filled commit message for you about the merge.</p>
<p>It’s as simple as that really, this approach also makes it much easier to develop on multiple machines, without having to get rid of SVN as your main repo (which depending on circumstances, requirements, or the people that make those decisions, may not be an easy sell).</p>
Git Manuals, Docs and Handy Links2010-04-06T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-04-06/git-manuals-docs-and-handy-links<p>As i am a recent git convert I find myself reading a lot of guides etc on the best way to use git and how my workflow can change now i’m using a DVCS.</p>
<p>This is an attempt to collate my more useful findings, partly for myself, but it may prove useful for you too.</p>
<h3 id="git-books">Git Books</h3>
<p><a href="http://book.git-scm.com/index.html">http://book.git-scm.com/index.html</a><br />
<a href="http://progit.org/book/">http://progit.org/book/</a></p>
<h3 id="git-svn-resources">Git-SVN Resources</h3>
<p><a href="http://orestis.gr/blog/2008/08/23/git-svn-tutorial/">http://orestis.gr/blog/2008/08/23/git-svn-tutorial/</a></p>
<h3 id="full-git-online-manual">Full Git online manual</h3>
<p><a href="http://www.kernel.org/pub/software/scm/git/docs/v1.7.0.4/git.html">http://www.kernel.org/pub/software/scm/git/docs/v1.7.0.4/git.html</a></p>
<h3 id="combining-multiple-git-commits-into-1-svn-commit">Combining multiple git commits into 1 SVN commit</h3>
<p>In some cases I use git as a local repo, but the main repo upstream is SVN. This sample enables me to combine multiple local git commits into a single commit back to SVN.
This was taken from <a href="http://stackoverflow.com/questions/1408381/combine-local-git-commits-into-one-commit-with-git-svn" title="Stack Overflow git commit squashing">Stack Overflow</a></p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git tag <span class="nb">local</span> <span class="c"># create a temporary tag</span>
git reset <span class="nt">--hard</span> trunk
git merge <span class="nt">--squash</span> <span class="nb">local
</span>git commit <span class="c"># write your single commit message here</span>
git svn dcommit
git tag <span class="nt">-d</span> <span class="nb">local</span> <span class="c"># delete the temporary tag named local</code></span>
</code></pre></div></div>
<p>Delicious
I also tend to bookmark a lot of stuff over at Delicious so you can check out my git stuff there too. Items tagged ‘Git’ at my Delicious</p>
Zebra Striping with PHP the Easy Way2010-03-16T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-03-16/zebra-striping-with-php-the-easy-way<p>Using one of the built in Maths functions of PHP we can easily create zebra striped lists.<br />
Let’s say we have an array of entries stored within the $comments variable.<br />
All we have to do with this is to use the fmod function and assign a css class that alternates per entry.</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><ul></span>
<span class="cp"><?php</span> <span class="k">foreach</span> <span class="p">(</span><span class="nv">$comments</span> <span class="k">as</span> <span class="nv">$int</span> <span class="o">=></span> <span class="nv">$comment</span><span class="p">)</span><span class="o">:</span> <span class="cp">?></span>
<span class="nt"><li</span> <span class="na">class=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nb">fmod</span><span class="p">(</span><span class="nv">$int</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">?</span> <span class="s1">'even'</span> <span class="o">:</span> <span class="s1">'odd'</span> <span class="cp">?></span><span class="s">"</span><span class="nt">></span>
<span class="cp"><?php</span> <span class="k">endforeach</span><span class="p">;</span> <span class="cp">?></span>
<span class="nt"></ul></span>
</code></pre></div></div>
<p>Then just give the even and odd classes different colours to suit your layout.</p>
<div class="language-css highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">li</span><span class="nc">.even</span> <span class="p">{</span>
<span class="nl">background-color</span><span class="p">:</span><span class="m">#FFFFFF</span><span class="p">;</span>
<span class="nl">color</span><span class="p">:</span><span class="m">#000000</span><span class="p">;</span>
<span class="p">}</span>
<span class="nt">li</span><span class="nc">.odd</span> <span class="p">{</span>
<span class="nl">background-color</span><span class="p">:</span><span class="m">#000000</span><span class="p">;</span>
<span class="nl">color</span><span class="p">:</span><span class="m">#FFFFFF</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>And you’re done!</p>
Using helpers within an action in symfony 1.02010-03-16T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-03-16/using-helpers-within-an-action-in-symfony-1-0<p>If you ever need to use a helper outside a template, you can still load a helper group from anywhere by calling</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?php</span>
<span class="n">sfLoader</span><span class="o">::</span><span class="nf">loadHelpers</span><span class="p">(</span><span class="nv">$helpers</span><span class="p">)</span>
</code></pre></div></div>
<p>where $helpers is a helper group name or an array of helper group names.
For instance, if you want to use simple_format_text() in an action, you need to call</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?php</span>
<span class="n">sfLoader</span><span class="o">::</span><span class="nf">loadHelpers</span><span class="p">(</span><span class="s1">'Text'</span><span class="p">);</span>
</code></pre></div></div>
<p>I know this is covered in the symfony docs but it’s a fairly handy thing to know so thought I would make it easier to find.</p>
The use of 301 rewrite2010-03-16T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-03-16/the-use-of-301-rewrite<p>If you are hosting a domain (or multiple domains) using VirtualHost entries, it is bad practice to use individual entries for the same domain just to cover the inclusion or exclusion of the www in the address, amongst other things it is bad for SEO, but of course you still want visitors to be able to go to your site via the 2 starting addresses http://sedlmayr.co.uk and http://www.sedlmayr.co.uk</p>
<p>For example you should not have an entry for www.sedlmayr.co.uk and another for sedlmayr.co.uk
There are a few ways you can do this but have found this particular one to be effective.
Whatever url you go to; http://sedlmayr.co.uk or http://www.sedlmayr.co.uk a redirect happens on the http://sedlmayr.co.uk that sends you to http://www.sedlmayr.co.uk.</p>
<p>But what about people that go to specific pages such as http://sedlmayr.co.uk/services</p>
<p>We use a RewriteRule so that whatever is after the domain itself (in this case services)(When using http://sedlmayr.co.uk) http://sedlmayr.co.uk/services is shown as http://www.sedlmayr.co.uk/services
It is very simple to achieve this.</p>
<p>Within you VirtualHost entry you need to specify a ServerAlias. So I would have</p>
<div class="language-conf highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">ServerName</span> <span class="n">www</span>.<span class="n">sedlmayr</span>.<span class="n">co</span>.<span class="n">uk</span>
<span class="n">ServerAlias</span> <span class="n">sedlmayr</span>.<span class="n">co</span>.<span class="n">uk</span>
</code></pre></div></div>
<p>And then within the vhost file for your project you would have</p>
<div class="language-conf highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">RewriteCond</span> %{<span class="n">HTTP_HOST</span>} ^<span class="n">sedlmayr</span>\.<span class="n">co</span>.<span class="n">uk</span>
<span class="n">RewriteRule</span> ^(.*)$ <span class="n">http</span>://<span class="n">www</span>.<span class="n">sedlmayr</span>.<span class="n">co</span>.<span class="n">uk</span>/$<span class="m">1</span> [<span class="n">R</span>=<span class="m">301</span>,<span class="n">L</span>]
</code></pre></div></div>
<p>Which needs to go at the top.
That’s it!
Hope this is helpful to you at some point.</p>
Imagemagick sfThumbnailPlugin fix for scaling under symfony 1.02010-03-16T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-03-16/imagemagick-sfthumbnail-plugin-fix-for-scaling-under-symfony-1-0<p>I’ve been using the sfThumbnail Plugin in symfony 1.0 for image resizing when users upload.<br />
When I asked the plugin to resize an image with scaling there was a problem and the image came out skewed and distorted.<br />
After a little research I found the following fix.</p>
<p>Once you have installed the plugin, edit the sfImageMagickAdapter.class.php in the plugin dir.</p>
<p>Change lines 223-237:</p>
<p>From</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?php</span>
<span class="nv">$width</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="n">sourceWidth</span><span class="p">;</span>
<span class="nv">$height</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="n">sourceHeight</span><span class="p">;</span>
<span class="nv">$x</span> <span class="o">=</span> <span class="nv">$y</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">switch</span> <span class="p">(</span><span class="o">@</span><span class="nv">$this</span><span class="o">-></span><span class="n">options</span><span class="p">[</span><span class="s1">'method'</span><span class="p">])</span> <span class="p">{</span>
<span class="k">case</span> <span class="s2">"shave_all"</span><span class="o">:</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$width</span> <span class="o">></span> <span class="nv">$height</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$x</span> <span class="o">=</span> <span class="nb">ceil</span><span class="p">((</span><span class="nv">$width</span> <span class="o">-</span> <span class="nv">$height</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="p">);</span>
<span class="nv">$width</span> <span class="o">=</span> <span class="nv">$height</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">elseif</span> <span class="p">(</span><span class="nv">$height</span> <span class="o">></span> <span class="nv">$width</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$y</span> <span class="o">=</span> <span class="nb">ceil</span><span class="p">((</span><span class="nv">$height</span> <span class="o">-</span> <span class="nv">$width</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">);</span>
<span class="nv">$height</span> <span class="o">=</span> <span class="nv">$width</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>To</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?php</span>
<span class="nv">$width</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="n">sourceWidth</span><span class="p">;</span>
<span class="nv">$height</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="n">sourceHeight</span><span class="p">;</span>
<span class="nv">$mWidth</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="n">maxWidth</span><span class="p">;</span>
<span class="nv">$mHeight</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="n">maxHeight</span><span class="p">;</span>
<span class="nv">$x</span> <span class="o">=</span> <span class="nv">$y</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">switch</span> <span class="p">(</span><span class="o">@</span><span class="nv">$this</span><span class="o">-></span><span class="n">options</span><span class="p">[</span><span class="s1">'method'</span><span class="p">])</span> <span class="p">{</span>
<span class="k">case</span> <span class="s2">"shave_all"</span><span class="o">:</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$width</span> <span class="o">></span> <span class="nv">$height</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$x</span> <span class="o">=</span> <span class="nb">ceil</span><span class="p">((</span><span class="nv">$width</span> <span class="o">-</span> <span class="p">(</span><span class="nv">$height</span><span class="o">*</span><span class="nv">$mWidth</span><span class="p">)</span><span class="o">/</span><span class="nv">$mHeight</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="p">);</span>
<span class="nv">$width</span> <span class="o">=</span> <span class="nv">$height</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">elseif</span> <span class="p">(</span><span class="nv">$height</span> <span class="o">></span> <span class="nv">$width</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$y</span> <span class="o">=</span> <span class="nb">ceil</span><span class="p">((</span><span class="nv">$height</span> <span class="o">-</span> <span class="nv">$width</span><span class="o">*</span><span class="p">(</span><span class="nv">$mHeight</span><span class="o">/</span><span class="nv">$mWidth</span><span class="p">))</span> <span class="o">/</span> <span class="mi">2</span><span class="p">);</span>
<span class="nv">$height</span> <span class="o">=</span> <span class="nv">$width</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>It’s a straight forward edit so you should be able to see why this simple change has the desired effect, and your images will now behave nicely when scaling.</p>
How-to collapse the web debug toolbar in symfony 1.0 by default2010-03-16T00:00:00+00:00http://chris.sedlmayr.co.uk/2010-03-16/howto-collapse-the-web-debug-toolbar-in-symfony-1-0-by-default<p>To automatically collapse, hide, shrink (or whatever you want to call it) the web debug toolbar to just the SF and close icons; add this line</p>
<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">window</span><span class="p">.</span><span class="nx">onload</span><span class="o">=</span><span class="nx">sfWebDebugToggleMenu</span><span class="p">;</span>
</code></pre></div></div>
<p>to the end of this file</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>...\symfony\web\sf\sf_web_debug\js\main.js
</code></pre></div></div>
<p>This handy little tip courtesy of IsRobot.</p>