<?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>stick&#039;s corner &#187; ruby</title>
	<atom:link href="http://stick.gk2.sk/blog/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://stick.gk2.sk</link>
	<description>All composite phenomena are impermanent. All contaminated things and events are unsatisfactory.</description>
	<lastBuildDate>Wed, 01 Feb 2012 17:58:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Version sorting in Ruby</title>
		<link>http://stick.gk2.sk/blog/2011/07/version-sorting-in-ruby/</link>
		<comments>http://stick.gk2.sk/blog/2011/07/version-sorting-in-ruby/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 13:59:53 +0000</pubDate>
		<dc:creator>Pavol Rusnak</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[buildservice]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[opensuse]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://stick.gk2.sk/?p=1923</guid>
		<description><![CDATA[Today I needed to implement &#8220;human sort&#8221; for a list of distributions we support in the Open Build Service. I wanted to sort them alphabetically but at the same time the newest ones at the top. I ended up with the following code: module Enumerable def version_sort sort_by { &#124;key,val&#124; key.gsub(/_SP/,'.').gsub(/_Factory/,'_100').split(/_/) \ .map { &#124;v&#124; [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Today I needed to implement &#8220;human sort&#8221; for a list of distributions we support in the <a href="http://openbuildservice.org/">Open Build Service</a>. I wanted to sort them alphabetically but at the same time the newest ones at the top. I ended up with the following code:</p>
<pre>module Enumerable
  def version_sort
    sort_by { |key,val|
       key.gsub(/_SP/,'.').gsub(/_Factory/,'_100').split(/_/) \
          .map { |v| v =~ /\A\d+(\.\d+)?\z/ ? -(v.to_f) : v.downcase }
    }
  end
end

@distros = [
  'openSUSE_Factory_PPC',
  'CentOS_6',
  'openSUSE_11.4',
  'RHEL_4',
  'Mandriva_2010',
  'RHEL_5',
  'Debian_5.0',
  'SLE_10',
  'Ubuntu_9.04',
  'Fedora_14',
  'RHEL_6',
  'Ubuntu_11.04',
  'SLE_11',
  'Mandriva_2009.1',
  'CentOS_5',
  'openSUSE_11.3',
  'Debian_6.0',
  'openSUSE_11.1_Evergreen',
  'Ubuntu_10.04',
  'ScientificLinux_6',
  'openSUSE_Factory',
  'Ubuntu_10.10',
  'SLE_11_SP1',
  'Fedora_15',
  'Ubuntu_8.04',
  'Ubuntu_9.10',
  'Mandriva_2010.1',
]

@distros.version_sort.each{ |v|
  puts v
}</pre>
<p style="text-align: justify;">which produces this list:</p>
<pre>CentOS_6
CentOS_5
Debian_6.0
Debian_5.0
Fedora_15
Fedora_14
Mandriva_2010.1
Mandriva_2010
Mandriva_2009.1
openSUSE_Factory
openSUSE_Factory_PPC
openSUSE_11.4
openSUSE_11.3
openSUSE_11.1_Evergreen
RHEL_6
RHEL_5
RHEL_4
ScientificLinux_6
SLE_11_SP1
SLE_11
SLE_10
Ubuntu_11.04
Ubuntu_10.10
Ubuntu_10.04
Ubuntu_9.10
Ubuntu_9.04
Ubuntu_8.04</pre>
<p style="text-align: justify;">Nifty, right? <img src='http://stick.gk2.sk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  The idea is simple. I use the <code>sort_by</code> function which pre-computes the values that are later compared. I replace some special values like &#8220;_Factory&#8221; or &#8220;_SP&#8221;, because I want &#8220;Factory&#8221; to be the newest (100 is higher than any other openSUSE version) and &#8220;11_SP1&#8243; to behave exactly like &#8220;11.1&#8243;. Then I split the key using the &#8220;_&#8221; delimiter and turn any string in form &#8220;digit&#8221; or &#8220;digit.digit&#8221; to float number. I change the sign, because I want versions to be sorted in the reverse direction. Good thing is that Ruby operator <code>&lt;=&gt;</code> works on arrays also, so I&#8217;m done with key modifications and the sort does the rest &#8230;</p>
<p style="text-align: justify;">PS: I used <code>|key,val|</code> in <code>sort_by</code> block because I want to use this function also to sort hashes by their key. This way it works both for arrays and hashes with any further modifications.</p>
]]></content:encoded>
			<wfw:commentRss>http://stick.gk2.sk/blog/2011/07/version-sorting-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gemcutter + openSUSE Build Service cooperation (idea)</title>
		<link>http://stick.gk2.sk/blog/2010/01/gemcutter-opensuse-build-service-cooperation-idea/</link>
		<comments>http://stick.gk2.sk/blog/2010/01/gemcutter-opensuse-build-service-cooperation-idea/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 14:32:23 +0000</pubDate>
		<dc:creator>Pavol Rusnak</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[gemcutter]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[idea]]></category>
		<category><![CDATA[mandriva]]></category>
		<category><![CDATA[opensuse]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://stick.gk2.sk/?p=1013</guid>
		<description><![CDATA[If you are closely following Ruby development and especially the situation around ruby gems, you might already know of Gemcutter. It is a new service, which provides a very easy way how to publish gems and also a good API to deal with them. It is not trying to replace RubyForge as whole, just its [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-1017" style="margin-right: 8px;" title="Gemcutter" src="http://stick.gk2.sk/blog/wp-content/uploads/2010/01/gemcutter.png" alt="" width="128" height="128" /></p>
<p style="text-align: justify;">If you are closely following <a href="http://www.ruby-lang.org/">Ruby</a> development and especially the situation around ruby gems, you might already know of <a href="http://gemcutter.org/">Gemcutter</a>. It is a new service, which provides a very easy way how to publish gems and also a good <a href="http://gemcutter.org/pages/api_docs">API</a> to deal with them. It is not trying to replace <a href="http://rubyforge.org/">RubyForge</a> as whole, just its gem hosting (+ now defunct <a href="http://gems.github.com/">GitHub gem hosting</a>) and will soon become the central and the only place for Ruby gems. The whole site is <a href="http://www.opensource.org/licenses/mit-license.php">MIT licensed</a> and the code is available on <a href="http://github.com/qrush/gemcutter">GitHub</a>.</p>
<p style="text-align: justify;">During the winter holidays I wrote a <a href="http://gitorious.org/opensuse/misc/blobs/master/buildservice-gemcutter-versions">simple script</a> which utilizes the <a href="http://gemcutter.org/">Gemcutter</a> API and prints versions of <code>rubygem-*</code> packages in our <code>devel:languages:ruby:extensions</code> <a href="http://en.opensuse.org/Build_Service">Build Service</a> repository compared with the corresponding gem versions on Gemcutter. Using this script and a great <a href="http://rubyforge.org/projects/gem2rpm/">gem2rpm</a> (more particularly <code>gem2rpm-opensuse</code> command which applies openSUSE template and is available from <code>rubygem-gem2rpm</code> package), I was able to update nearly a hundred of gems in just two hours. <a href="http://rubyonrails.org/">Rails</a> rubygems have a specific packaging in openSUSE, so I left them out, but more than 90% of the rest didn&#8217;t need any changes in autogenerated spec file.</p>
<p style="text-align: justify;">This brought me an idea. If only <a href="http://gemcutter.org/">Gemcutter</a> had an option to somehow send out notification that a new gem has been pushed, we could automate the process and have up-to-date rubygems in our <code>devel:languages:ruby:extensions</code> repository almost instantly. (We would still need to keep the list of &#8220;dirty&#8221; rubygems that need to be updated manually, though. For example, <a href="http://rubyonrails.org/">Rails</a> packages I mentioned earlier, where we keep multiple versions, or others where we need to add a patch replacing <code>/usr/local/bin/ruby</code> with <code>/usr/bin/ruby</code> in scripts).</p>
<p style="text-align: justify;">Few days later, <a href="http://gemcutter.org/">Gemcutter</a> gained RSS feed support, but only for the gems one is interested in. I didn&#8217;t find the option to have RSS feed for all gems. This could have helped in creating such mechanism, but that won&#8217;t be needed anymore because &#8230;</p>
<p style="text-align: justify;">&#8230; yesterday <a href="http://twitter.com/qrush">Nick Quaranto</a> of <a href="http://gemcutter.org/">Gemcutter</a> announced <a href="http://gemcutter.org/pages/gem_docs#webhook">webhook support</a>. I&#8217;m really excited, because that&#8217;s exactly what we need! When one registers a webhook, <a href="http://gemcutter.org/">Gemcutter</a> emits a POST request on a certain URL when a gem is pushed or updated. This request is a JSON document containing the info about gem. What we need is to create a mechanism that:</p>
<ul>
<li>receives notification via POST JSON request</li>
<li>checks whether the package is not &#8220;dirty&#8221; → exit if it is (and probably send some email &#8230;)</li>
<li>fetches the package from the <a href="http://en.opensuse.org/Build_Service">Build Service</a> or create a new one</li>
<li>fetches the new gem, removes the old one</li>
<li>runs <code>gem2rpm-opensuse</code> to create a spec file replacing the old one</li>
<li>adds changelog entry</li>
<li>pushes the updated package back into the <a href="http://en.opensuse.org/Build_Service">Build Service</a></li>
</ul>
<p style="text-align: justify;">Last but not least: If <a href="http://fedoraproject.org/">Fedora</a> and <a href="http://mandriva.com/">Mandriva</a> had <a href="http://rubyforge.org/projects/gem2rpm/">gem2rpm</a> templates in a perfect shape too, <a href="http://en.opensuse.org/Build_Service">Build Service</a> could provide packaged gems also for their distributions.</p>
<p style="text-align: justify;">So what do you think? Any volunteers for this? Right now, I&#8217;m off to fix some small bugs I found in <a href="http://rubyforge.org/projects/gem2rpm/">gem2rpm</a> while fiddling with it &#8230; <img src='http://stick.gk2.sk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://stick.gk2.sk/blog/2010/01/gemcutter-opensuse-build-service-cooperation-idea/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>image_url function in Ruby on Rails</title>
		<link>http://stick.gk2.sk/blog/2009/12/image_url-function-in-ruby-on-rails/</link>
		<comments>http://stick.gk2.sk/blog/2009/12/image_url-function-in-ruby-on-rails/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 15:40:31 +0000</pubDate>
		<dc:creator>Pavol Rusnak</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://stick.gk2.sk/?p=997</guid>
		<description><![CDATA[If you need to get the full URL of an image, just put the following code snippet into ApplicationHelper module in your app/helpers/application_helper.rb: def image_url(source) abs_path = image_path(source) unless abs_path =~ /^http/ abs_path = "#{request.protocol}#{request.host_with_port}#{abs_path}" end abs_path end I wonder why this function is not already a standard part of Rails. (Idea by Rob Biedenharn)]]></description>
			<content:encoded><![CDATA[<p>If you need to get the full URL of an image, just put the following code snippet into <code>ApplicationHelper</code> module in your <code>app/helpers/application_helper.rb</code>:</p>
<pre>  def image_url(source)
    abs_path = image_path(source)
    unless abs_path =~ /^http/
      abs_path = "#{request.protocol}#{request.host_with_port}#{abs_path}"
    end
   abs_path
  end</pre>
<p>I wonder why this function is not already a standard part of Rails.</p>
<p>(<a href="http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ab495ed6596afe21">Idea</a> by <a href="http://biedenharn.us/">Rob Biedenharn</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://stick.gk2.sk/blog/2009/12/image_url-function-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

