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

                    Float clearing CSS...

.container:after {
    content: "."; 
    display: block; 
    height: 0; 
    clear: both; 
    visibility: hidden;
}

.container {display: inline-table;}

/* Hides from IE-mac \*/
* html .container {height: 1%;}
.container {display: block;}
/* End hide from IE-mac */
                
                    If WEBrick is leaking out of control, which it does do all the time, shut it down and restart it. 
Ctrl-c + Up + Enter
WEBrick can slow your computer down to a crawl so it is reccomended that you only use it when it's needed. Otherwise just runs tests, WEBrick's leaks are just another great reason to adapt to test driven development.                
                    one-liner to print out the current date & time given the time()

perl -le 'print scalar localtime shift'
                
                    <!--
*** str_repeat
*** Returns str repeated multiplier times
*** Param str = the string
*** Param multiplier = the string
-->
-
	<xsl:stylesheet version="1.0">
-
	<xsl:template match="/">
<xsl:param name="string" select="'Hello'"/>
-
	<xsl:call-template name="str_repeat">
<xsl:with-param name="str" select="$string"/>
<xsl:with-param name="multiplier" select="number(10)"/>
</xsl:call-template>
</xsl:template>
-
	<xsl:template name="str_repeat">
<xsl:param name="str"/>
<xsl:param name="multiplier"/>
<xsl:param name="count" select="number(1)"/>
-
	<xsl:if test="$count <= $multiplier">
-
	<xsl:call-template name="str_repeat">
<xsl:with-param name="str" select="$str"/>
<xsl:with-param name="multiplier" select="$multiplier"/>
<xsl:with-param name="count" select="$count+1"/>
</xsl:call-template>
<xsl:value-of select="$str"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>                
                    <!--
*** ucfirst
*** Make a string's first character uppercase
*** Param str = the string
-->
-
	<xsl:stylesheet version="1.0">
-
	<xsl:template match="/">
<xsl:param name="string" select="'the quick brown fox jumped over the lazy dog.'"/>
-
	<xsl:call-template name="ucfirst">
<xsl:with-param name="str" select="$string"/>
</xsl:call-template>
</xsl:template>
-
	<xsl:template name="ucfirst">
<xsl:param name="str"/>
<xsl:param name="strLen" select="string-length($str)"/>
<xsl:variable name="firstLetter" select="substring($str,1,1)"/>
<xsl:variable name="restString" select="substring($str,2,$strLen)"/>
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="translate" select="translate($firstLetter,$lower,$upper)"/>
<xsl:value-of select="concat($translate,$restString)"/>
</xsl:template>
</xsl:stylesheet>                
                    def foobar(astring, bstring)
  Hash.new do |l,(i, j)|
    if l.key? [i, j]
      l[[i, j]]
    else
      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
    end
  end[[0, 0]]
end
                
                    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 ^(.*)$ http://www.example.com/$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 "somediscernible-feature.com" '{}' \; | 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

/var/spool/postfix/active/D/D8832E38
/var/spool/postfix/active/D/D78EC1C72
/var/spool/postfix/active/D/D593D279D
/var/spool/postfix/active/D/D0EB32833

And then the mv, moves it.                
                    
class ApplicationController < ActionController::Base
  before_filter :choose_theme
  
  private
  def choose_theme
    ActionController::Base.template_root = File.join(RAILS_ROOT, 'app/views', @params['theme'])
  end
end