<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: default code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 07 Sep 2008 16:49:37 GMT</pubDate>
    <description>DZone Snippets: default code</description>
    <item>
      <title>Windows XP System Variables</title>
      <link>http://snippets.dzone.com/posts/show/4507</link>
      <description>// Windows XP Default System Variables&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;%SystemDrive%  		C:&lt;br /&gt;&lt;br /&gt;%SystemRoot% 		C:\WINNT, C:\WINDOWS&lt;br /&gt;&lt;br /&gt;%SystemDirectory% 	C:\WINNT\System32, C:\WINDOWS\System32&lt;br /&gt;&lt;br /&gt;%WinDir% 		C:\WINNT, C:\WINDOWS, C:\WINNT\Program Files&lt;br /&gt;&lt;br /&gt;%ComSpec% 		C:\WINNT\system32\cmd.exe&lt;br /&gt;&lt;br /&gt;%Temp% 			C:\DOCUME~1\Usr\LOCALS~1\Temp from C:\Documents and Settings\Usr\Local Settings\Temp&lt;br /&gt;&lt;br /&gt;%HOMEDRIVE% 		C: The drive letter associated with the user's home directory&lt;br /&gt;&lt;br /&gt;%HOMEPATH% 		The path to the user's home directory (excluding drive): \Documents and Settings\Guest&lt;br /&gt;&lt;br /&gt;%OS% 			Windows_NT -&gt; The operating system the user is running&lt;br /&gt;&lt;br /&gt;%USERDOMAIN% 		The name of the domain that contains the user's account&lt;br /&gt;&lt;br /&gt;%USERNAME% 		The user's name&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 07 Sep 2007 09:09:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4507</guid>
      <author>dubby (Dave)</author>
    </item>
    <item>
      <title>Default Sort Order For Rails models</title>
      <link>http://snippets.dzone.com/posts/show/4387</link>
      <description>// provide a default sort order in case an order by clause isn't defined in the find clause&lt;br /&gt;// Place this code somewhere in your model's class file.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;        def self.find(*args)&lt;br /&gt;          order_arg = args.collect do |arg|&lt;br /&gt;            if arg.kind_of? Hash &lt;br /&gt;              if arg.keys[0] == :order&lt;br /&gt;                arg&lt;br /&gt;              end&lt;br /&gt;            end&lt;br /&gt;          end&lt;br /&gt;&lt;br /&gt;          if order_arg.compact.empty?&lt;br /&gt;            args &lt;&lt; {:order=&gt;"place order by clause here e.g. 'name asc'"}&lt;br /&gt;          end&lt;br /&gt;          &lt;br /&gt;          super&lt;br /&gt;        end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 03 Aug 2007 20:02:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4387</guid>
      <author>mcmoyer ()</author>
    </item>
    <item>
      <title>Default dictionary</title>
      <link>http://snippets.dzone.com/posts/show/715</link>
      <description>I always want to do this, like I did in Perl.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt; d = DefaultDict(0)&lt;br /&gt;&gt;&gt; d[key] += 1     # no need to use d.get or d.setdefault&lt;br /&gt;&lt;br /&gt;&gt;&gt; d = DefaultDict([])  # similarly with list value&lt;br /&gt;&gt;&gt; d[key].append(item)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;See the implementation by Peter Norvig (of AI &amp; Google fame) &lt;br /&gt;&lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/389639&gt;here&lt;/a&gt;</description>
      <pubDate>Thu, 15 Sep 2005 01:11:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/715</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Counting characters in string</title>
      <link>http://snippets.dzone.com/posts/show/511</link>
      <description>&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; s = 'a;jfkd;aflhakfhaskfjalghlakfhfnkjafyksd'&lt;br /&gt;&gt;&gt;&gt; cnt = {}&lt;br /&gt;&gt;&gt;&gt; for c in s:&lt;br /&gt;	cnt[c] = cnt.get(c,0) + 1&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; print cnt&lt;br /&gt;{'a': 7, 'd': 2, 'g': 1, 'f': 7, 'h': 4, 'k': 6, 'j': 3, 'l': 3, 'n': 1, 's': 2, 'y': 1, ';': 2}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This can be used to count any distribution.&lt;br /&gt;Note the use of dict.get(key,default) to set to 0&lt;br /&gt;if the key is not avaiable. &lt;br /&gt;If this were perl, I would just do a&lt;br /&gt;&lt;code&gt;cnt[c] += 1&lt;/code&gt;&lt;br /&gt;But python will give an error instead of returning 0.&lt;br /&gt;It's not too bad, though.</description>
      <pubDate>Tue, 26 Jul 2005 18:39:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/511</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
