Javascript Exceptions - testing for true - When is undefined actually undefined?
if (unreferencedVariableName) { alert('Impossible! an unreferenced variable cannot return true. In fact it cannot return at all!'); }
/* is as true as the unescapable pain and suffering of being an alive human being */ if (typeof(cowBoySuckMonkey) === 'undefined') { console.log('suck it!') } /* these are false - no if-fu for you! */ if (typeof(cowBoySuckMonkeee) != 'undefined') { console.log('suck it again!') } if (!typeof(cowBoySuckMonkeee)) { console.log('suck it for real!') } /* 'undefined is something I guess - just not what I wanted to test against */ if (typeof(cowBoySuckMonke)) { console.log('suck it nut gobbler!') } var cowboySuckMonkay = ''; if (typeof(cowboySuckMonkay) != 'undefined') { console.log('suck it empty string!') } /* no joy */ if (typeof(cowboySuckMonkay)) { console.log('suck it empty string, part duex!') } /* well, I guess an empty string is false - CaulkGobblin! */ if (cowboySuckMonkay) { console.log('suck it empty string, you still not true!') } if (cowboySuckMonkay == '') { console.log('suck it empty string, now you true!') }
comparison of Fixnum with String failed
Where the error occured
Rails 2.1.2 / bundle_fu / Javascript fileWhy the fu…?
A javascript files that ends with a line commented out. -1 is being compared to an empty string.Fix
Add a blank line at the end of the Javscript file(s) that end with commented lines.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!)
rails rjs - things i learned the hard way | xi
too many div’s and things go POOF!
When you have a styled div set with an id inside another div on safari at least. I’m going to explore this further, but it seems at this point I’m stacking my nodes too deep, MEANING if a styled div is inside another div that is replaced by an rjs template which has a visual effect to appear the styled stuff inside the div inside the one affected by the javascript response will remain hidden while all the stuff around it will pop into view. Selecting on the screen around the blank areas will reveal the content. Use span’s or class declarations to avoid the same 4 hours of frustration I just had. Of course this could all be wrong and I’m foolishly pointing west when the true way is north. In any case it wasn’t working as expected and now it is so I am of the mind that I solved my problem, be it maybe for only a moment.
remember to float the containers holding the floats
And clear your floats. Boxes are a pain. Tables are ugly. Love thy stacked attributes.
That is all.
on the process of progress
the teh
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.
learned the hard way | I.
- USE ‘apachectl’ NOT ‘httpd’ to stop apache1.3 and release the port. THEN ’ sudo /opt/local/apache2/bin/apachectl -f /opt/local/apache2/conf/httpd.conf -k start ’ to get apache2 running. Specifying the full paths is how you tell apache2 it’s their turn to bat.
- apache2’s http.conf default took two days of my life away. Comment out the unique ID module line and blues skies will you see.
- to use new config use the command above, but replace ‘start’ with ‘graceful’
- alias and directory settings are a bitch.
One interesting twist is that the big bad scary complex command line has been demystified. I kinda got it now. Now when something doesn’t work I have a 50% chance of knowing what question to ask and where to look to find out what I’m not doing correctly. Prior to this point in time I would’ve had a snowballs chance in hell of fixing something on the command line if I broke it. This is what an optimistic person would call progress.
I started as a graphic designer (layout monkey) and it’s been a long road of learning by necessity how to make stuff with html, css, php, mysql, javascript, and now ruby/rails. Still learning. Always have been. Always will be. It’s a bitch.