<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: module code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 13:19:37 GMT</pubDate>
    <description>DZone Snippets: module code</description>
    <item>
      <title>Unix Console Styler</title>
      <link>http://snippets.dzone.com/posts/show/4822</link>
      <description>This modue can be used to apply many style on Unix* terminals&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# Unix Console Style&lt;br /&gt;# You can use this module to apply a style on the terminal&lt;br /&gt;#&lt;br /&gt;# &lt;b&gt;DON'T WORK ON WINDOWS (Only on *nix Terminal)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;module UnixConsoleStyler&lt;br /&gt;  class StyleNotFoundException &lt; Exception; end&lt;br /&gt;  &lt;br /&gt;  # Availables Styles&lt;br /&gt;  STYLE = {&lt;br /&gt;      :default    =&gt;    "\033[0m",&lt;br /&gt;    	# styles&lt;br /&gt;    	:bold       =&gt;    "\033[1m",&lt;br /&gt;    	:underline  =&gt;    "\033[4m",&lt;br /&gt;    	:blink      =&gt;    "\033[5m",&lt;br /&gt;    	:reverse    =&gt;    "\033[7m",&lt;br /&gt;    	:concealed  =&gt;    "\033[8m",&lt;br /&gt;    	# font colors&lt;br /&gt;    	:black      =&gt;    "\033[30m", &lt;br /&gt;    	:red        =&gt;    "\033[31m",&lt;br /&gt;    	:green      =&gt;    "\033[32m",&lt;br /&gt;    	:yellow     =&gt;    "\033[33m",&lt;br /&gt;    	:blue       =&gt;    "\033[34m",&lt;br /&gt;    	:magenta    =&gt;    "\033[35m",&lt;br /&gt;    	:cyan       =&gt;    "\033[36m",&lt;br /&gt;    	:white      =&gt;    "\033[37m",&lt;br /&gt;    	# background colors&lt;br /&gt;    	:on_black   =&gt;    "\033[40m", &lt;br /&gt;    	:on_red     =&gt;    "\033[41m",&lt;br /&gt;    	:on_green   =&gt;    "\033[42m",&lt;br /&gt;    	:on_yellow  =&gt;    "\033[43m",&lt;br /&gt;    	:on_blue    =&gt;    "\033[44m",&lt;br /&gt;    	:on_magenta =&gt;    "\033[45m",&lt;br /&gt;    	:on_cyan    =&gt;    "\033[46m",&lt;br /&gt;    	:on_white   =&gt;    "\033[47m" }&lt;br /&gt;  &lt;br /&gt;  # Methods to use if you want to apply a style&lt;br /&gt;  def UnixConsoleStyler::apply_style(style)&lt;br /&gt;    if STYLE.has_key? style&lt;br /&gt;      STDOUT.write STYLE[style]&lt;br /&gt;    else&lt;br /&gt;      raise StyleNotFoundException, "Style #{style} not found"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 28 Nov 2007 19:21:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4822</guid>
      <author>kedare (Mathieu Poussin)</author>
    </item>
    <item>
      <title>Convert Unicode codepoints to UTF-8 characters with Module#const_missing</title>
      <link>http://snippets.dzone.com/posts/show/4546</link>
      <description>From: http://www.davidflanagan.com/blog/2007_08.html#000136&lt;br /&gt;Author: David Flanagan&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;# This module lazily defines constants of the form Uxxxx for all Unicode&lt;br /&gt;# codepoints from U0000 to U10FFFF. The value of each constant is the&lt;br /&gt;# UTF-8 string for the codepoint.&lt;br /&gt;# Examples:&lt;br /&gt;#   copyright = Unicode::U00A9&lt;br /&gt;#   euro = Unicode::U20AC&lt;br /&gt;#   infinity = Unicode::U221E&lt;br /&gt;#&lt;br /&gt;module Unicode&lt;br /&gt;  def self.const_missing(name)  &lt;br /&gt;    # Check that the constant name is of the right form: U0000 to U10FFFF&lt;br /&gt;    if name.to_s =~ /^U([0-9a-fA-F]{4,5}|10[0-9a-fA-F]{4})$/&lt;br /&gt;      # Convert the codepoint to an immutable UTF-8 string,&lt;br /&gt;      # define a real constant for that value and return the value&lt;br /&gt;      #p name, name.class&lt;br /&gt;      const_set(name, [$1.to_i(16)].pack("U").freeze)&lt;br /&gt;    else  # Raise an error for constants that are not Unicode.&lt;br /&gt;      raise NameError, "Uninitialized constant: Unicode::#{name}"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;puts copyright = Unicode::U00A9&lt;br /&gt;puts euro = Unicode::U20AC&lt;br /&gt;puts euro = Unicode::U20AC&lt;br /&gt;puts infinity = Unicode::U221E&lt;br /&gt;puts Unicode.const_get(:U221E)&lt;br /&gt;p Unicode.constants&lt;br /&gt;puts Unicode.constants&lt;br /&gt;Unicode.constants.each { |u| puts Unicode.const_get(u) }&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sat, 15 Sep 2007 12:25:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4546</guid>
      <author>ntk ()</author>
    </item>
    <item>
      <title>Using path module</title>
      <link>http://snippets.dzone.com/posts/show/780</link>
      <description>Here's an example codes using &lt;a href=http://www.jorendorff.com/articles/python/path/&gt;path module&lt;/a&gt;.&lt;br /&gt;You first need to download it here: &lt;a href=http://www.jorendorff.com/articles/python/path/path.py&gt;path.py&lt;/a&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# make some files excutable&lt;br /&gt;d = path('/usr/home/guido/bin')&lt;br /&gt;for f in d.files('*.py'):&lt;br /&gt;    f.chmod(0755)&lt;br /&gt;&lt;br /&gt;# Directory walking - delete Emacs backup files&lt;br /&gt;d = path(os.environ['HOME'])&lt;br /&gt;for f in d.walkfiles('*~'):&lt;br /&gt;    f.remove()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Using os.path is difficult. I can hardly remember how to&lt;br /&gt;use which method. Need to lookup the manual every time.&lt;br /&gt;This path module is much much easier to use.&lt;br /&gt;I've heard it will be included in python 2.5 as well.</description>
      <pubDate>Sat, 01 Oct 2005 19:39:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/780</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
