<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Elliottcable's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 08:20:21 GMT</pubDate>
    <description>DZone Snippets: Elliottcable's Code Snippets</description>
    <item>
      <title>file extension methods</title>
      <link>http://snippets.dzone.com/posts/show/5509</link>
      <description>Allows you to use file extensions as methods&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class File&lt;br /&gt;  # Feel free to add more here, as you need them.&lt;br /&gt;  Extensions = %r=^(txt|rb|markdown|textile|haml|sass|css|html|xhtml)$=i&lt;br /&gt;  &lt;br /&gt;  module Extension&lt;br /&gt;    def method_missing(meth, *args)&lt;br /&gt;      if Extensions =~ meth.to_s&lt;br /&gt;        [self, '.', meth.to_s].join&lt;br /&gt;      else&lt;br /&gt;        super&lt;br /&gt;      end # if&lt;br /&gt;    end # method_missing&lt;br /&gt;  end # Extension&lt;br /&gt;end # File&lt;br /&gt;&lt;br /&gt;class Symbol&lt;br /&gt;  include File::Extension&lt;br /&gt;end&lt;br /&gt;class String&lt;br /&gt;  include File::Extension&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;'myfile'.html&lt;br /&gt;# =&gt; "myfile.html"&lt;br /&gt;&lt;br /&gt;:a_file.rb&lt;br /&gt;# =&gt; "a_file.rb"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 17 May 2008 02:08:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5509</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>CSS *true* centering</title>
      <link>http://snippets.dzone.com/posts/show/5252</link>
      <description>This will truely center something in CSS. Not tested in IE, knowing IE, it will burn in flames.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#center-me { /* There can be only one Centerlander! */&lt;br /&gt;  height: 100%;&lt;br /&gt;  display: table !important;&lt;br /&gt;  margin: auto;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#center-me &gt; * {&lt;br /&gt;  display: table-cell !important; /* Don't touch me! I MEAN IT! DON- ... don't touch me. Really, don't touch me. */&lt;br /&gt;  vertical-align: middle !important;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div id="center-me"&gt;&lt;br /&gt;  &lt;h1&gt;I'm centered!&lt;/h1&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 19 Mar 2008 07:30:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5252</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>quote-delineated tag sets</title>
      <link>http://snippets.dzone.com/posts/show/5228</link>
      <description>snippet to surround a tag with &#8220;smart quotes&#8221; if it contains any odd characters. i.e. to display tags entered in a flickr-like style (space separated except inside quotes)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;tag.gsub(/^/,'&amp;ldquo;').gsub(/$/,'&amp;rdquo;') if tag[0].match(/[^A-Za-z0-9\-_.]/)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Mar 2008 21:16:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5228</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>abbr formatting</title>
      <link>http://snippets.dzone.com/posts/show/5227</link>
      <description>haml (easily transformed to css) snippet to format abbrs in a proper manner - you can still type them in ALL CAPS, but they will be displayed in Titlecase and small-caps. If you're using this, you're probably also using a custom face via @font-face, so you might want to explicitly declare the small-caps and lowercase variants of the typeface - the browser often fucks up auto-small-caps.&lt;br /&gt;&lt;br /&gt;also, not tested in internet explorer. nothing I write is.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;abbr&lt;br /&gt;  :display inline-block&lt;br /&gt;  :text-transform lowercase&lt;br /&gt;  :font-variant small-caps&lt;br /&gt;  &lt;br /&gt;  &amp;:first-letter&lt;br /&gt;    :text-transform uppercase&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Mar 2008 21:13:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5227</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>[ruby] plugin structure</title>
      <link>http://snippets.dzone.com/posts/show/5159</link>
      <description>plugin structure sorta thing. Use inherited to concatenate all plugins to a library in a Plugins constant in said library.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Library&lt;br /&gt;  Plugins = []&lt;br /&gt;  &lt;br /&gt;  def initialize#(...)&lt;br /&gt;    Plugins.each do |plugin|&lt;br /&gt;      # Here you can run a certain class method or grab some data from each class&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  # ...&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class LibraryPlugin&lt;br /&gt;  # ...&lt;br /&gt;  &lt;br /&gt;  def self.inherited(sub); Library::Plugins &lt;&lt; sub; end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class LibraryFooer &lt; LibraryPlugin&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;class LibraryBarer &lt; LibraryPlugin&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;Library::Plugins.inspect #=&gt; [LibraryFooer, LibraryBarer]&lt;/code&gt;</description>
      <pubDate>Thu, 21 Feb 2008 06:42:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5159</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>[Ruby] Script/bot to send MediaWiki Recent Changes over UDP to a Campfire room</title>
      <link>http://snippets.dzone.com/posts/show/5037</link>
      <description>Requires the Tinder gem, and PHP on the server running MediaWiki must be compiled with --enable-sockets. The computer running the bot will also have to be open to the web - it can't be behind a firewall.&lt;br /&gt;&lt;br /&gt;First, add this code to your MediaWiki LocalSettings.php, replacing the IP address with the IP of the server/computer running the bot, and the port to whatever you want to use (probably something above 40,000, but it's up to you):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$wgRC2UDPAddress = '69.178.6.244';&lt;br /&gt;$wgRC2UDPPort = '41895';&lt;br /&gt;$wgRC2UDPPrefix = "";&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now, you can run the bot! This is extremely hackish, because the retarded collective-mailing-list-coding system of the MediaWiki repos has somehow managed to code IRC color codes directly into their exported strings (at least with MediaWiki 1.2alpha, which is what I'm running right now).&lt;br /&gt;You'll need to replace the new tinder definition with your subdomain on Campfire, the username and password with ones for the bot account you've created on your campfire room, and the room name with the room you want the updates to be sent to.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'tinder'&lt;br /&gt;require 'socket'&lt;br /&gt;puts 'Dependencies loaded...'&lt;br /&gt;&lt;br /&gt;campfire = Tinder::Campfire.new 'subdomain'&lt;br /&gt;campfire.login 'email@domain.com', 'password'&lt;br /&gt;exit unless room = campfire.find_room_by_name('Case Sensitive Room Name')&lt;br /&gt;puts 'Campfire logged in...'&lt;br /&gt;&lt;br /&gt;server = UDPSocket.new&lt;br /&gt;exit unless server.bind('0.0.0.0', 41895)&lt;br /&gt;puts 'Socket listening...'&lt;br /&gt;&lt;br /&gt;loop do&lt;br /&gt;  msg = server.recv(2048).gsub(/\003[\d]{0,2}/,'').chomp&lt;br /&gt;  print "sending to room: #{msg.inspect}..."&lt;br /&gt;  exit unless room.speak msg.to_s&lt;br /&gt;  puts ' sent!'&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 26 Jan 2008 14:29:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5037</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>ruby: random alphanumeric string</title>
      <link>http://snippets.dzone.com/posts/show/5017</link>
      <description>generate random alphanumeric string 'size' characters long&lt;br /&gt;&lt;br /&gt;&lt;code&gt;size = 8; (1..size).map{([*('a'..'z')]+[*('A'..'Z')]+[*(1..9)].map{|n|n.to_s}).instance_eval{self[rand(self.size)]}}.join&lt;/code&gt;</description>
      <pubDate>Mon, 21 Jan 2008 09:03:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5017</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>Ruby dictionary username generation</title>
      <link>http://snippets.dzone.com/posts/show/4536</link>
      <description>Generate a new random name from dictionary words.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;DICT_PATH = '/usr/share/dict/words'&lt;br /&gt;DICT_SIZE = 234936&lt;br /&gt;&lt;br /&gt;def self.generated_name words = 2, length = 23&lt;br /&gt;  name = 'a'*(length+1)&lt;br /&gt;  while name.length &gt; length&lt;br /&gt;    name = (1..words).map{%x[sed -n '#{rand(DICT_SIZE)} {p;q;}' '#{DICT_PATH}'].chomp.capitalize}.join&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Sep 2007 13:57:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4536</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
  </channel>
</rss>
