<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: block code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 10:19:47 GMT</pubDate>
    <description>DZone Snippets: block code</description>
    <item>
      <title>J2ME - Alert Bloccante</title>
      <link>http://snippets.dzone.com/posts/show/3576</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import javax.microedition.lcdui.Alert;&lt;br /&gt;import javax.microedition.lcdui.AlertType;&lt;br /&gt;import javax.microedition.lcdui.Command;&lt;br /&gt;import javax.microedition.lcdui.CommandListener;&lt;br /&gt;import javax.microedition.lcdui.Displayable;&lt;br /&gt;&lt;br /&gt;public class MessageBox extends Alert implements CommandListener&lt;br /&gt;{&lt;br /&gt;	protected Chattando midlet;&lt;br /&gt;	&lt;br /&gt;	private boolean isReady = false;&lt;br /&gt;	&lt;br /&gt;	private Displayable dspBACK;&lt;br /&gt;	&lt;br /&gt;	public MessageBox(String title, String text, AlertType type, Chattando midlet)&lt;br /&gt;	{&lt;br /&gt;		super(title, text, null, type);&lt;br /&gt;		&lt;br /&gt;		this.midlet = midlet;&lt;br /&gt;		&lt;br /&gt;		this.setCommandListener(this);&lt;br /&gt;		this.setTimeout(Alert.FOREVER);&lt;br /&gt;		&lt;br /&gt;		// Display Precedente&lt;br /&gt;		dspBACK = midlet.getDisplay().getCurrent();&lt;br /&gt;		&lt;br /&gt;		// Mostra l'alert&lt;br /&gt;		midlet.getDisplay().setCurrent(this);&lt;br /&gt;		&lt;br /&gt;		// Attendi la conferma di chiusura&lt;br /&gt;		waitForDone();&lt;br /&gt;		&lt;br /&gt;		// Visualizza il precedente Display&lt;br /&gt;		midlet.getDisplay().setCurrent(dspBACK);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	private void waitForDone()&lt;br /&gt;	{&lt;br /&gt;		try&lt;br /&gt;		{&lt;br /&gt;			while(!isReady)&lt;br /&gt;			{&lt;br /&gt;				synchronized(this)&lt;br /&gt;				{&lt;br /&gt;					this.wait();&lt;br /&gt;					&lt;br /&gt;				}&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		catch(Exception error)&lt;br /&gt;		{&lt;br /&gt;			&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public void commandAction(Command cmd, Displayable dsp)&lt;br /&gt;	{&lt;br /&gt;		if(cmd == Alert.DISMISS_COMMAND)&lt;br /&gt;		{&lt;br /&gt;			isReady = true;&lt;br /&gt;			&lt;br /&gt;			synchronized(this)&lt;br /&gt;			{&lt;br /&gt;				this.notify();&lt;br /&gt;			}			&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 24 Feb 2007 14:20:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3576</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>BlockFlash-Revisited.user.js</title>
      <link>http://snippets.dzone.com/posts/show/3054</link>
      <description>&lt;code&gt;&lt;br /&gt;// ==UserScript==&lt;br /&gt;// @name		BlockFlash-Revisited&lt;br /&gt;// @namespace		http://snippets.dzone.com/posts/show/3054&lt;br /&gt;// @description	Do not start Flash animation until you click on them.&lt;br /&gt;// @include		*&lt;br /&gt;// @exclude		http://www.macromedia.com/*&lt;br /&gt;// @exclude		http://www.atomfilms.com/*&lt;br /&gt;// @exclude		http://uploads.ungrounded.net/*&lt;br /&gt;// @exclude		http://www.albinoblacksheep.com/*&lt;br /&gt;// ==/UserScript==&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;	Revised by Andrew Pennebaker (andrew.pennebaker@gmail.com)&lt;br /&gt;&lt;br /&gt;	Author: Jos van den Oever (jos@vandenoever.info)&lt;br /&gt;&lt;br /&gt;	License: GPL&lt;br /&gt;&lt;br /&gt;	Version history:&lt;br /&gt;		2006-02-12: initial version&lt;br /&gt;		2006-11-28: changed appearance&lt;br /&gt;&lt;br /&gt;Inspiration for this script comes from the removeFlash script and the FlashBlock firefox extension.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;(function () {&lt;br /&gt;	var objects=document.getElementsByTagName("object");&lt;br /&gt;&lt;br /&gt;	for (i=0; i&lt;objects.length; i++) {&lt;br /&gt;		var flash=objects[i];&lt;br /&gt;&lt;br /&gt;		if (flash.innerHTML.match(/.swf|shockwave|flash/)) {&lt;br /&gt;			var placeholder=document.createElement("div");&lt;br /&gt;&lt;br /&gt;			placeholder.style.cursor='pointer';&lt;br /&gt;			placeholder.style.background='orange'; // 'gray '&lt;br /&gt;			placeholder.style.textAlign='center';&lt;br /&gt;			placeholder.style.color='black';&lt;br /&gt;			placeholder.innerHTML="[Play Flash]";&lt;br /&gt;&lt;br /&gt;			flash.parentNode.insertBefore(placeholder, flash);&lt;br /&gt;			flash.on=false;&lt;br /&gt;&lt;br /&gt;			placeholder.addEventListener(&lt;br /&gt;				'click',&lt;br /&gt;				function() {&lt;br /&gt;					if (flash.on) {&lt;br /&gt;						flash.style.display='none';&lt;br /&gt;						placeholder.innerHTML="[Play Flash]";&lt;br /&gt;						flash.on=false;&lt;br /&gt;					}&lt;br /&gt;					else {&lt;br /&gt;						flash.style.display='';&lt;br /&gt;						placeholder.innerHTML="[Stop Flash]";&lt;br /&gt;						flash.on=true;&lt;br /&gt;					}&lt;br /&gt;				},&lt;br /&gt;				true&lt;br /&gt;			);&lt;br /&gt;&lt;br /&gt;			flash.style.display='none';&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;})();&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 29 Nov 2006 01:03:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3054</guid>
      <author>mcandre (Andrew Pennebaker)</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>SINGLE-LINE-MOLD</title>
      <link>http://snippets.dzone.com/posts/show/3008</link>
      <description>&lt;code&gt;&lt;br /&gt;	single-line-mold: func [&lt;br /&gt;	    "Reformats a block or object-spec to a single line."&lt;br /&gt;	    val [any-block! object!]&lt;br /&gt;	] [&lt;br /&gt;	    val: copy either any-block? val [val] [third val]&lt;br /&gt;	    replace/all mold new-line/all val  off  "^/" "^^/"&lt;br /&gt;	]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Nov 2006 05:09:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3008</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>GROUP - group like elements in a block</title>
      <link>http://snippets.dzone.com/posts/show/2947</link>
      <description>&lt;code&gt;&lt;br /&gt;    group: func [&lt;br /&gt;        {Returns a block of sub-blocks with items partitioned by value.}&lt;br /&gt;        block  [any-block!]&lt;br /&gt;        /local result&lt;br /&gt;    ][&lt;br /&gt;        result: copy []&lt;br /&gt;        ; First, build up a list of keys, with a place for values&lt;br /&gt;        ; to go with each key.&lt;br /&gt;        foreach item block [&lt;br /&gt;            if not find/only/skip result item 2 [&lt;br /&gt;                repend result [item copy []]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;        ; Add items to the block associated with each key.&lt;br /&gt;        foreach item block [append/only select result item item]&lt;br /&gt;        result&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 01 Nov 2006 21:30:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2947</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title> call sort with a block</title>
      <link>http://snippets.dzone.com/posts/show/2120</link>
      <description>From http://practicalruby.blogspot.com/2006/05/call-sort-with-block.html:&lt;br /&gt;&lt;br /&gt;I needed to sort a list of partners today so I added:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Partner&lt;br /&gt;  def &lt;=&gt;(other)&lt;br /&gt;     self.name &lt;=&gt; other.name&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;However, I could have just done:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Partner.find(:all).sort { |one, other| one.name &lt;=&gt; other.name }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Doc for &lt;a href="http://ruby-doc.org/core/classes/Array.html#M000424"&gt;sort&lt;/a&gt; here.&lt;br /&gt;&lt;br /&gt;From Comments:&lt;br /&gt;You could also have used sort_by as long as the target supports the spaceship operator. ie:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Partner.find(:all).sort_by { |partner| partner.name }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;With active_support required (or 'facet/symbol/to_proc' from the facets library) you can even:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Partner.find(:all).sort_by(&amp;:name)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Sweet.</description>
      <pubDate>Tue, 30 May 2006 09:05:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2120</guid>
      <author>MattScilipoti (Matt Scilipoti)</author>
    </item>
    <item>
      <title>content_tag that accepts a block = block_tag</title>
      <link>http://snippets.dzone.com/posts/show/1910</link>
      <description>Sometimes I want to do something like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;% content_tag("div", :class =&gt; "section_with_error" do %&gt;&lt;br /&gt;  HTML GOES HERE&lt;br /&gt;&lt;% end %&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;instead of this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%= content_tag("div", "HTML GOES HERE", :class =&gt; "section_with_error") %&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Put the following code in ApplicationHelper, and you can do just that (replacing "content_tag" in the example above with "block_tag", of course):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  def block_tag(tag, options = {}, &amp;block)&lt;br /&gt;    concat(content_tag(tag, capture(&amp;block), options), block.binding)&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Apr 2006 02:08:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1910</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
    <item>
      <title>spec-block-to-named-block</title>
      <link>http://snippets.dzone.com/posts/show/1568</link>
      <description>&lt;code&gt;&lt;br /&gt;spec-block-to-named-block: func [&lt;br /&gt;    "Change all set-words in a spec block to regular words."&lt;br /&gt;    input [block!]&lt;br /&gt;][&lt;br /&gt;    input: copy input&lt;br /&gt;    parse input [&lt;br /&gt;        some [mark: set-word! any-type! (change mark to word! first mark)]&lt;br /&gt;    ]&lt;br /&gt;    input&lt;br /&gt;]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 24 Feb 2006 22:33:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1568</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>spec-block-is-subset? - is a spec block a subset of an object's spec?</title>
      <link>http://snippets.dzone.com/posts/show/1544</link>
      <description>&lt;code&gt;&lt;br /&gt;spec-block-is-subset?: func [block [block!] object [object!]] [&lt;br /&gt;    all [&lt;br /&gt;        spec-block? block&lt;br /&gt;        subset? first construct block  first object&lt;br /&gt;    ]&lt;br /&gt;]&lt;/code&gt;</description>
      <pubDate>Tue, 21 Feb 2006 07:09:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1544</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>spec-block-matches? - does a spec block match the spec for an object?</title>
      <link>http://snippets.dzone.com/posts/show/1543</link>
      <description>&lt;code&gt;&lt;br /&gt;spec-block-matches?: func [block [block!] object [object!]] [&lt;br /&gt;    all [&lt;br /&gt;        spec-block? block&lt;br /&gt;        equal? first construct block  first object&lt;br /&gt;    ]&lt;br /&gt;]&lt;/code&gt;</description>
      <pubDate>Tue, 21 Feb 2006 07:08:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1543</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
