<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Jnunemaker's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 05:04:05 GMT</pubDate>
    <description>DZone Snippets: Jnunemaker's Code Snippets</description>
    <item>
      <title>no www</title>
      <link>http://snippets.dzone.com/posts/show/3061</link>
      <description>&lt;code&gt;&lt;br /&gt;RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]&lt;br /&gt;RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 30 Nov 2006 07:00:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3061</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>SSH Key Pairs Stuff</title>
      <link>http://snippets.dzone.com/posts/show/2478</link>
      <description>//allows for copying of ssh keys&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ssh-keygen -t dsa&lt;br /&gt;ssh user@host 'cat &gt;&gt; .ssh/authorizedkeys' &lt; .ssh/id_dsa.pub&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 27 Aug 2006 22:47:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2478</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Easy default options for methods in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2332</link>
      <description>&lt;code&gt;&lt;br /&gt;def my_method(opts={})&lt;br /&gt;  {:arg_one =&gt; 'foo', :arg_two =&gt; 'two'}.merge(opts)&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 27 Jul 2006 17:27:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2332</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Tag Cloud in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2251</link>
      <description>The options.delete with the default looks mildly interesting. Just wanted to remember that.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def font_size_for_tag_cloud( total, lowest, highest, options={} )&lt;br /&gt; return nil if total.nil? or highest.nil? or lowest.nil?&lt;br /&gt; #&lt;br /&gt; # options&lt;br /&gt; maxf = options.delete( :max_font_size ) || 14&lt;br /&gt; minf = options.delete( :min_font_size ) || 11&lt;br /&gt; maxc = options.delete( :max_color ) || [ 0, 0, 0 ]&lt;br /&gt; minc = options.delete( :min_color ) || [ 156, 156, 156 ]&lt;br /&gt; hide_sizes = options.delete( :hide_sizes )&lt;br /&gt; hide_colours = options.delete( :hide_colours )&lt;br /&gt; #&lt;br /&gt; # function to work out rgb values&lt;br /&gt; def rgb_color( a, b, i, x)&lt;br /&gt;  return nil if i &lt;= 1 or x &lt;= 1&lt;br /&gt;  if a &gt; b&lt;br /&gt;   a-(Math.log(i)*(a-b)/Math.log(x)).floor&lt;br /&gt;  else&lt;br /&gt;   (Math.log(i)*(b-a)/Math.log(x)+a).floor&lt;br /&gt;  end&lt;br /&gt; end&lt;br /&gt; #&lt;br /&gt; # work out colours&lt;br /&gt; c = []&lt;br /&gt; (0..2).each { |i| c &lt;&lt; rgb_color( minc[i], maxc[i], total, highest ) || nil }&lt;br /&gt; colors = c.compact.empty? ? minc.join(',') : c.join(',')&lt;br /&gt; #&lt;br /&gt; # work out the font size&lt;br /&gt; spread = highest.to_f - lowest.to_f&lt;br /&gt; spread = 1.to_f if spread &lt;= 0&lt;br /&gt; fontspread = maxf.to_f - minf.to_f&lt;br /&gt; fontstep = spread / fontspread&lt;br /&gt; size = ( minf + ( total.to_f / fontstep ) ).to_i&lt;br /&gt; size = maxf if size &gt; maxf&lt;br /&gt; #&lt;br /&gt; # display the results&lt;br /&gt; size_txt = "font-size:#{ size.to_s }px;" unless hide_sizes&lt;br /&gt; color_txt = "color:rgb(#{ colors });" unless hide_colours&lt;br /&gt; return [ size_txt, color_txt ].join&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 06 Jul 2006 17:01:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2251</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>pop2imap</title>
      <link>http://snippets.dzone.com/posts/show/1958</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;pop2imap --host1 westk.org --user1 rod@westk.org --password1 password --host2 orderedserver.com --user2 rod@addictedtonew.com --password2 password &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 25 Apr 2006 04:07:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1958</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Easy Selects in Ruby on Rails</title>
      <link>http://snippets.dzone.com/posts/show/1879</link>
      <description>Via http://habtm.com/articles/2006/04/10/handy-select-functions&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;module ActiveRecord&lt;br /&gt;  class Base  &lt;br /&gt;    def self.to_select(conditions = nil)&lt;br /&gt;      find(:all).collect { |x| [x.name,x.id] }&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class Array&lt;br /&gt;  def to_select&lt;br /&gt;    self.collect { |x| [x.name,x.id] }&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 10 Apr 2006 17:37:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1879</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Restart apache on Mac OS X</title>
      <link>http://snippets.dzone.com/posts/show/1878</link>
      <description>&lt;code&gt;&lt;br /&gt;sudo apachectl restart&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 10 Apr 2006 17:36:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1878</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Change iChat status from terminal.app</title>
      <link>http://snippets.dzone.com/posts/show/1877</link>
      <description>&lt;code&gt;&lt;br /&gt;osascript ichatloc.scpt "This is a test"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 10 Apr 2006 17:27:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1877</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Add MySQL User</title>
      <link>http://snippets.dzone.com/posts/show/1876</link>
      <description># add a mysql user (http://dev.mysql.com/doc/refman/5.0/en/grant.html)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;grant all privileges on *.* to 'user'@'localhost' identified by 'password' with grant option;&lt;br /&gt;flush priveleges;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 10 Apr 2006 17:25:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1876</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Creating a PDF using iText and ColdFusion</title>
      <link>http://snippets.dzone.com/posts/show/1646</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;cfscript&gt;&lt;br /&gt;// create document&lt;br /&gt;document 		= CreateObject("java", "com.lowagie.text.Document");&lt;br /&gt;document.init();&lt;br /&gt;&lt;br /&gt;// writer&lt;br /&gt;fileIO 			= CreateObject("java", "java.io.FileOutputStream");&lt;br /&gt;fileIO.init(pdf_path);&lt;br /&gt;writer 			= CreateObject("java", "com.lowagie.text.pdf.PdfWriter");&lt;br /&gt;writer.getInstance(document, fileIO);&lt;br /&gt;document.open();&lt;br /&gt;&lt;br /&gt;// newsinfo header image&lt;br /&gt;Image 			= CreateObject("java", "com.lowagie.text.Image");&lt;br /&gt;jpg 			= Image.getInstance(header_image);&lt;br /&gt;jpg.setAbsolutePosition(28, 713);&lt;br /&gt;jpg.setDpi(300,300);&lt;br /&gt;document.add(jpg);&lt;br /&gt;&lt;br /&gt;// top margin; dumb i know but i was in a hurry&lt;br /&gt;paragraph = CreateObject("java", "com.lowagie.text.Paragraph");&lt;br /&gt;paragraph.init(" ");&lt;br /&gt;for (i=0; i lt 9; i=i+1) {&lt;br /&gt;	document.add(paragraph);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// the fonts&lt;br /&gt;FontFactory 	= createobject("java", "com.lowagie.text.FontFactory");&lt;br /&gt;Font 			= createObject("java", "com.lowagie.text.Font");&lt;br /&gt;TimesLargeBI 	= Font.init(Font.TIMES_ROMAN, 14.0, Font.BOLDITALIC);&lt;br /&gt;TimesNormal 	= Font.init(Font.TIMES_ROMAN, 12.0);&lt;br /&gt;&lt;br /&gt;// all the text&lt;br /&gt;paragraph 		= CreateObject("java", "com.lowagie.text.Paragraph");&lt;br /&gt;&lt;br /&gt;paragraph.init("Hello World!", TimesLargeBI);&lt;br /&gt;paragraph.setIndentationLeft(indentation_left);&lt;br /&gt;paragraph.setIndentationRight(indentation_right);&lt;br /&gt;document.add(paragraph);&lt;br /&gt;&lt;br /&gt;paragraph.init("#dateFormat(now(), 'long')#", TimesNormal);&lt;br /&gt;paragraph.setIndentationLeft(indentation_left);&lt;br /&gt;paragraph.setIndentationRight(indentation_right);&lt;br /&gt;document.add(paragraph);&lt;br /&gt;&lt;br /&gt;document.close();&lt;br /&gt;&lt;/cfscript&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 07 Mar 2006 01:54:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1646</guid>
      <author>jnunemaker ()</author>
    </item>
  </channel>
</rss>
