<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: object code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 12 May 2008 00:22:38 GMT</pubDate>
    <description>DZone Snippets: object code</description>
    <item>
      <title>You have a nil object when you didn't expect it!</title>
      <link>http://snippets.dzone.com/posts/show/4861</link>
      <description>As seen on my webpage: http://freezzo.com&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%= @object.association.variable rescue nil %&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 07 Dec 2007 16:14:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4861</guid>
      <author>freezzo (Randy)</author>
    </item>
    <item>
      <title>Excel object</title>
      <link>http://snippets.dzone.com/posts/show/4317</link>
      <description>// Excel object&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// 'create object&lt;br /&gt;Set excelobj = CreateObject( "Excel.Application")&lt;br /&gt;Set exp_data_workbook=excelobj.workbooks.open("c:\debug_expected.xls")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'get the sheet count&lt;br /&gt;exp_sheetcnt=exp_data_workbook.Sheets.Count&lt;br /&gt;	&lt;br /&gt;&lt;br /&gt;'select a sheet&lt;br /&gt;For i = 1 to exp_sheetcnt&lt;br /&gt;	sheet_tblname=exp_data_workbook.Sheets(i).Name&lt;br /&gt;	If  UCASE(Trim(sheet_tblname)) = "Sheet_name" Then&lt;br /&gt;		exp_data_workbook.Sheets(i).select&lt;br /&gt;&lt;br /&gt;		'once selected set the range object	&lt;br /&gt;		set exp_rangeobj=exp_data_workbook.Sheets(i).UsedRange&lt;br /&gt;	end if&lt;br /&gt;next&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'Get the column count for the &lt;br /&gt;&lt;br /&gt;columncnt=exp_rangeobj.columns.count&lt;br /&gt;&lt;br /&gt;'find  the column index of  the column column_name&lt;br /&gt;		For i=1 to columncnt&lt;br /&gt;			colname=exp_rangeobj.cells(1,i).value&lt;br /&gt;			If UCASE(Trim(colname)) = "column_name" Then&lt;br /&gt;				pos_id_idx = i&lt;br /&gt;				Exit For&lt;br /&gt;			End If&lt;br /&gt;		Next		&lt;br /&gt;&lt;br /&gt;'proceess the value from that column&lt;br /&gt;&lt;br /&gt;rowcnt=exp_rangeobj.rows.count&lt;br /&gt;&lt;br /&gt;		'Strat reading the values from the 2nd row since the first row contains the column names.&lt;br /&gt;		If rowcnt &gt; 1 Then&lt;br /&gt;			For i=2 to rowcnt				 &lt;br /&gt;				'process the expected file row if it has a value&lt;br /&gt;				If  Len(Trim(exp_rangeobj.cells(i,1).value))&gt;0 Then &lt;br /&gt;					posIndex = (exp_rangeobj.cells(i,pos_id_idx).value) -1&lt;br /&gt;				end if&lt;br /&gt;			next &lt;br /&gt;		end if&lt;br /&gt;		&lt;/code&gt;</description>
      <pubDate>Wed, 18 Jul 2007 14:14:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4317</guid>
      <author>sarunbe (Arun Kumar)</author>
    </item>
    <item>
      <title>Wrap all methods of an object</title>
      <link>http://snippets.dzone.com/posts/show/4087</link>
      <description>Given an existing object "obj", wraps all of its methods.  In this case, the wrapper prints a log of the method invocation, and the call stack of the call, but you can modify it to do anything...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;virtual_class = class &lt;&lt;obj; self; end&lt;br /&gt;&lt;br /&gt;virtual_class.class_eval {&lt;br /&gt;  obj.methods.each { |method|&lt;br /&gt;    the_alias = method.gsub(/([^?]+)(\??)/, "\\1_orig\\2").to_sym&lt;br /&gt;    alias_method the_alias, method&lt;br /&gt;&lt;br /&gt;    define_method(method) { |*args|&lt;br /&gt;        args_str = args.map { |a| a.inspect }.join(", ")&lt;br /&gt;        unless method == "to_s"&lt;br /&gt;          puts "#{self.inspect_orig}.#{method}(#{args_str}) called from #{caller.inspect}"&lt;br /&gt;        end&lt;br /&gt;        self.send_orig(the_alias, *args)&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 May 2007 23:23:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4087</guid>
      <author>haberman (Joshua Haberman)</author>
    </item>
    <item>
      <title>Object alternative to iframe for XHTML 1.0 strict</title>
      <link>http://snippets.dzone.com/posts/show/3864</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;object data="mypage.php" type="text/html"&gt;&lt;/object&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Apr 2007 23:46:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3864</guid>
      <author>nathancarnes (Nathan Carnes)</author>
    </item>
    <item>
      <title>Javascript Ajax Object</title>
      <link>http://snippets.dzone.com/posts/show/3650</link>
      <description>&lt;code&gt;&lt;br /&gt;// Just a stub function we'll tell ajaxObject to call when it's done&lt;br /&gt;// callback functions get responseText, and responseStat respectively&lt;br /&gt;// in their arguments.&lt;br /&gt;function fin(responseTxt,responseStat) {&lt;br /&gt;  alert(responseStat+' - '+responseTxt);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// create a new ajaxObject, give it a url it will be calling and&lt;br /&gt;// tell it to call the function "fin" when its got data back from the server.&lt;br /&gt;var test1 = new ajaxObject('http://someurl.com/server.cgi',fin);&lt;br /&gt;    test1.update();&lt;br /&gt;		&lt;br /&gt;// create a new ajaxObject, give it a url and tell it to call fin when it&lt;br /&gt;// gets data back from the server.  When we initiate the ajax call we'll&lt;br /&gt;// be passing 'id=user4379' to the server.		&lt;br /&gt;var test2 = new ajaxObject('http://someurl.com/program.php',fin);&lt;br /&gt;    test2.update('id=user4379');&lt;br /&gt;		&lt;br /&gt;// create a new ajaxObject but we'll overwrite the callback function inside&lt;br /&gt;// the object to more tightly bind the object with the response hanlder.&lt;br /&gt;var test3 = new ajaxObject('http://someurl.com/prog.py', fin);&lt;br /&gt;    test3.callback = function (responseTxt, responseStat) {&lt;br /&gt;      // we'll do something to process the data here.&lt;br /&gt;      document.getElementById('someDiv').innerHTML=responseTxt;&lt;br /&gt;    }&lt;br /&gt;    test3.update('coolData=47&amp;userId=user49&amp;log=true');	&lt;br /&gt;		&lt;br /&gt;// create a new ajaxObject and pass the data to the server (in update) as&lt;br /&gt;// a POST method instead of a GET method.&lt;br /&gt;var test4 = new ajaxObject('http://someurl.com/postit.cgi', fin);&lt;br /&gt;    test4.update('coolData=47&amp;userId=user49&amp;log=true','POST');	&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function ajaxObject(url, callbackFunction) {&lt;br /&gt;  var that=this;      &lt;br /&gt;  this.updating = false;&lt;br /&gt;  this.abort = function() {&lt;br /&gt;    if (that.updating) {&lt;br /&gt;      that.updating=false;&lt;br /&gt;      that.AJAX.abort();&lt;br /&gt;      that.AJAX=null;&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  this.update = function(passData,postMethod) { &lt;br /&gt;    if (that.updating) { return false; }&lt;br /&gt;    that.AJAX = null;                          &lt;br /&gt;    if (window.XMLHttpRequest) {              &lt;br /&gt;      that.AJAX=new XMLHttpRequest();              &lt;br /&gt;    } else {                                  &lt;br /&gt;      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;    }                                             &lt;br /&gt;    if (that.AJAX==null) {                             &lt;br /&gt;      return false;                               &lt;br /&gt;    } else {&lt;br /&gt;      that.AJAX.onreadystatechange = function() {  &lt;br /&gt;        if (that.AJAX.readyState==4) {             &lt;br /&gt;          that.updating=false;                &lt;br /&gt;          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        &lt;br /&gt;          that.AJAX=null;                                         &lt;br /&gt;        }                                                      &lt;br /&gt;      }                                                        &lt;br /&gt;      that.updating = new Date();                              &lt;br /&gt;      if (/post/i.test(postMethod)) {&lt;br /&gt;        var uri=urlCall+'?'+that.updating.getTime();&lt;br /&gt;        that.AJAX.open("POST", uri, true);&lt;br /&gt;        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");&lt;br /&gt;        that.AJAX.send(passData);&lt;br /&gt;      } else {&lt;br /&gt;        var uri=urlCall+'?'+passData+'&amp;timestamp='+(that.updating.getTime()); &lt;br /&gt;        that.AJAX.open("GET", uri, true);                             &lt;br /&gt;        that.AJAX.send(null);                                         &lt;br /&gt;      }              &lt;br /&gt;      return true;                                             &lt;br /&gt;    }                                                                           &lt;br /&gt;  }&lt;br /&gt;  var urlCall = url;        &lt;br /&gt;  this.callback = callbackFunction || function () { };&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 09 Mar 2007 03:06:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3650</guid>
      <author>pcx99 (Patrick)</author>
    </item>
    <item>
      <title>Prototype-based Ruby</title>
      <link>http://snippets.dzone.com/posts/show/3378</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;br /&gt;# From: http://programming.reddit.com/info/ob4m/comments/cobr4&lt;br /&gt;# Author: Brian Mitchell&lt;br /&gt;# cf. http://t-a-w.blogspot.com/2006/10/prototype-based-ruby.html&lt;br /&gt;&lt;br /&gt;Proto = Class.new(Class)    # Beware: magic.&lt;br /&gt;def Proto.clone&lt;br /&gt;  Class.new(self)&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# Demo&lt;br /&gt;a = Proto.clone&lt;br /&gt;def a.f&lt;br /&gt;  puts 42&lt;br /&gt;end&lt;br /&gt;a.f                     #=&gt; 42&lt;br /&gt;&lt;br /&gt;b = a.clone&lt;br /&gt;b.f                     #=&gt; 42&lt;br /&gt;def b.f&lt;br /&gt;  puts 43&lt;br /&gt;end&lt;br /&gt;a.f                      #=&gt; 42&lt;br /&gt;b.f                      #=&gt; 43&lt;br /&gt;&lt;br /&gt;def a.g&lt;br /&gt;  "Hello differential inheritance"&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;bool_val = (a.g == b.g)&lt;br /&gt;p bool_val                #=&gt; true&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# From: http://www.ruby-forum.com/topic/94696&lt;br /&gt;# cf. http://tech.rufy.com/2006/06/classes-are-just-prototype-pattern.html&lt;br /&gt;&lt;br /&gt;AnimalSounds = Module.new&lt;br /&gt;&lt;br /&gt;AnimalSounds.class_eval %q!&lt;br /&gt;def createSound(attr_name)&lt;br /&gt;class_eval &lt;&lt;-EOS&lt;br /&gt;   #def self.#{attr_name};  puts "class method '#{attr_name}' called"; end &lt;br /&gt;   def self.#{attr_name}(arg = nil) &lt;br /&gt;      str = "class method '#{attr_name}' of class #{self.inspect} called"&lt;br /&gt;      arg ? (puts str + " with " + arg.to_s) : (puts str)&lt;br /&gt;   end&lt;br /&gt;EOS&lt;br /&gt;end!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;puts&lt;br /&gt;p AnimalSounds&lt;br /&gt;p AnimalSounds.class&lt;br /&gt;p AnimalSounds.class.superclass&lt;br /&gt;p AnimalSounds.class.ancestors&lt;br /&gt;p AnimalSounds.singleton_methods&lt;br /&gt;puts&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Pet = Object.clone.extend(AnimalSounds)    &lt;br /&gt;Pet.createSound("meow")                    # create a class method&lt;br /&gt;Pet.meow                                   &lt;br /&gt;Pet.meow("argument")      &lt;br /&gt;&lt;br /&gt;p Pet&lt;br /&gt;p Pet.class&lt;br /&gt;p Pet.class.superclass&lt;br /&gt;p Pet.class.ancestors&lt;br /&gt;p Pet.singleton_methods&lt;br /&gt;puts&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;fido = Pet.clone           &lt;br /&gt;fido.meow           &lt;br /&gt;fido.meow("argument")&lt;br /&gt;fido.createSound("woof")    &lt;br /&gt;fido.woof&lt;br /&gt;fido.woof("argument")&lt;br /&gt;puts&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;fido2 = fido.clone                        &lt;br /&gt;fido2.woof&lt;br /&gt;fido2.woof("argument")&lt;br /&gt;fido2.createSound("woof2")                 &lt;br /&gt;fido2.woof2&lt;br /&gt;fido2.woof2("argument")&lt;br /&gt;&lt;br /&gt;puts&lt;br /&gt;p Pet.singleton_methods&lt;br /&gt;p fido.singleton_methods&lt;br /&gt;p fido2.singleton_methods&lt;br /&gt;puts&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 27 Jan 2007 20:02:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3378</guid>
      <author>ntk ()</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>longest-field-name - Return the longest word in the object, as a string</title>
      <link>http://snippets.dzone.com/posts/show/2768</link>
      <description>&lt;code&gt;&lt;br /&gt;longest-field-name: func [&lt;br /&gt;    "Return the longest word in the object, as a string."&lt;br /&gt;    obj [object!]&lt;br /&gt;][&lt;br /&gt;    last sort-by-length change-all remove first obj :form&lt;br /&gt;]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 02 Oct 2006 23:04:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2768</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>words-like - Returns a block of words in the object that match the given pattern.</title>
      <link>http://snippets.dzone.com/posts/show/2752</link>
      <description>&lt;code&gt;&lt;br /&gt;words-like: func [&lt;br /&gt;    "Returns a block of words in the object that match the given pattern."&lt;br /&gt;    object  [object!]&lt;br /&gt;    pattern [word! any-string!]&lt;br /&gt;    ;??? Add an /unbound refinement&lt;br /&gt;][&lt;br /&gt;    pattern: join form pattern "*"&lt;br /&gt;    collect w [&lt;br /&gt;        foreach word next first object [&lt;br /&gt;            if find/match/any form word pattern [w: bind word in object 'self]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 01 Oct 2006 22:25:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2752</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>save Data with db4o</title>
      <link>http://snippets.dzone.com/posts/show/2613</link>
      <description>// save Data with db4o&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import com.db4o.Db4o;&lt;br /&gt;import com.db4o.ObjectContainer;&lt;br /&gt;import com.db4o.ObjectSet;&lt;br /&gt;import com.db4o.query.Query;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;public class DbUtil {&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;  * save someObject to DB&lt;br /&gt;  */&lt;br /&gt;  public static void saveData(SomeClass someObject, String DbFilename) {&lt;br /&gt;    ObjectContainer db=Db4o.openFile(DbFilename);&lt;br /&gt;    try {&lt;br /&gt;      db.set(idGenerator);&lt;br /&gt;    }&lt;br /&gt;    finally {&lt;br /&gt;      db.close();&lt;br /&gt;    }&lt;br /&gt;  } //saveData(SomeClass ..)&lt;br /&gt;&lt;br /&gt;  ..&lt;br /&gt;&lt;br /&gt;} //DbUtil&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 17 Sep 2006 19:22:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2613</guid>
      <author>ovhaag (Oliver Haag)</author>
    </item>
  </channel>
</rss>
