some of my favorite ruby gem names
Snow Leopard 10.6 Rails/Passenger
*** Exception RangeError in PhusionPassenger::Railz::ApplicationSpawner (integer 4294967294 too big to convert to `int') (process 1097):
stupid arguments
## controller code def find_my_fucking_shit @my_class = MyClass.special_method_in_model(params[:shit], params[:not]) end ## controller spec # This will fail and you will want to punch a bitch in the nose because you spent two fucking days # figuring you were just really goddamn stupid (which may be true) because it should work but it doesn't it "should find shit" do MyClass.should_receive(:special_method_in_model).with({:shit => 'will', :not => 'work'}).and_return(mock_my_shit) get 'find_my_fucking_shit', :shit => 'will', :not => 'work' end # This will pass it "should find shit" do MyClass.should_receive(:special_method_in_model).with('will', 'work').and_return(mock_my_shit) get 'find_my_fucking_shit', :shit => 'will', :not => 'work' end
shelling out to the man
# stupid simple shell command - from irb or a script to get file listing system 'ls -al ~/jeremy '
In ruby script: Return the result of a command line operation. Without back-ticks ruby will just return true or false from the exit of the issued command. [wikipedia backticks - computer related]
# the path to ghostscript on the system without the newline character on the end gs_path = `which gs`.strip # use the path to convert a file outside of ruby - will return true or false system %(#{gs_path} -q -dSAFER -dNOPAUSE -sDEVICE#tiffg4 -sOutputFile#foo.pdf foo.tif -c quit 2>/dev/null) # if I want the output from the command suppressed so it doesn't spew oodles of info (after I'm sure it works - it will stop useful errors as well) `#{gs_path} -q -dSAFER -dNOPAUSE -sDEVICE#tiffg4 -sOutputFile#foo.pdf foo.tif -c quit 2>/dev/null`
Ruby Docs have massive amount of info about ERRNO (whatever the fuck it is - i'm guessing errors and such but haven't learned it yet). These error objects matter greatly and I think ruby has them wrapped up in a rubish way, but as I said I'm ignorant at the moment. I guess there is shorthand for error objects: $! - last exception; $@ - backtrace; There are many more of these. (whimper!)
typo theme: bird flu update
things i learned the hard way | VI
Error handling in rails is very technical. The TextMate Backtracer Plugin has been invaluable to me in my development in recent days, yet it only gets me to the file(s) when something is amiss in the code.
Building and running tests is one way of confirming the functionality of your application, and I’m learning the power of good testing, be it quite slowly and with a lot of errors.I’ll get there.
Here is a short list of things I had to consider when flopping from code to browser during development and things kept blowing up in my face:
- Ruby/Rails has RESERVED WORDS. If you have a class/table that isn’t playing nice make sure you aren’t naming it with one of these. This is tantamount to pouring sugar in your gas tank. And then driving in reverse at full speed. While wearing a blindfold. With your hair on fire.
- Column names in your tables need to change with alterations to any class/model names, as well as any has_many/belongs_to associations along with any model inclusions in your controllers. If you’re not to invested in the code it’d probably be easier to regenerate a fresh app with the correct model/controller name. Running ./script/destroy (the arch nemesis of ./script/generate) can help in crime scene clean up, but you still have all those pesky symbols/variables/methods with the poison name throughout your app patiently waiting to spurt their demonic ire. Exterminate them with aggression.
- An objects information will carry from request to request in the session but you still have to stuff it into an instance variable inside whatever controller method is being called upon. I have a tingling sensation in my unmentionables that suggests session customization and databases can smooth out this bumpy road, but this strains the withering tethers of my sanity upon contemplation. I can only learn so much each day.
- Getting compile errors means you’re trying to bake a duck with a hammer on a string in a pail of kittens. It won’t work. Ruby/Rails doesn’t know or particularly care what you are trying to do, but how you are going about doing whatever it is you are trying to do will never, ever work no matter what. Get rid of whatever you added since the last time it worked and try again. Remember when you went to grandmas house and you had to take off your shoes and you weren’t supposed to go out into the field because you’d get muddy? Yeah, Rails has grandma rules that sometimes take all the fun out of life and make your feet cold.
Throwing away code is a part of development, just as throwing away designs is a part of being a designer. Having the willingness to let go of what’s not working makes room for what will. Even if what that is is nowhere to be seen at the moment.
idiotis.ms
things i learned the hard way | V.
@project = Project.find(params[:id]) @hours = @project.hours.find(:all)
has_many :hours
belongs_to :project
@total = @hours.billed_hours.inject(0) {|sum, element| sum + element}
*_WRONG!*_
I kept getting a noMethodError because there was no method called *billed_hours* in my model. WTF? After I inquired at the irc room #rubyonrails about how to do something like this I was directed back to the *inject* method, except this time I got the little nugget of enlightenment I so desperately needed. Check it out:
@total = @hours.inject(0) {|sum, element| sum + element.billed_hours}
holy slow sudo port install mod_ruby
There is a ghost impression of the keyboard etched into the surface of the LCD screen from the oil left on the keys by my fingers. I have dropped, sat on, stepped on, rolled over, spit on, slammed shut, forced open, poked, prodded, wedged, and pried loose this poor machine during the 6 years, 2 SXSW’s, many business trips, not as many vacations, and 6 operating system upgrades of it’s life.Every time I do something beyond surf the web on grandpa pismo and it doesn’t start smoking or tell me to hold the power button down in 5 different languages I experience a trepid euphoria not unlike that experienced by a man who only hears the metallic click of the firing pin during a game of russian roulette.
Around minute 30 of hour 2 of installing mod_ruby using darwin ports (just to see if I could) I started to get nervous. I was using a wireless connection, the elderly (original) battery was at 50% and sinking and I was having a hard time staying awake. it was 2:30 a.m. which is actually 3:30 am to my internal clock seeing as we’re only a few days in to the daylight savings time switch.
Being the dedicated, task focused person I am I… fell asleep.
I have yet to assess the outcome of this latest haphazard command line escapade.
