<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8036882423231997944</id><updated>2011-12-23T16:58:50.179-08:00</updated><title type='text'>Extending and Enhancing Ruby and Rails</title><subtitle type='html'>helping you venture into the unknown.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ericsteeninfo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ericsteeninfo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Eric Steen</name><uri>http://www.blogger.com/profile/14741338610361814527</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8036882423231997944.post-6353482837842480928</id><published>2010-09-05T21:38:00.000-07:00</published><updated>2011-04-21T11:47:03.225-07:00</updated><title type='text'>Skipping Active Record Callbacks in Rails</title><content type='html'>&lt;p&gt;It is often desirable to skip ActiveRecord callbacks defined on rails model objects. For a somewhat contrived(but true life) example, let's say we have an ActiveRecord::Observer that defines an after_save callback which can be called on the observed models. Sort of like &lt;i&gt;"pseudo polymorphic callback inheritance"?&lt;/i&gt; &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Updating, saving, validating, or performing other ActiveRecord operations on our model object inside the callback itself can cause stack overflows and other undesired behavior to occur, and it's not always obvious where the problem is occuring.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;One elegant solution to avoiding this particular problem can be achieved by extending ActiveRecord::Observer with a &lt;i&gt;skip_callback&lt;/i&gt; method. With the following code, we get a singleton method on our observer model. This method accepts a block of (almost) any arbitrary code. The method first stubs out our callback as a boolean, yields to our code, and then re-defines the callback method as originally defined:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;i&gt;config/initializers/active_record_observer_extensions.rb:&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre name="code" class="ruby"&gt;class ActiveRecord::Observer&lt;br /&gt;  def self.skip_callback(callback, &amp;block)&lt;br /&gt;    method = instance_method(callback)&lt;br /&gt;    remove_method(callback) if respond_to?(callback)&lt;br /&gt;    define_method(callback){ true }&lt;br /&gt;    yield&lt;br /&gt;    remove_method(callback)&lt;br /&gt;    define_method(callback, method)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Where I am assuming your observer looks something like this:&lt;/p&gt;&lt;p&gt;&lt;i&gt;app/models/fyle_observer.rb:&lt;br /&gt;&lt;/i&gt;&lt;/p&gt;&lt;pre name="code" class="ruby"&gt;class FyleObserver &lt; ActiveRecord::Observer&lt;br /&gt;  observe :script, :document, :image&lt;br /&gt;&lt;br /&gt;  def after_save(observed)&lt;br /&gt;      ...assign upload attributes, etc...&lt;br /&gt;      FyleObserver.skip_callback(:after_save) do&lt;br /&gt;        Fyle.update_attributes(:mime_type =&gt; 'application/msword')&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Code Explanation:&lt;/b&gt;&lt;/i&gt; If you tried to update Fyle inside the after_save method in FyleObserver without skipping the callback, your application would surely freeze up because you would trigger an endless chain of after_save callbacks(like standing between two mirrors and seeing infinity!) Here's what happens in the skip_callback method: First the callback is placed into the temp variable named &lt;i&gt;method&lt;/i&gt;. Then the original callback named as a parameter is removed from the ActiveRecord::Observer class if it responds to it. Next it is defined as a simple method that returns true. Then the code comprising our block is evaluated before finally the simple method is removed and the original re-defined.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8036882423231997944-6353482837842480928?l=ericsteeninfo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ericsteeninfo.blogspot.com/feeds/6353482837842480928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/09/skipping-callbacks-in-rails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/6353482837842480928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/6353482837842480928'/><link rel='alternate' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/09/skipping-callbacks-in-rails.html' title='Skipping Active Record Callbacks in Rails'/><author><name>Eric Steen</name><uri>http://www.blogger.com/profile/14741338610361814527</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8036882423231997944.post-7214699675379194470</id><published>2010-08-24T21:19:00.000-07:00</published><updated>2010-08-24T21:20:27.485-07:00</updated><title type='text'>Overriding ActiveRecord methods</title><content type='html'>I recently needed to delete a file along with an active record model, and I wasn't sure about overriding rails' ActiveRecord::Base#delete method, but the following code worked without a hitch in my model:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="ruby"&gt;def delete&lt;br /&gt; File.delete( File.join( Rails.root, fyle.path ) )&lt;br /&gt; super&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;However, overriding the initialize method in the same way is not recommended unless you really know what you are doing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8036882423231997944-7214699675379194470?l=ericsteeninfo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ericsteeninfo.blogspot.com/feeds/7214699675379194470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/08/overriding-activerecord-methods.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/7214699675379194470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/7214699675379194470'/><link rel='alternate' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/08/overriding-activerecord-methods.html' title='Overriding ActiveRecord methods'/><author><name>Eric Steen</name><uri>http://www.blogger.com/profile/14741338610361814527</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8036882423231997944.post-2050675952745022964</id><published>2010-01-24T16:07:00.000-08:00</published><updated>2010-03-27T11:27:40.665-07:00</updated><title type='text'>Grade Point Median</title><content type='html'>Before dropping out of graduate school, I did my B.S. in Statistics with a minor in business administration. My real focus was computer science, however, and I was learning programming when I could have been doing better homework. I graduated with a 3.1 gpa, but I argue that a GPM(grade point median) is a better way to calculate an aggregate of academic performance. In my case, two F's during one bad quarter in 2005 during a breakup with my fiance are high influence points unrelated to academic ability. I think even a 5% trimmed mean would put me above a 3.3 gpa.&lt;br /&gt;&lt;br /&gt;The point is, although some academics are pretty good at analyzing their student population, along with individual track records, and grading accordingly, few students are going to print a stable performance history. Life is too volatile. For the few who are regularly outstanding, they won't lose anything by cutting a few of their worst and best grades. But for the unfortunate students experiencing the turbulence of life, a GPM or trimmed mean provides a more accurate representation of typical performance.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8036882423231997944-2050675952745022964?l=ericsteeninfo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ericsteeninfo.blogspot.com/feeds/2050675952745022964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/01/before-dropping-out-of-graduate-school.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/2050675952745022964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/2050675952745022964'/><link rel='alternate' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/01/before-dropping-out-of-graduate-school.html' title='Grade Point Median'/><author><name>Eric Steen</name><uri>http://www.blogger.com/profile/14741338610361814527</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8036882423231997944.post-5032338554601893130</id><published>2010-01-23T23:04:00.000-08:00</published><updated>2010-03-27T11:35:29.754-07:00</updated><title type='text'>Data mining gets a bad rap</title><content type='html'>Yes, the business landscape is very competitive. Every day we hear about new business intelligence solutions and advancements in computer technology that make us wonder just what the heck is going on in some of the nations largest corporations with the data they gather from us. When I hear another appraiser complain about how data mining is destroying their livelihood, I feel sympathetic to their struggle in this horrible market, but I also feel the urge to shed some light on the virtues of data mining.&lt;br /&gt;&lt;br /&gt;Data mining and artificial intelligence in general may give someone the resources to be evil, but the same thing has been said about computers(remember apple's 1984 commercial about big brother?). I don't see big brother cracking down on the masses, in fact, isn't google cracking down on china for censorship? Many people have gotten a call from their credit card company about fraudulent activity on their accounts. Guess how the credit card company found out about the fraud? Yep. More than likely, Data mining. Guess how some important advancements in technology, including medical advancements, are discovered? Data mining.&lt;br /&gt;&lt;br /&gt;So next time you hear someone extolling the evils of data mining and how its ruining their livelihood, ask them why they haven't yet built a web crawler to put google out of business, or designed a low overhead online financial institution. Maybe they just need a nudge in the right direction.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8036882423231997944-5032338554601893130?l=ericsteeninfo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ericsteeninfo.blogspot.com/feeds/5032338554601893130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/01/data-mining-gets-bad-rap.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/5032338554601893130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/5032338554601893130'/><link rel='alternate' type='text/html' href='http://ericsteeninfo.blogspot.com/2010/01/data-mining-gets-bad-rap.html' title='Data mining gets a bad rap'/><author><name>Eric Steen</name><uri>http://www.blogger.com/profile/14741338610361814527</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8036882423231997944.post-8908168992760078864</id><published>2009-11-13T15:15:00.001-08:00</published><updated>2010-09-06T10:02:47.600-07:00</updated><title type='text'>New Models of the Organization</title><content type='html'>I have been doing a lot of thinking lately about how many existing models of the organization are insufficient in addressing some important sociological issues. Most important of these, I believe, are the general desire for autonomy, individuality, and self-expression. I feel that most people appreciate being actively involved in the organizational process. Most experts with deep knowledge of human behavior agree that human beings put enormous value on independence and self-expression. So then why is it that so many organizations are engineered in such a way as to hinder these very basic societal needs instead of fostering them? Much new research points to the latter as more effective in the achievement of a vast array of organizational objectives, most important of which may be improvements in marketing and market prediction, research and development, administrative and operational processes, communications, and human capital risk management.&lt;br /&gt;&lt;br /&gt;In this new technological age of data mining, crowdsourcing, and social network analysis, many companies still haven't realized the enormous gains to be achieved through systematic de-centralization and the enabling of self-organizing teams. It is well accepted in operations research, for example, that the worst team dynamics result from appointed teams and over-direction from outsiders. It is also a fact that the most successfully innovative research and development teams in history were given virtually non-existent timelines. As someone who has worked for many years under multiple strict daily production deadlines appraising real estate, I see major implications here in terms of quality control. It goes without saying that the highest form of motivation is that which is generated internally, and many 'incentive programs' are way off the mark.&lt;br /&gt;&lt;br /&gt;While the most successful organizations today have wholeheartedly embraced the new paradigm, there are many destined to suffer through the process of Creative Destruction. Fortunately, models are made to be destroyed so we can learn from them, and the stakes are higher now than ever.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8036882423231997944-8908168992760078864?l=ericsteeninfo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ericsteeninfo.blogspot.com/feeds/8908168992760078864/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ericsteeninfo.blogspot.com/2009/11/new-models-of-organization.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/8908168992760078864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8036882423231997944/posts/default/8908168992760078864'/><link rel='alternate' type='text/html' href='http://ericsteeninfo.blogspot.com/2009/11/new-models-of-organization.html' title='New Models of the Organization'/><author><name>Eric Steen</name><uri>http://www.blogger.com/profile/14741338610361814527</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
