Code tagged with debugging

Handy CSS debugging snippet

I use the following bit of CSS to help visualize the structure of an XHTML (or HTML) document by putting a colored outline around the border of every element. At each level in the hierarchy the color changes so you can see when �??depth�?? changes.

* { outline: 2px dotted red }
* * { outline: 2px dotted green }
* * * { outline: 2px dotted orange }
* * * * { outline: 2px dotted blue }
* * * * * { outline: 1px solid red }
* * * * * * { outline: 1px solid green }
* * * * * * * { outline: 1px solid orange }
* * * * * * * * { outline: 1px solid blue }

I usually keep this block of rules at the top of a stylesheet, commented out with /*�?�*/, which I remove when I want to see the structure.
Language CSS / Tagged with debugging

Debugging with breakpoint

# Breakpoints allow you to step into a running program and poke around its 
# innards. This ability is great for both debugging and code exploration.

# Specifically, a breakpoint will pop up an interactive ruby(irb) session 
# at a pre-defined break point in a Ruby application.

Quick tips:

* use CTRL-D (Unix) or CTRL-Z (Windows) or exit to leave the breakpoint and continue running the program
* use exit! to terminate the program from within a breakpoint
* other interesting things to check out include: local_variables, instance_variables, caller, methods
* just type the name of your variable to check its value
* Note that you can enter any type of regular Ruby code into a breakpoint IRB shell. You can even hot patch your deployed code to fix a problem at run-time!
Language Ruby / Tagged with debugging

Automatically checking erb files for errors

(Posted by ulysses)
A bunch of errors occur because of bad template code. Although you can debug these by switching between your browser and IDE, it�??s easier if you can view the problems in your IDE.

An quick way to do this is to add this script to your path:
#!/bin/sh
/usr/bin/erb -x $1 | ruby -c
Configuring your IDE to run this script is highly dependent on which IDE you use. It should be pretty easy however, and any editor worth its bits should support running it with a quick key combo.
Language Ruby / Tagged with debugging