<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Rajan Agaskar’s weblog.</description><title>agaskar.com</title><generator>Tumblr (3.0; @ragaskar)</generator><link>http://agaskar.com/</link><item><title>Bundler with :git and force-pushed commits</title><description>&lt;p&gt;I have the bad habit of occasionally force-pushing to master if I&amp;#8217;m pretty confident that no-one else is using the repo (IE, personal side projects, etc). This bit of laziness saves me the git overhead of branch/merging, but I just found a *new* way to get burned. If you are using a gem built from a remote git repo with bundler like so: 

&lt;pre&gt;
gem "mygem", :git =&amp;gt; "http://github.com/ragaskar/mygem.git" 
&lt;/pre&gt;

any force-pushes you commit to that repo will not be properly pulled by bundler (which makes sense, as it thinks it&amp;#8217;s up to date on head). 

This is pretty easy to fix &amp;#8212; find your BUNDLE_PATH (where bundler installs gems to). If you&amp;#8217;re using rvm, it&amp;#8217;s probably in ~/.rvm/gems/your-gemset/bundler, blow away any directories that contain your gem, and also clear out your ~/.rvm/gems/your-gemset/cache/bundler/ directory. Lastly, nuke your Gemfile.lock and re-bundle.

Or maybe just don&amp;#8217;t force push.&lt;/p&gt;</description><link>http://agaskar.com/post/5073423744</link><guid>http://agaskar.com/post/5073423744</guid><pubDate>Sat, 30 Apr 2011 09:55:00 -0700</pubDate></item><item><title>Mobility HD2400XT (94c8) working with OSX 10.6.3 on a Gateway M6824.</title><description>&lt;p&gt;Took awhile, but here&amp;#8217;s what worked for me: &lt;/p&gt;

&lt;p&gt;1. Retail OSX Snow Leopard 10.6.3 restored to an 8GB usb key with disk utility.&lt;br/&gt;
2. Add nawcom modded MyHack Installer (&lt;a href="http://blog.nawcom.com/?p=242"&gt;http://blog.nawcom.com/?p=242&lt;/a&gt;) with the pkg installer, being sure to select your USB drive. Only options that should be deselected are Chocolate Kernel and Graphics Disabler. &lt;br/&gt;
3. Boot with USB key and install normally. You should be able to install to a MBR formatted drive (for windows/linux dual booting).   &lt;br/&gt;
4. Install fails during post-install phase (after reboot, before registration, etc). Boot in single-user mode (hit tab a few times at the screen, pick the drive you installed to, and type &amp;#8220;-s&amp;#8221; then enter). mount -uw / as instructed, then cd to /System/Library/Extensions and rm -rf ATI* (all ATI files). reboot. &lt;br/&gt;
5. Boot of your new install should now succeed. Proceed through the regular post-installation. Install the boot loader to the install drive using the myHack pkg from the USB drive, using the same options you did before. Reboot.&lt;br/&gt;
6. sudo vim /Extra/com.apple.boot.plist, remove both the &amp;#8220;GraphicsMode&amp;#8221; and &amp;#8220;GraphicsEnabler&amp;#8221; entries (both the key name and values). &lt;br/&gt;
7. Download the latest RadeonHD driver (&lt;a href="http://code.google.com/p/osx86-driver-radeonhd/downloads/list"&gt;http://code.google.com/p/osx86-driver-radeonhd/downloads/list&lt;/a&gt;). Download KextUtility (&lt;a href="http://www.google.com/search?q=kextutility"&gt;http://www.google.com/search?q=kextutility&lt;/a&gt;). Install the RadeonHD kext by dragging it onto the KextUtility icon.&lt;br/&gt;
8. Reboot normally. You should now be at 1280x800. If you have an &amp;#8216;color-block&amp;#8217; mouse cursor (I did), modify the /System/Library/Extensions/RadeonHD.kext/Contents/Info.plist and set the key &amp;#8220;enableHWCursor&amp;#8221; to false. Reboot. &lt;/p&gt;

&lt;p&gt;Haven&amp;#8217;t got QE/CI working yet, but not sure how much I care. The built-in wireless is not really supported either, but I purchased an Airlink Wireless-N usb dongle that is fairly small in size and has native OSX support for under $15. &lt;/p&gt;

&lt;p&gt;Still seem to have a few overheating problems, but have been running the machine without a shutdown on a cool-pad for the last few hours, so it seems possible to mitigate these issues. &lt;/p&gt;

&lt;p&gt;Hope this helps someone! I&amp;#8217;ve been trying to get this working for over 2 years now.&lt;/p&gt;</description><link>http://agaskar.com/post/3987624894</link><guid>http://agaskar.com/post/3987624894</guid><pubDate>Sun, 20 Mar 2011 13:06:00 -0700</pubDate></item><item><title>Undefined constant OpenSSL::Digest::SHA256</title><description>&lt;p&gt;This is probably because you have an old version of OpenSSL.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re running rvm (and you should be), it&amp;#8217;s easily fixed by installing a local openssl and then rebuilding your rubies. See &lt;a href="http://rvm.beginrescueend.com/packages/openssl/"&gt;http://rvm.beginrescueend.com/packages/openssl/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This actually bombed out for me when I tried to reinstall ree (errors during install), so I just sudo port install-ed openssl. That seemed to fix.&lt;/p&gt;</description><link>http://agaskar.com/post/3388531273</link><guid>http://agaskar.com/post/3388531273</guid><pubDate>Sat, 19 Feb 2011 13:31:22 -0800</pubDate></item><item><title>has_many through issue with postgres and namespaced models</title><description>&lt;p&gt;Let&amp;#8217;s say you have the following models: 

&lt;pre&gt;
class Carton &amp;lt; ActiveRecord::Base
  has_many :carton_eggs, :class_name =&amp;gt; "Carton::Egg"
  has_many :eggs, :through =&amp;gt; :carton_eggs, :order =&amp;gt; "egg_order"
end

class Carton::Egg &amp;lt; ActiveRecord::Base
  belongs_to :carton
  belongs_to :egg
end

class Egg &amp;lt; ActiveRecord::Base
end
&lt;/pre&gt;

When running the following:
&lt;pre&gt;
carton.eggs
&lt;/pre&gt;
You&amp;#8217;ll likely get an error like this: 
&lt;pre&gt;
ERROR:  table name "carton_eggs" specified more than once
STATEMENT:  SELECT "carton_eggs".* FROM "carton_eggs" INNER JOIN "carton_eggs" ON "carton_eggs".id = "carton_eggs".egg_id WHERE (("carton_eggs".carton_id = 157)) ORDER BY display_order
&lt;/pre&gt;
The first table should definitely be &amp;#8220;eggs&amp;#8221;, not &amp;#8220;carton_eggs&amp;#8221;, but for some reason it&amp;#8217;s not. 

I didn&amp;#8217;t dig in much into why the sql was incorrect here &amp;#8212; looking through a debugger the activerecord association proxy object looked largely correct, but after 30 minutes I just yanked the namespacing &amp;#8212; used CartonEgg instead of Carton::Egg &amp;#8212; and boom, everything worked. 

A bit of a bummer, since I typically like the neater organization of namespaced models (this particular model was in a carton/ sub dir, with the filename of egg.rb). I guess I&amp;#8217;ll revisit this later when I have more than 5 models in my app. Apparently many folks aren&amp;#8217;t fans of namespacing in models (&lt;a href="http://m.onkey.org/namespaced-models"&gt;http://m.onkey.org/namespaced-models&lt;/a&gt;), and I&amp;#8217;ve definitely hit namespace bugs before, so maybe in this project I&amp;#8217;ll avoid them and see how far I can get.&lt;/p&gt;</description><link>http://agaskar.com/post/2893744910</link><guid>http://agaskar.com/post/2893744910</guid><pubDate>Sun, 23 Jan 2011 09:09:00 -0800</pubDate></item><item><title>Fun state_machine rspec gotcha</title><description>&lt;p&gt;Let&amp;#8217;s say you&amp;#8217;ve got the following: 

&lt;pre&gt;
class Thing  :draft do
    event :publish do
      transition all =&amp;gt; :published
    end
     state :published do
      validates_presence_of :author
    end
  end
end
&lt;/pre&gt;
You want to test your validations on the state transition like so: 

&lt;pre&gt;
it "requires an author to transition to published" do
    thing = Thing.new
    thing.author.should be_nil
    thing.publish
    thing.should have(1).error_on(:author)
end
&lt;/pre&gt;

This test fails.

Why? 

1) When a state_machine transition fails, it automatically rolls you back to the prior state.
2) The prior state will now be valid, as we don&amp;#8217;t have the extra validations added by state machine. Calling valid? at this point will clear out the (correct) errors that state_machine added to your object when it tried to transition it. 
3) error_on calls valid? under the hood. 

This seems to have implications for controllers too &amp;#8212; you&amp;#8217;d never want to change a state and then save, you&amp;#8217;d always want to thing.save if (thing.publish).

An interesting gotcha that confounded me for a bit, particularly since the internals of state_machine tend towards the meta. Eventually I just poked at my model in a console until I figured out what was going on.&lt;/p&gt;</description><link>http://agaskar.com/post/1627270986</link><guid>http://agaskar.com/post/1627270986</guid><pubDate>Sat, 20 Nov 2010 08:01:14 -0800</pubDate></item><item><title>grep conflicting matchers specified rvm</title><description>&lt;p&gt;Getting this from RVM? &lt;/p&gt;

&lt;p&gt;I had to upgrade grep in order to prevent it from popping up. Turns out the version I had on sarge (the default install for the Netgear ReadyNAS) was waaaaay older than rvm expected. A simple apt-get install grep fixed that. &lt;/p&gt;

&lt;p&gt;You also want to apt-get install less, then cp in the /etc/bash.bashrc and /root/.profile to your home directory. The rvm install is weird &amp;#8212; it complains about missing aptitude, but it only needs apt-get. You have to manually checkout rvm into a ~/.rvm file, and run the installer. I found that it wasn&amp;#8217;t quite able to upgrade the scripts properly, I had to manually chmod them to 755 to make them executable. &lt;/p&gt;

&lt;p&gt;Installing ree for rvm was somewhat harder. To build it I had to manually apt-get the dependencies (ree says you need to install build-essentials &amp;#8212; but the ReadyNAS can&amp;#8217;t install this &amp;#8212; the main parts you need are g++ and gcc, which can be installed). Then you have to manually configure ree to &amp;#8212;build=sparc-linux and skip the tcmalloc install. IE: &lt;/p&gt;

&lt;p&gt;./installer -a /home/ragaskar/.rvm/rubies/ree-1.8.7-2010.02  &amp;#8212;no-tcmalloc &amp;#8212;dont-install-useful-gems -c &amp;#8220;&amp;#8212;build=sparc-linux&amp;#8221; &lt;/p&gt;

&lt;p&gt;It takes awhile. &lt;/p&gt;

&lt;p&gt;But now I have a reasonable ruby on my little ReadyNAS. &lt;/p&gt;

&lt;p&gt;(PS check this for screen support: &lt;a href="http://www.readynas.com/forum/viewtopic.php?f=11&amp;amp;t=23244"&gt;http://www.readynas.com/forum/viewtopic.php?f=11&amp;amp;t=23244&lt;/a&gt;)&lt;/p&gt;</description><link>http://agaskar.com/post/1410485683</link><guid>http://agaskar.com/post/1410485683</guid><pubDate>Tue, 26 Oct 2010 18:09:00 -0700</pubDate></item><item><title>The nokogiri install locally magic.</title><description>&lt;p&gt;If you&amp;#8217;re building your own libxslt and libxml2 because you&amp;#8217;re on shared hosting, the *right* gem install magic is&amp;#160;:&lt;/p&gt;

&lt;p&gt; gem install nokogiri &amp;#8212; &amp;#8212;with-xml2-lib=&amp;lt;YOUR_INSTALL_DIR&amp;gt;/lib &amp;#8212;with-xml2-include=&amp;lt;YOUR_INSTALL_DIR&amp;gt;/include/libxml2  &amp;#8212;with-xslt-lib=&amp;lt;YOUR_INSTALL_DIR&amp;gt;/lib &amp;#8212;with-xslt-include=&amp;lt;YOUR_INSTALL_DIR&amp;gt;/include/&lt;/p&gt;

&lt;p&gt;You should be ./configure &amp;#8212;prefix=&amp;lt;YOUR_INSTALL_DIR&amp;gt; when you compile libxml2 and libxslt. &lt;/p&gt;

&lt;p&gt;The docs recommend &lt;/p&gt;

&lt;p&gt;gem install nokogiri &amp;#8212; &amp;#8212;with-xml2-lib=/home/joe/builds/lib \&lt;br/&gt;
                        &amp;#8212;with-xml2-include=/home/joe/builds/include/libxml2 \&lt;br/&gt;
                        &amp;#8212;with-xslt-lib=/home/joe/builds/lib \&lt;br/&gt;
                        &amp;#8212;with-xslt-include=/home/joe/builds/include/libxslt&lt;/p&gt;

&lt;p&gt;This is close, but not close enough if you&amp;#8217;re not used to compiling your own libraries. Taking a peek at mkmf.log is pretty helpful here too. Good luck!!!!&lt;/p&gt;</description><link>http://agaskar.com/post/910180937</link><guid>http://agaskar.com/post/910180937</guid><pubDate>Thu, 05 Aug 2010 18:09:00 -0700</pubDate></item><item><title>"Commands to take advantage of bash’s Emacs Mode:
ctrl-a	Move cursor to beginning of..."</title><description>“Commands to take advantage of bash’s Emacs Mode:&lt;br/&gt;
ctrl-a	Move cursor to beginning of line&lt;br/&gt;
ctrl-e	Move cursor to end of line&lt;br/&gt;
meta-b	Move cursor back one word&lt;br/&gt;
meta-f	Move cursor forward one word&lt;br/&gt;
ctrl-w	Cut the last word&lt;br/&gt;
ctrl-u	Cut everything before the cursor &lt;br/&gt;
ctrl-k	Cut everything after the cursor&lt;br/&gt;
ctrl-y	Paste the last thing to be cut&lt;br/&gt;
ctrl-_	Undo”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;&lt;a href="http://www.hypexr.org/bash_tutorial.php"&gt;&lt;a href="http://www.hypexr.org/bash_tutorial.php"&gt;http://www.hypexr.org/bash_tutorial.php&lt;/a&gt;&lt;/a&gt;&lt;/em&gt;</description><link>http://agaskar.com/post/540764633</link><guid>http://agaskar.com/post/540764633</guid><pubDate>Thu, 22 Apr 2010 07:43:00 -0700</pubDate></item><item><title>Removing a file from git .... FOREVER</title><description>&lt;p&gt;Successfully used a combination of this &lt;a href="http://stackoverflow.com/questions/307828/git-remove-file-accidentally-added-to-the-repository"&gt;Stack Overflow question (Git: Remove file accidentally added to the repository.)&lt;/a&gt; and this &lt;a href="http://github.com/guides/completely-remove-a-file-from-all-revisions"&gt;Github Guide (Guides: Completely remove a file from all revisions)&lt;/a&gt; to kill some files from my repo for good.  For those of you wondering why you&amp;#8217;d ever want to do this: git sends all deltas when you checkout, meaning every file ever committed gets sent down the wire, even if you `git rm` it later. Kinda sucks if you accidentally check in a 15, 20M file that you have to download only to delete immediately. In my case the file was only 500k, but I wanted to kill it before I made too many more commits. Here&amp;#8217;s the exact command sequence I ran: &lt;/p&gt;

&lt;ol&gt;&lt;li&gt;
First, make a backup of your local repo, and make sure there&amp;#8217;s no local commits. No need to have things get confusing. &lt;/li&gt;
&lt;li&gt;&lt;pre&gt;git filter-branch --index-filter 'git rm --cached --ignore-unmatch all_the_files.you want_to_remove.here' &amp;lt;OLDEST COMMIT SHA WITH THE FILES YOU WANT TO REMOVE&amp;gt;..HEAD&lt;/pre&gt; Make sure you get all the files you want to kill in one swoop &amp;#8212; git throws an error if you try to re-run this command without pushing/refreshing&lt;/li&gt;
&lt;li&gt;&lt;pre&gt;git push --force&lt;/pre&gt; Github recommends &lt;pre&gt;git push --force --verbose --dry-run&lt;/pre&gt; and I&amp;#8217;m assuming this&amp;#8217;ll throw an error if something terrible is about to happen, but it printed nothing in my case, so I just moved on. It couldn&amp;#8217;t hurt to try.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;I&amp;#8217;m not sure I&amp;#8217;d use this on a repo where I was working with more than a few other people; I imagine everyone would have to re-checkout the repo from master, so it could be pretty disruptive. Another good reason to look at the changesets before you push. &lt;/p&gt;

&lt;p&gt;If you haven&amp;#8217;t actually pushed yet, but the file you want to remove isn&amp;#8217;t in your last commit, you can `git reset SHA`, which will jump you to that commit and move already committed files to your staging where you can then modify your commit. If you just want to remove a file in your last commit (and you haven&amp;#8217;t actually pushed yet), git rm that file and use `git commit &amp;#8212;amend`&lt;/p&gt;</description><link>http://agaskar.com/post/474869912</link><guid>http://agaskar.com/post/474869912</guid><pubDate>Fri, 26 Mar 2010 07:57:00 -0700</pubDate></item><item><title>authlogic doesn't seem to like html multipart in tests</title><description>&lt;pre&gt;
      xhr :post, :create, { :item_id =&amp;gt; @item.id.to_param, :Filedata =&amp;gt; fixture_file_upload('images/sample1.jpg', 'image/jpeg') }, :html =&amp;gt; { :multipart =&amp;gt; true }
&lt;/pre&gt;

fails

&lt;pre&gt;
      xhr :post, :create, { :item_id =&amp;gt; @item.id.to_param, :Filedata =&amp;gt; fixture_file_upload('images/sample1.jpg', 'image/jpeg') }
&lt;/pre&gt;

succeeds.

&lt;p&gt;not going to track this one down, because my test was green without it. Maybe this is blowing away some important headers? &amp;#8230;&lt;/p&gt;</description><link>http://agaskar.com/post/416412811</link><guid>http://agaskar.com/post/416412811</guid><pubDate>Sat, 27 Feb 2010 16:51:28 -0800</pubDate></item><item><title>Rails Routing Namespaces with Nested Routes can cause Model failures.</title><description>Working on my side project, I refactored some controllers into an admin namespace, resulting in a directory tree that looked something like this: 

&lt;pre&gt;
-controllers/
  -admin/
    -item/
      -photo_controller.rb
    -item_controller.rb
&lt;/pre&gt;

All the tests passed, yet whenever I hit my (previously working) admin/items controller, I got:

&lt;pre&gt;
NoMethodError (undefined method `find' for Admin::Item:Module):
  app/controllers/admin/items_controller.rb:7:in `index'
&lt;/pre&gt;

&lt;p&gt;
It looked like the route was somehow forcing the namespacing of the model. I went nuts googling for it and found zero explanations. Finally, on a hunch, I renamed the item directory to items and the photo_controller to Admin::Items::PhotoController instead of Admin::Item::PhotoController and everything worked. 
&lt;/p&gt;
&lt;p&gt;
Another option is to use ::Item in your controller instead of Item. I think I might go with this one &amp;#8212; would rather be more specific than resort to naming tricks.
&lt;/p&gt;
&lt;p&gt;
I&amp;#8217;m still bewildered as to how or why this is happening &amp;#8212; I can&amp;#8217;t quite see how having an Admin::Item:: namespace means that all of the sudden, Item will now refer to Admin::Item, although I do have a pet theory. Perhaps when Item is not found in the current namespace, it goes UP a namespace and eventually hits the model. Since I now have an Admin::Item, it doesn&amp;#8217;t bother looking in the main namespace.
&lt;/p&gt;&lt;p&gt;
I can&amp;#8217;t believe this was so tough to google for. I imagine this would nail anyone who has a nested route in a namespace. I&amp;#8217;m a bit surprised it&amp;#8217;s not a more common error.
&lt;/p&gt;
&lt;p&gt;
I&amp;#8217;m assuming tests didn&amp;#8217;t fail because the Admin::Item::PhotosController was not loaded during the Admin::ItemsController test.
&lt;/p&gt;</description><link>http://agaskar.com/post/416224051</link><guid>http://agaskar.com/post/416224051</guid><pubDate>Sat, 27 Feb 2010 14:58:00 -0800</pubDate></item><item><title>Active Record DB Types: A Reference</title><description>&lt;p&gt;&lt;h3&gt;Native types:&lt;/h3&gt;


&lt;pre&gt;
add_column :native_type, :name, :options
&lt;/pre&gt;

&lt;pre&gt;
:primary_key 
:string 
:text
:integer 
:float
:decimal
:datetime
:timestamp 
:time 
:date 
:binary 
:boolean
&lt;/pre&gt;

&lt;h3&gt; Native Type Options:&lt;/h3&gt;
&lt;pre&gt;
:limit - Requests a maximum column length. This is number of characters for :string and :text columns and number of bytes for :binary and :integer columns.
:default - The column‘s default value. Use nil for NULL.
:null - Allows or disallows NULL values in the column. This option could have been named :null_allowed.
:precision - Specifies the precision for a :decimal column.
:scale - Specifies the scale for a :decimal column.
&lt;/pre&gt;

&lt;h3&gt;Table definitions:&lt;/h3&gt;

&lt;pre&gt;
  create_table :products do |t|
    t.integer :shop_id, :creator_id
    t.string  :name, :value, :default =%gt; "Untitled"
    t.timestamps
  end
&lt;/pre&gt;

You can use any native type, or the following helpers.&lt;br/&gt;&lt;h3&gt;timestamps&lt;/h3&gt;
adds created_at and updated_at timestamp columns to your table.

&lt;pre&gt;
...
t.timestamps
...
&lt;/pre&gt;

&lt;h3&gt;references&lt;/h3&gt;
Adds the integer field &amp;#8220;#{name}_id&amp;#8221;. Also adds the string field &amp;#8220;#{name}_type&amp;#8221; if polymorphic is true. You can pass a hash to polymorphic and specify a default if desired.
 
&lt;pre&gt;
create_table :taggings do |t|
    t.references :tag
    t.references :tagger, :polymorphic =&amp;gt; true
    t.references :taggable, :polymorphic =&amp;gt; { :default =&amp;gt; 'Photo' }
  end
&lt;/pre&gt;

&lt;h3&gt;Auto-generate an add_column migration&lt;/h3&gt;
There is a special syntactic shortcut to generate migrations that add fields to a table.
&lt;pre&gt;
 script/generate migration add_fieldname_to_tablename fieldname:string
&lt;/pre&gt;&lt;/p&gt;</description><link>http://agaskar.com/post/401077990</link><guid>http://agaskar.com/post/401077990</guid><pubDate>Sat, 20 Feb 2010 12:34:00 -0800</pubDate></item><item><title>has_many :through, accepts_nested_attributes_for, and validations</title><description>&lt;p&gt;I had a need to write some code that would permit the following: 

&lt;pre&gt;
it "accepts attributes for item_photos" do
    photo = Factory(:photo)
    item = Item.create!(Factory.attributes_for(:item, :item_photos_attributes =&amp;gt; [{:photo_id =&amp;gt; photo.id}]))
    item.item_photos.should have(1).item_photo
    item.photos.first.should == photo
end
&lt;/pre&gt;

Basically, you can use nested attributes to when creating items to create lookup records for existing photos. 

Of course, the create kept failing due to the item_photo in question missing an item (well, actually &amp;#8230; I started with a create, which of course happily continued on its way until I tried to look at item photos and it was blank. The lesson is that you should ALWAYS test that your create or saves have occured, either with a should be_true or a bang method so they explode). 

This blew my mind &amp;#8212; how does accept_nested_attributes_for even work if you need to have an id before saving child associations? Well, it was my fault, of course. My item_photos model looked like this: 

&lt;pre&gt;
class ItemPhoto &amp;lt; ActiveRecord::Base
  belongs_to :item
  belongs_to :photo

  validates_presence_of :item
  validates_presence_of :photo
end
&lt;/pre&gt;

I added the validations because I believed it would be silly to have an item_photo without an associated item or photo. What would you do with such a thing? Of course, my overzealous validating meant my accept_nested_attributes could never hope to succeed. 

Removing these validations made the test pass happily.  Basically, this seems to indicate that Rails can&amp;#8217;t yet handle validations on parent belongs_to associations in children yet, so you&amp;#8217;re probably going to have to skip them. It sounds like this is possibly going to make it into a future version of rails, but if not, there you have it: a simple solution for a foolish problem that is *really* hard to google for.&lt;/p&gt;</description><link>http://agaskar.com/post/396150446</link><guid>http://agaskar.com/post/396150446</guid><pubDate>Wed, 17 Feb 2010 22:23:00 -0800</pubDate></item><item><title>Fun (and evil) tricks with rspec</title><description>&lt;p&gt;&lt;pre&gt;
      original_glob = Dir.method(:glob)
      Dir.stub!(:glob).and_return do |glob_string|
        if glob_string =~ /public/
          glob_string
        else
          original_glob.call(glob_string)
        end
      end
&lt;/pre&gt;

Of course, you shouldn&amp;#8217;t do this because return blocks on stubs (calculated return blocks) are evil.

Still fun, though.&lt;/p&gt;</description><link>http://agaskar.com/post/355625717</link><guid>http://agaskar.com/post/355625717</guid><pubDate>Tue, 26 Jan 2010 21:16:17 -0800</pubDate></item><item><title>JSON.stringify bug with Native FF Implementation</title><description>&lt;p&gt;Firefox past 3.5.4 natively implements JSON.stringify with replacers, similarly to the way JSON2 works. However, it&amp;#8217;s doing something wrong (optimization related?). Supposedly, you can pass stringify a replacer function as a second argument and it will use whatever is returned from that argument as the value in the serialized copy. HOWEVER, if you pass a value back that contains the same values (but is not === to) the original value, the JSON.stringify uses the original value instead. This sucks for me, because I want to pass back an array with the toJSON method wiped, without destroying the (incorrectly implemented by Prototype) toJSON method on the original.

Here&amp;#8217;s a jasmine spec: 

&lt;pre&gt;
function json2PrototypeFix(key, value) {
  if (typeof this[key] == 'object' &amp;amp;&amp;amp; Object.prototype.toString.apply(this[key]) === '[object Array]') {
    var copy = this[key].slice(0);
    this[key] = [1];
     return copy;
  } else {
    return value
  }

}
describe('JSON with protoype', function () {

 it('should properly stringify an object with child arrays', function() {
    var array = [1,2];
    var obj = {"foo": array};
    var result = JSON.stringify(obj, json2PrototypeFix);
    expect(result).toEqual("{\"foo\":[1,2]}");
  });
});
&lt;/pre&gt;

The failure I get here is 

&lt;pre&gt;Expected '{"foo":"[1]"}' to equal '{"foo":[1,2]}'.&lt;/pre&gt; 

which implies I&amp;#8217;m using the original value, even though I passed back the copy I made of it.

If I allow Crockford&amp;#8217;s original JSON2 to overwrite the stringify function, then everything works as expected. 

This is super frustrating &amp;#8212; both Prototype AND Firefox are broken in this case, so I can&amp;#8217;t reliably fix the parts of Jasmine that need JSON.stringify to work correctly when Prototype is present. I think I&amp;#8217;m just going to check for the presence of prototype and then just use their toJSON, instead of fixing the issue using JSON2&amp;#8217;s replacer support (which isn&amp;#8217;t going to be present everywhere anyways &amp;#8212; sounds like it&amp;#8217;ll break in browsers that implement JSON.stringify without the replacer arg; ie FF&lt;/p&gt;</description><link>http://agaskar.com/post/349461220</link><guid>http://agaskar.com/post/349461220</guid><pubDate>Sat, 23 Jan 2010 12:25:31 -0800</pubDate></item><item><title>Tracking a remote fork locally with Git</title><description>&lt;p&gt;&lt;pre&gt;
git add remote SomeRemote git://github.com/SomeRemote/some-project.git
git fetch SomeRemote
git branch --track SomeRemote SomeRemote/master
git checkout SomeRemote
&lt;/pre&gt;

Now you&amp;#8217;ve got a local branch (named after the user who created it) that is tracking changes to that repo. Meaning if you &lt;pre&gt;git pull&lt;/pre&gt; in there, you&amp;#8217;ll get their latest changes. If you&amp;#8217;ve got someone you frequently collaborate with who makes changes to their own fork, this is super handy.&lt;/p&gt;</description><link>http://agaskar.com/post/308834562</link><guid>http://agaskar.com/post/308834562</guid><pubDate>Wed, 30 Dec 2009 17:46:23 -0800</pubDate></item><item><title>"First, you need to include the library and create a new instance using the new2 method (or new with..."</title><description>“First, you need to include the library and create a new instance using the new2 method (or new with a lot of parameters or new3 with a hash of every parameter needed; it’s sort of up to you).”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;&lt;p&gt;according to this &lt;a href="http://www.slideshare.net/knoppix/ruby-tutorial"&gt;Ruby tutorial slideshow transcription&lt;/a&gt;, these are the basic differences between new, new2, and new3 constructors for xmlrpc. Can I take a moment to salute the careful consideration that was given to these names? [1]&lt;/p&gt;

&lt;p&gt;[1] Yes, I am using my middle finger here.&lt;/p&gt;&lt;/em&gt;</description><link>http://agaskar.com/post/285414276</link><guid>http://agaskar.com/post/285414276</guid><pubDate>Tue, 15 Dec 2009 17:42:24 -0800</pubDate></item><item><title>"if ENV[‘RAILS_ENV’] == ‘production’
ENV[‘GEM_PATH’] =..."</title><description>“&lt;p&gt;if ENV[‘RAILS_ENV’] == ‘production’&lt;br/&gt;
ENV[‘GEM_PATH’] = ‘/home/USERNAME/.gems’&lt;br/&gt;
require ‘/home/USERNAME/.gems/gems/rack-1.0.0/lib/rack.rb’&lt;br/&gt;
end&lt;/p&gt;

&lt;p&gt;is apparently the crap you have to add to get the correct version of rack on dreamhost. Really? That seems like a pain in the ass.&lt;/p&gt;”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;&lt;a href="http://www.42.mach7x.com/2009/08/24/rubygem-version-error-rack0-3-0-not-1-0-0/"&gt;RubyGem version error: rack(0.3.0 not ~&gt; 1.0.0) » 42&lt;/a&gt;&lt;/em&gt;</description><link>http://agaskar.com/post/278601316</link><guid>http://agaskar.com/post/278601316</guid><pubDate>Thu, 10 Dec 2009 22:10:59 -0800</pubDate></item><item><title>rspec, errors, and idiocy</title><description>&lt;p&gt;Just spent ten minutes writing a test that should&amp;#8217;ve taken thirty seconds. The final test looks like this: 

&lt;pre&gt;
it "should throw an Already Running error if there is already a server running" do
    some_thing.should_receive(:some_method).and_raise(RuntimeError.new('no error'))
    lambda {
      some_thing.that_triggers_the_error()
      }.should raise_error(RuntimeError, "some error")
end
&lt;/pre&gt;

The first mistake was mine. I wrote: 

&lt;pre&gt;
some_thing.should_receive(:some_method).and_throw(RuntimeError.new('some error'))
&lt;/pre&gt;

Too much javascript, I guess. But the crazy thing is, yes, it throws. You end up getting a NameError: uncaught throw for &amp;#8216;some error&amp;#8221;. Super confusing, right? Easy mistake to make, though. 

The second issue is more of an rspec message shortcoming. I originally had: 

&lt;pre&gt;
 .should raise_error(RuntimeError.new('some error'))
&lt;/pre&gt;

which resulted in the matcher error: 

&lt;pre&gt;
expected some error but nothing was raised 
&lt;/pre&gt;

But something *was* raised &amp;#8212; it just wasn&amp;#8217;t being matched correctly because I used the wrong matcher arguments. This is, yes, technically also my fault, but the unhelpful matcher error makes it difficult to catch. 

Anyways, hopefully this gotcha description finds its way into the hands of people who need it, since google wasn&amp;#8217;t super helpful when I dropped in some key words.&lt;/p&gt;</description><link>http://agaskar.com/post/229028346</link><guid>http://agaskar.com/post/229028346</guid><pubDate>Sat, 31 Oct 2009 10:45:00 -0700</pubDate></item><item><title>Old News about Icons » UIE Brain Sparks</title><description>&lt;a href="http://www.uie.com/brainsparks/2009/06/28/old-news-about-icons/"&gt;Old News about Icons » UIE Brain Sparks&lt;/a&gt;: &lt;p&gt;Ran across this interesting advice on Icons vs. Text while flipping through the Google Popular articles that now sits on the google reader login page (which, by the way, is a great feature! I find myself going through these every once in awhile — keeps me fresh on the memes of the day). &lt;/p&gt;

&lt;p&gt;It’s short, but the gist? “Text + image works better than just image or just text. However, just text works better than just image.” Also: don’t move icons around and don’t make icons for concepts that are difficult to iconize.&lt;/p&gt;</description><link>http://agaskar.com/post/133880702</link><guid>http://agaskar.com/post/133880702</guid><pubDate>Wed, 01 Jul 2009 19:48:14 -0700</pubDate></item></channel></rss>

