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


  • submit to reddit

Recent Snippets

                    def foobar(astring, bstring) do |l,(i, j)|
    if l.key? [i, j]
      l[[i, j]]
      a, b = astring[i], bstring[j]
      l[[i, j]] = case
      when !a, !b then  0
      when a == b then  1 + l[[i + 1, j + 1]]
      else              [ l[[i + 1, j]], l[[i, j + 1]] ].max
  end[[0, 0]]
                    Use this in your print style sheet. Works only in "better browsers".

a[href] {
  text-decoration: none;

a[href]:after {
  content: " (" attr(href)") ";
RewriteEngine On

RewriteCond %{HTTP_HOST} !^(.*)\.example\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]
                    We don't really want to delete them all just in case.

cd /usr/local/scratch/
mkdir junk
find /var/spool/postfix -exec grep "" '{}' \; | awk '{print($3)}' | xargs -J X mv X ./junk/

The "find" produces

Binary file /var/spool/postfix/active/D/D8832E38 matches
Binary file /var/spool/postfix/active/D/D78EC1C72 matches
Binary file /var/spool/postfix/active/D/D593D279D matches
Binary file /var/spool/postfix/active/D/D0EB32833 matches

The awk


And then the mv, moves it.                
class ApplicationController < ActionController::Base
  before_filter :choose_theme
  def choose_theme
    ActionController::Base.template_root = File.join(RAILS_ROOT, 'app/views', @params['theme'])
                    To always show the vertical scrollbar, regardless of whether there is content to scroll (à la Internet Explorer), add this to userContent.css

html {
     overflow: -moz-scrollbars-vertical;

Tested in Firefox 1.0 and above.                
                    To have a <DIV> shrink and enlarge based on its content, use this CSS:

div.autosize { display: table; width: 1px; }
div.autosize > div { display: table-cell; }

In your HTML, enclose the <DIV> you want autosized in another <DIV> with class="autosize"


I want this to be auto sized!


<div class="autosize">
I want this to be auto sized!

Tested in Firefox, Mozilla, Safari, Opera 7, and Internet Explorer 6.                
                    If you have a table with rowspans and colspans, it's especially likely that IE6 will begin to ignore your width settings (even if they all add up to the right number) and create a monster table that spreads off into the distance. If your tables work perfectly in FF/Safari/etc, and in IE6 your content is positioned properly but the invisible elements of the table (visible only with borders on) extends to the side so that you get a horizontal scroll bar no matter what you do, you might want to try this drastic CSS tweak:

html {
    overflow-y: hidden;

If that doesn't work, try it in body:
body {
    overflow-y: hidden;

<disclaimer>Note that this is somewhat hackish, as a last resort if you *know* your tables are *fine* and IE6 is screwing up, and that overflow-x/y are IE6-only and not real CSS. </disclaimer>                
function hexToRGB ( hex:Number ){
   var returnObj:Object = new Object();   
   var returnObj .r = hex >> 16;
   var temp = hex ^ r << 16;
   var returnObj .g = temp >> 8;
   var returnObj .b = temp ^ g << 8;

   return returnObj;
function RGBToHex (r, g, b ){
    var hex = r << 16 ^ g << 8 ^ b;
   return hex;