<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: series code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 11 May 2008 21:00:31 GMT</pubDate>
    <description>DZone Snippets: series code</description>
    <item>
      <title>R3 compatible MAP</title>
      <link>http://snippets.dzone.com/posts/show/5186</link>
      <description>; Not terrribly efficient, but it works.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    ; R3-compatible interface&lt;br /&gt;    map: func ['word data [block!] body [block!]] [&lt;br /&gt;        collect/only res compose/deep [&lt;br /&gt;            repeat (word) data [res: do bind/copy body (to lit-word! word)]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 29 Feb 2008 05:36:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5186</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>execute a task serially on different hosts, not in parallel</title>
      <link>http://snippets.dzone.com/posts/show/3837</link>
      <description>// This code will let you define a task, using the same conventions as Capistrano's "task", that executes serially on the hosts defined by its role rather than in parallel.  This is useful if you are deploying to multiple live servers behind a load balancer, the deployment process takes down the server, and you want only one server down at a given time.&lt;br /&gt;&lt;br /&gt;This efinitely uses magic.  we're not sure if this will work in future versions of Capistrano, but changing it should be relatively simple.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def serial_task(name, options = {}, &amp;block)&lt;br /&gt;  servers = self.roles[options[:roles]].collect {|server| server.host}&lt;br /&gt;  task_syms = []&lt;br /&gt;  servers.each do |hostname|&lt;br /&gt;    role_sym = "_serial_task_#{name.to_s}_#{hostname}".to_sym&lt;br /&gt;    task_sym = "_do_task_#{name.to_s}_#{hostname}".to_sym&lt;br /&gt;    task_syms &lt;&lt; task_sym&lt;br /&gt;    role role_sym, hostname&lt;br /&gt;    task task_sym, :roles =&gt; role_sym, &amp;block&lt;br /&gt;  end&lt;br /&gt;  task name do&lt;br /&gt;    task_syms.each do |t|&lt;br /&gt;      self.send t&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here is an example.  Note the syntax is just the same as Capistrano's "task".&lt;br /&gt;&lt;code&gt;&lt;br /&gt;serial_task :pwd, :roles =&gt; web do&lt;br /&gt;  run "pwd"&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 18 Apr 2007 19:37:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3837</guid>
      <author>stephen.judkins (stephen judkins)</author>
    </item>
    <item>
      <title>MERGE two series</title>
      <link>http://snippets.dzone.com/posts/show/3796</link>
      <description>&lt;code&gt;&lt;br /&gt;merge: func [&lt;br /&gt;    "Merge A and B together, like a zipper, alternating elements"&lt;br /&gt;    a [series!]&lt;br /&gt;    b [series!]&lt;br /&gt;    /only "Merge items as sub-blocks"&lt;br /&gt;    /local res val&lt;br /&gt;][&lt;br /&gt;    res: make a length? a&lt;br /&gt;    repeat i max length? a length? b [&lt;br /&gt;        val: reduce [pick a i  pick b i]&lt;br /&gt;        either only [append/only res val] [append res val]&lt;br /&gt;    ]&lt;br /&gt;    res&lt;br /&gt;]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 11 Apr 2007 16:19:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3796</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>LIMIT - Make sure val falls between lower and upper bounds, inclusive; uses length for series values.</title>
      <link>http://snippets.dzone.com/posts/show/3111</link>
      <description>&lt;code&gt;&lt;br /&gt;    limit: func [&lt;br /&gt;        "Make sure val falls between lower and upper bounds, inclusive; uses length for series values."&lt;br /&gt;        val&lt;br /&gt;        lower [integer!]&lt;br /&gt;        upper [integer!]&lt;br /&gt;        /show "For series values, show extension/truncation (dot/none for extension, 3 dots for truncation)."&lt;br /&gt;        /local fill&lt;br /&gt;    ][&lt;br /&gt;        either not series? val [max min val upper lower] [&lt;br /&gt;            either all [&lt;br /&gt;                upper &gt;= length? val&lt;br /&gt;                lower &lt;= length? val&lt;br /&gt;            ] [val] [&lt;br /&gt;                ; If extending the series, use NONE as the fill value, so the&lt;br /&gt;                ; block can still be processed easily.&lt;br /&gt;                fill: either any-string? val ["."] [none]&lt;br /&gt;                head either lower &gt;= length? val [&lt;br /&gt;                    insert/only/dup tail val fill subtract lower length? val&lt;br /&gt;                ][&lt;br /&gt;                    clear skip val upper&lt;br /&gt;                    either show [change/dup skip tail val -3 '. 3] [val]&lt;br /&gt;                ]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 08 Dec 2006 22:46:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3111</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>sparse-rec-to-fixed-block</title>
      <link>http://snippets.dzone.com/posts/show/3018</link>
      <description>&lt;code&gt;&lt;br /&gt;	sparse-rec-to-fixed-block: func [&lt;br /&gt;		rec [block!]&lt;br /&gt;		col-names [block!] "All column names in full schema"&lt;br /&gt;	][&lt;br /&gt;		if not all-words? col-names [alert join "sparse-rec-to-fixed-block: col-names has non-word values: " mold col-names]&lt;br /&gt;		collect/only val [&lt;br /&gt;			foreach name col-names [&lt;br /&gt;				val: attempt [first select/skip rec name 2]&lt;br /&gt;			]&lt;br /&gt;		]&lt;br /&gt;	]&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 19 Nov 2006 02:22:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3018</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>sparse-rec?</title>
      <link>http://snippets.dzone.com/posts/show/3017</link>
      <description>&lt;code&gt;&lt;br /&gt;	; Like named-fields?, this func can't guarantee that a record is really&lt;br /&gt;	; a sparse rec; it can only tell us if it's not.&lt;br /&gt;	sparse-rec?: func [&lt;br /&gt;		rec [block!]&lt;br /&gt;		col-names [block!] "All column names in full schema"&lt;br /&gt;	][&lt;br /&gt;		if not all-words? col-names [alert join "sparse-rec?: col-names has non-word values: " mold col-names]&lt;br /&gt;		all [&lt;br /&gt;			named-fields? rec&lt;br /&gt;			(length? rec) &lt;&gt; (2 * length? col-names) &lt;br /&gt;		]&lt;br /&gt;	]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 19 Nov 2006 02:17:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3017</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>sort-by-length - sort a series by element length</title>
      <link>http://snippets.dzone.com/posts/show/2770</link>
      <description>&lt;code&gt;&lt;br /&gt;    sort-by-length: func [series] [sort/compare series :cmp-length]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 02 Oct 2006 23:21:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2770</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>cmp-length - compare the length of two series and return -1, 0, or 1, to support stable sorts by length</title>
      <link>http://snippets.dzone.com/posts/show/2769</link>
      <description>&lt;code&gt;&lt;br /&gt;    ; Support func for stable sort comparator&lt;br /&gt;    cmp-length: func [a [series!] b [series!] /local len-a len-b] [&lt;br /&gt;        len-a: length? a&lt;br /&gt;        len-b: length? b&lt;br /&gt;        case [&lt;br /&gt;            len-a &lt; len-b [-1]&lt;br /&gt;            len-a &gt; len-b [1]&lt;br /&gt;            len-a = len-b [0]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 02 Oct 2006 23:19:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2769</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>drop-highest - remove the highest value from a series</title>
      <link>http://snippets.dzone.com/posts/show/2730</link>
      <description>&lt;code&gt;&lt;br /&gt;drop-highest: func [block] [head remove maximum-of block]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 29 Sep 2006 18:31:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2730</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>drop-lowest - remove the lowest value from a series</title>
      <link>http://snippets.dzone.com/posts/show/2729</link>
      <description>&lt;code&gt;&lt;br /&gt;drop-lowest:  func [block] [head remove minimum-of block]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 29 Sep 2006 18:30:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2729</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
