<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>Samuel Cochran</title><generator>Tumblr (3.0; @sj26)</generator><link>http://blog.sj26.com/</link><item><title>Predictable Random Elements from ActiveRecord</title><description>&lt;p&gt;Say you want to get some random examples to display, but you want those examples to be the same for each user. Ruby doesn&amp;#8217;t really make it easy to seed a random number generator, so instead we can use a hash digest:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Digest::MD5.hexdigest("bob@example.com")
=&amp;gt; "4b9bb80620f03eb3719e0a061c14283d"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This gives a predictably unique(ish) result for each unique input, so each user&amp;#8217;s email or username should be sufficient. The hex representation isn&amp;#8217;t all that useful though. If we can generate full bytes then we can chop off some bytes as unsigned numbers&amp;#8230;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Digest::MD5.digest("bob@example.com")
=&amp;gt; "K\x9B\xB8\x06 \xF0&amp;gt;\xB3q\x9E\n\x06\x1C\x14(="
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Cool! Let&amp;#8217;s run the unpack method over this bad boy:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Digest::MD5.digest("bob@example.com").unpack "C*"
=&amp;gt; [75, 155, 184, 6, 32, 240, 62, 179, 113, 158, 10, 6, 28, 20, 40, 61]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We get some few 8-bit unsigned integers. If 255 isn&amp;#8217;t big enough for you, you can grab 16, 32 or even 64-bit unsigned integers instead, but we&amp;#8217;ll get fewer:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Digest::MD5.digest("bob@example.com").unpack "Q*"
=&amp;gt; [12916024801687542603, 4406794345975029361]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we have some numbers we can seed a new random number generator:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;random = Random.new Digest::MD5.digest("bob@example.com").unpack("Q").first
=&amp;gt; #&amp;lt;Random:0x007fed619e5060&amp;gt;
random.rand
=&amp;gt; 0.1594236871887449
random.rand
=&amp;gt; 0.03664397704408895
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will always produce the same sequence of random numbers.&lt;/p&gt;

&lt;p&gt;If you want to instead just shuffle an array of items, try:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;random = Random.new Digest::MD5.digest("bob@example.com").unpack("Q").first
=&amp;gt; #&amp;lt;Random:0x007fed619e5060&amp;gt;
["one", "two", "three"].sort_by { random.rand }
=&amp;gt; ["two", "one", "three"]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are probably different and better ways to do this, but this way works for me!&lt;/p&gt;</description><link>http://blog.sj26.com/post/12268579119</link><guid>http://blog.sj26.com/post/12268579119</guid><pubDate>Thu, 03 Nov 2011 10:14:25 +0800</pubDate></item><item><title>Ruby 1.9.3 p0 ruby-debug with RVM (easy version)</title><description>&lt;p&gt;If you just want to use 1.9.3 p0 with ruby-debug on RVM, here&amp;#8217;s one I prepared earlier (thanks to &lt;a href="http://twitter.com/ed_ruder"&gt;@ed_ruder&lt;/a&gt;):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ curl &lt;a href="https://github.com/sj26/ruby-1.9.3-p0/compare/ruby_1_9_3_0...master.diff"&gt;https://github.com/sj26/ruby-1.9.3-p0/compare/ruby_1_9_3_0...master.diff&lt;/a&gt; &amp;gt; /tmp/ruby-1.9.3-visibility.diff
$ rvm install 1.9.3-p0 --patch /tmp/ruby-1.9.3-visibility.diff
$ rvm use 1.9.3-p0
$ gem install ruby-debug19
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The full explanation is in &lt;a href="http://blog.sj26.com/post/12146951658/updated-using-ruby-debug-on-ruby-1-9-3-p0"&gt;my previous post&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.sj26.com/post/12158422699</link><guid>http://blog.sj26.com/post/12158422699</guid><pubDate>Mon, 31 Oct 2011 20:37:00 +0800</pubDate></item><item><title>Updated: Using ruby-debug on Ruby 1.9.3 p0</title><description>&lt;p&gt;This is an updated re-post of &lt;a href="http://blog.sj26.com/post/10263431961/using-ruby-debug-on-ruby-1-9-3-preview1"&gt;Using ruby-debug on Ruby 1.9.3 preview1&lt;/a&gt; updated for Ruby 1.9.3 p0 (release, patch level 0).&lt;/p&gt;

&lt;p&gt;Ruby 1.9.3 has a slightly broken build process. In the final step of compilation it hides a number of symbols while linking the ruby binary. This means &lt;a href="http://rubyforge.org/projects/ruby-debug/"&gt;ruby-debug&lt;/a&gt;&amp;#8217;s extension can&amp;#8217;t get all the information it needs to make the debugger work and it breaks.&lt;/p&gt;

&lt;p&gt;To fix, first grab some coffee, &lt;a href="http://tenderlovemaking.com/2009/10/17/full-text-search-on-heroku/"&gt;tenderlove-style&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You need to recompile after removing &lt;a href="https://github.com/ruby/ruby/blob/ruby_1_9_3/configure.in#L496"&gt;a line&lt;/a&gt; from &lt;code&gt;configure.in&lt;/code&gt;. Make sure you&amp;#8217;ve got a copy of the &lt;a href="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.bz2"&gt;ruby 1.9.3 source&lt;/a&gt; then apply &lt;a href="https://github.com/ruby/ruby/pull/56"&gt;this patch&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ git apply &amp;lt;( curl &lt;a href="https://github.com/ruby/ruby/pull/56.diff"&gt;https://github.com/ruby/ruby/pull/56.diff&lt;/a&gt; )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Recompile, making sure you run autoconf (I don&amp;#8217;t think RVM does by default):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ autoconf -f &amp;amp;&amp;amp; ./configure --prefix="$HOME/.rbenv/versions/1.9.3-p0" &amp;amp;&amp;amp; make -j3
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Double check it&amp;#8217;s worked by checking the &lt;code&gt;_ruby_current_thread&lt;/code&gt; symbol is visible (or you can just trust me):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ nm ruby | grep current_thread
00000001002249d0 D _ruby_current_thread
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then install as normal (&lt;code&gt;make install&lt;/code&gt;), set up rubygems, &lt;code&gt;gem install ruby-debug19&lt;/code&gt; and try it out:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; $ ruby -v -r rubygems -r ruby-debug -e 'Debugger.start and puts Debugger.current_context'
ruby 1.9.3p0 (2011-10-30 revision 33569) [x86_64-darwin11.2.0]
#&amp;lt;Debugger::Context:0x007fea0b8957e0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hooray! The future is now; you can get back to debugging your Rails 3.1 apps with ruby-debug on Ruby 1.9.3.&lt;/p&gt;

&lt;p&gt;This probably isn&amp;#8217;t the canonical solution&amp;#8212;I&amp;#8217;m no autotools or C expert&amp;#8212;but it works for now. I&amp;#8217;m sure they&amp;#8217;ll fix it properly for the next release.&lt;/p&gt;</description><link>http://blog.sj26.com/post/12146951658</link><guid>http://blog.sj26.com/post/12146951658</guid><pubDate>Mon, 31 Oct 2011 11:00:00 +0800</pubDate></item><item><title>Declarative cucumber scenario's</title><description>&lt;a href="http://www.mariovisic.com/post/12029944261/declarative-cucumber-scenarios"&gt;Declarative cucumber scenario's&lt;/a&gt;: &lt;p&gt;&lt;a href="http://www.mariovisic.com/post/12029944261/declarative-cucumber-scenarios" class="tumblr_blog"&gt;mariovisic&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;I did a tech talk at work about how we were using cucumber and how we should be using it instead. It goes over using declarative cucumber scenarios instead of imperative.&lt;/p&gt;

&lt;p&gt;Slides are here: &lt;a href="http://mariovisic.github.com/Cucumber-Examples/"&gt;mariovisic.github.com/Cucumber-  Examples/&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;</description><link>http://blog.sj26.com/post/12146981611</link><guid>http://blog.sj26.com/post/12146981611</guid><pubDate>Mon, 31 Oct 2011 10:57:30 +0800</pubDate></item><item><title>Microwave Self-Saucing Chocolate Pudding in a Cup</title><description>&lt;p&gt;After sampling various microwave desserts in a cup, I was craving my favourite—self-saucing chocolate pudding. The Internet failed to provide a microwave cup recipe so I adapted a larger one. On my third attempt I discovered the perfect recipe:&lt;/p&gt;

&lt;p&gt;In a cup or ramequin combine&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;1.5 tbsp sr flour&lt;/li&gt;
&lt;li&gt;1.5 tbsp sugar&lt;/li&gt;
&lt;li&gt;1.5 tbsp cocoa&lt;/li&gt;
&lt;li&gt;1.5 tbsp milk&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;and spoon mix until smooth.&lt;/p&gt;

&lt;p&gt;Sprinkle&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;1/2 tbsp cocoa&lt;/li&gt;
&lt;li&gt;1 tbsp brown sugar&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;on top, then carefully pour on&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;1 tbsp hot water.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;Put it on a saucer—it might overflow—and microwave for 30s. Time may vary based on the power of your microwave, try 1m on medium if this doesn&amp;#8217;t work for you. You want it to look cakey on top but still be liquid underneath.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;</description><link>http://blog.sj26.com/post/11907529159</link><guid>http://blog.sj26.com/post/11907529159</guid><pubDate>Tue, 25 Oct 2011 22:11:00 +0800</pubDate></item><item><title>Using ruby-debug on Ruby 1.9.3 preview1</title><description>&lt;p&gt;UPDATE: confirmed still problematic on &lt;a href="http://www.ruby-lang.org/en/news/2011/09/24/ruby-1-9-3-rc1-has-been-released/"&gt;ruby 1.9.3 rc1&lt;/a&gt;. This fix still works. (&lt;a href="https://twitter.com/janminarik/status/121956486497832962"&gt;Thanks @janminarik!&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.ruby-lang.org/en/news/2011/08/01/ruby-1-9-3-preview1-has-been-released/"&gt;Ruby 1.9.3 preview1&lt;/a&gt; has a slightly broken build process. In the final step of compilation it hides a number of symbols while linking the ruby binary. This means &lt;a href="http://rubyforge.org/projects/ruby-debug/"&gt;ruby-debug&lt;/a&gt;&amp;#8217;s extension can&amp;#8217;t get all the information it needs to make the debugger work and it breaks.&lt;/p&gt;

&lt;p&gt;To fix, first grab some coffee, &lt;a href="http://tenderlovemaking.com/2009/10/17/full-text-search-on-heroku/"&gt;tenderlove-style&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You need to recompile after removing &lt;a href="https://github.com/ruby/ruby/blob/v1_9_3_preview1/configure.in#L496"&gt;a line&lt;/a&gt; from &lt;code&gt;configure.in&lt;/code&gt;. Make sure you&amp;#8217;ve got a copy of the &lt;a href="http://www.ruby-lang.org/en/news/2011/08/01/ruby-1-9-3-preview1-has-been-released/"&gt;ruby 1.9.3 preview1 source&lt;/a&gt; then apply &lt;a href="https://github.com/ruby/ruby/pull/47"&gt;this patch&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ git apply &amp;lt;( curl &lt;a href="https://github.com/ruby/ruby/pull/47.diff"&gt;https://github.com/ruby/ruby/pull/47.diff&lt;/a&gt; )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Recompile:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ autoconf &amp;amp;&amp;amp; ./configure --prefix="$HOME/.rbenv/versions/1.9.3-preview1" &amp;amp;&amp;amp; make -j3
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Double check it&amp;#8217;s worked by checking the &lt;code&gt;_ruby_current_thread&lt;/code&gt; symbol is visible (or you can just trust me):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ nm ruby | grep current_thread
00000001002249d0 D _ruby_current_thread
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then install as normal (&lt;code&gt;make install&lt;/code&gt;), set up rubygems, &lt;code&gt;gem install ruby-debug19&lt;/code&gt; and try it out:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; $ ruby -v -r rubygems -r ruby-debug -e 'Debugger.start and puts Debugger.current_context'
ruby 1.9.3dev (2011-07-31 revision 32780) [x86_64-darwin11.0.1]
#&amp;lt;Debugger::Context:0x007ff1e2450fe8&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hooray! The future is now; you can get back to debugging your Rails 3.1 apps with ruby-debug on Ruby 1.9.3.&lt;/p&gt;

&lt;p&gt;This probably isn&amp;#8217;t the canonical solution&amp;#8212;I&amp;#8217;m no autotools or C expert&amp;#8212;but it works for now. I&amp;#8217;m sure they&amp;#8217;ll fix it properly for the next release.&lt;/p&gt;</description><link>http://blog.sj26.com/post/10263431961</link><guid>http://blog.sj26.com/post/10263431961</guid><pubDate>Fri, 16 Sep 2011 10:08:00 +0800</pubDate></item><item><title>Parse a natural duration into seconds in JavaScript</title><description>&lt;p&gt;I wrote this for a little Chrome extension I maintain and thought it might be useful to someone else. It parses a natural language duration like &amp;#8220;1h30m&amp;#8221; or &amp;#8220;37 days, 1 hr, 3 mins and 7s&amp;#8221; into a straight number of seconds.&lt;/p&gt;
&lt;script src="https://gist.github.com/930528.js"&gt; &lt;/script&gt;</description><link>http://blog.sj26.com/post/4771025197</link><guid>http://blog.sj26.com/post/4771025197</guid><pubDate>Wed, 20 Apr 2011 14:53:31 +0800</pubDate></item><item><title>How to install Pow from source on OS X</title><description>&lt;p&gt;A couple of people have asked me, so:&lt;/p&gt;



&lt;ol&gt;&lt;li&gt;Install &lt;a href="http://developer.apple.com/tools/xcode/"&gt;Xcode&lt;/a&gt; if you haven&amp;#8217;t already.&lt;/li&gt;&#13;
&lt;li&gt;Install &lt;a title="Homebrew" href="https://github.com/mxcl/homebrew"&gt;Homebrew&lt;/a&gt; and be one of the cool kids:&#13;
&lt;blockquote&gt;&lt;code&gt;curl &lt;a href="https://gist.github.com/raw/323731/install_homebrew.rb"&gt;https://gist.github.com/raw/323731/install_homebrew.rb&lt;/a&gt; | bash&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;/li&gt;&#13;
&lt;li&gt;Install &lt;a href="http://nodejs.org/"&gt;Node.js&lt;/a&gt;:&#13;
&lt;blockquote&gt;&lt;code&gt;brew install node&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;/li&gt;&#13;
&lt;li&gt;Install &lt;a href="http://npmjs.org/"&gt;npm&lt;/a&gt;:&#13;
&lt;blockquote&gt;&lt;code&gt;curl &lt;a href="http://npmjs.org/install.sh"&gt;http://npmjs.org/install.sh&lt;/a&gt; | sh&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;/li&gt;&#13;
&lt;li&gt;Clone &lt;a href="https://github.com/37signals/pow"&gt;pow&lt;/a&gt; git repository somewhere safe (I use &lt;code&gt;~/Development&lt;/code&gt;):&#13;
&lt;blockquote&gt;&lt;code&gt;git clone &lt;a href="https://github.com/37signals/pow.git"&gt;https://github.com/37signals/pow.git&lt;/a&gt;&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;/li&gt;&#13;
&lt;li&gt;Inside your new pow checkout, install the development dependencies. Run:&#13;
&lt;blockquote&gt;&lt;code&gt;npm install --dev&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;/li&gt;&#13;
&lt;li&gt;If you haven&amp;#8217;t installed Pow before, setup the &lt;code&gt;~/.pow&lt;/code&gt; directory:&#13;
&lt;blockquote&gt;&lt;code&gt;mkdir -p ~/Library/Application\ Support/Pow/Hosts &amp;amp;&amp;amp; ln -s ~/Library/Application\ Support/Pow/Hosts ~/.pow&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;p&gt;and the firewall forwarding and resolvers:&lt;/p&gt;&#13;
&lt;blockquote&gt;&lt;code&gt;sudo ./bin/pow --install-system&lt;br/&gt; sudo launchctl load /Library/LaunchDaemons/cx.pow.firewall.plist&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;/li&gt;&#13;
&lt;li&gt;Finally, run pow (send an interrupt to quit):&#13;
&lt;blockquote&gt;&lt;code&gt;./bin/pow&lt;/code&gt;&lt;/blockquote&gt;&#13;
&lt;/li&gt;&#13;
&lt;/ol&gt;&lt;p&gt;You&amp;#8217;ve a couple of other options. Get a list of cake tasks with &lt;code&gt;./node_modules/coffee-script/bin/cake&lt;/code&gt; then run tasks with &lt;code&gt;./node_modules/coffee-script/bin/cake &amp;lt;task&amp;gt;&lt;/code&gt; (or install cake globally &amp;#8212; it&amp;#8217;s similar to &lt;a href="http://www.gnu.org/software/make/"&gt;make&lt;/a&gt; or &lt;a href="http://rake.rubyforge.org/"&gt;rake&lt;/a&gt; but for coffee script). You can also check out the &lt;a href="https://github.com/37signals/pow/tree/master/Cakefile"&gt;Cakefile&lt;/a&gt;. A good one is &lt;code&gt;cake watch&lt;/code&gt; which will stay running and watch your coffee files for changes, recompiling them into javascript as neccessary.&lt;/p&gt;



&lt;p&gt;If you don&amp;#8217;t already have pow installed, you&amp;#8217;ll need to create the firewall rule to forward all port 80 traffic to pow and add the DNS resolver for the dev TLD. To do this, run &lt;code&gt;cake install&lt;/code&gt; as above.&lt;/p&gt;



&lt;p&gt;Have fun!&lt;/p&gt;</description><link>http://blog.sj26.com/post/4605394037</link><guid>http://blog.sj26.com/post/4605394037</guid><pubDate>Thu, 14 Apr 2011 20:15:00 +0800</pubDate></item><item><title>Pow via Bonjour</title><description>&lt;p&gt;I fell in love with &lt;a href="https://github.com/37signals/pow"&gt;Pow&lt;/a&gt; the moment it was released. Easily deployed multi-app multi-ruby rvm-aware rack development? &amp;lt;3!&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve modified Pow so it publishes via &lt;a title="Multicast DNS" href="http://www.multicastdns.org/"&gt;mDNS&lt;/a&gt;, also known as &lt;a href="http://developer.apple.com/opensource/"&gt;Bonjour&lt;/a&gt;. This means you can send someone across the office a link to your current development copy of an app to break for you.&lt;/p&gt;
&lt;p&gt;Anything that works at &lt;code&gt;&lt;a href="http://myapp.dev"&gt;http://myapp.dev&lt;/a&gt;&lt;/code&gt; will also work at &lt;code&gt;&lt;a href="http://myapp.mycomputer.local"&gt;http://myapp.mycomputer.local&lt;/a&gt;&lt;/code&gt; within the local network. If you don&amp;#8217;t know what your computer name is, look in the &lt;a href="http://support.apple.com/kb/HT3056"&gt;Mac OS X Sharing preference pane&lt;/a&gt;. It handily tells you the name that other computers can access your computer via.&lt;/p&gt;
&lt;p&gt;There are a few caveats, and there&amp;#8217;s still quite a bit to do&amp;#8230; it doesn&amp;#8217;t notice changed hostnames, doesn&amp;#8217;t say goodbye when leaving (host entries may linger for other users), it doesn&amp;#8217;t publish _http._tcp services for browsability (but who uses this anyway), and it only publishes the default route over all interfaces so if your network topology is the least bit interesting it might break.&lt;/p&gt;
&lt;p&gt;The code&amp;#8217;s on GitHub:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/sj26/pow"&gt;&lt;a href="https://github.com/sj26/pow"&gt;https://github.com/sj26/pow&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#8217;t want to publish a release contrary to 37signals&amp;#8217;, so it&amp;#8217;s from-source installation only. There&amp;#8217;s &lt;a href="https://github.com/37signals/pow/issues/80"&gt;a discussion about the feature&lt;/a&gt; and a &lt;a href="https://github.com/37signals/pow/pull/95"&gt;pull request&lt;/a&gt;, so I hope it might get into master. I hear from-source instructions are coming. Until then, see &lt;a href="https://github.com/37signals/pow/issues/31"&gt;this discussion&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.sj26.com/post/4549392715</link><guid>http://blog.sj26.com/post/4549392715</guid><pubDate>Tue, 12 Apr 2011 17:14:00 +0800</pubDate></item><item><title>Nice nested layouts</title><description>&lt;a href="https://gist.github.com/911446"&gt;Nice nested layouts&lt;/a&gt;: &lt;p&gt;I really wanted a nicer way of doing nested layouts using &lt;a title="#haml" href="http://haml-lang.com/"&gt;HAML&lt;/a&gt; in &lt;a title="Ruby on Rails" href="http://rubyonrails.org/"&gt;Rails&lt;/a&gt;. The &lt;a title="Ruby on Rails Guides: Layouts and Rendering in Rails" href="http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts"&gt;rails example&lt;/a&gt; including &lt;code&gt;yield(:content) || yield&lt;/code&gt; makes me want to heave. Okay, so they use &lt;code&gt;content_for?&lt;/code&gt; now, but it’s still horrid, and what happens when you’re more than one or two levels deep?&lt;/p&gt;
&lt;p&gt;Ideally, layouts should be able to dictate they inherit from something else. Partially inspired by the &lt;a title="Nested Layouts Plugin for Rails 2" href="http://nested-layouts.rubyforge.org/"&gt;NestedLayouts plugin for Rails 2&lt;/a&gt;, the best way to do this I could come up is to use a capture block in my layout. This means I can use:&lt;/p&gt;
&lt;script src="https://gist.github.com/911446.js?file=app%2fviews%2flayouts%2fadmin.html.haml"&gt;&lt;/script&gt;&lt;p&gt;Inside my application layout:&lt;/p&gt;
&lt;script src="https://gist.github.com/911446.js?file=app%2fviews%2flayouts%2fapplication.html.haml"&gt;&lt;/script&gt;&lt;p&gt;and now use &lt;code&gt;layout :admin&lt;/code&gt; in my admin controllers:&lt;/p&gt;
&lt;script src="https://gist.github.com/911446.js?file=app%2fcontrollers%2fadmin_controller.rb"&gt;&lt;/script&gt;&lt;p&gt;and it will nest nicely as expected.&lt;/p&gt;
&lt;p&gt;The helper itself looks like:&lt;/p&gt;
&lt;script src="https://gist.github.com/911446.js?file=app%2fhelpers%2fnested_layouts_helper.rb"&gt;&lt;/script&gt;&lt;p&gt;and these extracts are all part of &lt;a href="https://gist.github.com/911446"&gt;this gist&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I hope you find it useful too. Have fun!&lt;/p&gt;</description><link>http://blog.sj26.com/post/4517457786</link><guid>http://blog.sj26.com/post/4517457786</guid><pubDate>Mon, 11 Apr 2011 14:29:00 +0800</pubDate><category>programming</category><category>ruby</category><category>rails</category></item><item><title>Drupal OpenID Provider Profile module</title><description>&lt;a href="http://github.com/sj26/openid_provider_profile"&gt;Drupal OpenID Provider Profile module&lt;/a&gt;: &lt;p&gt;I’ve published a module for Drupal which lets you use profile fields in attribute exchange when using the OpenID Provider module on a Drupal site. This means that users who login to another site, possibly another Drupal site, can login using their OpenID from your site and the other site can request their login name, email, language, timezone and any other fields you care to exchange, such as first name, last name, gender, etc.&lt;/p&gt;</description><link>http://blog.sj26.com/post/4386283967</link><guid>http://blog.sj26.com/post/4386283967</guid><pubDate>Thu, 29 Jul 2010 10:41:00 +0800</pubDate></item><item><title>trappedonearth:

The Doctor Who Themes (Every Doctor Who Theme...</title><description>&lt;iframe width="400" height="245" src="http://www.youtube.com/embed/6J_3rsEwYVE?wmode=transparent&amp;autohide=1&amp;egm=0&amp;hd=1&amp;iv_load_policy=3&amp;modestbranding=1&amp;rel=0&amp;showinfo=0&amp;showsearch=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;a href="http://trappedonearth.tumblr.com/post/848371271"&gt;trappedonearth&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://www.youtube.com/watch?v=6J_3rsEwYVE&amp;feature=autoshare"&gt;The Doctor Who Themes (Every Doctor Who Theme 1963-2010)&lt;/a&gt; (via &lt;a href="http://youtube.com/user/BrianRimmer"&gt;BrianRimmer&lt;/a&gt;) #DoctorWho&lt;/p&gt;
&lt;p&gt;Includes the unused electronic ‘Delaware’ theme from the Jon Pertwee era.&lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://blog.sj26.com/post/848550810</link><guid>http://blog.sj26.com/post/848550810</guid><pubDate>Fri, 23 Jul 2010 14:38:17 +0800</pubDate></item><item><title>(via yimmyayo)</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_l5fi18qMZA1qz7lxdo1_500.png"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;(via &lt;a href="http://blog.yimmyayo.com/"&gt;yimmyayo&lt;/a&gt;)&lt;/p&gt;</description><link>http://blog.sj26.com/post/804583899</link><guid>http://blog.sj26.com/post/804583899</guid><pubDate>Tue, 13 Jul 2010 10:38:02 +0800</pubDate></item><item><title>DynDNS Updates</title><description>&lt;p&gt;I use &lt;a href="http://freedns.afraid.org/"&gt;Afraid FreeDNS&lt;/a&gt; to host my DNS and perform DynDNS for my home machine. Today I decided it would be neat to also DynDNS my laptop. Afraid uses a simple update mechanism: perform and HTTP request using a unique token and your DynDNS is updated to the request IP.&lt;!-- more --&gt; At home, in my crontab, I have:&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;curl -s http­://freedns.afraid.org/dynamic/update.php?&lt;em&gt;TOKEN&lt;/em&gt; | logger -p user.info -t dyndns&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;This isn&amp;#8217;t great, so today I updated it. For my MacBook Pro I&amp;#8217;m using the in-built net command to do a host lookup to check if networking is up and whether my IP has changed, or we just shouldn&amp;#8217;t bother. It looks something like:&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;current="$(net lookup &lt;em&gt;DOMAIN&lt;/em&gt;)" &amp;amp;&amp;amp; actual="$(curl -s http­://whatismyip.org)" &amp;amp;&amp;amp; ( if [ "$current" != "$actual" ]; then curl -s http­://freedns.afraid.org/dynamic/update.php?&lt;em&gt;TOKEN&lt;/em&gt; | logger -p user.info -t dyndns; fi )&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;At home, however, is a Linux box. Substitute a terse dig for net and we&amp;#8217;re set:&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;current="$(dig +short &lt;em&gt;DOMAIN&lt;/em&gt;)" &amp;amp;&amp;amp; actual="$(curl -s http­://whatismyip.org)" &amp;amp;&amp;amp; ( if [ "$current" != "$actual" ]; then curl -s http­://freedns.afraid.org/dynamic/update.php?&lt;em&gt;TOKEN&lt;/em&gt; | logger -p user.info -t dyndns; fi )&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;Much better!&lt;/p&gt;</description><link>http://blog.sj26.com/post/617966144</link><guid>http://blog.sj26.com/post/617966144</guid><pubDate>Fri, 21 May 2010 10:55:00 +0800</pubDate></item><item><title>Lipsum Generator</title><description>&lt;a href="http://gist.github.com/332507"&gt;Lipsum Generator&lt;/a&gt;: &lt;p&gt;I wrote a “Lorem ipsum…” generator for Python. Dissatisfied with what was available, I took the original corpus (&lt;a href="http://la.wikisource.org/wiki/De_finibus_bonorum_et_malorum/Liber_Primus"&gt;De finibus bonorum et malorum/Liber Primus&lt;/a&gt;) and made it generate rudimentary sentences using approximate word distribution.&lt;/p&gt;
&lt;p&gt;Maybe this will get better. I don’t know what the official approach is, but I’d like to analyse the complete corpus for semantic relationships and replicate them probabilistically and model clauses and quotes more realistically. Only slightly.&lt;/p&gt;
&lt;p&gt;Oh, it’ll probably do length limiting by characters, words, sentences and paragraphs eventually. &lt;em&gt;Eventually.&lt;/em&gt;&lt;/p&gt;</description><link>http://blog.sj26.com/post/449588642</link><guid>http://blog.sj26.com/post/449588642</guid><pubDate>Mon, 15 Mar 2010 16:24:14 +0800</pubDate></item><item><title>Mono for Mac - CA Certificates</title><description>&lt;p&gt;So &lt;a href="http://www.mono-project.com/"&gt;Mono&lt;/a&gt; for &lt;a title="Mac OS X" href="http://www.apple.com/macosx/"&gt;OS X&lt;/a&gt; doesn&amp;#8217;t include any CA certificates by default. Handily, they provide a tool — &lt;code&gt;mozroots&lt;/code&gt; — to import the &lt;a href="http://www.mozilla.org/projects/security/certs/"&gt;Mozilla CA certificate store&lt;/a&gt; into your mono installation:&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;sudo mozroots --import --machine --ask-remove&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;Why don&amp;#8217;t they do this at install time or, even better, let Mono use OS X&amp;#8217;s &lt;a title="Mac OS X Keychain Services" href="http://developer.apple.com/mac/library/documentation/Security/Reference/keychainservices/"&gt;Keychain&lt;/a&gt;?&lt;/p&gt;</description><link>http://blog.sj26.com/post/433846560</link><guid>http://blog.sj26.com/post/433846560</guid><pubDate>Mon, 08 Mar 2010 11:45:44 +0800</pubDate></item><item><title>Chrome Viewstate Inspector</title><description>&lt;a href="https://chrome.google.com/extensions/detail/lidplipfigoldfaeaglmkkjphmdncama"&gt;Chrome Viewstate Inspector&lt;/a&gt;: &lt;p&gt;Culmination of a couple of hours hacking: A viewstate inspector for Chrome. It will get better!&lt;/p&gt;</description><link>http://blog.sj26.com/post/411149363</link><guid>http://blog.sj26.com/post/411149363</guid><pubDate>Thu, 25 Feb 2010 21:43:06 +0800</pubDate></item><item><title>Google Provisioning API 5-day delete restriction hack</title><description>&lt;a href="http://sweetjesus26.livejournal.com/22050.html"&gt;Google Provisioning API 5-day delete restriction hack&lt;/a&gt;</description><link>http://blog.sj26.com/post/194775004</link><guid>http://blog.sj26.com/post/194775004</guid><pubDate>Wed, 23 Sep 2009 14:07:01 +0800</pubDate></item><item><title>OpenLDAP 2.3, Python 2.5 and Python-LDAP on Debian Etch</title><description>&lt;a href="http://sweetjesus26.livejournal.com/21957.html"&gt;OpenLDAP 2.3, Python 2.5 and Python-LDAP on Debian Etch&lt;/a&gt;</description><link>http://blog.sj26.com/post/189292727</link><guid>http://blog.sj26.com/post/189292727</guid><pubDate>Wed, 16 Sep 2009 19:28:49 +0800</pubDate></item><item><title>JavaScript: The World's Most Misunderstood Programming Language</title><description>&lt;a href="http://crockford.com/javascript/javascript.html"&gt;JavaScript: The World's Most Misunderstood Programming Language&lt;/a&gt;</description><link>http://blog.sj26.com/post/185533293</link><guid>http://blog.sj26.com/post/185533293</guid><pubDate>Sat, 12 Sep 2009 04:13:28 +0800</pubDate></item></channel></rss>

