<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Sikelianos's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 07:46:32 GMT</pubDate>
    <description>DZone Snippets: Sikelianos's Code Snippets</description>
    <item>
      <title>Ruby method to determine if a string would look more readable on black vs. white.</title>
      <link>http://snippets.dzone.com/posts/show/5455</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def self.ideal_font_color_for(hex_str)&lt;br /&gt;	hex_str = hex_str.split('#').last&lt;br /&gt;&lt;br /&gt;	threshold = 105&lt;br /&gt;&lt;br /&gt;	r = hex_str[0..1].hex&lt;br /&gt;	g = hex_str[2..3].hex&lt;br /&gt;	b = hex_str[4..5].hex&lt;br /&gt;&lt;br /&gt;	delta = (r*0.299) + (g*0.587) + (b*0.114)&lt;br /&gt;&lt;br /&gt;	255 - delta &lt; threshold ? "#000000" : "#FFFFFF"&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 02 May 2008 20:41:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5455</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Sort last 1000 shell commands by popularity</title>
      <link>http://snippets.dzone.com/posts/show/5421</link>
      <description>&lt;code&gt;&lt;br /&gt;  history 1000 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 22 Apr 2008 04:16:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5421</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Bashy Perlness for generating Favicon text for OpenSearches</title>
      <link>http://snippets.dzone.com/posts/show/5418</link>
      <description>&lt;code&gt;&lt;br /&gt;echo -n '&lt;Image width="16" height="16"&gt;data:image/xicon,' ; perl -ne 's/(.)/"%".unpack("H2",$1)/egs; print' ~/Desktop/favicon.ico ; echo '&lt;/Image&gt;' &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 21 Apr 2008 19:58:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5418</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Ruby: Escape, Unescape, Encode, Decode, HTML, XML, URI, URL</title>
      <link>http://snippets.dzone.com/posts/show/5180</link>
      <description>This example will show you how to escape and un-escape a value to be included in a URI and within HTML. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'cgi'&lt;br /&gt;&lt;br /&gt;# escape&lt;br /&gt;name = "ruby?"&lt;br /&gt;value = "yes"&lt;br /&gt;url = "http://example.com/?" + CGI.escape(name) + '=' + CGI.escape(value) + "&amp;var=T"&lt;br /&gt;# url: http://example.com/?ruby%3F=yes&amp;var=T&lt;br /&gt;html = %(&lt;a href="#{CGI.escapeHTML(url)}"&gt;example&lt;/a&gt;)&lt;br /&gt;# html: &lt;a href="http://example.com/?ruby%3F=yes&amp;amp;var=T"&gt;example&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;# unescape&lt;br /&gt;name_encoded = html.match(/http:([^"]+)/)[0]&lt;br /&gt;# name_encoded: http://example.com/?ruby%3F=yes&amp;amp;var=T&lt;br /&gt;href = CGI.unescapeHTML(name_encoded)&lt;br /&gt;# href: http://example.com/?ruby%3F=yes&amp;var=T&lt;br /&gt;query = href.match(/\?(.*)$/)[1]&lt;br /&gt;# query: ruby%3F=yes&amp;var=T&lt;br /&gt;pairs = query.split('&amp;')&lt;br /&gt;# pairs: ["ruby%3F=yes", "var=T"]&lt;br /&gt;name, value = pairs[0].split('=').map{|v| CGI.unescape(v)}&lt;br /&gt;# name, value: ["ruby?", "yes"]&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 26 Feb 2008 23:23:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5180</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Single-Line commenting in Actionscript with Textmate</title>
      <link>http://snippets.dzone.com/posts/show/5170</link>
      <description>- open the bundle editor and select the Actionscript bundle&lt;br /&gt;- use the add button to make a new preference item, give it a scope of source.actionscript&lt;br /&gt;- name it whatever&lt;br /&gt;- paste in the following:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;{   shellVariables = (&lt;br /&gt;        {   name = 'TM_COMMENT_START';&lt;br /&gt;            value = '// ';&lt;br /&gt;        },&lt;br /&gt;    );&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;- that's it! got these instructions on IRC from Infininight: http://pastie.textmate.org/private/clmfldbv2sexjcd7u6qjw</description>
      <pubDate>Sun, 24 Feb 2008 22:49:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5170</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>AS3 FlashVars equivalent: LoaderInfo</title>
      <link>http://snippets.dzone.com/posts/show/5138</link>
      <description>// Add this to your package..&lt;br /&gt;import flash.text.*;&lt;br /&gt;&lt;br /&gt;// And throw this in wherever..&lt;br /&gt;var t:TextField = new TextField();&lt;br /&gt;t.autoSize = TextFieldAutoSize.LEFT;&lt;br /&gt;t.border = true;&lt;br /&gt;addChild(t);&lt;br /&gt;&lt;br /&gt;t.appendText("params:" + "\n");&lt;br /&gt;try {&lt;br /&gt;	var key:String;&lt;br /&gt;	var val:String;&lt;br /&gt;	var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;&lt;br /&gt;	for (key in flashvars) {&lt;br /&gt;		val = String(flashvars[key]);&lt;br /&gt;		t.appendText("\t" + key + ":\t" + val + "\n");&lt;br /&gt;	}&lt;br /&gt;} catch (error:Error) {&lt;br /&gt;	t.appendText(error);&lt;br /&gt;}</description>
      <pubDate>Wed, 13 Feb 2008 18:25:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5138</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Make AS3 clips turn cursor into a hand on rollover..</title>
      <link>http://snippets.dzone.com/posts/show/5131</link>
      <description>&lt;code&gt;&lt;br /&gt;  buttonMode = true; &lt;br /&gt;  mouseChildren = false;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Feb 2008 07:11:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5131</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>AS3 SwapDepths Equivalent</title>
      <link>http://snippets.dzone.com/posts/show/5130</link>
      <description>&lt;code&gt;&lt;br /&gt;function move_to_top() {&lt;br /&gt;  // This will move the current object to the topmost z-index&lt;br /&gt;  parent.setChildIndex(this, parent.numChildren-1);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Feb 2008 06:30:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5130</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Ruby word count</title>
      <link>http://snippets.dzone.com/posts/show/5112</link>
      <description>&lt;code&gt;&lt;br /&gt;module StringExtensions&lt;br /&gt;  def words&lt;br /&gt;    s = self.dup&lt;br /&gt;    s.gsub!(/\w+/, 'X')&lt;br /&gt;    s.gsub!(/\W+/, '')&lt;br /&gt;    s.length&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 06 Feb 2008 19:29:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5112</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Find all subdirectories of a given path at a particular depth</title>
      <link>http://snippets.dzone.com/posts/show/5111</link>
      <description>&lt;code&gt;&lt;br /&gt;def subdirectories_of(path, options = {}) depth = options[:at_depth_of] || 1 Dir[File.join(path, * ["*"] * depth + [""])] end &gt;&gt; subdirectories_of("/var") =&gt; ["/var/agentx/", "/var/amavis/", "/var/at/", "/var/audit/", "/var/backups/", "/var/db/", "/var/empty/", "/var/folders/", ...] &gt;&gt; subdirectories_of("/var", :at_depth_of =&gt; 2) =&gt; ["/var/amavis/db/", "/var/amavis/tmp/", "/var/at/jobs/", "/var/at/spool/", "/var/at/tabs/", "/var/at/tmp/", &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 06 Feb 2008 19:25:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5111</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
  </channel>
</rss>
