Things I learned the hard way XIVII

jQuery When the DOM isn't reacting to your javascript selectors as expected try a little specificity: instead of this:
  $("#item_id > a")
do this:
  $("#item_id > ul > li > a'")

Posted by jeremy Sun, 14 Feb 2010 23:41:00 GMT


Snow Leopard 10.6 Rails/Passenger

Got this error when loading a rails site served under my local apache"
*** Exception RangeError in PhusionPassenger::Railz::ApplicationSpawner (integer 4294967294 too big to convert to `int') (process 1097):
I updated my passenger gem and regenerated the apache passenger module, updated the httpd.conf at it was all good after that.

Posted by jeremy Sat, 05 Sep 2009 23:10:00 GMT


Javascript Exceptions - testing for true - When is undefined actually undefined?

Javascript has to know what 'it' is before Javascript can tell if 'it' is what you want 'it' to be. Example:
if (unreferencedVariableName) { alert('Impossible! an unreferenced variable cannot return true. In fact it cannot return at all!'); }
Result: ReferenceError: unreferencedVariableName is not defined
/* 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!') }
so much to remember…

Posted by jeremy Tue, 18 Aug 2009 22:06:00 GMT


comparison of Fixnum with String failed

Where the error occured

Rails 2.1.2 / bundle_fu / Javascript file

Why 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.

Posted by jeremy Sat, 15 Aug 2009 14:45:00 GMT


snipdbits

I've been rocking the Javascript one liners lately. Syntax like this is way not noob friendly.
// both are the same
  if ( 0 == 0 && 0 === 0)
    alert('0 is equal to 0, and 0 is the same value and object type as 0');


  if ( 0 == 0 && 0 === 0)  alert('0 is equal to 0, and 0 is the same value and object type as 0');

Posted by jeremy Thu, 06 Aug 2009 15:28:00 GMT


designation agitator

My favorite class name when styling a page is ‘padahoe’. If anyone ever asks what it stands for I’ll tell them “pad a horizontally oriented element”. Lies, damn lies, statistics.

When I commit to git I tend to flavor my commit messages with humorous snark, usually related to how something in the application is deviously circumventing my attempts to enforce my authority. My logic is shot through with regression insurgents.

Posted by jeremy Thu, 02 Apr 2009 21:14:00 GMT


jrails link_to_function hackaway

<%= link_to_function( "insert it", :id => 'foo') do |page| 
      partial = escape_javascript(render :partial => "my_partial", :object => Object.new)
      page <<  "$('#my_div').append('#{partial}')"
    end %>

Sweetness.

Posted by jeremy Wed, 01 Apr 2009 08:56:00 GMT


happens not adderall in the business of

all lies – less pain to just use current_user and accept the inaccurate naming of the models intent in the instance variable.

fuckin’ fuck, man.

I use restful_acl gem and the restful_auth plugin – restful_auth has generators so that when you create the restful authorization model it will take your class name and fill in the places where it needs to go I have an account model instead of a user model so it filled in all of the instance variables for authenticated user methods with current_account. The restful_acl gem is hardcoded to the current_user instance variable. So I opened the module and method in a file in /lib called restful_acl_controller_hacks.rb so I could alias current_account to current_user.


module RestfulAclController
  module ClassMethods
    def has_permission?
      alias current_user current_account
    end
  end
end

Then I required the file in the application controller:

  require 'restful_acl_controller_hacks'

Now has_permission? works and my specs pass and all is right with the world. For about 2 minutes until I smash into another coding wall due to my lack of experience and inability to remember most things of importance related to OOP.

Posted by jeremy Sat, 07 Feb 2009 02:56:00 GMT


stupid arguments

rspec controller specs: YourClass.should_receive(:find).with() really cares about argument order and does not accept a hash of values where the params[:key] is named like the key in the hash key => value so:
## 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
Yes, I know about hash_including(). For some reason it failed because ":action => '_controller_action_', :only_path => true" was being included in the with() arguments hash and it made the should_receive fail - even though hash_including is supposed to deal with this. It may be a rspec_rails thing. I have not dug into the rspec code very deep to see what I was doing wrong or if it's a bug or if the universe just hates me.

Posted by jeremy Thu, 22 Jan 2009 06:44:00 GMT


probable knot

Programming wasn't something that I thought I could learn a few years ago. I was a web designer. I struggled to xhtml/css as I tried to cut up the psd of a site design and make it into a web page. Even though it was what I did exclusively at that time as my profession, I found the end of every project a narrow escape from total annihilation. Rarely did the conclusion of a project leave me with a sense of accomplishment. The problem was (and still is) that design is so subjective. A clients taste, mood, corporate politics, over developed sense of competence, favorite color, or what ever can lead them to totally rip apart a well reasoned, professional interface design. Design is too subjective. Don't get me wrong on this, I understand that the client is always right and I was being paid to make them happy and not satisfy my aesthetic sense and motivations. It was the random and non-sensical ways they would destroy something I had spent many hours crafting. All that thought, research, and experimentation swiped aside on a whim by someone who thinks they know more about how to design a website than I do, and yet are paying me to make one for them.

What attracted me to the development side of things is the absolutes. A function returns the right value or it doesn't. It is all about consistent and repeatable results. A finite set of rules govern all aspects. You can always find a solution, and when you have it there is a verifiable outcome to confirm it. Not so much with the wild ass world of colors, images, tones, and narratives. I can learn the rules of the language and build outward in my knowledge and understanding. With design the rules are different in how you understand them and their application. Most importantly clients don't know a damn thing about programming, mostly convinced its dangerous magic that will burn them if they touch it.

Programming has the same potential for creative exploration. I know this, and I really want to get to a place where I have the familarty and experience with the tools to do some of this exploration, but I am constantly set back due to my lack of the personality and natural abilities of a traditional programmer. I really love logic and elegance, but I don't naturally think in numbers and equations. I do not have a mathmatical brain. I've always struggled with language and symbols, I was even diagnosed in my school years with a learning disability in english. I find it very hard to draw the lines between ideas and concepts and where I should practically apply them, more so how to go about even starting to. I do have breakthroughs though. I can hammer my head against an idea or programming concept for 12 hours straight and after I've broke it every way possible and read dozens of tutorials, blog posts, and book pages I'll suddenly have an intuitive insight into how to apply the idea to my problem and then I will rapidly sprint to a complete solution.

And I will only retain 20% of my understanding so the next time its almost like starting over. That is the most frustrating part. How little of the knowledge I retain that I've worked so hard to find. I write notes, comment my code, play with mnemonic devices to remember argument orders or function names but I still struggle and have to spend nearly as much time looking things up as being productive. And that's for the easy stuff. I have no idea if this is a normal experience or not. If other people find it as difficult to learn and retain the myriad of syntax, patterns, methodologies, and rules that are designed to make it easier to write things a computer can turn into machine code.

I really wish I knew how to ask questions. Most times it feels like if I knew what question I was asking I wouldn't need to ask it. That is, if I could articulate with words the difficulty I'm experiencing with something - the part I don't understand - just the act of coming up with those words would make apparent the answer. I also fear that my questions are probably one level or more below where I'm trying to work - such as I'm struggling with object type handling (like how to think about what an object is) while this knowledge is assumed and the stuff I'm trying to accomplish requires concrete understanding of enumerations, module mixins, closures, proc/lamda, or class inheritance.

So why do I do it? Partly because of the stimulation. I possess intense amounts of curiosity. Programming at times is so much outside my intellectual capabilities that I feel crushing demoralization, but those times I gleam some intuitive understanding of the inner workings of a complex system of events I become electrified. I beat the motherfucker! Ha ha universe! Fuck you and your abject indifference! I made this bitch work! Suck it!

What follows is a dark period of inactivity that lasts until the next struggle to learn, breakthrough, and crash. The cycle repeats and I learn and retain just a little more so that the next time I find out how to make the problems harder. It's not nearly as stimulating to solve something over again as it is to make what I want to achieve more complex.

Posted by jeremy Tue, 20 Jan 2009 03:52:00 GMT