<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mangled &#187; Coding</title>
	<atom:link href="http://mangled.me/blog/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://mangled.me/blog</link>
	<description>The Mangled world of Matthew</description>
	<lastBuildDate>Sun, 06 Nov 2011 22:13:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rhino Mocks with Managed C++</title>
		<link>http://mangled.me/blog/coding/rhino-mocks-with-managed-c/</link>
		<comments>http://mangled.me/blog/coding/rhino-mocks-with-managed-c/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 20:46:00 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=531</guid>
		<description><![CDATA[Having just had the unfortunate need to use rhino mocks from managed C++ I thought I would document the “how” Let’s say you want to mock/stub IFoo. Which has two methods: IQux Bar() int Baz(int) Create a MockRepository: IFoo^ foo_stub = MockRepository::GenerateStub&#60;IFoo^&#62;(); Stub out Bar() -&#62; Note it doesn’t take a parameter: Rhino::Mocks::Function&#60;IFoo^, IQux^&#62;^ foo_bar [...]]]></description>
			<content:encoded><![CDATA[<img width="528" height="250" src="/blog/wp-content/uploads/2011/08/curves.jpg" alt="Rhino Mocks with Managed C++" /><p>Having  just had the unfortunate need to use rhino mocks from managed C++ I  thought I would document the “how”</p>
<p>Let’s say you want to mock/stub IFoo. Which has two methods:</p>
<ul>
<li>IQux Bar()</li>
<li>int Baz(int)</li>
</ul>
<p>Create a MockRepository:</p>
<pre>IFoo^ foo_stub = MockRepository::GenerateStub&lt;IFoo^&gt;();</pre>
<p>Stub out Bar() -&gt; Note it doesn’t take a parameter:</p>
<pre>Rhino::Mocks::Function&lt;IFoo^, IQux^&gt;^ foo_bar =
    gcnew Rhino::Mocks::Function&lt;IFoo^, IQux^&gt;(&amp;IFoo::Bar);

RhinoMocksExtensions::Stub(foo_stub, foo_bar)-&gt;Return(
    /* Another mock/stub or a real IQux */
);</pre>
<p>Stub out Baz() -&gt; Note it takes a parameter:</p>
<p>Note, the static method, this will configure the stub for a specific argument, in this example when Baz(1) is called we return 2.</p>
<pre>Rhino::Mocks::Function&lt;IFoo^, int&gt;^ foo_baz =
    gcnew Rhino::Mocks::Function&lt;IFoo^, int&gt;(&amp;Test::FooStubBaz);

RhinoMocksExtensions::Stub(foo_stub, foo_baz)-&gt;Return(2);

// IFoo will actually be a rhino mock/stub
int Test::FooStubBaz(IFoo^ foo) {
    return foo-&gt;Baz(1);
}</pre>
<p>Now foo_stub-&gt;Baz(1) will return 2</p>
<p>I imagine you could remove the need for a static method but this was enough for my needs and my head!</p>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/rhino-mocks-with-managed-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NeuroSky Mindset gem &#8230; Is nearing completion</title>
		<link>http://mangled.me/blog/coding/neurosky-mindset-gem-is-nearing-completion/</link>
		<comments>http://mangled.me/blog/coding/neurosky-mindset-gem-is-nearing-completion/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 20:13:17 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=523</guid>
		<description><![CDATA[I have recently been playing with the NeuroSky mindset &#8211; I have always found this subject fascinating&#8230; Unfortunately the device didn&#8217;t come with any Linux software so I decided to write some using ruby. Had a good run at coding this weekend and I&#8217;m now finalising the gem &#8211; Hope to have it up on [...]]]></description>
			<content:encoded><![CDATA[<img width="528" height="250" src="/blog/wp-content/uploads/2011/07/mind.jpg" alt="NeuroSky Mindset gem ... Is nearing completion" /><p>I have recently been playing with the <a title="NeuroSky" href="http://store-eu.neurosky.com/" target="_blank">NeuroSky</a> mindset &#8211; I have always found this subject fascinating&#8230;</p>
<p>Unfortunately the device didn&#8217;t come with any Linux software so I decided to write some using ruby. Had a good run at coding this weekend and I&#8217;m now finalising the gem &#8211; Hope to have it up on git hub and ruby forge this week. I can then move onto coding some fun software on top. Doubt it will have a huge demand but at least it will make using the device a little easier on Linux (and Windows), I needed it so at least one person will benefit!</p>
<p><span style="text-decoration: underline;">Update</span>: I have placed an almost finished (just some documentation tidying left) version on <a href="https://github.com/mangled/mindset" target="_blank">GitHub</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/neurosky-mindset-gem-is-nearing-completion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeFoo: Agile Feedback Loops Via The Commit</title>
		<link>http://mangled.me/blog/thoughts/codefoo-agile-feedback-loops-via-the-commit/</link>
		<comments>http://mangled.me/blog/thoughts/codefoo-agile-feedback-loops-via-the-commit/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 19:50:18 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=518</guid>
		<description><![CDATA[I&#8217;ve been thinking about agile/LEAN feedback loops lately, primarily how I could introduce fun ways to kick start them and hopefully keep them maintained. With this in mind my thoughts turned to the &#8220;commit&#8221; process. It&#8217;s something all developers do (hopefully else your coding without revision control) and provides a nice point in time to [...]]]></description>
			<content:encoded><![CDATA[<img width="528" height="250" src="/blog/wp-content/uploads/2011/07/CodeFoo.jpg" alt="CodeFoo: Agile Feedback Loops Via The Commit" /><p>I&#8217;ve been thinking about agile/LEAN feedback loops lately, primarily how I could introduce fun ways to kick start them and hopefully keep them maintained. With this in mind my thoughts turned to the &#8220;commit&#8221; process. It&#8217;s something all developers do (hopefully else your coding without revision control) and provides a nice point in time to inject some automated feedback.</p>
<p>The idea is to have each commit analysed for some simple &#8220;agile&#8221; metrics, nothing too complex or tricky, examples:</p>
<ul>
<li> Did the commit touch unit tests</li>
<li> Was the commit &#8220;small&#8221;</li>
</ul>
<p>I imagine you could also run a few simple code quality algorithms also (ones that are regarded as being sensible) and maybe a copy and paste checker. Overall the main aim is to find around three or four simple metrics that the team can agree on that signify good practice.</p>
<p>Then the fun starts, you normalise the values and plug them into a simple fighting game, where they impact the fighters abilities (and looks?), clearly weighted towards the better the metrics, the better the fighter. This new fighter then battles the current one (winner of the last commit war) to see who remains king of the hill.</p>
<p>The whole fight can be e-mailed back as a small movie, statistics can also be kept &#8211; If you commit small, unit tested code often you have a high chance of ranking highly.</p>
<p>Think I will code this up. Also wondered about wiring the commit to net hack or an adventure game, I.e. your commit log would contain a string for your next move, on commit you are e-mailed a response. E.g.</p>
<pre># open door

&lt;commit&gt;

"You see a wolf"</pre>
<p>Fun, possibly, but not where I was heading.</p>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/thoughts/codefoo-agile-feedback-loops-via-the-commit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Port of TinyMud (WIP!)</title>
		<link>http://mangled.me/blog/coding/ruby-port-of-tinymud-wip/</link>
		<comments>http://mangled.me/blog/coding/ruby-port-of-tinymud-wip/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 22:37:23 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=483</guid>
		<description><![CDATA[It started with a conversation in a pub (don&#8217;t most things?) related to porting &#8220;old&#8221; code to newer languages. With my interest in TinyMud I decided to take on the challenge of porting the original c-code to Ruby. This is now becoming an intense labour of love! I&#8217;m wrapping the old TinyMud code as Ruby [...]]]></description>
			<content:encoded><![CDATA[<img width="528" height="250" src="/blog/wp-content/uploads/2010/12/DSC02294.jpg" alt="Ruby Port of TinyMud (WIP!)" /><p>It started with a conversation in a pub (don&#8217;t most things?) related to porting &#8220;old&#8221; code to newer languages. With my interest in <a href="http://en.wikipedia.org/wiki/TinyMUD">TinyMud</a> I decided to take on the challenge of porting the original c-code to Ruby.</p>
<p>This is now becoming an intense labour of love! I&#8217;m wrapping the old TinyMud code as Ruby extensions and writing as many test cases as I can. I&#8217;m over half way through now. The idea being to get good test coverage of the c-code (in Ruby) then switch to Ruby equivalent code &#8211; Then re-factor to a more Ruby&#8217;esque style.</p>
<p>I have to say I&#8217;m impressed by the original source code (although I&#8217;m finding some edge case defects). I wonder if the Ruby code will be any more compact? Intending to put the result on GitHub at some point &#8211; For now it&#8217;s a one man mission!</p>
<p>Once complete I will run this on a server and prove wikipedia (sort of) wrong, I quote &#8220;No active games currently run on a TinyMUD server&#8221;. I could host the original (and I&#8217;m in a position to), but I think running a modernised equivalent would be more interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/ruby-port-of-tinymud-wip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Synchronizing ruby threads with a shared queue</title>
		<link>http://mangled.me/blog/coding/synchronizing-ruby-threads-with-a-shared-queue/</link>
		<comments>http://mangled.me/blog/coding/synchronizing-ruby-threads-with-a-shared-queue/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 23:05:04 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=466</guid>
		<description><![CDATA[Whilst working on improving Poodle&#8217;s crawler I ran into a nasty problem. I had multiple threads all producing and consuming content from a shared &#8220;queue&#8221;. In pseudo code: queue = ....new() # Not a ruby "queue" (see why below), but "thread safe" a,b,c,.. = Thread.new do begin queue.pop ...Compute stuff... queue.push(stuff) if stuff end while [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst working on improving Poodle&#8217;s crawler I ran into a nasty problem. I had multiple threads all producing and consuming content from a shared &#8220;queue&#8221;.</p>
<p><span id="more-466"></span><br />
In pseudo code:</p>
<pre class="brush:[ruby]">
queue = ....new() # Not a ruby "queue" (see why below), but "thread safe"

a,b,c,.. = Thread.new do
    begin
        queue.pop
        ...Compute stuff...
        queue.push(stuff) if stuff
    end while !queue.done? # i.e. empty? or done
end

trap CTRL-C { queue.done = true }
a,b,c,...join
</pre>
<p>The problem I had was if &#8220;queue.pop&#8221; was blocking e.g. I used a ruby queue, then &#8220;main&#8221; could enter deadlock, e.g. imagine the queue had one item, thread &#8220;a&#8221; takes the first item, the remaining threads block. Unless &#8220;a&#8221; pushes new content then it causes deadlock as &#8220;b,c..&#8221; are left and &#8220;waiting&#8221;.</p>
<p><strong>Note</strong>: This is a slightly weird case of producer and consumer in one. Essentially you can&#8217;t stop processing until all the input has been consumed and processed (as the last item might generate more content for processing).</p>
<p>The following is my solution:</p>
<pre class="brush:[ruby]">
def initialize(initial = nil)
     @user_cancelled = false
     @items = []
     @removing_mutex = Mutex.new
     @check_removing = ConditionVariable.new
     @items_mutex = Mutex.new
     @removing = 0
end

def pop()
    @removing_mutex.lock
    item = @items.shift
    while (@removing > 0) and item.nil?
        @check_removing.wait(@removing_mutex)
        item = @items.shift
    end
    if item.nil?
        @check_removing.signal
        @removing_mutex.unlock
    else
        @removing += 1
        @removing_mutex.unlock
        begin
           @processed << (yield item)
        ensure
           @removing_mutex.lock
           @removing -= 1
           @check_removing.signal
           @removing_mutex.unlock
        end
    end
    return !(@user_cancelled or item.nil?)
end

def push(item)
    @items_mutex.synchronize do
        @items << item
    end
end

def kill()
   @user_cancelled = true
end
</pre>
<p>The loop becomes:</p>
<pre class="brush:[ruby]">
a,b,c,.. = Thread.new do
    ok = true
    while ok
        ok = queue.pop do |item|
            ...Compute stuff...
            queue.push(stuff) if stuff
        end
    end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/synchronizing-ruby-threads-with-a-shared-queue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Poodle is now on github</title>
		<link>http://mangled.me/blog/coding/poodle-is-now-on-github/</link>
		<comments>http://mangled.me/blog/coding/poodle-is-now-on-github/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 14:13:13 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=454</guid>
		<description><![CDATA[It&#8217;s taken me more than my highly underestimated &#8220;few days&#8221; to complete, but  I now have a version of my ruby based search tool up on github, it&#8217;s called &#8220;Poodle&#8221;.  Feel free to use/contribute to, more information here. It still requires some more work (hence the &#8220;0.9&#8243; revision number), hopefully someone else will find it [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-thumbnail wp-image-442 alignnone" src="http://mangled.me/blog/wp-content/uploads/2010/10/poodle-150x150.jpg" alt="" width="150" height="150" /></p>
<p>It&#8217;s taken me more than my highly underestimated &#8220;few days&#8221; to complete, but  I now have a version of my ruby based search tool up on github, it&#8217;s called &#8220;Poodle&#8221;.  Feel free to use/contribute to, more information <a href="http://mangled.me/blog/poodle/">here</a>.</p>
<p>It still requires some more work (hence the &#8220;0.9&#8243; revision number), hopefully someone else will find it of use and help out.</p>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/poodle-is-now-on-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Solr and Ruby on Rails</title>
		<link>http://mangled.me/blog/coding/fun-with-solr-and-ruby-on-rails/</link>
		<comments>http://mangled.me/blog/coding/fun-with-solr-and-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 19:35:32 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=427</guid>
		<description><![CDATA[I have been researching search tools for our Intranet/enterprise, after looking at Nutch, MS search server 2010 (express) and plenty of others I decided to write my own, why? A fair question, basically they all had something not quite right about them, varying from rubbish web-front ends to an inability to authenticate with NTLM or [...]]]></description>
			<content:encoded><![CDATA[<img width="528" height="250" src="/blog/wp-content/uploads/2010/09/shutter.jpg" alt="Fun with Solr and Ruby on Rails" /><p>I have been researching search tools for our Intranet/enterprise, after looking at Nutch, MS search server 2010 (express) and plenty of others I decided to write my own, why? A fair question, basically they all had something not quite right about them, varying from rubbish web-front ends to an inability to authenticate with NTLM or go through proxies. Lastly, I thought it would be fun!</p>
<p>The result &#8211; I&#8217;m almost done, 3 hours of coding! I didn&#8217;t start from scratch though, I wrote a simple ruby crawler, wired it to Apache Solr and wrote a rails application to call out to Solr and display the results (no rails database involved &#8211; Which differs from the normal RoR and Solr configuration). The RoR application even supports open-search.</p>
<p>The result is excellent! Just fine tuning now and tidying, I will put the code up in a day or two &#8211; It will be instructive if nothing else&#8230;</p>
<p>[<em>The code is now on Github</em>:<a href="https://github.com/mangled/Poodle"> https://github.com/mangled/Poodle</a>]</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/fun-with-solr-and-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a single movie/video from a mix of static images and movies</title>
		<link>http://mangled.me/blog/coding/creating-a-single-movievideo-from-a-mix-of-static-images-and-movies/</link>
		<comments>http://mangled.me/blog/coding/creating-a-single-movievideo-from-a-mix-of-static-images-and-movies/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 21:33:03 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=391</guid>
		<description><![CDATA[Recently I needed to create a script to make a single movie from static images and existing movie files. I hacked this together with ruby, ffmpeg and ImageMagick. Note, it will function under windows with little code change. Putting it up in case someone finds it of use! #!/usr/bin/ruby require 'fileutils' # !! Script requires [...]]]></description>
			<content:encoded><![CDATA[<img width="528" height="250" src="/blog/wp-content/uploads/2010/06/DSC01691.jpg" alt="Creating a single movie/video from a mix of static images and movies" /><p>Recently I needed to create a script to make a single movie from static images and existing movie files. I <span style="text-decoration: underline;">hacked</span> this together with ruby, ffmpeg and ImageMagick. Note, it will function under windows with little code change.</p>
<p>Putting it up in case someone finds it of use!</p>
<p><span id="more-391"></span></p>
<pre class="brush:[ruby]">#!/usr/bin/ruby
require 'fileutils'

# !! Script requires image magick to be installed (for convert) and ffmpeg !!
#
# This was *hacked* up quickly, apologies for the general cr*ppy style, its
# functional but not beautiful!
#
# Note: I pipe ffmpeg output (STDOUT/STDERR) to /dev/null - If ffmpeg fails to
# convert you might want to remove this "feature".
#
# Also note you will have to change jpg_to_mpeg() to alter how long static
# images play for.
#
# Also, also note, its hardcoded to look for specific file extensions, you
# might want to alter these as well.
#

# For a given folder, find a unique filename of random string + post_fix
def unique_filename_at(folder, post_fix)
  name = nil
  begin
    name = File.join(folder, ((1..8).map{|i| ('a'..'z').to_a[rand(26)]}.join) + post_fix)
  end while File.exists?(name)
  name
end

# Resize all image files in env[:src] writing them to env[:dst]
def resize_images_as_jpg(env)
  resized_names = []
  images = Dir.glob(File.join(env[:src], '*.{jpg}'), File::FNM_CASEFOLD)
  images.each do |image|
    resized_names &lt;&lt; unique_filename_at(env[:dst], ".jpg")     `convert -scale #{env[:width]}x#{env[:height]} #{image} #{resized_names[-1]}`     `identify #{resized_names[-1]}` =~ /(\d+)x(\d+)/     # Scale attempts to best fit (based on image aspect ratio), it doesn't guarantee the exact size, so     # add extents (pad) the image to one which has the desired dimensions     if (env[:width] - $1.to_i) &gt; 0 or (env[:height] - $2.to_i) &gt; 0
      `convert -gravity Center -extent #{env[:width]}x#{env[:height]} #{resized_names[-1]} #{resized_names[-1]}`
    end
  end
  resized_names
end

# Resize all the movie files in env[:src] writing them to env[:dst]
def resize_movies(env)
  resized_names = []
  movies = Dir.glob(File.join(env[:src], '*.{mpg,mp4,flv}'), File::FNM_CASEFOLD)
  movies.each do |movie|
    resized_names &lt;&lt; unique_filename_at(env[:dst], ".mpg")     `ffmpeg -i #{movie} -s #{env[:width]}x#{env[:height]} -sameq -r 25 #{resized_names[-1]} &gt; /dev/null 2&gt;&amp;1`
  end
  resized_names
end

# Convert the given file (must end .jpg) to an mpeg
# !! Hard-coded to create movies of length 10 seconds
# !! 25 frames per second and 250 frames in total
def jpg_to_mpeg(file)
  movie_name = File.join(File.dirname(file), File.basename(file, ".jpg") + ".mpg")
  `ffmpeg -loop_input -qscale 1 -f image2 -vframes 250 -r 25 -i #{file} #{movie_name} &gt; /dev/null 2&gt;&amp;1`
  movie_name
end

# Usage: tomov src_folder dest_folder
# src_folder contains images/movies
# dest_folder will contain the final result
if __FILE__ == $0

  # Change this to set the resultant video size
  env = { :width =&gt; 640, :height =&gt; 480 }

  # Get src/dest folders - I didn't care about fancy argument checks at the time...
  if ARGV.length != 2
      puts "tomov in_folder out_folder"
      exit(-1)
  end
  env[:src] = ARGV[0]
  env[:dst] = ARGV[1]
  exit(-1) unless File.exists?(env[:src])
  exit(-1) unless File.exists?(env[:dst])

  # Get the movie files to be consistent
  movies = resize_movies(env)

  # Get the image files to be consistent and convert to movie files
  resized_images = resize_images_as_jpg(env)
  movies.concat(resized_images.collect {|resized_image| jpg_to_mpeg(resized_image) })

  out_tmp = File.join(env[:dst], "movie.mpg")
  out_final = File.join(env[:dst], "final.avi")

  # Concat individual movies into a single movie
  # (the sort tries to ensure video's and images are mingled (not guaranteed though))
  `cat #{movies.sort_by{rand}.join(" ")} &gt; #{out_tmp}`

  # Ensure the final movie is consistent and the format I want...
  `ffmpeg -i #{out_tmp} -sameq -vcodec mpeg4 -an -r 25 #{out_final} &gt; /dev/null 2&gt;&amp;1`

  # Clean-up intermediate files
  File.delete(out_tmp)
  resized_images.each {|i| File.delete(i) }
  movies.each {|i| File.delete(i) }
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/creating-a-single-movievideo-from-a-mix-of-static-images-and-movies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Downloading YouTube videos with Ruby</title>
		<link>http://mangled.me/blog/coding/downloading-youtube-videos-with-ruby/</link>
		<comments>http://mangled.me/blog/coding/downloading-youtube-videos-with-ruby/#comments</comments>
		<pubDate>Sun, 30 May 2010 13:12:38 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=356</guid>
		<description><![CDATA[A random script I hacked together (through searching and experimentation) for pulling down videos from YouTube with ruby, its only guaranteed to last along as the current YouTube html formatting lasts. Will work under windows, with some minor changes (and installation of curl and ffmpeg). Usage should be obvious, it takes the YouTube url (with [...]]]></description>
			<content:encoded><![CDATA[<img width="528" height="250" src="/blog/wp-content/uploads/2010/05/DSC019691.jpg" alt="Downloading YouTube videos with Ruby" /><p>A random script I hacked together (through searching and experimentation) for pulling down videos from YouTube with ruby, its only guaranteed to last along as the current YouTube html formatting lasts.</p>
<p><span id="more-356"></span></p>
<p>Will work under windows, with some minor changes (and installation of curl and ffmpeg). Usage should be obvious, it takes the YouTube url (with watch? in it) as an argument (try quoting &#8220;&#8221;)</p>
<pre class="brush:[ruby]">#!/usr/bin/ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'

USER_AGENT = %{Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3}

def parse_youtube(url)
  youtube = "http://www.youtube.com/"
  url =~ /watch\?v=(.*)/
  doc = Hpricot(open("#{youtube}watch\?v=#{$1.split("&amp;")[0]}"))
  doc.search("/html/body/").each do |foo|
    matches = URI.unescape(foo.inner_html).scan(/\|(.*?http.+?),.*?\|/)
    matches.each do |match|
      match.each do |item|
        return URI.unescape(item) if item =~ /videoplayback/
      end
    end
  end
  nil
end

if __FILE__ == $0 and ARGV[0]
  url = parse_youtube(ARGV[0])
  `curl -o \"foo.flv\" -L -A \"#{USER_AGENT}\" \"#{url}\"`
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/downloading-youtube-videos-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Idea: Wiki based IDE&#8217;s</title>
		<link>http://mangled.me/blog/coding/idea-wiki-based-ides/</link>
		<comments>http://mangled.me/blog/coding/idea-wiki-based-ides/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 22:51:37 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://mangled.me/blog/?p=342</guid>
		<description><![CDATA[Idea for the day, why not use a wiki as an integrated development environment (IDE)? I.e. write code in the wiki, configure the build similarly, i.e. which pages will be compiled. Modern wiki&#8217;s have configuration management built in, so bye bye svn, git etc. (ok, wiki&#8217;s don&#8217;t handle this well enough, but again this is [...]]]></description>
			<content:encoded><![CDATA[<p>Idea for the day, why not use a wiki as an integrated development environment (IDE)?</p>
<p>I.e. write code in the wiki, configure the build similarly, i.e. which pages will be compiled. Modern wiki&#8217;s have configuration management built in, so bye bye svn, git etc. (ok, wiki&#8217;s don&#8217;t handle this well enough, but again this is an idea not a real product).</p>
<p>The environment by itself supports cross linking, so it self documents and people find it easy to document! The compiler and automated tests can update a build/test result page! With a little thought I think a wiki could manage code better than current IDE&#8217;s and integrate the social side. I guess execution of code might be an issue, but one which some more thought would overcome. Possibly this could be integrated into Google Wave?</p>
<p>It&#8217;s worth some discussion and further thought &#8211; Somewhere, off to bed!</p>
]]></content:encoded>
			<wfw:commentRss>http://mangled.me/blog/coding/idea-wiki-based-ides/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

