April 2011
1 post
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 =>...
March 2011
1 post
Mobility HD2400XT (94c8) working with OSX 10.6.3...
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...
February 2011
1 post
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.
January 2011
1 post
has_many through issue with postgres and...
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...
November 2010
1 post
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
...
October 2010
1 post
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 —...
August 2010
1 post
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...
April 2010
1 post
Commands to take advantage of bash’s Emacs Mode:
ctrl-a Move cursor to...
– http://www.hypexr.org/bash_tutorial.php
March 2010
1 post
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...
February 2010
4 posts
authlogic doesn't seem to like html multipart in...
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...
Rails Routing Namespaces with Nested Routes can...
Working on my side project, I refactored some controllers into an admin namespace, resulting in a directory tree that looked something like this:
-controllers/
-admin/
-item/
-photo_controller.rb
-item_controller.rb
All the tests passed, yet whenever I hit my (previously working) admin/items controller, I got:
NoMethodError (undefined method `find' for Admin::Item:Module):
...
Active Record DB Types: A Reference
Native types:
add_column :native_type, :name, :options
:primary_key
:string
:text
:integer
:float
:decimal
:datetime
:timestamp
:time
:date
:binary
:boolean
Native Type Options:
: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...
has_many :through, accepts_nested_attributes_for,...
I had a need to write some code that would permit the following:
it "accepts attributes for item_photos" do
photo = Factory(:photo)
item = Item.create!(Factory.attributes_for(:item, :item_photos_attributes => [{:photo_id => photo.id}]))
item.item_photos.should have(1).item_photo
item.photos.first.should == photo
end
Basically, you can use nested attributes to when...
January 2010
2 posts
Fun (and evil) tricks with rspec
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
Of course, you shouldn’t do this because return blocks on stubs (calculated return blocks) are evil.
Still fun, though.
JSON.stringify bug with Native FF Implementation
Firefox past 3.5.4 natively implements JSON.stringify with replacers, similarly to the way JSON2 works. However, it’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...
December 2009
3 posts
Tracking a remote fork locally with Git
git add remote SomeRemote git://github.com/SomeRemote/some-project.git
git fetch SomeRemote
git branch --track SomeRemote SomeRemote/master
git checkout SomeRemote
Now you’ve got a local branch (named after the user who created it) that is tracking changes to that repo. Meaning if you git pull in there, you’ll get their latest changes. If you’ve got someone you frequently...
First, you need to include the library and create a new instance using the new2...
– according to this Ruby tutorial slideshow transcription, 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]
[1] Yes, I am using my middle finger here.
if ENV[‘RAILS_ENV’] == ‘production’
ENV[‘GEM_PATH’] =...
– RubyGem version error: rack(0.3.0 not ~> 1.0.0) » 42
October 2009
1 post
rspec, errors, and idiocy
Just spent ten minutes writing a test that should’ve taken thirty seconds. The final test looks like this:
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...
July 2009
1 post
Old News about Icons » UIE Brain Sparks →
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).
It’s short, but the gist? “Text + image works better than just image or just text. However,...
June 2009
9 posts
GRUB error 17 ( Debian/Ubuntu ) « Just a thought →
With the help of this link I was able to make the necessary changes in order to boot after the Error 17 caused by blowing away my Kubuntu partition with gparted.
OSX Style Keymap: Swapping WIN and ALT keys on...
I’m 100% lost without the Rubymine keymap for OS X. (Not ‘Default for OS X’, but ‘OS X’). This is available on the Ubuntu version, however, my keymap out of the box was not supported. By default, my left ALT key sends ‘left ALT’, and my Win key sends ‘Win’ (which, yes, is pretty sensible). I wanted my left ALT key to send ‘Meta’...
Have you checked in the current profile of gnome-terminal the option “Run...
– how to get .bash_profile sourced when launching Terminal in Ubuntu: Ubuntu question #1770: “configure the .bash_profile”
awesome git plugin gotcha
1. (apparently) git considers any directory with a .git file in it as a submodule.
2. the restful_authentication recommends cloning instead of using script/plugin (which removes the .git file) because of naming issues.
3. capistrano does not appear to pull git submodules by defaul
1 + 2 + 3 = tests pass on local, but production can’t run (because the plugin code doesn’t deploy).
...
rspec w/ frozen rails
Getting this error on all your controller tests?
ArgumentError in ‘Controller::TestCase should destroy user’
wrong number of arguments (0 for 1)
Possibly an impedance mismatch between some gem and the frozen version of rails. Either way, upgrading to 2.3.2 in my vendor/rails fixed it for me. But man, was that ever hard to figure out.
could not find any SCM named git
Capistrano deploy problems.
Happened to me.
Here’s the story.
1) you probably don’t have the correct keys on your target machine to git pull from your git repo. Make sure you can do a git pull where you’re deploying to.
2) scm_command and scm settings seem to get called as methods. If they’re set to anything but ‘git’ (like, a full path), you’re...
Gitosis - DreamHost →
Good instructions for setting up a git repo (with Gitosis) on Dreamhost. Not a fan of Dreamhost at all for hosting, but it’s occasionally suitable for side-project, non-critical repos. Except, of course, when my load is over 200 — which it has been more than once — and my repo commits (not surprisingly) time out. Still, for $9 a year*, it’s significantly cheaper than github...
See Jeff Run: xclip: A Cut-and-Paste Aid →
Handy utility I saw a co-worker use the other day:
pipe to pbcopy to get output from shell in the paste buffer on OSX, pipe to xsel to get output from shell in the paste buffer on linux.
(pbpaste also does what you would expect.)
Decent setup instructions for a ROR stack on... →
All you really need to know here is the magic apt-get string, which is
sudo apt-get install ruby-full build-essential
As of this writing, the ruby that comes with ruby-full is the latest build of 1.8.7.
If you follow their instructions for installing rubygems, skip to the last paragraph and use
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
tar xzvf...
May 2009
2 posts
Introducing ... JAZZ HANDS
Jazzhands is a set of scripts and tasks that helps integrate the Jasmine javascript testing framework into your rails project. It’s still in a very early stage, so there’s not a lot of documentation, but you can create a project with integrated javascript unit testing (assuming you already have rspec installed on your machine) by doing the following:
rails ./some-project
cd...
Importing your Drupal blog posts to Tumblr with...
You’ll need the mysql and tumblr gems. Comments and tags are thrown to the four winds.
require 'rubygems'
require 'mysql'
require 'tumblr'
def create_post(row)
post(:type => 'regular',
:title => row['title'],
:body => row['body'],
:date => Time.at(row['created'].to_i).localtime
)
end
connection = Mysql.new('YOUR_MYSQL_SERVER', 'YOUR_MYSQL_USER',...
August 2008
1 post
Prototype.js, IE, and method not found
Prototype has two ways of calling a prototype method on an object. The first is the one most people will use: the object is — to borrow a phrasing from a co-worker — ‘prototype-ized’, and then methods can be directly called on it using dot syntax. In the second, static* methods may be called on an object by accessing the method via the class definition and passing in the...
July 2008
3 posts
apt-get: Sub-process bzip2 returned an error code...
If you get this error, it can seemingly be fixed by commenting out all your sources (in /etc/apt/sources.list, and possibly in /etc/apt/sources.list.d) and doing an ‘apt-get update’, then uncommenting them and ‘apt-get update’-ing again.
Which really isn’t so much a “fix”, as it is a workaround, but hey, it works! I’m ok with it being magic for...
Reverting to XP from a dual-boot GRUB.
My old laptop (a Dell Inspiron 2200) was configured to run XP and Debian Etch. It turns out that I was using Photoshop and Illustrator enough that I rarely booted into Linux
Tangentially: I’ve since found that VMware on a sensibly speedy machine works fantastically: I’ve got an Ubuntu install running alongside XP, and it’s very convenient to be able to switch into an Linux...
Auto-completion with apt-get
tab completion with apt-get install is possible by sourcing the bash_completion script — which should already live in /etc/bash_completion if you’re running debian. Simply type:
source /etc/bash_completion
Very handy — I’ve sometimes had to look at package names two or three times before typing them in correctly. This also enables tab completion for a number of other...
June 2008
3 posts
Django On Google App Engine -- First Thoughts.
I’m in the midst of converting a semi-complete Django application to deploy on Google Apps Engine. It’s not going as smoothly as I’d like, to say the least. After the jump, my first thoughts on the subject and a couple gotchas I ran into.
If you haven’t completed your application, don’t write it for Django. GAE-Django is a completely different beast.
There’s...
Handling GET vars in django templates using custom...
Django has some fantastic features for pretty URLs, but I haven’t been able to find an elegant way to handle multiple GET vars.
Now, it may just be that making requests with GET vars isn’t very ‘django’-like, but I find GET vars are a very appropriate vector for view filters. Sticking sort and search filters into a URL is problematic, because it will result in...
Installing XP on a Gateway M-6824 Laptop
I’ll admit it — I gave up on Vista. It seemed like every 20 minutes the extra loud fan on my Gateway M-6824 would start whirring, and I was super-annoyed by the two-step flow to the Task Manager. (I hated the obviously tacked-on User Access Control, but that was quickly turned off). After the jump, a touch more whining about Vista and how to install XP on a M-6824.
I don’t need...
May 2008
6 posts
BeautifulStoneSoup: Getting XML tag properties
BeautifulSoup is pretty easy to use, but I find the documentation confusing at times — some of the simpler applications aren’t covered in sufficient detail, or at all. One of these is a clear example regarding the fetching of XML tag attributes, a pretty common task. Getting a tag attribute is covered in the documentation here:
The attributes of Tags
Tag and NavigableString objects...
Super simple Drupal clean URLs with lighttpd.
Agaskar.com runs lighttpd to squeeze the most it can out of a tiny 64M VPS (which, believe it or not, Drupal 6.x can run on — I usually have about 2-4M free at any given time, and probably could’ve had a bit more had I chosen a 32-bit architecture instead of a 64-bit one!) I’ve been meaning to turn on clean urls on agaskar.com for awhile, but everything I’d read about...
Another reason to love django: the regroup...
If you’ve ever done any CMS work, you’ll know that you’ll often want to group a list of database records together by date or another properties. Django makes this easy with the regroup template tag. Read on to find out how it works.
For instance, you might want to have something like the following:
<div class="week"><h2>This Week</h2>
<div...
admin page memory issue / WSOD with free tag...
If you’re using free tagging, you will eventually WSOD (White Screen Of Death) your admin content manage page. I say eventually, because one of our projects has 64M of mem allocated to each PHP thread (a non-trivial amount, imho — if you’re wondering, it’s set that high to permit large uploads) and it’s WSOD-ing on 32K tags. Now, 32 thousand tags might seem high in...
Upgrade from Drupal 5.x to Drupal 6.x: The easy...
I just completed an upgrade (of this site) from Drupal 5.x to the latest version of 6, and I’m happy to report that it’s pretty seamless, IF, you have shell access on your machine. I’m using lighttpd, but you shouldn’t experience any issues doing this upgrade with Apache. The key here is to leave your old install in place and create a new database and directory in which...
Handy vim tip: 'pipe' files into vim tabs.
Every once in awhile I’ll use absolute paths in files on the test server in order to remove all doubt that the path is correct. Of course, when it comes time to deploy, all of these need to be fixed. Now, you can go the long way around, which is to do a grep, then open vim, save/exit (or shell), grep again, until you’ve fixed all the instances. Naturally, there’s a MUCH quicker...
April 2008
4 posts
Box2D AS3 HelloWorld boxDef extents 'issue'.
You may have, like me, been very excited to use the AS3 Box2D library in a couple of little Flash experiments.
You may have also, again, as I did, immediately pulled out the default Sprites that the HelloWorld example runs with and replaced them with your own (possibly drawn on the fly), only to find that nothing worked properly.
Debugging the problem, after the jump.
Is it the extents? Well,...
Incredibly useful Illustrator script: 'Round Any...
Illustrator has myriad shape tools and fairly decent support for rounding corners, but sometimes you may find yourself in a situation where it’s not obvious how to create a ‘proper’ (two anchor point) rounded corner on a sharp (single anchor point) edge. You could use a ‘jig’ that you build by subtracting a rounded corner shape from another, but then you have to deal...
How to logrotate your Drupal cron logs.
The ‘man logrotate’ command should actually give you a very accessible overview (unlike many other man pages) about how to use logrotate. However, if you’re like me and search google before looking at manpages, read on for detailed instructions.
First off, I’m logging my drupal cron jobs using the following commands in crontab (‘crontab -l’ lists,...
vim (vi) emulation with viPlugin in FlexBuilder...
Download a trial here: http://www.satokar.com/viplugin/. You need the one compatible with Eclipse 3.0+. Drop the contents of the ‘features’ and ‘plugins’ directory into the corresponding folders where your FlexBuilder install lives and restart for joy.
Read more about downsides and my usage notes after the jump.
Two downsides:
1. It’s not free — there is a...
March 2008
3 posts
AS3, Custom Flex / Flash Preloaders, Apache 2,...
UPDATE: This *almost* did the trick. See the full update below.
Writing a movie preloader in “pure” ActionScript 3 is reputedly more complex than creating preloaders have been previously. As I’ve just now had the opportunity to do some Flash development, I’ve been largely spared the half-script, half-Flash-timeline implementations that were common preceding AS3. Still,...
Getting transferred to an agent with Bank Of...
I had cause to call BOFA today, and they’ve managed to make it near impossible to find the menu option to get in line for an agent. Every single number they have, even the number for “my” bank (the location that is printed on my checks), goes to the same voice tree.
Googling found this, which recommended hitting 1, then *, but this did not work for me.
What worked after the...