DZone 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

Snippets

  • submit to reddit

Recent Snippets

                    You can set sys.path from command line option.
I use it with Jython
java -Dpython.path="%GUESS_HOME%\src\Lib" -classpath "..."
                
                    
dir(obj)
vars(obj)
obj.__dict__

There are more information when call it again with
obj.__class__ and klass.__bases__                
                    By Lucas Carlson - http://tech.rufy.com/

class Integer
    alias _to_s to_s
    def to_s
        _to_s.reverse.gsub(/(\d{3})/, '\1,').chomp(",").reverse
    end
end
                
                    
<input type="button" value="Close" onclick="CloseWindow();" />
<script type='text/javascript'>
<!--
function CloseWindow() {
	ww = window.open(window.location, "_self");
	ww.close();
} 
-->
</script>
                
                    
font-family: "Hoefler Text", Baskerville, "Big Caslon", "Adobe Garamond Pro", Georgia, Palatino, "Times New Roman", serif;
                
                    By Ryan Carver of fivesevensix.com. Place in your application_helper.rb and call with <%= bodytag_id %>..

def bodytag_id
  a = controller.class.to_s.underscore.gsub(/_controller$/, '')
  b = controller.action_name.underscore
  "#{a}-#{b}".gsub(/_/, '-')
end
                
                    I need a fast, user friendly hash. This means I want it to be only capital letters and digits. No symbols that people can't pronounce, and no mixed case to be misunderstood on the phone, etc. Use a hashing method like MD5 or SHA1 first, and then apply this..

Ruby
newhash = oldhash.scan(/./).map{|t1| t2 = t1[0] % 36; t2 < 26 ? (t2+65).chr : (t2+22).chr }.join
Perl
$newhash = join "", map { $t1 = ord($_) % 36; $t1 < 26 ? chr($t1+65) : chr($t1+22) } split(//, $oldhash);
This turns any hash into only using [A-Z0-9]. Even a 8 character hash/key using [A-Z0-9] results in 2,821,109,907,456 combinations ;-)                
                    
https://USERNAME:PASSWORD@gmail.google.com/gmail/feed/atom
                
                    
class ApplicationController < ActionController::Base
  before_filter :disable_link_prefetching

  private
    def disable_link_prefetching
      if request.env["HTTP_X_MOZ"] == "prefetch" 
        logger.debug "prefetch detected: sending 403 Forbidden" 
        render_nothing "403 Forbidden" 
        return false
      end
    end
end

Code by David Heinemeier Hansson.