<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Neverintheoffice.net - Home</title>
  <id>tag:neverintheoffice.net,2008:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  <link href="http://neverintheoffice.net/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://neverintheoffice.net/" rel="alternate" type="text/html"/>
  <updated>2008-01-02T12:39:44Z</updated>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2008-01-02:18</id>
    <published>2008-01-02T12:31:00Z</published>
    <updated>2008-01-02T12:39:44Z</updated>
    <category term="Geekliness"/>
    <category term="Tutorial"/>
    <category term="gmap"/>
    <category term="gmap2"/>
    <category term="google maps"/>
    <category term="mappa"/>
    <category term="plugin"/>
    <category term="rails"/>
    <category term="ruby"/>
    <category term="Ruby on Rails"/>
    <category term="ruby on rails"/>
    <link href="http://neverintheoffice.net/2008/1/2/marker-creation-with-extra-cruft-rails-with-mappa-part-iv" rel="alternate" type="text/html"/>
    <title>Marker Creation with extra cruft! (rails with mappa Part IV)</title>
<content type="html">
            &lt;p&gt;The story so far: 
If you&#8217;ve been reading along, you&#8217;ll have learned how to add maps, markers, and listeners, and it&#8217;s all been too easy: a few lines in a controller, a bit of modular reusable javascript, the merest of touches to your views.&lt;/p&gt;

&lt;p&gt;&#8216;Okay&#8217;, I can hear you say, &#8216;that&#8217;s all well and good, but I want to do more with my markers! I want to be able to click on my marker and have it reveal a nice little piece of html formatted text! I want to be able to use my own personal type of marker shaped like a truck!! I want to be able to click on the map and be teleported there in real time!!&#8217; &lt;/p&gt;

&lt;p&gt;Okay, okay, simmer down, we&#8217;re getting there. &lt;/p&gt;

&lt;h3&gt;The javascript&lt;/h3&gt;

&lt;p&gt;We are going to create our marker in much the same way as we created our listener in &lt;a href=&quot;http://neverintheoffice.net/2008/1/1/how-do-you-handle-that-click-click-click-rails-with-mappa-part-iii&quot;&gt;Part III&lt;/a&gt;, using an external, modular, re-usable javascript function.&lt;/p&gt;

&lt;p&gt;Create a new file called &#8216;_createWithIconAndHtml.mjs&#8217; in your mapping/public/javascripts/map_js directory and cut and paste the following javascript into that file.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;function createMarker(point,html,icon_image) {
              var icon = new GIcon();

              icon.image =   icon_image  ;

              icon.shadow = &amp;quot;http://labs.google.com/ridefinder/images/mm_20_shadow.png&amp;quot;;
              icon.iconSize = new GSize(12, 20);
              icon.shadowSize = new GSize(22, 20);
              icon.iconAnchor = new GPoint(6, 20);
              icon.infoWindowAnchor = new GPoint(5, 1);

              var marker = new GMarker(point,icon);

              GEvent.addListener(marker, &amp;quot;click&amp;quot;, function() {
                marker.openInfoWindowHtml(html);
              });
            return marker;
          }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We didn&#8217;t have to give it such a long name, but 1) it&#8217;s explicit and expressive and 2) it gives your fingers more exercise than just cut and paste, and as I&#8217;ve made this all so easy for you I thought I&#8217;d give you some work to do to stop you falling asleep.&lt;/p&gt;

&lt;p&gt;You will also notice that the name of the function is different from the name of the file. This merely demonstrates that the two do not have to be the same.&lt;/p&gt;

&lt;h3&gt;The image&lt;/h3&gt;

&lt;p&gt;Clearly, we are going to need an image for our marker. You wanted a truck (or perhaps a tardis!), but in light of recent news regarding climate change, I&#8217;m not going to give you the truck as I&#8217;m imposing a truck moratorium on my maps until I can determine the effect it has on my carbon footprint, and as for the tardis, well, I suspect there&#8217;ll be copyright issues there.&lt;/p&gt;

&lt;p&gt;But, here&#8217;s a nice innocuous blue marker spot you can use: right click (or control click, or whatever fancy clicky-button-press your own brand of OS uses) and save it to gmapping/public/images &lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://neverintheoffice.net/assets/2008/1/2/marker6.png&quot; /&gt;&lt;/p&gt;

&lt;h3&gt;The Controller code&lt;/h3&gt;

&lt;p&gt;Once again, edit your map_controller file and copy the following the method into the file.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def scripted_marker_with_icon_and_html

    @page_title = action_name

    @gmap = Mappa::GMap.new()

    @gmap.api_key = @@key

    @gmap.lat = 51.775362610
    @gmap.lng = -0.00100011

    @gmap.zoom = 16
    @gmap.add_control(:control =&amp;gt; 'large')
    @gmap.add_control(:control =&amp;gt; 'type')

    marker_lat = 51.77530
    marker_lng = -0.002


    # Here we read our _createWithIconAndHtml.mjs file, telling gmap we're using this 

    @gmap.use_marker_code('createWithIconAndHtml', :with_args =&amp;gt; [:point, :html, :icon_image])

    incident_point = Mappa::GLatLng.new(:lat =&amp;gt; marker_lat, :lng =&amp;gt; marker_lng)
    @gmap.add_marker(:point =&amp;gt; incident_point, :create_with =&amp;gt; 'createWithIconAndHtml', :html =&amp;gt; &amp;quot;'Click &amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;here&amp;lt;/a&amp;gt; to teleport!'&amp;quot;, :icon_image =&amp;gt; &amp;quot;'/images/marker6.png'&amp;quot;)    

    render :template =&amp;gt; &amp;quot;map/index&amp;quot;
  end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Let&#8217;s look at that again. What did we add to our controller?&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;@gmap.use_marker_code('createWithIconAndHtml', :with_args =&amp;gt; [:point, :html, :icon_image])&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That one line tells Mappa to use the _createWithIconAndHtml.mjs file to find the create marker code.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;@gmap.add_marker(:point =&amp;gt; incident_point, :create_with =&amp;gt; 'createWithIconAndHtml', :html =&amp;gt; &amp;quot;'Click &amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;here&amp;lt;/a&amp;gt; to teleport!'&amp;quot;, :icon_image =&amp;gt; &amp;quot;'/images/marker6.png'&amp;quot;)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And that&#8217;s our one line, nice and nifty, little add_marker code. I don&#8217;t think it needs much explanation for now, suffice to say: notice the way we use :html, :point and :icon_image, and how it ties into the :with_args argument of gmap.use_marker_code.&lt;/p&gt;

&lt;p&gt;And that&#8217;s it. We&#8217;re all done now. Try it out: &lt;a href=&quot;http://localhost:3000/map/scripted_marker_with_icon_and_html&quot;&gt;http://localhost:3000/map/scripted_marker_with_icon_and_html&lt;/a&gt; and don&#8217;t forget to click on the marker to see the html!&lt;/p&gt;

&lt;p&gt;&#8220;Hey!&#8221; I hear you bellow ( Shhhh&#8230;. for it is the day after new year and some of us still have a sore head!)&lt;/p&gt;

&lt;p&gt;&#8220;hey&#8221; I hear you whisper (thank you!), &#8220;What about the teleporting?&#8221;&lt;/p&gt;

&lt;p&gt;Oh yes, teleporting. I did mention teleporting, didn&#8217;t I. Well, I&#8217;ve got to leave you &lt;em&gt;something&lt;/em&gt; to do, or it&#8217;s all just too easy, isn&#8217;t it! So I&#8217;m leaving the teleportation code as an exercise for the reader.&lt;/p&gt;

&lt;p&gt;Happy new year.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2008-01-01:16</id>
    <published>2008-01-01T02:09:00Z</published>
    <updated>2008-01-02T12:34:04Z</updated>
    <category term="Geekliness"/>
    <category term="Tutorial"/>
    <category term="gmap"/>
    <category term="gmap2"/>
    <category term="google maps"/>
    <category term="mappa"/>
    <category term="plugin"/>
    <category term="rails"/>
    <category term="ruby"/>
    <category term="Ruby on Rails"/>
    <category term="ruby on rails"/>
    <link href="http://neverintheoffice.net/2008/1/1/how-do-you-handle-that-click-click-click-rails-with-mappa-part-iii" rel="alternate" type="text/html"/>
    <title>How do you handle that 'Click click click...' (rails with mappa part III)</title>
<content type="html">
            &lt;p&gt;So, we&#8217;ve added a marker via code in our controller, we&#8217;ve added those google map controls, we&#8217;ve put our javascript map code into the header (thus allowing us to take better advantage of the &#8216;Gunload&#8217; garbage collection method) but we want to do more. We crave more power&#8230;We&#8217;re itching to handle map clicks and write our own, more complex, more specific Javascript. Oh what fun!&lt;/p&gt;

&lt;p&gt;So, here goes&#8230;&lt;/p&gt;

&lt;p&gt;User story: When I click on the map, i want it to place a marker on the spot I click. When I click on a marker i want it to delete that marker. &lt;/p&gt;

&lt;p&gt;First we want some Javascript. A function that fulfills the user story. Here&#8217;s one I baked earlier:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;function addMapPinClick(marker, point) {
          if (marker) {
            gmap.removeOverlay(marker);

            } else {
              gmap.addOverlay(new GMarker(point));
            }  
      }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Okay, so the next question must surely be: &#8216;where do we put it?&#8217;
Navigate to your mapping/public/javascripts directory and create a new directory called map_js. Inside that directory create a file called &#8216;_addMapPinClick.mjs&#8217;.&lt;/p&gt;

&lt;p&gt;Now, copy and paste that little function above, into your new _addMapPinClick.mjs file.
And that&#8217;s our Javascript done. Really. No more. I promise.&lt;/p&gt;

&lt;p&gt;Now let&#8217;s edit mapping/app/controllers/map_controller.rb. We are going to create a new method called map_with_onclick&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def map_with_onclick

    # Because I can't be bothered to think too hard, let alone think up a name, 
    # I've let rails do my thinking for me and used action_name to get hold of the
    # name of this action, and store it in the @page_title instance variable. 
    @page_title = action_name

    @gmap = Mappa::GMap.new()

    # Much better to store our api key in one place. Here we are using a class variable 
    # that we'll place at the top of this controller file (after the class definition). We may 
    # eventually decide it's best placed in the application.rb
    @gmap.api_key = @@key

    @gmap.lat = 51.775362610
    @gmap.lng = -0.00100011

    @gmap.zoom = 16
    @gmap.add_control(:control =&amp;gt; 'large')
    @gmap.add_control(:control =&amp;gt; 'type')

    #This is where we read in our function
    @gmap.include_funcs('addMapPinClick')

    # Here we add our listener. The method call is pretty self-explanatory, methinks.
    @gmap.add_listener( :element =&amp;gt; 'gmap', :action =&amp;gt; 'click', :method =&amp;gt; 'addMapPinClick')

    # Once again, we're doing nothing special here, so why not reuse our 
    # marker_onload template, eh? :-)
    render :template =&amp;gt; &amp;quot;map/marker_onload&amp;quot;

  end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The top of that file now also needs to have the @@key variable. Once you&#8217;ve made your edits, the top of the controller file should look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;class MapController &amp;lt; ApplicationController

  #This is the google map API key for localhost:3000. Don't forget to change it when you need to!
  @@key = 'ABQIAAAArjtwNyA-0TDmcb74hMzhHBTJQa0g3IQ9GZqIMmInSLzwtGDKaBRSDWK-cqMmi3YB5dD-8a6Kwe1Qmg'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now go back to your browser and try it out: &lt;a href=&quot;http://localhost:3000/mapping/map_with_onclick&quot;&gt;
http://localhost:3000/mapping/map_with_onclick&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Neat, eh?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next: adding markers with extra cruft!&lt;/strong&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2008-01-01:15</id>
    <published>2008-01-01T01:01:00Z</published>
    <updated>2008-01-02T12:35:27Z</updated>
    <category term="Geekliness"/>
    <category term="gmap"/>
    <category term="gmap2"/>
    <category term="google maps"/>
    <category term="mappa"/>
    <category term="plugin"/>
    <category term="ruby"/>
    <category term="Ruby on Rails"/>
    <category term="ruby on rails"/>
    <link href="http://neverintheoffice.net/2008/1/1/mappa-into-subversion" rel="alternate" type="text/html"/>
    <title>Mappa into subversion</title>
<content type="html">
            &lt;p&gt;It was always in subversion, but you can now get it via the following svn url: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn checkout svn://neverintheoffice.net/mappa/trunk/mappa
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you&#8217;re installing it as a rails plugin, the following shoud work fine:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;script/plugin install svn://neverintheoffice.net/mappa/trunk/mappa
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For now, the documentation is a bit weak - this is in the process of being rectified. Keep your eyes peeled on this blog.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-12-31:14</id>
    <published>2007-12-31T02:28:00Z</published>
    <updated>2008-01-02T12:37:07Z</updated>
    <category term="Geekliness"/>
    <category term="Tutorial"/>
    <category term="API"/>
    <category term="beginner"/>
    <category term="gmap"/>
    <category term="gmap2"/>
    <category term="google maps"/>
    <category term="mappa"/>
    <category term="rails"/>
    <category term="ruby"/>
    <category term="Ruby on Rails"/>
    <category term="ruby on rails"/>
    <category term="Tutorial"/>
    <link href="http://neverintheoffice.net/2007/12/31/making-your-mark-on-the-world-rails-with-mappa-part-ii" rel="alternate" type="text/html"/>
    <title>Making your mark on the World (rails with mappa - Part II)</title>
<content type="html">
            &lt;p&gt;Now let&#8217;s look at adding markers, special google navigation controls, onload functionality and then let&#8217;s refactor and add a little Rails DRYness.&lt;/p&gt;

&lt;h3&gt;1) Adding a marker&lt;/h3&gt;

&lt;p&gt;Open map_controller.rb (you will find it in gmapping/app/controllers) in your favourite editor (no, let&#8217;s not go there!). Add the following method:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def marker
    @page_title = 'My first map with marker!'

    @gmap = Mappa::GMap.new()

    # the gmap api key for localhost:3000 - remember to change this!
    @gmap.api_key = &amp;quot;ABQIAAAArjtwNyA-0TDmcb74hMzhHBTJQa0g3IQ9GZqIMmInSLzwtGDKaBRSDWK-cqMmi3YB5dD-8a6Kwe1Qmg&amp;quot;
    @gmap.lat = 51.775362610
    @gmap.lng = -0.00100011

    # now for the lat and lng of the marker we want to add. 
    marker_lat = 51.78530
    marker_lng = -0.015
    #create our marker 
    marker = Mappa::GLatLng.new(:lat =&amp;gt; marker_lat, :lng =&amp;gt; marker_lng)

    #add the marker to the map.
    @gmap.add_marker(:point =&amp;gt; marker)    
    @gmap.zoom = 12

    @gmap.onload = false

  end&lt;/code&gt;&lt;/pre&gt; 

&lt;p&gt;Now let&#8217;s create the view file. This is very easy, because there are no changes to the file aside from the dynamically created javascript. By default, rails will look for a marker.rhtml file in gmapping/app/views/map. So, let&#8217;s copy our index.rhtml to marker.rhtml.&lt;/p&gt;

&lt;p&gt;That&#8217;s it. go and try it.: &lt;a href=&quot;http://localhost:3000/map/marker&quot;&gt;http://localhost:3000/map/marker&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;2) Adding google map controls and drying it up a bit&lt;/h3&gt;

&lt;p&gt;The method for adding controls is: 
    Mappa.add_control(:control =&gt; &#8216;controltype&#8217;)
The control can be one of: small, large, type, overview.&lt;/p&gt;

&lt;p&gt;edit the map_controller.rb again and add the following lines to the bottom of the marker method you added (see above).&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;@gmap.add_control(:control =&amp;gt; 'small')
    @gmap.add_control(:control =&amp;gt; 'type')
    @gmap.add_control(:control =&amp;gt; 'overview')&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Because there was no difference between our index.rhtml and our marker.rhtml, we didn&#8217;t really need it, so let&#8217;s tell rails to render the same layout the for the marker method as we used for the index method. 
Add the following line to the very end of the method, just above the &#8216;end&#8217; statement:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;render :template =&amp;gt; 'map/index'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Your marker method should now look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def marker
    @page_title = 'My first map with marker!'

    @gmap = Mappa::GMap.new()

    # the gmap api key for localhost:3000 - remember to change this!
    @gmap.api_key = &amp;quot;ABQIAAAArjtwNyA-0TDmcb74hMzhHBTJQa0g3IQ9GZqIMmInSLzwtGDKaBRSDWK-cqMmi3YB5dD-8a6Kwe1Qmg&amp;quot;
    @gmap.lat = 51.775362610
    @gmap.lng = -0.00100011

    # now for the lat and lng of the marker we want to add. 
    marker_lat = 51.78530
    marker_lng = -0.015

    #create our marker 
    marker = Mappa::GLatLng.new(:lat =&amp;gt; marker_lat, :lng =&amp;gt; marker_lng)

    #add the marker to the map.
    @gmap.add_marker(:point =&amp;gt; marker)    
    @gmap.zoom = 12

    @gmap.onload = false
    @gmap.add_control(:control =&amp;gt; 'small')
    @gmap.add_control(:control =&amp;gt; 'type')
    @gmap.add_control(:control =&amp;gt; 'overview')

    render :template =&amp;gt; 'map/index'

  end&lt;/code&gt;&lt;/pre&gt; 

&lt;p&gt;Take another look: &lt;a href=&quot;http://localhost:3000/map/marker&quot;&gt;http://localhost:3000/map/marker&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;3) Getting it all out of the body, into the head and using onload (and introducing partials and helpers!)&lt;/h3&gt;

&lt;p&gt;To call something via onload in the header of our page, to actually include that content into the header section, and to keep it all nice and DRY requires a few new steps.&lt;/p&gt;

&lt;p&gt;First let&#8217;s edit our layout file. open gmapping/app/views/layout/map.rhtml in your editor and replace the line that contains the body tag: &lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;body&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;with &lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;%= body_tag_creator %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;the &#8216;body_tag_creator&#8217; is something new: a helper method. change directory to: mapping/app/helpers and open the application_helper.rb file in your favourite editor, and add the body_tag_creator method.  When you&#8217;ve finished, your file should look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;module ApplicationHelper

  def body_tag_creator
    if !@gmap.nil? &amp;amp;&amp;amp; @gmap.onload
      '&amp;lt;body onload=&amp;quot;' + @gmap.onload_func_name + '()&amp;quot; onunload=&amp;quot;GUnload&amp;quot;&amp;gt;'
    else
      '&amp;lt;body&amp;gt;'
    end
  end

end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This new method is now available to every view. We could also have restricted it to those views generated by the map_controller, by only adding it to the map_helper.rb. Helpers help us to keep view generating code out of our view files.&lt;/p&gt;

&lt;p&gt;Add the following method to your map_controller.rb:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def marker_onload
    @page_title = 'My first map with marker!'

    @gmap = Mappa::GMap.new()

    # the gmap api key for localhost:3000 - remember to change this!
    @gmap.api_key = &amp;quot;ABQIAAAArjtwNyA-0TDmcb74hMzhHBTJQa0g3IQ9GZqIMmInSLzwtGDKaBRSDWK-cqMmi3YB5dD-8a6Kwe1Qmg&amp;quot;
    @gmap.lat = 51.775362610
    @gmap.lng = -0.00100011

    # now for the lat and lng of the marker we want to add. 
    marker_lat = 51.78530
    marker_lng = -0.015

    #create our marker 
    marker = Mappa::GLatLng.new(:lat =&amp;gt; marker_lat, :lng =&amp;gt; marker_lng)

    #add the marker to the map.
    @gmap.add_marker(:point =&amp;gt; marker)    

    marker2_lat = 51.7900
    marker2_lng = -0.025

    #create our marker 
    marker2 = Mappa::GLatLng.new(:lat =&amp;gt; marker2_lat, :lng =&amp;gt; marker2_lng)

    #add the marker to the map.
    @gmap.add_marker(:point =&amp;gt; marker2)    

    @gmap.zoom = 12

    @gmap.add_control(:control =&amp;gt; 'large')
    @gmap.add_control(:control =&amp;gt; 'type')
    @gmap.add_control(:control =&amp;gt; 'overview')

  end&lt;/code&gt;&lt;/pre&gt; 

&lt;p&gt;Now let&#8217;s create a new view, and in the process introduce the rails :partial template.&lt;/p&gt;

&lt;p&gt;create a file called marker_onload.rhtml in gmapping/app/views/map. Edit that file and add the following layout:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;%= render :partial =&amp;gt; 'headers' %&amp;gt;
&amp;lt;div style=&amp;quot;height:400px;width:400px&amp;quot; id=&amp;quot;gmap&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&#8217;s it for the view, now let&#8217;s look at the partial. The name of the partial, according to the render call in the marker_onload.rhtml file, is &#8216;headers&#8217;. All partial file names start with an underscore, so, create a file called _headers.rhtml in gmapping/app/views/map. Edit that file and add the following layout:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;% content_for :map_headers do %&amp;gt;
    &amp;lt;%= map_header(@gmap) %&amp;gt;
    &amp;lt;%= map_body(@gmap) %&amp;gt;
&amp;lt;% end %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Why did we use a partial? Partials are generally used for small chunks of oft used code. In this case we are saving ourselves repetitive use of those four lines of markup, as it&#8217;s highly likely we will be using them again. Notice also, that the map_body mappahelper method is now included along with map_header in the &amp;lt;head&gt; section of the web page. We&#8217;re doing this because we are now going to be calling our map generating javascript from an onload that looks to the &amp;lt;head&gt; section for its code.&lt;/p&gt;

&lt;p&gt;And that&#8217;s all for now folks. If you&#8217;ve been following along, you should be able to see what you&#8217;ve done by point your browser to: &lt;a href=&quot;http://localhost:3000/map/marker_onload&quot;&gt;http://localhost:3000/map/marker_onload&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next: handling map events, creating more custom marker creation methods and reading from external .mjs files&lt;/strong&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-12-30:12</id>
    <published>2007-12-30T20:57:00Z</published>
    <updated>2008-01-02T12:38:12Z</updated>
    <category term="Geekliness"/>
    <category term="Tutorial"/>
    <category term="API"/>
    <category term="beginner"/>
    <category term="gmap"/>
    <category term="gmap2"/>
    <category term="google maps"/>
    <category term="mappa"/>
    <category term="ruby"/>
    <category term="Ruby on Rails"/>
    <category term="ruby on rails"/>
    <category term="Tutorial"/>
    <link href="http://neverintheoffice.net/2007/12/30/hello-world-with-mappa" rel="alternate" type="text/html"/>
    <title>Hello World (rails with mappa - Part I)</title>
<content type="html">
            &lt;p&gt;As promised, here&#8217;s the first in a little series of mappa.rb usage tutorials for Ruby on Rails.&lt;/p&gt;

&lt;p&gt;These tutorials should provide something for all users, but for the sake of clarity and to help any rails virgin, I&#8217;ve written this tutorial in particular from the perspective of the beginner. So, we&#8217;re pretty much starting from the scratch. I&#8217;m assuming the you, the reader, aren&#8217;t a complete command line newbie, know how to use an editor of some sort and are familiar with command line navigation and command execution. &lt;/p&gt;

&lt;p&gt;If you are not a beginner, ignore anything you consider beneath you and demonstrate your superior knowledge by just extracting the knowledge you require from the content below :-)..&lt;/p&gt;

&lt;p&gt;Subsequent tutorials will make assumptions about your knowledge level based upon what you will have picked up already, and will probably assume &#8220;you already know it&#8221;, or have already read this tutorial.&lt;/p&gt;

&lt;p&gt;Because I use OS X - a unix operating system, I&#8217;m using a Unix operating system in my examples. If you are using a non-unix based operating system, I recommend you translate my example command line instructions into those relevant to your operating system.&lt;/p&gt;

&lt;p&gt;And, for the non-beginner (and beginner too!), I recommend you look at the forthcoming, more detailed, Mappa api article that will provide detail on all the key api methods. &lt;/p&gt;

&lt;p&gt;[Clearly, you will need to have ruby and Ruby on Rails installed on your computer. Installation is beyond the scope of this article. For more information got to: &lt;a href=&quot;http://rubyonrails.org/&quot;&gt;Ruby on Rails&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Ready? Let&#8217;s begin!&lt;/p&gt;

&lt;h3&gt;1) Create a project and install the plugin &lt;/h3&gt;

&lt;p&gt;Enter the directory you wish to use to hold your rails project, copy the mappa.tar.gz file into that directory. &lt;/p&gt;

&lt;p&gt;If you haven&#8217;t already downloaded it, go and get it from: &lt;a href=&quot;http://neverintheoffice.net/mappa.tar.gz&quot;&gt;Here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Type or cut and paste the following code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
rails gmapping
cd gmapping/vendor/plugins
cp ../../../mappa.tar.gz .
tar xzvf mappa.tar.gz
cd ../..
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This should leave us in the gmapping directory, ready to create a rails controller.&lt;/p&gt;

&lt;h3&gt;2) Create the controller.&lt;/h3&gt;

&lt;p&gt;In the top level gmapping directory, generate a map controller by typing the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
ruby script/generate controller map index
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once you&#8217;ve done this, open a new shell, change to your gmapping directory and type: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
ruby script/server
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once the server starts, open a browser and point it to http://localhost:3000/map
You should see this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Map#index&lt;/strong&gt;
Find me in app/views/map/index.rhtml&lt;/p&gt;

&lt;p&gt;Clearly not what we want, yet&#8230; but we&#8217;re nearly there. First, let&#8217;s edit the controller, and then we&#8217;ll edit the view.&lt;/p&gt;

&lt;p&gt;Change directory to the app/controllers directory (cd app/controllers should do it ;-) ). 
Using your favourite editor (really, whatever you want - this isn&#8217;t the place for editor wars. I&#8217;m a &#8216;textmate&#8217; or &#8216;vi&#8217; person myself, but you know, if you wish to twist your brain with emacs, that&#8217;s up to you.), open the map_controller.rb file and replace: &lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def index
  end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;with this: &lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def index

    @page_title = 'Hello world!'

    #Create our new Gmap object
    @gmap = Mappa::GMap.new()

    # the gmap api key for localhost:3000 - remember to change this!
    @gmap.api_key = 'ABQIAAAArjtwNyA-0TDmcb74hMzhHBTJQa0g3IQ9GZqIMmInSLzwtGDKaBRSDWK-cqMmi3YB5dD-8a6Kwe1Qmg'

    # set the longitude and latitiude of the centre point of our map
    @gmap.lat = 51.775362610
    @gmap.lng = -0.00100011

    # set the zoom level of our map. This number is in the range of 1-18. 1 is lowest zoom and 18 is highest
    # we've picked a nice middling 12.
    @gmap.zoom = 12

    # by default gmap.onload is set to true. setting it to false allows (and expects)
    # you to want your javascript within the &amp;lt;body&amp;gt; section and not the &amp;lt;head&amp;gt;
    @gmap.onload = false

  end&lt;/code&gt;&lt;/pre&gt; 

&lt;p&gt;Now we&#8217;re ready to create our view.&lt;/p&gt;

&lt;h3&gt;3) Create the view&lt;/h3&gt;

&lt;p&gt;First, we&#8217;re going to create a layout file. A layout is basically a special template that controls the global layout of our page: the html, the header and often the body definition, the kind of things that get repeated across many pages. 
Using the Google Maps API requires that we have a google map API key, so we are going to put that inside our layout file. 
Change into the app/views/layout directory and create a file called map.rhtml.
edit that file, and add the following:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; 
  &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&amp;gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; lang=&amp;quot;en&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;&amp;lt;%= @page_title || 'map' %&amp;gt;&amp;lt;/title&amp;gt;
    &amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=utf-8&amp;quot; /&amp;gt;
    &amp;lt;%= yield :map_headers %&amp;gt; 
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;%= yield %&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, let&#8217;s create our action specific view. Change directory until you are in gmapping/app/views/map (cd ../map shoud do it ;-) )
open the index.rhtml file in an editor and replace :&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;h1&amp;gt;Map#index&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;Find me in app/views/map/index.rhtml&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;with this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;% content_for :map_headers do %&amp;gt;
    &amp;lt;%= map_header(@gmap) %&amp;gt;
&amp;lt;% end %&amp;gt;

&amp;lt;div style=&amp;quot;height:400px;width:400px&amp;quot; id=&amp;quot;gmap&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;%= map_body(@gmap) %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;4) That&#8217;s all folks&lt;/h3&gt;

&lt;p&gt;No really. try it. &lt;a href=&quot;http://localhost:3000/map&quot;&gt;http://localhost:3000/map&lt;/a&gt;. Go on, I dare you.&lt;/p&gt;

&lt;h3&gt;What did we just do??&lt;/h3&gt;

&lt;p&gt;&#8220;Whowa there.&#8221; I hear you say as, already, I&#8217;ve mired and obscured your beginners knowledge. What&#8217;s with that &#8220;content_for :map&#8221; jive??
Ah, yes. A little niftiness. As it says, it&#8217;s the content for map_headers. Pretty self explanatory, isn&#8217;t it? No? Scroll up a bit and look at the layout file. See the lines: &lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;&amp;lt;%= @page_title || 'map' %&amp;gt;&amp;lt;/title&amp;gt;
    &amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=utf-8&amp;quot; /&amp;gt;
    &amp;lt;%= yield :map_headers %&amp;gt; 
  &amp;lt;/head&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There you go. Your first rails trick. dynamically generating content for the containing layout using content_for.
I&#8217;ll let you in on a secret: we don&#8217;t really need it here&#8230; but we will do&#8230; later&#8230; when we want to put all our javascript in the header section of our layout, dynamically. &lt;/p&gt;

&lt;p&gt;Virtually Every rails template should contain a &amp;lt;%= yield %&gt; line, and this is where the content generated for your view will end up. In our case, whatever is generated by the index.rhtml file is slotted in there &lt;strong&gt;EXCEPT&lt;/strong&gt; that content generated by :&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;% content_for :map_headers do %&amp;gt;
    &amp;lt;%= map_header(@gmap) %&amp;gt;
&amp;lt;% end %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;which ends up being picked up by the &amp;lt;%= yield :map_headers %&gt;  part of the rails template.
What you see there is a call to a helper method that you get with mappa.rb, called map_header. map_header will then generate the relevant html header required (normally to include javascript files).&lt;/p&gt;

&lt;p&gt;The &lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;%= map_body(@gmap) %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;line at the bottom of the index.rhtml did the rest of the dirty work. Another Mappa.rb helper method, map_body takes our @gmap variable, created in our index method in the controller, and generates the javascript required. This Javascript makes use of a div with the id of &#8216;gmap&#8217; to act as the container for the map. This is the default value, but, as you&#8217;ll see in later tutorials, is easily cahnged. Now and finally, Take a look at the html source to see what it produced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NEXT&lt;/strong&gt; markers and onload&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-12-28:10</id>
    <published>2007-12-28T01:34:00Z</published>
    <updated>2008-01-02T12:39:10Z</updated>
    <category term="Geekliness"/>
    <category term="Tutorial"/>
    <category term="gmap"/>
    <category term="gmap2"/>
    <category term="google maps"/>
    <category term="mappa"/>
    <category term="ruby"/>
    <category term="ruby on rails"/>
    <category term="Ruby on Rails"/>
    <category term="Spotcrime API"/>
    <link href="http://neverintheoffice.net/2007/12/28/mappa-new-gmap-plugin-for-rails" rel="alternate" type="text/html"/>
    <title>mappa - new gmap plugin for rails</title>
<content type="html">
            &lt;p&gt;Seasons greetings to all!&lt;/p&gt;

&lt;p&gt;As my gift to the community I have made a first public version of Mappa.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://neverintheoffice.net/mappa.tar.gz&quot;&gt;Download it here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Mappa is a Rails plug-in map-creation API for creating maps embedded in html web pages. Presently it only supports Google's Gmap2 API.
It was written primarily because of the hacks required to make the Cartographer.rb rails plugin work with the new Gmap2 API. &lt;/p&gt;

&lt;p&gt;Following on from a basic implementation I got frustrated with the amount of javascript I was having to embed within my controller code, a necessity because of the dynamic nature of many of the maps (and map creation techniques) I was using. The result was the latest version of mappa which enables you to build your map Javascript from external files.&lt;/p&gt;

&lt;p&gt;Mappa has been written specifically to provide &lt;a href=&quot;http://spotcrime.net&quot;&gt;Spotcrime.net&lt;/a&gt; with handy and useable Google maps. Take a look to get an idea of the potential of Mappa.&lt;/p&gt;

&lt;p&gt;Over the next few days I will provide a series of tutorial articles to help with using Mappa.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-12-28:11</id>
    <published>2007-12-28T01:27:00Z</published>
    <updated>2007-12-28T01:33:30Z</updated>
    <category term="IE7 mappa gmap mephisto"/>
    <link href="http://neverintheoffice.net/2007/12/28/back-to-basics" rel="alternate" type="text/html"/>
    <title>Back to basics</title>
<content type="html">
            &lt;p&gt;Well, sort of....&lt;/p&gt;

&lt;p&gt;I am not going to turn this into a rant about Internet Explorer, but It seems that many of these mephisto templates don't layout well in that particular breed of browser. You can still read it, but until I get the time to have a look, either accept it, or use Firefox or Safari. [obviously, I believe the world would be a nicer place if we all used Firefox, but that's just a dream... ;-) ]&lt;/p&gt;

&lt;p&gt;For now I have to focus my attention on releasing the mappa.rb ruby on rails plugin. Keep your eyes peeled.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-08-02:9</id>
    <published>2007-08-02T11:56:00Z</published>
    <updated>2007-08-06T13:33:06Z</updated>
    <category term="chris ruby"/>
    <link href="http://neverintheoffice.net/2007/8/2/too-long-too-few" rel="alternate" type="text/html"/>
    <title>Too long, too few,</title>
<content type="html">
            &lt;p&gt;It's been far too long since I posted anything. But time's been limited and the death of a friend kicked me back a bit*. If anyone reading this knew chris, don't hesitate to post or pass me something to post on the site set up in tribute to a great guy: &lt;a href=&quot;http://chrisdownham.net&quot;&gt;Chris Downham&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Anyway, I'll rectify and resume activity! Soon, a little 'why i love ruby' meta-programming jive. keep your eyes peeled.&lt;/p&gt;

&lt;p&gt;*Chris would probably tell me that was a weak excuse but still suggest we go and have a glass of wine :-).&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-03-30:8</id>
    <published>2007-03-30T14:37:00Z</published>
    <updated>2007-12-28T02:13:09Z</updated>
    <category term="Amusements"/>
    <category term="Commentary"/>
    <category term="Photography"/>
    <category term="desks monitors"/>
    <category term="kulchur culture zonezero commentary cat photography flickr zooomr rant photograph cameras digital &quot;web 2.0"/>
    <link href="http://neverintheoffice.net/2007/3/30/we-are-not-all-photographers" rel="alternate" type="text/html"/>
    <title>We are NOT all photographers. </title>
<content type="html">
            &lt;p&gt;The last 6 years has seen an explosion in the amount of photographic imagery that surrounds our ever increasingly digital lives. Now, anyone with 50 quid can afford a relatively high-resolution camera. With 200 (or less, if you go to ebay) you can purchase a consumer level SLR camera, and with a few hundred more you can step up to the plate with a technological neckpiece that, 10 years ago, would have had a paparazzi plotting a mugging.&lt;/p&gt;

&lt;p&gt;But, Mega-pixels do not a photographer make and having the latest Nikoanon 120DE with its 25 megapixel sensor will not turn you from a happy snapper into an Adams, Cunningham, Mapplethorpe, Modotti, Weegee or Weston (to name a few too many old classics for such a short piece!). Proof for this theory is kindly provided by web 2.0 photo sites like Zooomr and Flickr (to name only two of many) where a profligation (894,000) of &lt;a href=&quot;http://www.flickr.com/photos//tags/cat&quot;&gt;cat photos&lt;/a&gt; does nothing to disabuse one of this notion. No, really, you don&#8217;t want to see my cat, you do? Oh, &lt;a href=&quot;http://www.flickr.com/photos/45082971@N00/88281325/&quot;&gt;Okay&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;The ever expanding net is littered with photographic imagery taken by everyone, their granny and their dog. Read the &#8216;about&#8217; section on the blogs of many a Technologist, Programmer, or Social commentator, and you will invariably find &#8216;photography&#8217; listed as an interest or hobby (who? moi?), and it&#8217;s now de rigeur to have a Flickr widget on your blog (even i&#8217;ll have one - oneday!). But guys, listen, a photo of &#8220;&lt;a href=&quot;http://images.google.com/images?hl=en&amp;amp;amp;safe=off&amp;amp;amp;client=safari&amp;amp;amp;rls=en&amp;amp;amp;q=My%20desk&amp;amp;amp;btnG=Search&amp;amp;amp;ie=UTF-8&amp;amp;amp;oe=UTF-8&amp;amp;amp;um=1&amp;amp;amp;sa=N&amp;amp;amp;tab=wi&quot;&gt;my desk&lt;/a&gt;&#8221;, is stretching the bounds of what anyone is going to find interesting. don&#8217;t get me onto photos of &#8220;&lt;a href=&quot;http://images.google.co.uk/images?svnum=10&amp;amp;amp;um=1&amp;amp;amp;hl=en&amp;amp;amp;client=firefox-a&amp;amp;amp;rls=org.mozilla%3Aen-US%3Aofficial&amp;amp;amp;q=my+monitor&amp;amp;amp;btnG=Search+Images&quot;&gt;monitor screens&lt;/a&gt;&#8221;.&lt;/p&gt;

&lt;p&gt;So what prompted this rant? &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://zonezero.com/exposiciones/english.html&quot;&gt;zonezero&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Brilliance. You can easily lose 3 hours on that site. These people -are- photographers. Go look. I urge you.&lt;/p&gt;

&lt;p&gt;It&#8217;s not all bad though (did I say it was bad?)! Just consider, for a moment, the depth and richness of information our ancestors will have in 100+ years time; all of that social history captured, stored, and replicated like a virus in a multitude of digital media; all of those remade TV programs; all of those social history lecturer jobs; etc&#8230;  And of course (more frivolously), there&#8217;s no longer any need to wade through Auntie Jane&#8217;s holiday snaps, with one eye on the clock and one eye on the stack of 3 sorted photo albums, looking like you&#8217;re really interested (why don&#8217;t you just say &#8216;look, this is boring auntie jane?&#8217;); ask for a link to her photosite! If she doesn&#8217;t have one, tell her to get one! We&#8217;ve all got them now!
I could soak up more of my time (and yours I&#8217;m hoping) extrapolating on the value in all of this digital information, but I&#8217;ll leave that for another day.&lt;/p&gt;

&lt;p&gt;And, drifting away from the general theme of photography, there&#8217;s all that sharing and togetherness, and the proof that it&#8217;s no longer all about &lt;a href=&quot;http://images.google.com/images?svnum=10&amp;amp;amp;hl=en&amp;amp;amp;gbv=2&amp;amp;amp;safe=off&amp;amp;amp;q=me&amp;amp;amp;btnG=Search+Images&quot;&gt;me me me&lt;/a&gt; (google only returns 1000 images). and really much more about &lt;a href=&quot;http://images.google.com/images?svnum=10&amp;amp;amp;hl=en&amp;amp;amp;gbv=2&amp;amp;amp;safe=off&amp;amp;amp;q=you&amp;amp;amp;btnG=Search+Images&quot;&gt;you&lt;/a&gt; (116,000,000 images). Come on, feel the love ;-)&lt;/p&gt;

&lt;p&gt;Comments, thoughts?&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-03-20:7</id>
    <published>2007-03-20T18:10:00Z</published>
    <updated>2007-12-28T02:12:04Z</updated>
    <category term="Amusements"/>
    <category term="Geekliness"/>
    <category term="regex trainer"/>
    <category term="vi funny training perl &quot;regular expressions"/>
    <link href="http://neverintheoffice.net/2007/3/20/thank-you-humour" rel="alternate" type="text/html"/>
    <title>Thank you humour</title>
<content type="html">
            &lt;p&gt;I taught a short (2 day) Perl training course a few weeks ago and it included one heavy little component that&#8217;s all regular expressions. As it&#8217;s something that always figures as a training requirement, it&#8217;s now pretty well practiced, and, I like to think, effective too, but mid-afternoon on the second day, after a lunch that included pret-a-manger sushi, even -I- feel the pain of /(?:\s[1-9]{1,2})+\w+/. Too much too soon can be like being forced to spend the afternoon peeling onions: it makes your eyes hurt and can induce tears. It&#8217;s hard to make regular expressions anything other than &lt;strong&gt;heavy&lt;/strong&gt; machinery and I&#8217;m sure that they are one of the reasons that Perl gets this bad press of being &#8216;line noise&#8217; (despite the fact that perl style regular expressions are in use in many languages).  &lt;/p&gt;

&lt;p&gt;So, naturally, I was very pleased when I received this email from one of the course students, about a week after the course had finished:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you Nito! I very much enjoyed it&#8230; and on that note: &lt;a href=&quot;http://xkcd.com/c208.html&quot;&gt;http://xkcd.com/c208.html&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It&#8217;s always nice to get feedback, and that&#8217;s &lt;strong&gt;perfect feedback&lt;/strong&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-03-20:5</id>
    <published>2007-03-20T01:02:00Z</published>
    <updated>2007-12-28T02:13:42Z</updated>
    <category term="Geekliness"/>
    <category term="Tutorial"/>
    <category term="slicehost subversion howto svn setup"/>
    <link href="http://neverintheoffice.net/2007/3/20/getting-that-subversion-setup-right" rel="alternate" type="text/html"/>
    <title>Getting that Subversion setup right</title>
<content type="html">
            &lt;p&gt;So, things are going well with my slicehost slice and now I want to get things under version control using subversion. Conventional wisdom would dictate that Apache + mod_dav_svn is the way to go - But,  as much as everyone seems to swear by Apache + mod_dav_svn, It&#8217;s just more memory usage of a 256mb slice that I can do without. &lt;/p&gt;

&lt;p&gt;So, I thought about it for a little while and came up with the following criteria:  &lt;/p&gt;

&lt;p&gt;i) I want to be able to have multiple authorized users accessing one repository, both locally and remotely.&lt;br /&gt;
ii) I don&#8217;t want to provide any anonymous access.&lt;br /&gt;
iii) I don&#8217;t want any clear text passwords and I must have encryption of remote subversion access.&lt;br /&gt;
iv) I don&#8217;t want to use Apache + mod_dav_svn.   &lt;/p&gt;

&lt;p&gt;If the list above matches your requirements read on, and hopefully what follows will be of some help. Bear in mind that this is all on an unbuntu linux slice.&lt;/p&gt;

&lt;p&gt;Let&#8217;s be smart here and say we&#8217;ve got hold of subversion and installed it using the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
sudo apt-get -V install subversion subversion-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And now it&#8217;s time to get it working:&lt;br /&gt;
&lt;strong&gt;1) create an svn group and add all local users with subversion usage requirements&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
sudo addgroup --system svn   
sudo adduser username svn
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Obviously replace &lt;em&gt;username&lt;/em&gt; with a real username, and repeat for every user you want to provide subversion to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) wrap the subversion tools in umasked wrappers:&lt;/strong&gt;&lt;br /&gt;
First we&#8217;ll move the original files (we&#8217;ll make the fairly likely assumption that they&#8217;re in /usr/bin)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
sudo mv /usr/bin/svn /usr/bin/svn-real
sudo mv /usr/bin/svnadmin /usr/bin/svnadmin-real
sudo mv /usr/bin/svnlook /usr/bin/svnlook-real
sudo mv /usr/bin/svnserve /usr/bin/svnserve-real
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we create some wrapper files. Using your favourite editor ( mine happens to be vi(m) ) create a new file called svn with the following content:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
#!/bin/sh

umask 002
/usr/bin/svn-real &quot;$@&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Do the same for svnadmin, svnlook and svnserve, remembering in each case to substitute svn-real for svnserve-real, svnadmin-real or svnlook-real.&lt;br /&gt;
Clear as mud? i hope so!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) create the repository&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
sudo mkdir /var/lib/subversion
sudo svnadmin create /var/lib/subversion/repos
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;4) change ownership and permissions of the repository&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
sudo chown -R :svn /var/lib/subversion
sudo chmod -R g+w /var/lib/subversion
sudo chmod g+s /var/lib/subversion/repos/db
sudo chmod -R g+rw /var/lib/subversion/repos/locks
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;5) Edit the svnserve.conf file and deny access to all anonymous users:&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; 
sudo vi /var/lib/subversion/repos/conf/svnserve.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make sure that (for now at least) only the following line is uncommented (with no hash/pound) in front of it. And if the line doesn&#8217;t exist, add it!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
anon-access = none
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;6) And That&#8217;s All Folks!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, now we have an empty subversion repository all ready to use!  So, how do we use it? We&#8217;re going to assume we&#8217;re on our slice which we&#8217;ll regard as &#8216;local&#8217;.
First, lets put a new project under source code control&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7) Create the source directory&lt;/strong&gt;&lt;br /&gt;
Rather than just import a project into subversion, we create a specific source directory and we structure the contents of that directory according to a common subversion conventions.  You can create this directory wherever you want.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
mkdir myproject_src
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Inside the source directory, we create the following three sub-directories: branches, tags and trunk&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
mkdir myproject_src/branches myproject_src/tags myproject_src/trunk
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Assuming we have an existing project directory, we copy the contents of the existing project directory into myproject_src/trunk.&lt;br /&gt;
&lt;strong&gt;8) TIME to IMPORT&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
svn import myproject_src file:///var/lib/subversion/repos/myproject -m &quot;initial import&quot; -m &quot;initial import&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;9) Time to checkout our first version&lt;/strong&gt;&lt;br /&gt;
Local checkout:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
svn checkout  file:///var/lib/subversion/repos/myproject  myproject_dir
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Remote checkout:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; 
svn checkout svn+ssh:nito@mydomain.com/var/lib/subversion/repos/myproject myproject_dir
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that you will be asked numerous times for your password. This repetition is ssh as opposed to svn, and is a minor irritation that can be overcome with a local ssh password caching utility, but we won&#8217;t cover that here.&lt;/p&gt;

&lt;p&gt;And that&#8217;s about it! There&#8217;s &lt;strong&gt;no anonymous remote access&lt;/strong&gt; to the repository and all your usual subversion commands are now available remotely using svn+ssh: and locally using file: - sweet.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-03-15:4</id>
    <published>2007-03-15T23:42:00Z</published>
    <updated>2007-03-16T00:05:14Z</updated>
    <category term="Geekliness"/>
    <category term="In the beginning..."/>
    <category term="Slicehost blogging flickr dns dot mongrel"/>
    <link href="http://neverintheoffice.net/2007/3/15/back-after-dithering-with-dns-chasing-mongrels-and-googling-the-email" rel="alternate" type="text/html"/>
    <title>Back after dithering with DNS, chasing Mongrels and Googling the email!</title>
<content type="html">
            &lt;p&gt;I won&#8217;t claim to be a sysadmin, in fact, I&#8217;ll willingly announce that &#8216;I am NOT a System Administrator&#8217;, but I will happily sign up to the belief that a first class one is worth at least 5 years worth of expensive rackspace with 24/7 support and maximised bandwidth for a server-farm of at least 10 top-end Apple Xserves. I&#8217;m nearly serious.&lt;/p&gt;

&lt;p&gt;Right now though, I wish I was a sysadmin in the same way I wish I knew how all the bits in my car worked (and finding -that- out would probably lead me to repairing the inside light without having to pay! ). But, getting back to the point&#8230;
&#8230;It probably wasn&#8217;t that noticeable, but we were gone for a bit. Seriously absent. No longer here. You may notice the gap in dates. On the other hand, you may not have noticed or even cared. if I&#8217;d been a good sysadmin, or had one handy, no doubt these problems would never have occurred. especially not &#8220;the case of the missing dot!&#8221; &lt;/p&gt;

&lt;p&gt;It all started a few days ago. &#8216;Time to update the blog&#8217; I thought. &#8216;Time to add some links, perhaps a post, add that Paul Ingles &lt;a href=&quot;http://www.oobaloo.co.uk/articles/2006/12/2/flickr-plugin-for-mephisto&quot;&gt;flickr plugin&lt;/a&gt;, but I couldn&#8217;t post into the blog. Any attempt to get to neverintheoffice.net/admin returned an error and my logs were peppered with the likes of: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
[error] proxy: BALANCER: (balancer://mongrel_cluster). All workers are in error state
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It was eventually fixed by a visit to &lt;a href=&quot;http://mongrel.rubyforge.org/docs/apache.html&quot;&gt;mongrel/apache.html&lt;/a&gt;, modifying some code, making sure everything was shut down and then issuing the following commands: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
 $ mongrel_rails start -d -p 8000 \
   -e production -P /full/path/to/log/mongrel-1.pid
 $ mongrel_rails start -d -p 8001 \
   -e production -P /full/path/to/log/mongrel-2.pid
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Everything seems to be working now. I know there&#8217;s a lot of oddness and inconsistency as to how I&#8217;ve set this all up and sometime over the next week I will revisit this (and perhaps write about it).&lt;/p&gt;

&lt;p&gt;But that wasn&#8217;t what brought us down. it was the previously mentioned missing dot.
After playing around with postfix which brought about faint memories of Qmail I decided &#8216;hang this&#8217; and, after discovering this: &lt;a href=&quot;http://myersds.com/notebook/2007/03/09/using_google_apps_with_your_vps&quot;&gt;google apps with your vps&lt;/a&gt;, decided to take a look at the google way. I was encouraged by the fact that &lt;a href=&quot;http://myersds.com&quot;&gt;Larry Myers&lt;/a&gt; (another new &lt;a href=&quot;http://slicehost.com&quot;&gt;Slicehost&lt;/a&gt; user) with the same sort of mail requirement and reasoning as me: &lt;/p&gt;

&lt;p&gt;&#8220;My biggest motivation for doing this was not wanting to deal with the learning curve that comes with setting up Postfix and Spam Assassin.&#8221;&lt;/p&gt;

&lt;p&gt;So, I travelled over to the googlesphere and joined up. Right now it&#8217;s a very satisfactory solution to a small need. I&#8217;m wondering how it will scale, and when it will show itself to be insufficient. Watch this space. &lt;/p&gt;

&lt;p&gt;&#8220;But what about the missing dot?&#8221; I hear you cry out. Oh yes. The missing dot. Well, it&#8217;s simple really: when you go and sign up for your google apps account, do what &lt;a href=&quot;http://myersds.com&quot;&gt;Larry Myers&lt;/a&gt; tells you to do:&lt;br /&gt;
&#8220;When Google asks to verify your domain I’d suggest just going with the HTML check, as it’s much easier than dealing with changing DNS records.&#8221;&lt;/p&gt;

&lt;p&gt;He&#8217;s right. Because if you mess up, like I did, you can end up with neverintheoffice.net.neverintheoffice.net and sink your domain below the watermark, all for want of a missing dot. Of course, the missing dot is just one potential problem amongst &lt;a href=&quot;http://www.unix.org.ua/orelly/networking/dnsbind/ch13_03.htm&quot;&gt;many&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Oh, and of course you can now email me here: nito@thisdomain.net (change thisdomain to neverintheoffice).&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-03-07:2</id>
    <published>2007-03-07T02:10:00Z</published>
    <updated>2007-03-07T02:17:31Z</updated>
    <category term="Geekliness"/>
    <category term="agency"/>
    <category term="client"/>
    <category term="Dreamhost"/>
    <category term="rake"/>
    <category term="RoR"/>
    <category term="ruby"/>
    <category term="Ruby on Rails"/>
    <link href="http://neverintheoffice.net/2007/3/7/things-to-like-about-ruby-1" rel="alternate" type="text/html"/>
    <title>Things to like about Rake and Rails. </title>
<content type="html">
            &lt;p&gt;I get a phone call at 8:30am, it's an agency - calling from germany, about a contract they think I might be interested in.&lt;br /&gt;
&quot;Can we point the client to a site of yours?&quot;&lt;br /&gt;
&quot;Sure.&quot; I say, &quot;myrailsite.net is a good site to show them.&quot;  &lt;/p&gt;

&lt;p&gt;Two hours later i get an email from the agency.   &lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Subject: &lt;strong&gt;Website Error&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Is there any other Homepage which the client could have a look at? Because the website myrailsite.net says:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Application error 
    Change this error message for exceptions thrown outside of an action&lt;br /&gt;
    (like in Dispatcher setups or broken Ruby code) in public/500.html&lt;/code&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;I'm scratching my head.&lt;br /&gt;
An application error. Why? It was working only two weeks ago. Granted, It's a site i've been neglecting a little, but shouldn't that neglect pretty much guarantee it remaining in a state of fossilisation?&lt;br /&gt;
If I don't change anything, It should all be fine, shouldn't it?&lt;br /&gt;
No.
myrailsite.net is hosted on one of dreamhost's servers. A shared server.&lt;/p&gt;

&lt;p&gt;After steeling myself with a robust cup of coffee and a chocolate bourbon (the biscuit, not some chocolatised alcoholic beverage), I embarked upon a little digging, googling and peering through production logs, where the predominant error appeared to concern deprecated things (you'll have to bear with me here - I was under pressure and I wasn't taking notes! and it's late now, and really, those 'things' that were deprecated aren't that important. No really. Believe me).&lt;br /&gt;
A smatter of chattering to #ruby and #rubyonrails people confirmed my worst fears:
Dreamhost had upgraded their version of rails to 1.2 since I had last looked at myrailsite.net. The upgrade broke my application because of my application's reliance on Engines and specifically, the now very deprecated LoginEngine. Dammit. Drat. Expletive deleted.&lt;/p&gt;

&lt;p&gt;So at this point I'm feeling a little embarassed that a site I'm demonstrating isn't up and running, but also a little relieved that the problem isn't actually my fault. 'So', I thought, 'no worrys, I'll make a copy of the app, mess with it, fix it, give it a quick test and all will be fine'...&lt;br /&gt;
 Of course, I'm trying to do this in a hurry because I want the client to see a working site. And because I'm trying to do it in a hurry it's just not going to happen is it. And even if i was trying to do it properly, it's never going to happen quickly because it would really require pulling out the LoginEngine and replacing it with something like restful authorization or some such, and &lt;strong&gt;doing it properly&lt;/strong&gt; And I'm just hacking, so it's not going to work for me, is it. And, of course, it doesn't. I try a few things, including some migrations etc, but eventually I give up on that route.  &lt;/p&gt;

&lt;p&gt;At this point, the coffee and the biscuit are beginning to kick in and I go hitch a ride on the clue-train. I suddenly tune into a little voice in the back of my mind that says again and again: 'Change the version back to 1.1.6'. Of course. How silly. Now I feel stupid. Why didn't I just do that to begin with? Probably because I'm only human and it was a stressful day, and, as usual, I wasn't listening to myself and I wasn't being very zen. The fix takes no longer than the time it takes to type one line into the shell:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;[milliken] rake rails:freeze:edge TAG=rel_1-1-6&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Voila, we have a working website again. Of course we also have a little something to write about, a bit of rake/ruby/rails to glow about.&lt;/p&gt;

&lt;p&gt;What we learnt today: When we're deploying our applications in the wild, onto hosted services like textdrive or Dreamhost, or myfavouritehoster, take control of our rails applications and avoid at least -some- embarassing hiccups by freezing to an edge. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;if it makes you nervous, you can always unfreeze!&lt;/em&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://neverintheoffice.net/">
    <author>
      <name>nito</name>
    </author>
    <id>tag:neverintheoffice.net,2007-03-06:1</id>
    <published>2007-03-06T11:46:00Z</published>
    <updated>2007-03-06T23:51:09Z</updated>
    <category term="Geekliness"/>
    <category term="slicehost blogging mephisto"/>
    <link href="http://neverintheoffice.net/2007/3/6/at-last" rel="alternate" type="text/html"/>
    <title>At last</title>
<content type="html">
            &lt;p&gt;At last I&#8217;m back up and running, or should that be stumbling? This blog is now hosted at slicehost.net, which, despite a few erroneous in one of the setup pages wiki, seems good and fast and a radical improvement on dreamhost. It&#8217;s twice the price but you get so very much more.&lt;/p&gt;


	&lt;p&gt;Problems:
Changing the title and subtitle. 
I had the same problem running the blog on my local host in production mode. No matter what i do in the admin screen, i can&#8217;t seem to easily change the name of the blog (you&#8217;ll notice it reads &#8216;mephisto&#8217;) or the subtitle beneath it. So, that&#8217;s the next task on the list&lt;/p&gt;


	&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt;: I was wrong. It appears that it does actually work!&lt;/p&gt;


	&lt;p&gt;Now, all i&#8217;ve got to do is get it working nicely with apache.&lt;/p&gt;
          </content>  </entry>
</feed>
