<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>RSS Feed :: Ben Humphreys</title>
    <link>http://benhumphreys.co.uk/en/rss.xml</link>
    <description>Projects, articles and general musings of Ben Humphreys</description>
    <language>en</language>
    <item>
      <title>&#12393;&#12435;&#12393;&#12435; vs &#12384;&#12435;&#12384;&#12435;, &#12414;&#12377;&#12414;&#12377;</title>
      <description>&lt;h2&gt;&#12384;&#12435;&#12384;&#12435; vs &#12393;&#12435;&#12393;&#12435;&lt;/h2&gt;

&lt;p&gt;I was presented with this example sentence in a JLPT1 book.&lt;/p&gt;

&lt;p&gt;&#12300;&#32862;&#12356;&#12383;&#12381;&#12400;&#12363;&#12425;&#12289;&#65343;&#65343;&#35226;&#12360;&#12390;&#12356;&#12367;&#12392;&#12399;&#12289;&#24444;&#12398;&#35352;&#25014;&#21147;&#12399;&#25244;&#32676;&#12384;&#12290;&#12301;&lt;/p&gt;

&lt;p&gt;a) &#12393;&#12435;&#12393;&#12435;&#12288;b) &#12384;&#12435;&#12384;&#12435;&#12288;c) &#12422;&#12387;&#12367;&#12426;&lt;/p&gt;

&lt;p&gt;I was kind of stumped as I knew that &#12422;&#12387;&#12367;&#12426; meant slow, but didn't know the difference between &#12393;&#12435;&#12393;&#12435; and &#12384;&#12435;&#12384;&#12435;.  Thankfully &#12473;&#12452;&#12459;&#12373;&#12435; explained it to me like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&#12393;&#12435;&#12393;&#12435; is faster than &#12384;&#12435;&#12384;&#12435;.&lt;/li&gt;
&lt;li&gt;&#12393;&#12435;&#12393;&#12435; is about the &lt;strong&gt;thing itself&lt;/strong&gt; increasing (therefore faster).&lt;/li&gt;
&lt;li&gt;&#12384;&#12435;&#12384;&#12435; has an emphasis on &lt;strong&gt;time&lt;/strong&gt; passing (therefore slower).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's how she explained it:
&#12381;&#12400;&#12363;&#12425;&#12288;&#12398;&#24847;&#21619;&#12399;&#12300;&#27425;&#12293;&#12395;&#21516;&#12376;&#12371;&#12392;&#12434;&#32368;&#12426;&#36820;&#12375;&#12390;&#12427;&#27096;&#23376;&#12434;&#34920;&#12377;&#12301;&#12290;&#32368;&#12426;&#36820;&#12377;&#12384;&#12363;&#12425;&#12289;&#12300;&#12384;&#12435;&#12384;&#12435;&#12301;&#12384;&#12392;&#24605;&#12387;&#12383;&lt;/p&gt;

&lt;p&gt;&#12391;&#12418;&#27491;&#35299;&#12399;&#12393;&#12435;&#12393;&#12435;&lt;/p&gt;

&lt;p&gt;&#12393;&#12435;&#12393;&#12435;&#12398;&#12411;&#12358;&#12364;&#12289;&#12384;&#12435;&#12384;&#12435;&#12424;&#12426;&#12289;&#26089;&#12356;&lt;/p&gt;

&lt;p&gt;&#12393;&#12435;&#12393;&#12435;&#12399;&#12289;&lt;strong&gt;&#29289;&lt;/strong&gt;&#12364;&#22679;&#12360;&#12390;&#12356;&#12367;&#12363;&#12435;&#12376;&#12290;&lt;/p&gt;

&lt;p&gt;&#12384;&#12435;&#12384;&#12435;&#12399;&#12289;&lt;em&gt;_&#26178;&#38291;&lt;/em&gt;_&#12364;&#12383;&#12387;&#12390;&#12356;&#12367;&#12363;&#12435;&#12376;&#12290;&lt;/p&gt;

&lt;p&gt;&#32862;&#12356;&#12383;&#12381;&#12400;&#12363;&#12425;&#12288;&#12387;&#12390;&#12356;&#12358;&#12398;&#12399;&#12288;&#12300;&#32862;&#12356;&#12383;&#12354;&#12392;&#12289;&#12377;&#12368;&#12301;&#12288;&#12415;&#12383;&#12356;&#12394;&#24847;&#21619;&#12384;&#12363;&#12425;&#12289;&#12384;&#12435;&#12384;&#12435;&#12384;&#12392;&#12377;&#12368;&#12391;&#12399;&#12394;&#12356;&#12290;&#12385;&#12423;&#12387;&#12392;&#12289;&#26178;&#38291;&#12364;&#24517;&#35201;&#12394;&#12363;&#12435;&#12376;&#12290;&lt;/p&gt;

&lt;p&gt;&#12393;&#12435;&#12393;&#12435;&#12288;&#12384;&#12387;&#12383;&#12425;&#29289;&#12364;&#22679;&#12360;&#12390;&#12356;&#12367;&#24863;&#12376;&#12384;&#12363;&#12425;&#12289;&#32862;&#12356;&#12383;&#12354;&#12392;&#12377;&#12368;&#12395;&#12289;&#12393;&#12435;&#12393;&#12435;&#35226;&#12360;&#12390;&#12418;&#22823;&#19976;&#22827;&#12290;&lt;/p&gt;

&lt;h2&gt;Hard to Translate Phrases&lt;/h2&gt;

&lt;p&gt;&#12398;&#12426;&#12364;&#12356;&#12356;&#12288;Good sense of humour/timing?  How would you define &#8220;&#12398;&#12426;&#12364;&#12356;&#12356;&#8221;?  I'd really appreciate some feedback on this, as I'm still not sure how Japanese people perceive the phrase.&lt;/p&gt;

&lt;p&gt;&#21491;&#12395;&#20986;&#12427;&#12418;&#12398;&#12364;&#12394;&#12356; insurpassable, there isn't anything better than...&lt;/p&gt;

&lt;p&gt;&#19981;&#35998;&#23517; The dictionary says &#8220;futene - staying in bed out of spite&#8221; Does anyone use this nowadays?&lt;/p&gt;

&lt;h2&gt;Odd Japanese English&lt;/h2&gt;

&lt;p&gt;I found out a while back that Japanese people use two different English words to describe stripes.  For vertical stripes it's &#12473;&#12488;&#12521;&#12452;&#12503;, whereas horizontal stripes are usually called &#12508;&#12540;&#12480;&#12540;.&lt;/p&gt;

&lt;h2&gt;Notes on &#12414;&#12377;&#12414;&#12377;&lt;/h2&gt;

&lt;p&gt;Summarized, big things can get bigger, small things can get smaller.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&#9675; &#22823;&#12365;&#12356;&#29289;&#12364;&#12289;&#12414;&#12377;&#12414;&#12377;&#22823;&#12365;&#12367;&#12394;&#12428;&#12427;&lt;/li&gt;
&lt;li&gt;&#9675; &#23567;&#12373;&#12356;&#12418;&#12398;&#12418;&#12289;&#12414;&#12377;&#12414;&#12377;&#23567;&#12373;&#12367;&#12394;&#12428;&#12427;&lt;/li&gt;
&lt;li&gt;&#215; &#12362;&#12362;&#12365;&#12356;&#12418;&#12398;&#12364;&#12289;&#12414;&#12377;&#12414;&#12377;&#23567;&#12373;&#12367;&#12394;&#12427;&lt;/li&gt;
&lt;li&gt;&#215; &#12385;&#12356;&#12373;&#12356;&#12418;&#12398;&#12364;&#12414;&#12377;&#12414;&#12377;&#12362;&#12362;&#12365;&#12367;&#12394;&#12427;&#12289;&#12391;&#12365;&#12394;&#12356;&lt;/li&gt;
&lt;li&gt;&#215; &#12394;&#12356;&#12418;&#12398;&#12399;&#12289;&#12414;&#12377;&#12414;&#12377;&#22679;&#12360;&#12427;&lt;/li&gt;
&lt;li&gt;&#9675; big &#8594; bigger&lt;/li&gt;
&lt;li&gt;&#9675; small &#8594; smaller&lt;/li&gt;
&lt;li&gt;&#215; big &#8594; smaller&lt;/li&gt;
&lt;li&gt;&#215; small &#8594; bigger&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope people find this interesting.  If you have any ideas on what I've mentioned, or want to point out any mistakes I've made, I look forward to hearing from you :)&lt;/p&gt;</description>
      <pubDate>Mon, 08 Oct 2007 04:19:00 -0700</pubDate>
      <link>http://benhumphreys.co.uk/blogs/9</link>
      <guid>http://benhumphreys.co.uk/blogs/9</guid>
    </item>
    <item>
      <title>Japanese Nuances</title>
      <description>&lt;h2&gt;Comparisons&lt;/h2&gt;

&lt;p&gt;I often come across words in Anki that seem very similar, and I have a hard time remembering which kanji is associated with two seemingly identical descriptions.  To clear up the different nuances I asked some Japanese friends (thanks Gen&#12373;&#12435; and other 2ch-ers).&lt;/p&gt;

&lt;h3&gt;&#25298;&#32118;&#12288;vs&#12288;&#36766;&#36864;&lt;/h3&gt;

&lt;p&gt;&#25298;&#32118; is stronger, more severe. &#8220;No way in hell.&#8221; kind of feeling.&lt;/p&gt;

&lt;p&gt;&#36766;&#36864; is relatively soft.  The answer is no, but there&#8217;s a reason behind it.&lt;/p&gt;

&lt;h3&gt;&#36867;&#12370;&#12427;&#12288;vs&#12288;&#36867;&#12428;&#12427;&lt;/h3&gt;

&lt;p&gt;&#36867;&#12370;&#12427;&#12288;&#20154;&#12363;&#12425;&#36867;&#12370;&#12427;&#12288;&#12288;You run away from a person.&lt;/p&gt;

&lt;p&gt;&#36867;&#12428;&#12427;&#12288;&#28797;&#12356;&#12363;&#12425;&#36867;&#12428;&#12427;&#12288;You flee from a disaster.&lt;/p&gt;

&lt;p&gt;I'm still not 100% sure about this difference.&lt;/p&gt;

&lt;h3&gt;&#36969;&#24540;&#12288;vs&#12288;&#36969;&#29992;&lt;/h3&gt;

&lt;p&gt;&#36969;&#24540; &lt;strong&gt;Natural&lt;/strong&gt; adaptation to external conditions (becoming accustomed to the situation).&lt;/p&gt;

&lt;p&gt;&#36969;&#29992; &lt;strong&gt;Actively&lt;/strong&gt; adapting to external conditions (problem solving).&lt;/p&gt;

&lt;p&gt;When you consider the meanings of the 2nd kanji, it becomes more easy to remember:&lt;/p&gt;

&lt;p&gt;&#29992;&#12356;&#12427; = &lt;strong&gt;to use&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&#24540;&#12376;&#12427; = to respond, to satisfy, &lt;strong&gt;to comply with&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some examples
&#9675; &#20693;&#12364;&#28023;&#22806;&#12395;&#34892;&#12387;&#12390;&#29983;&#27963;&#32722;&#24931;&#12395;&#36969;&#24540;&#12375;&#12383;&#12290;&#12288;I became used to life in a foreign country.&lt;/p&gt;

&lt;p&gt;&#9675; &#12503;&#12525;&#12464;&#12521;&#12512;&#12434;&#36969;&#29992;&#12375;&#12383;&lt;/p&gt;

&lt;p&gt;&#215; &#12503;&#12525;&#12464;&#12521;&#12512;&#12434;&#36969;&#24540;&#12375;&#12383;&#12288;Because you are actively adapting the program, should be &#36969;&#29992;&lt;/p&gt;

&lt;h3&gt;&#35090;&#32654;&#12288;vs&#12288;&#29554;&#29289;&lt;/h3&gt;

&lt;p&gt;&#29554;&#29289; is the target, the thing you&#8217;re trying to get.  Reflected by its translations: game, spoils, trophy&lt;/p&gt;

&lt;p&gt;&#35090;&#32654; is more like a present, the reward you get for winning.&lt;/p&gt;

&lt;h2&gt;New Vocabulary&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&#21697;&#20999;&#12428;&#12288;&#12375;&#12394;&#12366;&#12428;&#12288;sold out&lt;/li&gt;
&lt;li&gt;&#38291;&#36817;&#12288;&#12288;&#12414;&#12386;&#12363;&#12288;&#12288;nearing&lt;/li&gt;
&lt;li&gt;&#12414;&#12427;&#12372;&#12392;&#12288;&#12288;&#12288;&#12288;&#12288;whole&lt;/li&gt;
&lt;li&gt;&#32080;&#25104;&#12288;&#12288;&#12369;&#12387;&#12379;&#12356;&#12288;formation&lt;/li&gt;
&lt;li&gt;&#31680;&#30446;&#12288;&#12288;&#12405;&#12375;&#12417;&#12288;&#12288;turning point&lt;/li&gt;
&lt;li&gt;&#25918;&#12388;&#12288;&#12288;&#12399;&#12394;&#12388;&#12288;&#12288;let loose, let fly, release&lt;/li&gt;
&lt;li&gt;&#20625;&#20316;&#12288;&#12288;&#12369;&#12387;&#12373;&#12367;&#12288;masterpiece&lt;/li&gt;
&lt;li&gt;&#20870;&#28288;&#12288;&#12288;&#12360;&#12435;&#12414;&#12435;&#12288;satisfactory&lt;/li&gt;
&lt;li&gt;&#31192;&#35363;&#12288;&#12288;&#12402;&#12369;&#12388;&#12288;&#12288;secret&lt;/li&gt;
&lt;li&gt;&#36942;&#37239;&#12288;&#12288;&#12363;&#12371;&#12367;&#12288;&#12288;stern&lt;/li&gt;
&lt;li&gt;&#37204;&#12387;&#12401;&#12288;&#12424;&#12387;&#12401;&#12288;&#12288;drunk (compare &#28450;&#23383;)&lt;/li&gt;
&lt;li&gt;&#33883;&#34276;&#12288;&#12288;&#12363;&#12387;&#12392;&#12358;&#12288;conflict&lt;/li&gt;
&lt;li&gt;&#30636;&#26178;&#12288;&#12288;&#12375;&#12421;&#12435;&#12376;&#12288;instant&lt;/li&gt;
&lt;li&gt;&#22766;&#40599;&#12288;&#12288;&#12381;&#12358;&#12428;&#12356;&#12288;magnificent&lt;/li&gt;
&lt;li&gt;&#24341;&#29992;&#12288;&#12288;&#12356;&#12435;&#12424;&#12358;&#12288;quotation&lt;/li&gt;
&lt;li&gt;&#12358;&#12394;&#12366;&#12398;&#12412;&#12426;&#12288;&#12288;&#12288;rapid promotion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Weird Japanese English&lt;/h2&gt;

&lt;p&gt;&#12499;&#12483;&#12464;&#12539;&#12479;&#12452;&#12450;&#12483;&#12503;&#12539;&#12471;&#12531;&#12464;&#12523;&#12288;Same as the English, the main single (song) that&#8217;s associated with the movie.&lt;/p&gt;

&lt;p&gt;&#12461;&#12515;&#12483;&#12481;&#12539;&#12467;&#12500;&#12540;&#12288;Taking something and using it.  The example was using a line from the title song as the main catchphrase of a movie.&lt;/p&gt;</description>
      <pubDate>Sun, 07 Oct 2007 02:43:00 -0700</pubDate>
      <link>http://benhumphreys.co.uk/blogs/8</link>
      <guid>http://benhumphreys.co.uk/blogs/8</guid>
    </item>
    <item>
      <title>attr_protected and Foreign Keys</title>
      <description>&lt;p&gt;Say you have a site that allows users to create favourites, and a favourite is composed of a url and a user_id.
How is it best to stop users trying to add favourites to other people's accounts?  I know this seems like an unlikely scenario but I think it's a point that highlights other security issues.&lt;/p&gt;

&lt;p&gt;One approach I thought about was using attr&lt;em&gt;protected :user&lt;/em&gt;id, which I think would do the job, but am I missing something about the way Rails works?&lt;/p&gt;

&lt;p&gt;As always, I'd appreciate any thoughts.&lt;/p&gt;</description>
      <pubDate>Sun, 16 Sep 2007 05:09:00 -0700</pubDate>
      <link>http://benhumphreys.co.uk/blogs/6</link>
      <guid>http://benhumphreys.co.uk/blogs/6</guid>
    </item>
    <item>
      <title>Learn from Existing Code: Typo</title>
      <description>&lt;p&gt;I find it really useful to learn from example code and look through existing applications to see how they tick.  I came across &lt;a href="http://typosphere.org/"&gt;Typo&lt;/a&gt; a while ago, but didn't really think much of it as I planned to write my own blog for practice.  It occurred to me the other day that as Ruby is an interpreted language, I could look at the source code of free apps like Typo.&lt;/p&gt;

&lt;p&gt;Typo is a large application and so it's a bit hard to get your head round at first, but if you're looking for a big example, try &lt;a href="http://typosphere.org/pages/download"&gt;downloading Typo&lt;/a&gt;, and then using it to write your own ;)&lt;/p&gt;</description>
      <pubDate>Thu, 06 Sep 2007 03:29:00 -0700</pubDate>
      <link>http://benhumphreys.co.uk/blogs/3</link>
      <guid>http://benhumphreys.co.uk/blogs/3</guid>
    </item>
    <item>
      <title>Caching in Rails</title>
      <description>&lt;p&gt;Caching in Rails is kind of like C++, if you know what you're doing it's possible to make a small elegant solution, but if you get it wrong then god help you when you try to work out what's going on.&lt;/p&gt;

&lt;p&gt;There are plenty of &lt;a href="http://scottstuff.net/presentations/rails-caching/"&gt;tutorials&lt;/a&gt; online and sections in books that go into the basics of caching and some of the finer points, but here are some particular problems I encountered.&lt;/p&gt;

&lt;h1&gt;Moving Parameters from Session&lt;/h1&gt;

&lt;p&gt;Most tutorials hammer in that Rails caching only works based on the URL, so session variables and parameters are completely forgotten.  The original version of my site stored the user's preferred language in the session and retrieved the language data based on that.&lt;/p&gt;

&lt;p&gt;By changing the language to be specified by the URL (e.g. 
benhumphreys.co.uk/en/...) instead of the session, I solved the caching problem.  Then it was just a matter of updating the &lt;/p&gt;

&lt;p&gt;&lt;code:ruby&gt;&lt;/p&gt;

&lt;h1&gt;routes.rb&lt;/h1&gt;

&lt;p&gt;map.home ':language/', :controller =&gt; 'entries', :requirements =&gt; { :language =&gt; /(en|ja)/}&lt;/p&gt;

&lt;p&gt;map.en 'en', :controller =&gt; 'entries', :language =&gt; 'en'
map.ja 'ja', :controller =&gt; 'entries', :language =&gt; 'ja'&lt;/p&gt;

&lt;p&gt;map.connect ':language/:controller/:action/:id', :requirements =&gt; { :language =&gt; /(en|ja)/ }
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the same way as when you specify a link_to with only the action Rails assumes you're in the same controller/path, Rails assumes you're in the same language/path if you don't specify the language.  So link_tos automatically point to the controller in the right language.&lt;/p&gt;

&lt;h1&gt;Get Your Paths Right&lt;/h1&gt;

&lt;p&gt;If like me you have your admin section in a subdirectory double-check that the path in your expire_page commands have a preceding backslash or you'll be trying to expire stuff in the same admin directory (thanks to rsl in #rubyonrails for helping me decypher this).&lt;/p&gt;

&lt;p&gt;Also, as far as I know you have to specify every part of the route.  When using link_to, Rails can use the current location to work out unspecified parts of the route.  However as sweepers can be called from any location, you must specify &lt;strong&gt;all&lt;/strong&gt; parts of the route (lines 21 &amp;amp; 24).
&lt;code:ruby&gt;
class EntrySweeper &amp;lt; ActionController::Caching::Sweeper &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;observe Entry

# QUESTION: Does anyone know how to roll these 3 into one method?
def after_create(entry)
    expire(entry)
end 

def after_update(entry)
    expire(entry)
end

def after_destroy(entry)
    expire(entry)
end

private
def expire(entry)
    # expire single page
    expire_page(:controller =&amp;gt; '/entries', :action =&amp;gt; 'view', :language =&amp;gt; entry.language, :type =&amp;gt; entry.type, :slug =&amp;gt; entry.slug)

    # expire list page for type
    expire_page(:controller =&amp;gt; '/entries', :action =&amp;gt; 'list', :language =&amp;gt; language, :type =&amp;gt; entry.type)

    # expire general list
    expire_page(:language =&amp;gt; language, :controller =&amp;gt; '/entries', :action =&amp;gt; 'list')

    # expire rss feed
    expire_page(:language =&amp;gt; language, :controller =&amp;gt; '/entries', :action =&amp;gt; 'rss')
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;end
&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;Use the Logs!&lt;/h1&gt;

&lt;p&gt;If you ever don't know what's going on in your Rails app, be sure to check the logs.  The same applies for when you're implementing caching.  Make sure you turn on caching in config/environment/development.rb, and use the logs to work out what pages are being expired and whether the paths are correct.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
Expired page: /en/articles/caching-in-rails.html (0.00367)
Expired page: /en/entries/list.html (0.00037)
Expired page: /en/rss.xml (0.00046)
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I'm not sure how this compares with other people's experience, but developing on a iBook the time taken to expire existing pages (the first entry) and the time taken to expire non-existant pages (usually indicative of a bug) are noticably different and can help you debug.  Not rocket science but I thought I'd point it out.&lt;/p&gt;

&lt;h1&gt;General Tips&lt;/h1&gt;

&lt;p&gt;Here are some general points to remember when implementing caching, some of them seem obvious but they might save you some time trying to solve unusual bugs:&lt;/p&gt;

&lt;h3&gt;render vs redirect_to&lt;/h3&gt;

&lt;p&gt;Cache files are created from the URL, irrespective of how the URL was reached.  Remember that the following code will stay at the original URL.
&lt;code:ruby&gt;
list
render :action =&gt; 'list'
&lt;/code&gt;
Whereas the following changes the URL.
&lt;code:ruby&gt;redirect_to :action =&gt; 'list'&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;Multiple Paths to Enlightenment&lt;/h3&gt;

&lt;p&gt;If you have many ways of reaching the same content, e.g view/id and permalink, you need to be especially careful.&lt;/p&gt;

&lt;h1&gt;Final Word&lt;/h1&gt;

&lt;p&gt;I'm still a long way from knowing how to do caching on a large scale and I've yet to do detailed fragment caching, so I'd appreciate any corrections anyone has on the points I've made.&lt;/p&gt;</description>
      <pubDate>Wed, 05 Sep 2007 18:43:00 -0700</pubDate>
      <link>http://benhumphreys.co.uk/articles/4</link>
      <guid>http://benhumphreys.co.uk/articles/4</guid>
    </item>
  </channel>
</rss>
