Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 11-16 of 16 total

Turn on DEBUG in C sources files

    //
    // Turn on debugging if desired.
    //
    char* env_ptr = getenv("DEBUG");
    if (env_ptr != NULL && toupper(*env_ptr) == 'Y')
    {
        SET_ZFLAG(ZFLAG_DEBUG_EVERYTHING);
    }

links for debugging javascript

// description of your code here

Loggers
my simple logger
MochiKit logger

Online interpreters
Squarefree JS shell 1.4
MochiKit JS interactive interpreter
TryIt Editor

debugging bookmarklets
view source
linked scripts list

// insert code here..

logging bookmarklets for debugging javascript

Dragg the following two links to your browser's toolbar (tested with Firefox 1.5 and IE 6) :
49.cl
49.sh

When you are writing some javascript embedded in a webpage and you want to debug your code, this gives you way to log things without alerting them.

Example :
// part of embedded javascript code
log49 = [];//log49 is global variable.
var num = 1;
log49.push('num = '+num); // log the state of num
num = num+1;
log49.push('second num ='+num); // again.


Then the two bookmarklets let you reset or view the log in runtime.
49.cl lets you reset the log by clearing the list stored in the global variable log49.
49.sh shows you the log by joining and alerting the value of log49.

Customize error dialog

window.onerror = function(mes,file,num){
    alert([
        "file    : " + file,
        "line    : " + num,
        "message : " + mes
    ].join("\n"));
    return true;
}

with XMLHttpRequest
http://la.ma.la/misc/js/debugscreen/

var_dump for javascript

hackish implementation of the php 'var_dump()' in javascript:

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump

Rails Debug Popup - Makes easy to debug info.

module DebugHelper
  
  def self.append_features(controller) #:nodoc:
    controller.ancestors.include?(ActionController::Base) ? controller.add_template_helper(self) : super
  end
    
  IGNORE = ["template_root", "template_class", "response", "template", "session", "url", "params", "subcategories", "ignore_missing_templates", "cookies", "request", "logger", "flash", "headers" ]

  
  def debug_popup

    popup_create do |script| 
      
      script << add( "<HTML><HEAD><TITLE>Smarty Debug Console_#{@controller.class.name}</TITLE></HEAD><BODY bgcolor=#ffffff>" )

      script << add( "<table border=0 width=100%>" )
      script << add( "<tr bgcolor=#cccccc><th colspan=2>Rails Debug Console</th></tr>" )
      
      script << add( "<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>" )      
      @controller.assigns.each do |key, value|
          script << add ("<tr bgcolor=#eeeeee><td valign=top><tt><font color=blue>#{h key}</font></tt></td><td><tt><font color=green>#{dump_obj(value)}</font></tt></td></tr>")  unless IGNORE.include?(key)
      end unless  @controller.assigns.nil?


      script << add( "<tr bgcolor=#cccccc><td colspan=2><b>request parameters:</b></td></tr>" )
      @controller.params.each do |key, value|
          script << add ("<tr bgcolor=#eeeeee><td valign=top><tt><font color=blue>#{h key}</font></tt></td><td><tt><font color=green>#{dump_obj(value)}</font></tt></td></tr>")  unless IGNORE.include?(key)          
      end unless  @controller.params.nil?


      script << add( "<tr bgcolor=#cccccc><td colspan=2><b>session variables:</b></td></tr>" )
      @controller.session.instance_variable_get("@data").each do |key, value|      
          script << add ("<tr bgcolor=#eeeeee><td valign=top><tt><font color=blue>#{h key}</font></tt></td><td><tt><font color=green>#{dump_obj(value)}</font></tt></td></tr>")  unless IGNORE.include?(key)          
      end unless  @controller.session.instance_variable_get("@data").nil?


      script << add( "<tr bgcolor=#cccccc><td colspan=2><b>flash variables:</b></td></tr>" )
      @controller.instance_variable_get("@flash").each do |key, value|
          script << add ("<tr bgcolor=#eeeeee><td valign=top><tt><font color=blue>#{h key}</font></tt></td><td><tt><font color=green>#{dump_obj(value)}</font></tt></td></tr>")  unless IGNORE.include?(key)
      end unless @controller.instance_variable_get("@flash").nil?
        
    end
  
  end

  private
  
  def popup_create
    
    script = "<SCRIPT language=javascript>\n<!--\n"
    script << "_rails_console = window.open(\"\",\"#{@controller.class.name}\",\"width=680,height=600,resizable,scrollbars=yes\");\n"
    yield script
    script << "_rails_console.document.close();\n"
    script << "-->\n</SCRIPT>"
  
  end
  
  
  def add(msg)
    "_rails_console.document.write(\"#{msg}\")\n"
  end  
  
  def dump_obj(object)
    begin
      Marshal::dump(object)
      "<pre>#{h(object.to_yaml).gsub("  ", "&nbsp; ").gsub("\n", "<br/>\"+\n\"" )}</pre>"
    rescue Object => e
      # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
      "<pre>#{h(object.inspect)}</pre>"
    end
  end

  
end


I got this from EpiLog after seeing it mentioned on on the HowToDebugViews wiki. It is a helper class which will raise a Smarty like popup dumping all assigns, sessions, parameter and flash. Install it into your helper directory and include DebugHelper in your application controller. In your view (perhaps the bottom of your generic layout) add <%= debug_popup %>. Make sure to disable your popup blocker.

This is especially useful if you work together with designers who have no idea what kind of information are exported by the controllers in a given view.
« Newer Snippets
Older Snippets »
Showing 11-16 of 16 total