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

                    
<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.                
                    
mount_smbfs -W workgroup //user@SERVER/folder ./mntpoint
                
                    By Shane Allen.

RewriteEngine On
RewriteCond %{HTTP_X_MOZ} ^prefetch$
RewriteRule ^.*$ - [F]
                
                    Suppose you have a bunch of files where you need to make the same substitution. This oneliner will make the substitution and keep the old version in backups. This is particularly handy for configuration files.

perl -p -i.bak -e 's:oldtext:newtext:g' *.conf