agaskar.com

Apr 30 2011

Bundler with :git and force-pushed commits

I have the bad habit of occasionally force-pushing to master if I’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:

gem "mygem", :git => "http://github.com/ragaskar/mygem.git" 
any force-pushes you commit to that repo will not be properly pulled by bundler (which makes sense, as it thinks it’s up to date on head). This is pretty easy to fix — find your BUNDLE_PATH (where bundler installs gems to). If you’re using rvm, it’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’t force push.

Comments (View)
Mar 20 2011

Mobility HD2400XT (94c8) working with OSX 10.6.3 on a Gateway M6824.

Took awhile, but here’s what worked for me:

1. Retail OSX Snow Leopard 10.6.3 restored to an 8GB usb key with disk utility.
2. Add nawcom modded MyHack Installer (http://blog.nawcom.com/?p=242) with the pkg installer, being sure to select your USB drive. Only options that should be deselected are Chocolate Kernel and Graphics Disabler.
3. Boot with USB key and install normally. You should be able to install to a MBR formatted drive (for windows/linux dual booting).
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 “-s” then enter). mount -uw / as instructed, then cd to /System/Library/Extensions and rm -rf ATI* (all ATI files). reboot.
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.
6. sudo vim /Extra/com.apple.boot.plist, remove both the “GraphicsMode” and “GraphicsEnabler” entries (both the key name and values).
7. Download the latest RadeonHD driver (http://code.google.com/p/osx86-driver-radeonhd/downloads/list). Download KextUtility (http://www.google.com/search?q=kextutility). Install the RadeonHD kext by dragging it onto the KextUtility icon.
8. Reboot normally. You should now be at 1280x800. If you have an ‘color-block’ mouse cursor (I did), modify the /System/Library/Extensions/RadeonHD.kext/Contents/Info.plist and set the key “enableHWCursor” to false. Reboot.

Haven’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.

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.

Hope this helps someone! I’ve been trying to get this working for over 2 years now.

Comments (View)
Feb 19 2011

Undefined constant OpenSSL::Digest::SHA256

This is probably because you have an old version of OpenSSL.

If you’re running rvm (and you should be), it’s easily fixed by installing a local openssl and then rebuilding your rubies. See http://rvm.beginrescueend.com/packages/openssl/

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.

Comments (View)
Jan 23 2011

has_many through issue with postgres and namespaced models

Let’s say you have the following models:

class Carton < ActiveRecord::Base
  has_many :carton_eggs, :class_name => "Carton::Egg"
  has_many :eggs, :through => :carton_eggs, :order => "egg_order"
end

class Carton::Egg < ActiveRecord::Base
  belongs_to :carton
  belongs_to :egg
end

class Egg < ActiveRecord::Base
end
When running the following:
carton.eggs
You’ll likely get an error like this:
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
The first table should definitely be “eggs”, not “carton_eggs”, but for some reason it’s not. I didn’t dig in much into why the sql was incorrect here — looking through a debugger the activerecord association proxy object looked largely correct, but after 30 minutes I just yanked the namespacing — used CartonEgg instead of Carton::Egg — 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’ll revisit this later when I have more than 5 models in my app. Apparently many folks aren’t fans of namespacing in models (http://m.onkey.org/namespaced-models), and I’ve definitely hit namespace bugs before, so maybe in this project I’ll avoid them and see how far I can get.

Comments (View)
Nov 20 2010

Fun state_machine rspec gotcha

Let’s say you’ve got the following:

class Thing  :draft do
    event :publish do
      transition all => :published
    end
     state :published do
      validates_presence_of :author
    end
  end
end
You want to test your validations on the state transition like so:
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
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’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 — you’d never want to change a state and then save, you’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.

Comments (View)
Oct 26 2010

grep conflicting matchers specified rvm

Getting this from RVM?

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.

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 — 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’t quite able to upgrade the scripts properly, I had to manually chmod them to 755 to make them executable.

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 — but the ReadyNAS can’t install this — the main parts you need are g++ and gcc, which can be installed). Then you have to manually configure ree to —build=sparc-linux and skip the tcmalloc install. IE:

./installer -a /home/ragaskar/.rvm/rubies/ree-1.8.7-2010.02 —no-tcmalloc —dont-install-useful-gems -c “—build=sparc-linux”

It takes awhile.

But now I have a reasonable ruby on my little ReadyNAS.

(PS check this for screen support: http://www.readynas.com/forum/viewtopic.php?f=11&t=23244)

Comments (View)
Aug 05 2010

The nokogiri install locally magic.

If you’re building your own libxslt and libxml2 because you’re on shared hosting, the *right* gem install magic is :

gem install nokogiri — —with-xml2-lib=<YOUR_INSTALL_DIR>/lib —with-xml2-include=<YOUR_INSTALL_DIR>/include/libxml2 —with-xslt-lib=<YOUR_INSTALL_DIR>/lib —with-xslt-include=<YOUR_INSTALL_DIR>/include/

You should be ./configure —prefix=<YOUR_INSTALL_DIR> when you compile libxml2 and libxslt.

The docs recommend

gem install nokogiri — —with-xml2-lib=/home/joe/builds/lib \
—with-xml2-include=/home/joe/builds/include/libxml2 \
—with-xslt-lib=/home/joe/builds/lib \
—with-xslt-include=/home/joe/builds/include/libxslt

This is close, but not close enough if you’re not used to compiling your own libraries. Taking a peek at mkmf.log is pretty helpful here too. Good luck!!!!

Comments (View)
Apr 22 2010
Commands to take advantage of bash’s Emacs Mode:
ctrl-a Move cursor to beginning of line
ctrl-e Move cursor to end of line
meta-b Move cursor back one word
meta-f Move cursor forward one word
ctrl-w Cut the last word
ctrl-u Cut everything before the cursor
ctrl-k Cut everything after the cursor
ctrl-y Paste the last thing to be cut
ctrl-_ Undo
Comments (View)
Mar 26 2010

Removing a file from git …. FOREVER

Successfully used a combination of this Stack Overflow question (Git: Remove file accidentally added to the repository.) and this Github Guide (Guides: Completely remove a file from all revisions) to kill some files from my repo for good. For those of you wondering why you’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’s the exact command sequence I ran:

  1. First, make a backup of your local repo, and make sure there’s no local commits. No need to have things get confusing.
  2. git filter-branch --index-filter 'git rm --cached --ignore-unmatch all_the_files.you want_to_remove.here' <OLDEST COMMIT SHA WITH THE FILES YOU WANT TO REMOVE>..HEAD
    Make sure you get all the files you want to kill in one swoop — git throws an error if you try to re-run this command without pushing/refreshing
  3. git push --force
    Github recommends
    git push --force --verbose --dry-run
    and I’m assuming this’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’t hurt to try.

I’m not sure I’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.

If you haven’t actually pushed yet, but the file you want to remove isn’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’t actually pushed yet), git rm that file and use `git commit —amend`

Comments (View)
Feb 27 2010

authlogic doesn’t seem to like html multipart in tests

      xhr :post, :create, { :item_id => @item.id.to_param, :Filedata => fixture_file_upload('images/sample1.jpg', 'image/jpeg') }, :html => { :multipart => true }
fails
      xhr :post, :create, { :item_id => @item.id.to_param, :Filedata => fixture_file_upload('images/sample1.jpg', 'image/jpeg') }
succeeds.

not going to track this one down, because my test was green without it. Maybe this is blowing away some important headers? …

Comments (View)
Page 1 of 9