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


shelling out to the man

In irb: get a listing of files/sym/hard links in my home directory
# 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!)

Posted by jeremy Mon, 05 Jan 2009 23:03:00 GMT


violating the linksys rvs4000

FTP is way the fuck broke on my past the return product policy expiration date of my gigabit router. I want to hack it but A) I'm just not that skilled in the ways of *nix; b) I'm too lazy to learn mips cross-compiling for linux embedded systems (whatever the fuck that means).

So I google my incompetence as usual. Search for "rvs4000 ftp" and you get a whole lot of what you already know. The shits broke. No ones gonna fix the shit. You're ten kinds of fucked if you want to ftp anything, ever.

So I roll a search on the processor "star 9202" which drops me a few gems of badassery:
Hacking the WRVS4400NX Stock Firmware V1.1.03 for Full Linux Shell Access
http://openwrt.org/logs/openwrt.log.20071102

Not my model - but it appears the only difference betweenRVS4000 and the WRVS4400N is that the WRVS4400N has a wireless chipset - that is a separate processor to run the wireless services with.

So they seem to be the same except one does wireless and one does not. So I go to the diagnostics pages of the administration ui and start pasting in the different commands from the "Hacking the WRV44...." post to see what happens. No dice. The ftp no longer works - probably a good thing - so I start stumbling around the web glossing over many pages of stuff about busybox. I try pasting in all kinds of shell commands into the way not secure 'Traceroute Target:' field when I happen to get a command to try off of the busybox wikipedia page: ';/bin/ls' - I paste-a-bitch and wa-la:

ARARPTable.htm
AccessRes.htm
Administration.htm
AppGaming.htm
Backup.htm
DHCPClientTable.htm
DMZ.htm
Diagnostics.htm
EditList.htm
Factorydefaults.htm
FirmwareUpgrade.htm
Hidden_telnet.htm
IM-P2P.htm
IPS-N.htm
LocalNetwork.htm
Log.htm
Ping.htm
PortRangeTriggering.htm
QoS.htm
Quick_vpn_setup.htm
RVS4000_Admin.pem
RVS4000_Client.pem
Reboot.htm
Report_Pic-n.jpg
Routercfg.cfg
Routing_Table.htm
Security.htm
Setup.htm
Setup_MAC.htm
Setup_lan.htm
Setup_routing.htm
Setup_summary.htm
Setup_time.htm
Setup_wan.htm
SingleForwarding.htm
Status.htm
Summary.htm
UI_02.gif
UI_03.gif
UI_04.gif
UI_05.gif
UI_06.gif
UI_07.gif
UI_10.gif
UI_Cisco.gif
UI_Linksys.gif
VPNPassthrough.htm
acl.htm
cisco.css
down_chart.jpg
err_msg
func.js
fw_version.pat
help
index.htm
info.htm
ip_conntrack.htm
left.gif
linux.js
log_data.htm
log_outin.htm
middle.gif
mm_menu.js
msg.js
new_rule.htm
po1_0.gif
po1_1.gif
po2_0.gif
po2_1.gif
po3_0.gif
po3_1.gif
po4_0.gif
po4_1.gif
ppp_log
qos_service_managment.htm
quickVpnStatus.htm
raw_data.htm
reboot_guage.htm
report.htm
restore_config.cgi
rh_bg.gif
rh_cisco.gif
right.gif
rvs4000
service.htm
set_vpn.js
setup.cgi
switch_8021x.htm
switch_diagnostic.htm
switch_dscp.htm
switch_mirror.htm
switch_param.htm
switch_port.htm
switch_qos.htm
switch_queue.htm
switch_rstp.htm
switch_status.htm
switch_vlan.htm
switch_vlan_mem.htm
switch_vlan_port.htm
table.jpg
table.png
tr069
tracert.htm
trash.gif
up_chart.jpg
upgrade_flash.cgi
upgrade_pem.cgi
upgrade_sig.cgi
upload_lang.cgi
vpn_adv.htm
vpn_main.htm
vpn_summary.htm
vpnsum.htm
wan_0.gif
wan_1.gif


Would you check that the fuck out!?! 'Hidden_telnet.html' I (again) paste-a-bitch and HOT DAMN if I don't get some purty radio buttons. And after i click yes in the little circle and save the settings hot damn if i don't have an insecure as all holy hell no login needed telnet accessible router spread wide open and waiting like a rufied sorority pledge coed at the frat kegger... and a quick test of my dyndns enabled domain confirms that yes, I do have world facing telnet access of my router sans any security. None, nada. Zero. Luckily I can uncheck my telnet access on my hidden telnet access page and then save settings so I longer have hidden telnet access.

speedy:~$ telnet 192.168.0.1
Trying 192.168.0.1...
Connected to 192.168.0.1.
Escape character is '^]'.


BusyBox v1.00 (2007.09.12-05:31+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

# help

Built-in commands:
-------------------
        . : break cd chdir continue eval exec exit export false hash
        help local pwd read readonly return set shift times trap true
        type ulimit umask unset wait

# ls
Active_ALG.list          linuxrc                  sbin
bin                      lost+found               tmp
dev                      nat-pt_packet_stats_log  usr
etc                      proc                     var
lib                      root                     www.eng
# ls bin
ash          df           ipaddr       mount        radvd        umount
brctl        dhcp6-serv   iplink       nat-pt       rm           uname
busybox      dmesg        iproute      netstat      sed          vi
cat          echo         iptunnel     ping         sh
chmod        flash_tools  kill         ping2file    sleep
chown        gzip         ln           ping6        sysinfo
cp           hostname     ls           ps           tar
date         ip           mkdir        pwd          touch
# exit
Connection closed by foreign host.


Maybe I can use this knowledge to fix my ftp problem. Or to get my whole home network compromised.

Posted by jeremy Tue, 17 Jun 2008 12:05:00 GMT


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.

Posted by jeremy Mon, 10 Apr 2006 23:28:00 GMT


on the process of progress

Essential understanding: In php str_replace and preg_replace do function similarly yet if you want exact matches you have to specify your regexp pattern with serious prejudice lest you match ANY and ALL partial or exact string matches and fubar your sweet logic with redundant nasties. I consider knowing this progress. Next up is understanding the hows and whys of stringing methods in ruby... Feet don't fail me now!

Posted by jeremy Fri, 10 Mar 2006 18:11:00 GMT


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.

Posted by jeremy Fri, 24 Feb 2006 17:29:00 GMT


things i learned the hard way | V.

First things first. When you make models and then relate them to each other using :belongs_to and :has_many you automagically add a _*method*_ that is the name of your class in your model to all of the other models it has a relationship with. Yes, I know this is 1A Rails stuff but I don't learn as fast as you big brains out there. I started on this journey in 1996 making label tags to stick on furniture for presidents day sales with one ink color while an angry marketing director denounced my lack of moxie. It's a long way from learning how to use the pen tool in illustrator 5 to here. Now that things are really weird here's some code:
@project = Project.find(params[:id])
@hours = @project.hours.find(:all)
I have a *Project* model and an *Hour* model. I have a _projects_ table and a _hours_ table in my database. I use:
has_many :hours
in my project model and:
belongs_to :project
in my hour model. This is why I can apply the _hours_ method to my @project array of objects. ActiveRecord does the hard stuff. Now I wanted to get the total of all the hours for a project. But how to do this? At first I tried looping and trying to add each hours_billed to the next one in the array but I kept getting a fixnum error, or being told that it can't write string to whatever. Yeah, I'm a big dumb monkey hoping to be the one in a million to randomly reproduce the works of shakespeare by banging on my powerbook while shrieking and flinging my poo. I eventually opened my picaxe and found something called *inject*. This looked promising. But I, in my unique way, visualized my @project array as needing to be fiddled with to extract the column I wanted and get the value that was inside of it. I tried:
@total = @hours.billed_hours.inject(0) {|sum, element| sum + element}
Thinking this is how it should work. I mean when you loop through your instance variables in your views you access the attributes of your object by putting _object.your_column_ so I thought this was the way to do it.

*_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 shit! It worked!. I was trying to force it before it was ready (that's what she said) and all I needed to do was understand how you use the *inject* method to iterate through a collection of objects. My assumption of needing to extract the attribute before the block was wrong _wrong_ _*wrong*_! You feed your collection of arrays into the block AND THEN call the attribute you want from each array inside of the block statement and as it evaluates each array that passes through your magic walking fingers machine it will add the stuff you tell it to and when it gets done you have a total. I plan on extrapolating this knowledge into more understanding and eventually prettier code. I'm always getting ahead of myself, and this was just one in a lifelong string of examples. The pragprog books use encouraging, accessible language to explain and educate someone who is using their materials to learn Ruby and Ruby on Rails. I know the words are giving me the information I need. The problem comes when my internal parser bends the words into a funhouse mirror reflection of their literal meaning and then I find myself feeling like I'm 2 steps behind and I missed the base abstractions that everyone else just knows because why wouldn't you know that, stupid? I'm fighting 3 battles at once with this stuff. I'm fighting the learning disability with language, the attention deficit disorder, and the peculiar emotional twists that can result from 30 years of living with the first two. I think in dependencies and relationships. Everything has a cause and effect. I've always understood that information is constant, it is just it's form that changes. The major hurdle has been translating the syntax into jeremy-speak and converting external information to internal understanding while avoiding the frustration and despair these activities can produce. So now I know you can get at the attributes of your object (the columns in your rows) inside the block that the inject method expects as an argument. Next.

Posted by jeremy Sat, 21 Jan 2006 17:32:00 GMT


imagemap rollovers with area shape="poly\

The document object model is sweet, sweet nectar dripping from the bosoms of the gods. The supa-genius cats who whipped that shit up are rock solid, grade A badassmotherfuckers.

It’s like this, all you gotta do to interact with the areas of your image map is a little javascript:

var map = document.getElementsByTagName('area');
Now there’s an objectHTMLCollection , or if you prefer, an array named map containing all of the area tags in the document. My page has 6 area tags. I can read the id attribute from any of the objects in the map array by using the index like this:
map[0].id
The above would return:
northamerica
which is AWESOME! You’ll see why in a second.

Next up is to access and alter the background of the invisible gif I’m using as a mask to show small sections of the HUGE background image that contains all of the over states for my image map links.

I’ve conveniently given my transparent gif the id of mapimg so all I have to do to play with it is:
mapbg = document.getElementById('mapimg');
Now I have my transparent gif and it’s attributes all tucked inside my mapbg variable ready to be fondled and violated. Violate it I will.

I’m going to take the id from the area my mouse is over in the map array and use it to alter the className in my mapbg object.

Now the AWESOME part: the id ’s in my area ’s have corresponding classes in my css file! So by looping through my map array I can get the relevant area and feed it to the hungry ‘onmouseover’ and ‘onmouseout’ event handlers:
function readMap ()
 {
     var map, i;
     // get array of map area tags
     map = document.getElementsByTagName('area');
     for(i=0;i<map.length;i++)
     {
     map[i].onmouseover=function(){shift(this);};
     map[i].onmouseout=function(){shift(this);};
     }
 }
And then hand things over to the shift function for some background repositioning madness:
function shift (o)
 {
     var mapbg, id;
     id = o.id;
     mapbg = document.getElementById('mapimg');
    if(id == mapbg.className){
     mapbg.className = 'mapbase'; 
    }else{
     mapbg.className = id;
     }
 }
First up after I initialize my var’s is to grab the id attribute from where the mouse is and give it to a variable named id. The o* in that line is where ever the mouse is hovering on the image map. It was passed from *this inside our readMap function.

Then I get the current state of the image map’s background and test to see if I need to un-hover by seeing if my id and my className match. If they don’t I rewrite the className (class) of the transparent gif with the id attribute of the area the mouse is over.

So when you roll over North America:
<img src="spacer.gif" usemap="#Map" class="mapbase" id="mapimg" />
Would become:
<img src="spacer.gif" usemap="#Map" class="northamerica" id="mapimg" />
and so on… It won’t work if I don’t call the function when the page is loaded:
 window.onload=function(){
  readMap();
 }

The next iteration of this script would be to capture the initial class attribute of the transparent gif and store that for testing instead of hardcoding the default class value into the if statement of the shift function. Then the only thing needing to be changed to use this code with any image map is the getElementById() id value. As long as you have a corresponding class for each area’s id value it should travel from page to page rather painlessly.

Any comments from people smarter than me would rock as I’m new to this DOM/Javascript gig.

Posted by jeremy Tue, 20 Dec 2005 11:12:00 GMT


holy slow sudo port install mod_ruby

Every time I challenge the silicon gods by installing yet another demanding software package on my powerbook G3 I always start by consciously dismissing the age and condition of the laptop. The machine is 6 years old, has 386mb of ram, a 9 gig hard drive, a 500mHz processor, and a first generation airport card. After installing tiger and developer tools there is a little under 2gb of disk space left.

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.

Posted by jeremy Wed, 23 Nov 2005 11:00:00 GMT


learned the hard way | I.

Ceaseless curiosity and always taking 3 lefts to go right. Some things gleamed recently:
  • 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.
Just a few of the many things I’ve learned. This knowledge is basic, but I didn’t have it before. I was stuck. With enough ritalin and diet coke I was able to keep banging my head on the terminal until a curiously dull exclamation mark would appear above my head and I would make a simple and obvious change in my approach that is assumed knowledge everyone got two minutes after they were taught where the power button was on their machine but I never learned because I don’t play well with others or authority figures.

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.

Posted by jeremy Sat, 19 Nov 2005 12:00:00 GMT