<?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-1711230518531562941</id><updated>2011-07-13T22:08:32.811-07:00</updated><category term='images'/><category term='jQuery'/><category term='plugins'/><category term='filmstrip'/><title type='text'>aligator crockettdile</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1711230518531562941.post-5632823818576521709</id><published>2010-05-14T10:16:00.000-07:00</published><updated>2010-05-14T11:19:23.234-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='filmstrip'/><category scheme='http://www.blogger.com/atom/ns#' term='plugins'/><category scheme='http://www.blogger.com/atom/ns#' term='images'/><category scheme='http://www.blogger.com/atom/ns#' term='jQuery'/><title type='text'>jQuery filmstrips</title><content type='html'>I needed a simple filmstrip plugin for the when I was building &lt;a href="http://demo.honk.com/new_styles/dodge/challenger/2010/2dr-cpe-se"&gt;a page for honk.com&lt;/a&gt; (see the "Honk Users also look at" section). I browsed &lt;a href="http://www.queness.com/post/3141/10-image-galleries-jquery-script-with-thumbnail-filmstrip"&gt;several plugins&lt;/a&gt;, and tried two: &lt;a href="http://spaceforaname.com/galleryview"&gt;GalleryView&lt;/a&gt;, and &lt;a href="http://flowplayer.org/tools/scrollable/index.html"&gt;Scrollable&lt;/a&gt;, and ended up using Scrollable.&lt;br /&gt;&lt;br /&gt;I had no need for a gallery, mouse-over animations, or timed slideshow options, but most of the tools I found that included filmstrip capability also included many or all of these extraneous features which I would have to disable to get my desired result. What I &lt;span style="font-style:italic;"&gt;did&lt;/span&gt; need was built in next/previous behavior (but not assets!) and the ability to style the slideshow elements and link them to an external page, rather than a gallery display.&lt;br /&gt;&lt;br /&gt;My first attempt used GalleryView, which is not really the best fit for the requirements listed above. While I suspect this is a lovely gallery tool if what you actually want is a photo gallery, I ended up sifting through lots and lots of unnecessary (for my purposes) code in order to strip away the features I didn't need, and while I was left with a working filmstrip, I couldn't style the buttons or filmstrip elements without breaking the functionality of the filmstrip. On top of these woes, I couldn't use anything but 22px x 22px images for the browse buttons. So I scrapped my GalleryView attempt and started over with Scrollable at the suggestion of a coworker.&lt;br /&gt;&lt;br /&gt;Scrollable takes the opposite approach: it starts with a simple filmstrip and you add more plugins if you want more functionality. It was perfect for my purposes because it consisted of relatively little code, and allowed me to make the scrollable items whatever kind of element I want, with fast setup and clear &lt;a href="http://flowplayer.org/tools/demos/scrollable/index.html"&gt;documentation&lt;/a&gt;. I could tell with very little time commitment that it was going to allow me to build what I needed. The browse buttons could be any size or kind of element I wanted - they are just tagged with a class. The one inflexible requirement is that you must structure your items in divs containing preset numbers of filmstrip elements. I can't say much about the functionality of Scrollable's gallery setup, animation, or other options, because I didn't need them, and so didn't have to touch them, which is the way it should be!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-5632823818576521709?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/5632823818576521709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/05/jquery-filmstrips.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/5632823818576521709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/5632823818576521709'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/05/jquery-filmstrips.html' title='jQuery filmstrips'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-1951380527780714910</id><published>2010-04-30T15:00:00.000-07:00</published><updated>2010-04-30T16:13:32.992-07:00</updated><title type='text'>Jelly for Unobtrusive Javascript</title><content type='html'>There seems to be a lot more talk about &lt;a href="http://labs.adobe.com/technologies/spry/articles/best_practices/separating_behavior.html"&gt;unobtrusive javascript&lt;/a&gt; than actual practice. This is probably due to the fact that despite the benefits of unobtrusive javascript, it can be a hassle to adhere to the &lt;a href="http://icant.co.uk/articles/seven-rules-of-unobtrusive-javascript/"&gt;standards of unobtrusiveness&lt;/a&gt;. It's so easy to just inline some code when you need it, sticking it right in your html, rather than use a hook and assign your script to a DOM element. However, if you do it the quick dirty way, it's both hard to test your javascript, and hard to mix up or swap out visual elements without touching (and possibly breaking) the behavior of your inline javascript. But don't fret, there are tools out there to help you keep your html clean, and your javascript testable.&lt;br /&gt;&lt;br /&gt;At Honk, we use Pivotal's &lt;span style="font-weight:bold;"&gt;jelly&lt;/span&gt; by Brian Takita to integrate javascript into our rails app. Jelly gives you the tools you need to attach scripts, watch for on-page events, and handle callbacks. With jelly, you keep your javascript in seperate .js files, and attach it using the method attach_javascript_component("SomeJS", *params), which will call the init function of your component using the params passed in. This is just the start - there are more methods for setting up observers and triggering responses. You can read in detail about jelly &lt;a href="http://github.com/pivotal/jelly"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-1951380527780714910?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/1951380527780714910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/04/jelly-for-unobtrusive-javascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/1951380527780714910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/1951380527780714910'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/04/jelly-for-unobtrusive-javascript.html' title='Jelly for Unobtrusive Javascript'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-8906968051689901158</id><published>2010-04-22T14:16:00.000-07:00</published><updated>2010-04-22T15:28:59.584-07:00</updated><title type='text'>More Sass.</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Variables, Part II:&lt;/span&gt;&lt;br&gt;&lt;br /&gt;Let me share with you some things that might be obvious, but I'll point them out just in case you are unnecessarily constraining yourself: &lt;br /&gt;&lt;br /&gt;&lt;a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#optional_assignment_"&gt;Optional assignment&lt;/a&gt; is supported in Sass. So go ahead and |= your heart out.&lt;br /&gt;Also, &lt;a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#arguments"&gt;Default arguments&lt;/a&gt; are supported for your Sass mixins. Just provide a default value the same way you would for ruby methods.&lt;br /&gt;&lt;br /&gt;This one might be less obvious: You can use ruby-style string &lt;a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#interpolation_"&gt;interpolation&lt;/a&gt; on variables, even in the middle of selectors or properties. I was pleasantly surprised to discover that it is totally acceptable to do something like&lt;br /&gt;&lt;pre&gt;&lt;blockquote&gt;&lt;br /&gt;p.#{!color_of_my_words}_text&lt;br /&gt;  color: !color_of_my_words&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;Which essentially amounts to "make blue_text blue." The ability to interpolate variables makes it easy to write template methods that construct CSS given just the few variables you care about changing.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Comments:&lt;/span&gt;&lt;br&gt;&lt;br /&gt;There are two kinds of &lt;a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#comments"&gt;comments&lt;/a&gt; in Sass. If you want your comment to show up in the CSS compiled document in addition to your Sass file, use &lt;span style="font-weight:bold;"&gt;/*&lt;/span&gt;, as in:&lt;br /&gt;&lt;pre&gt;&lt;blockquote&gt;&lt;br /&gt;/* Hey, I'm totally all up in your CSS. &lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;Or, if you want the comment to show up in your Sass file, but not in the CSS document, use &lt;span style="font-weight:bold;"&gt;//&lt;/span&gt;, as in:&lt;br /&gt;&lt;pre&gt;&lt;blockquote&gt;&lt;br /&gt;// Ssh, y'all can't see me except for right in this here Sass.&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;I find I use the quieter version of the comment almost exclusively, but what you use will probably depend on whether other developers will be looking at your Sass, or at the CSS it produces.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-8906968051689901158?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/8906968051689901158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/04/more-about-sass.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/8906968051689901158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/8906968051689901158'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/04/more-about-sass.html' title='More Sass.'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-7497872188603098550</id><published>2010-04-18T21:26:00.000-07:00</published><updated>2010-04-18T22:33:18.101-07:00</updated><title type='text'>Sass.</title><content type='html'>If you work with CSS, you owe it to yourself to check out &lt;a href="http://sass-lang.com/"&gt;SASS&lt;/a&gt;, or Syntactically Awesome Style Sheets. That's right, the A is for awesome. Here's why:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;It's pretty.&lt;/span&gt; Sass drops all the curly brackets and semi-colons, and just uses white space to figure out which property-value declarations go with which selectors. This makes for a very clean looking syntax. But it's hardly the only reason Sass is neat.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;It's DRY.&lt;/span&gt; As in Don't Repeat Yourself. For one, selectors may be nested within one another, avoiding the need to repeat selectors for more specific cases. If you want to refer to an li with a "my_list" class within a div, it's as simple as this:&lt;br /&gt;&lt;pre&gt;&lt;blockquote&gt;&lt;br /&gt;body&lt;br /&gt;  background-color: white&lt;br /&gt;&lt;br /&gt;  div&lt;br /&gt;    display: block&lt;br /&gt;    li.my_list&lt;br /&gt;      margin-left: 10px&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;Just throw in any other declarations below the selector you want them to apply to, and at the proper indentation. In RubyMine, groups of selectors are even collapsible, so you can keep irrelevant ones out of view.&lt;br /&gt;&lt;br /&gt;For two, it lets you use variables, which look like "!variable". This means you don't have to go around changing common values in multiple places, but it gets better - you can perform arithmetic operations on variables. You can set up the width of a div to be automatically adjusted if you change your margin variables, for example. This is really handy for value tweaking when you're fine tuning your styling.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Mixins.&lt;/span&gt; Are neat. Define a mixin with "=my_mixin" and use it with "+my_mixin". Use it all over the place. You can use it way more than once, but you secretly only have to write it once (shhh.) But it gets awesomer. Mixins can take variables, as in "=my_mixin(!var)". You can use mixins across multiple pages that share similarly styled elements, saving yourself a lot of work.&lt;br /&gt;&lt;br /&gt;Get Sassed. I swear you won't regret it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-7497872188603098550?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/7497872188603098550/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/04/sass.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/7497872188603098550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/7497872188603098550'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/04/sass.html' title='Sass.'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-4018208228752289007</id><published>2010-04-12T09:46:00.000-07:00</published><updated>2010-04-12T12:40:32.692-07:00</updated><title type='text'>ActiveRecord and MySQL</title><content type='html'>The way we interact with data from the rails side of things is conveniently object-oriented. Groups of objects are stored in tables, along with information about how they are connected to other objects. A table contains all instances of a given class as rows (one row per object), and is always pluralized.  So we might have a table containing all of our ArchEnemy objects, called arch_enemies. (By the way, there is a touch of rails magic happening here - rails knows that “people” is the plural of “person”, for example.)&lt;br /&gt;&lt;br /&gt;Without rails, however, the convenience of object-orientation is not built in to the database. Chances are the database is a relational database (like MySQL, Postgres, or SQLite). Without the convenience of rails, data can be accessed using the &lt;a href="http://www.kitebird.com/articles/ruby-mysql.html#TOC_3"&gt;ruby MySQL module&lt;/a&gt;, which has built in methods to establish connections, run queries, and interact with the resulting datasets returned by queries.&lt;br /&gt;&lt;br /&gt;If we want to interact with the database without having to write SQL queries, we need a layer of logic to map classes to tables, objects to rows, and attributes to columns, so that we can interact with the database as if it were object-oriented. The layer that handles this is doing object-relational mapping, or ORM. In rails, the built in ORM layer is &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html"&gt;ActiveRecord&lt;/a&gt;. Using ActiveRecord you can easily find information using methods like first, find, and find_all, and change information in the database using save, or update_attribute (which I use often for test purposes to directly change an attribute while circumventing a save and its associated validations.)&lt;br /&gt;&lt;br /&gt;Accessing data through the ActiveRecord layer is fine in many cases, but let’s say you need to add, retrieve, or modify a large amount of data, or maybe you want to use a massive CSV from an outside source, and are only interested in extracting portions of the data. In these cases, the usual methods can be unreasonably slow, and you will probably want to use SQL directly. This can be done using &lt;pre&gt;&lt;blockquote&gt;ActiveRecord::Base.execute(some_sql)&lt;/blockquote&gt;&lt;/pre&gt; To safeguard against SQL injection attacks, it’s a good idea to first run your query through sanitize_sql as such: &lt;br /&gt;&lt;pre&gt;&lt;blockquote&gt;ActiveRecord::Base.sanitize_sql(some_sql))&lt;/blockquote&gt;&lt;/pre&gt;&lt;br /&gt;ActiveRecord's execute method returns a Mysql::Result object, which is a result set. Result sets consists of a set of rows from the database, and a cursor that points to the current row. In order to access data from a row in a result set, that row must be the current row, and the cursor must iterate over all previous rows first. This makes it extremely expensive time-wise to access a particular attribute repeatedly (say inside a loop), and it can be very advantageous to assign data to a local variable if it is going to be needed multiple times during a loop.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-4018208228752289007?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/4018208228752289007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/04/activerecord-and-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/4018208228752289007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/4018208228752289007'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/04/activerecord-and-mysql.html' title='ActiveRecord and MySQL'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-3725074192539137728</id><published>2010-04-02T12:18:00.000-07:00</published><updated>2010-04-02T12:27:49.976-07:00</updated><title type='text'>lambda</title><content type='html'>Although they aren’t as common as blocks in ruby, I’ve been encountering some lambda usages, and usually find myself proper confused. This is undoubtedly because I have an incomplete understanding of closures, which goes something like this: I think of a closure as a bit of code that has a shorter lifespan than the variables it accesses. I understand blocks to be closures that are defined in the context of a method call, and by comparison, lambdas seem to be closures that are not dependent on a method call, but can rather be simply stated, assigned to a variable, or executed on the spot. You can explicitly pass a lambda as a block to a method like this:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;br /&gt;my_block = lambda {|x| puts x}&lt;br /&gt;some_method(&amp;my_block)&lt;/blockquote&gt;&lt;/pre&gt;&lt;br /&gt;Where my understanding gets especially fuzzy is how lambdas differ from procs - from what I can tell, “lambda” is *nearly* equivalent to “Proc.new”, except that it handles returns differently, as seen in the ruby example on &lt;a href="http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semantics"&gt;Wikipedia's closure page&lt;/a&gt;. &lt;br /&gt;I’d like to see some useful applications of lambda, maybe this would help me "get it." So far, the most common usage of lambda that I’ve seen in the last few weeks is in rspec tests to do something like this:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;br /&gt;it “should create a new customer entry” do&lt;br /&gt;    lambda do&lt;br /&gt;        make_new_customer(“John Doe”)&lt;br /&gt;    end.should change(Customer, :count).by(1)&lt;br /&gt;end&lt;/blockquote&gt;&lt;/pre&gt;&lt;br /&gt;which conveniently allows you to check that the count of your Customers changed without having to explicitly offload the count, call the method, and then check it again. (The &lt;a href="http://rspec.rubyforge.org/rspec/1.2.6/"&gt;rspec matcher&lt;/a&gt; “change” evaluates the provided value before and after the lambda.) For now, I'll keep my eyes out for more lambdas.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-3725074192539137728?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/3725074192539137728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/04/lambda.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/3725074192539137728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/3725074192539137728'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/04/lambda.html' title='lambda'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-1489947517360787450</id><published>2010-03-26T11:32:00.000-07:00</published><updated>2010-03-26T12:02:07.944-07:00</updated><title type='text'>the magical method_missing</title><content type='html'>In a typical method call, ruby will send the method name and arguments as a message to the object on which the method is being called. Most of the time, this will be an existing method, but if it is not, ruby calls a method called method_missing.  The default behavior of method_missing is to throw a NoMethodError, which is exactly what you will get if you try, for example “i’m a string”.bglarbl.&lt;br /&gt;&lt;br /&gt;Now, like any other method, method_missing can be overridden. A common rails use, and how I first discovered method_missing, is to simplify database queries and make them more readable. In rails, courtesy of method_missing, you can find_by_any_arbitrary_attribute without having to explicitly write the method to do so - as long as “any_arbitrary_attribute” is a column in your table, method_missing will take care of the rest.&lt;br /&gt;&lt;br /&gt;You can do all sorts of tricky things here, which is both an expressive and dangerous feature (an increasingly recurring theme, I find, the more I learn about ruby.)  You can do some really neat, useful things, like implement domain specific languages, but you can also do some really stupid, crazy-making things, like accidentally return “true” every time you call a non-existent, or even just a misspelled, method. Less dangerous, but still mildly annoying, is the fact that overriding method_missing can easily cause an object to respond to a method, while respond_to? will still return false for that method name, and the method will not show up in the array .methods returns. The big idea here is that overriding method_missing makes it really easy to make debugging really hard.&lt;br /&gt;&lt;br /&gt;There are some ways to avoid making debugging a pain, however. One is to also override respond_to. Alternatively, depending on the expected usage, you might want to have method_missing dynamically construct a method, which will add the method to the methods list, and cause the expected behavior for respond_to.  After some failed attempts at using define_method to do this, here’s one way to do this that works:&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;br /&gt;class MethodMissingTest&lt;br /&gt;    def method_missing(method_name)&lt;br /&gt;        method_source = "&lt;br /&gt;            def #{method_name}&lt;br /&gt;                puts 'added a method'&lt;br /&gt;            end&lt;br /&gt;        " &lt;br /&gt;        instance_eval(method_source)&lt;br /&gt;        send(method_name)&lt;br /&gt;    end&lt;br /&gt;end&lt;/blockquote&gt;&lt;/pre&gt;&lt;br /&gt;Now, you can make a new instance of MethodMissingTest - let's call it "feed_me_methods" and call any random string as a method on feed_me_methods, and feed_me_methods will now actually contain a method by that name, rather than just act like it does. &lt;br /&gt;&lt;br /&gt;If you want to play some more with this, Sarah Allen has made a fun test-first &lt;a href="http://github.com/ultrasaurus/test-first-teaching/tree/master/learn_ruby/builder/"&gt;xml tag-generator&lt;/a&gt; exercise. Cheers, and remember to method_missing responsibly!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-1489947517360787450?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/1489947517360787450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/03/magical-methodmissing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/1489947517360787450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/1489947517360787450'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/03/magical-methodmissing.html' title='the magical method_missing'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-3437716425236194392</id><published>2010-03-22T14:52:00.000-07:00</published><updated>2010-03-22T15:02:44.903-07:00</updated><title type='text'>infinite recursion</title><content type='html'>If you shovel an array into itself, it causes an infinite recursion. Watch me get dizzy in irb:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;blockquote&gt;&gt;&gt; whoa = ["one", "two", "three"]&lt;br /&gt;=&gt; ["one", "two", "three"]&lt;br /&gt;&gt;&gt; whoa &lt;&lt; whoa&lt;br /&gt;=&gt; ["one", "two", "three", [...]]&lt;br /&gt;&gt;&gt; whoa[3]&lt;br /&gt;=&gt; ["one", "two", "three", [...]]&lt;br /&gt;&gt;&gt; whoa[3][3][3]&lt;br /&gt;=&gt; ["one", "two", "three", [...]]&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;by the set of all sets, ain't that cool.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-3437716425236194392?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/3437716425236194392/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/03/infinite-recursion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/3437716425236194392'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/3437716425236194392'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/03/infinite-recursion.html' title='infinite recursion'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-7395420361074797516</id><published>2010-03-22T14:01:00.001-07:00</published><updated>2010-03-22T14:52:13.124-07:00</updated><title type='text'>RubyMine shortcuts for vim addicts</title><content type='html'>I'm a long-time vim user, but I've been using RubyMine recently for work. While I'm getting better and better at keeping the force of habit "3yy j p :wq" kind of nonsense out of my code, I still crave the lazyfingered awesomeness.  Still, I've found some neat shortcuts in RubyMine that almost make up for my stubborn vim withdrawals.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Find&lt;/span&gt;: RubyMine will find instances of a string in the current working file if you hit Ctrl-F, and will do a project-wide search if you hit Ctrl-Shift-F. I was particularly thrilled to discover Ctrl-Alt-B, which will search for the implementation of a method call, which is awesome, even if it doesn't work all the time...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Selecting&lt;/span&gt;: holding down control and hitting "." will select blocks of code, and subsequently hitting "." will work its way up the nesting tree selecting parents of parents. This is especially useful in Rspec, for selecting all contexts within a describe, or all examples in a context.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Yank/Put&lt;/span&gt;: If you select multiple lines (using shift + arrows, or home/end) you can then move those lines up and down through your code in a block by holding control+shift and using up and down arrows. If you're lucky, and RubyMine is smart enough, sometimes this will actually skip over whole blocks of code that are indented.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Collapse and Search&lt;/span&gt;: speaking of Rspec, it can also be handy to collapse an entire spec by hitting Ctrl + Shift + "-", and then find instances of a keyword, which will expand only the instances of that word as they are found, leaving irrelevant tests collapsed.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;Running Tests&lt;/span&gt;: with your test open, you can press Ctrl-Shift-F11 to run all tests in a spec file. Or, pressing Alt-Shift-F11 will run only the current example (according to cursor location). If the Run window is open, Ctrl-4 will move your cursor to the Run window, and Ctrl-F5 will repeat the last test run.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Commenting out code&lt;/span&gt;: pressing Ctrl and "/" will comment out any currently selected lines, and will use the appropriate commenting convention according to the file extension.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-7395420361074797516?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/7395420361074797516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/03/rubymine-shortcuts.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/7395420361074797516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/7395420361074797516'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/03/rubymine-shortcuts.html' title='RubyMine shortcuts for vim addicts'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1711230518531562941.post-5364701845870141215</id><published>2010-03-16T12:58:00.001-07:00</published><updated>2010-03-22T15:17:01.018-07:00</updated><title type='text'>block parameter scope weirdness</title><content type='html'>If the fact that external variables can be changed inside a block isn't strange enough for you, check out this example. What would you presume happens to "index" during the method call?&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;br /&gt;index = "watch this space"&lt;br /&gt;my_array = ["base", "basket", "tennis", "goof"]&lt;br /&gt;my_array.map {|index| index += "ball"}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;It is a little alarming, but index is now equal to "goofball." This could make for some very unexpected and undesired behavior if you are not careful about what you are naming your block parameters. Dangerous!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-5364701845870141215?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/5364701845870141215/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/03/block-parameter-scope-weirdness.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/5364701845870141215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/5364701845870141215'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/03/block-parameter-scope-weirdness.html' title='block parameter scope weirdness'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-2485028296483923793</id><published>2010-03-08T09:24:00.000-08:00</published><updated>2010-03-22T15:01:28.401-07:00</updated><title type='text'>ruby blocks</title><content type='html'>My first encounter with blocks in Ruby was in a koan, which was a black box kind of experience. I got stuck thinking of the block and the receiving function as two scopes, and under this assumption it seems that a block can return to a method *and* vice versa.&lt;br /&gt;&lt;br /&gt;As it turns out, the block convention acts more like a run time code splicer, putting the block of code (before evaluating it) IN the method so, really, there is a shared scope between the two. It’s like you’re slipping the method a little note for what to put in the yield spot. But you can also pass the block a variable from inside the method, by writing yield(variable). It looks something like this:&lt;br /&gt;&lt;blockquote&gt;&lt;pre name="code" class="ruby"&gt;&lt;br /&gt;def method_with_a_block&lt;br /&gt;    yield(parameter)&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;method_with_a_block {|parameter| parameter.do_stuff}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;if you prefer a multiple-line version, you can replace the brackets with do/end (and I'll also throw in an extra surprise):&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;variable_outside_method = "foo"&lt;br /&gt;&lt;br /&gt;method_with_a_block do |parameter_passed_to_block|&lt;br /&gt;    do_stuff_with(parameter_passed_to_block)&lt;br /&gt;    variable_outside_method += "bar&lt;br /&gt;end&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;If you are accustomed to C-like languages, as I am, it can be surprising that our variable_outside_method is actually changed to "foobar" once the method call is resolved. This is because blocks have access to the context in which they are called.&lt;br /&gt;&lt;br /&gt;Blocks are extremely expressive and useful for implementing a skeleton form of a task - in fact, enumerators in ruby (e.g. "each", "detect", "select") are implemented using blocks!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-2485028296483923793?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/2485028296483923793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/03/ruby-blocks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/2485028296483923793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/2485028296483923793'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/03/ruby-blocks.html' title='ruby blocks'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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-1711230518531562941.post-2144262107188086481</id><published>2010-03-04T12:20:00.000-08:00</published><updated>2010-03-04T12:41:00.128-08:00</updated><title type='text'>ruby on rails</title><content type='html'>I'm learning Ruby on Rails. I've been spending this week with &lt;a href="http://www.ultrasaurus.com/"&gt;Sarah Allen&lt;/a&gt;, and have done a lot of work on my own from home. For ruby, I've been working the &lt;a href="http://github.com/edgecase/ruby_koans"&gt;ruby koans&lt;/a&gt; from edgecase at github, and reading the &lt;a href="http://www.ruby-doc.org/docs/ProgrammingRuby/"&gt;ruby documentation&lt;/a&gt; and &lt;a href="http://mislav.uniqpath.com/poignant-guide/"&gt;why's poignant guide to Ruby&lt;/a&gt;. I've also taken a fresh look at CSS, and have found the &lt;a href="http://www.w3schools.com/css/"&gt;css tutorials&lt;/a&gt; at w3schools to be a huge help. For Rails, I've been using the&lt;span style="text-decoration: underline;"&gt; &lt;/span&gt;&lt;a href="http://guides.rubyonrails.org/"&gt;Rails guides&lt;/a&gt; and &lt;a href="http://api.rubyonrails.org/"&gt;Rails documentation&lt;/a&gt; for reference. That's it for now, much more to follow regarding the details of what I'm learning!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1711230518531562941-2144262107188086481?l=crockettdile.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crockettdile.blogspot.com/feeds/2144262107188086481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://crockettdile.blogspot.com/2010/03/ruby-on-rails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/2144262107188086481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1711230518531562941/posts/default/2144262107188086481'/><link rel='alternate' type='text/html' href='http://crockettdile.blogspot.com/2010/03/ruby-on-rails.html' title='ruby on rails'/><author><name>ali</name><uri>http://www.blogger.com/profile/08319526222616970274</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>
