Skip to content

Commit

Permalink
added rest of old posts
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Feb 14, 2009
1 parent 6bb6f56 commit 5889bc1
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 15 deletions.
4 changes: 1 addition & 3 deletions _layouts/master.html
Expand Up @@ -15,14 +15,12 @@
<div id='wrapper'>
<div id='header'>
<h1>Tagaholic </h1>
<h2>Just Tag It</h2>
</div>
<div id='menu'>
<ul>
<li><a href='/'>Home</a></li>
<li><a href='/blog.html'>Blog</a></li>
<li><a href='/project.html'>Projects</a></li>
<li><a href='http://github.com/cldwalker' target='_blank' rel='me'>GitHub</a></li>
<li><a href='/projects.html'>Projects</a></li>
</ul>
</div>
<div id='content'>
Expand Down
27 changes: 27 additions & 0 deletions _posts/2008-12-17-tags-trees-facets-oh-my.textile
@@ -0,0 +1,27 @@
---
layout: post
title: Tags, Trees and Facets, Oh My!
---

I've recently "rekindled my affair with organizing tags":http://github.com/cldwalker/tag-tree/tree/master. As in the "past":http://search.cpan.org/%7Ebozo/Fry-Lib-CDBI-Basic-0.15/lib/Fry/Lib/CDBI/Outline.pm, I started by outlining my tags. But this time some of it seems to be making sense.

Inspired by "wordnet":http://wordnetweb.princeton.edu/, I initially tried to organize my tags into lexical trees/outlines. This means I tried to organize the tags/words not by what they mean to me but what they mean to everybody. I gave up on this as my tags began to differ to much from what the word actually meant. (Yes, I'll have to revisit this someday when I want to effectively share my tag relationships with others.)

So I began organizing my tags semantically ie what they mean to me. Trying to learn from past pitfalls, I resisted the urge to make mega tag trees and instead made multiple, lean inheritance trees. For an example of an inheritance tree, take this one of my learning_subject tag:
<pre>
learning_subject
math
science
chem
bio
astro
physics
philosophy
art
</pre>

Reading from a leaf node to the root: chem (chemistry) is a science is a learning_subject. Of what use is this inheritance tree? Smarter querying and less tag pollution. If I tag an item with physics, I can alternatively get it back using my science or learning_subject tag. Less tag pollution because I don't have to tag every physics item with science and learning_subject as well. (Nothing new for you "semantic":http://zigtag.com/ "taggers":http://faviki.com/ "out there":http://entitydescriber.org/).

The more I organized my tags, the more I noticed that most of my trees were just lists. Why so many lists? I had tag lists of colors, programming languages, music genres, applications ... Were these nascent inheritance trees or "facets":http://en.wikipedia.org/wiki/Faceted_classification ? Were they serving as attributes of objects? The more I looked around at my tags, the more I saw that I had been forming different objects with tags. I had application objects that had attributes of a programming language, app type, operating system, etc. I had blog post objects that had attributes of learning type, programming language, author, etc. __In not treating tags as attribute values of a tag object, I had been cluttering my tags and losing semantic goodness.__ I had no idea if my tags were referring to an application mentioned in the webpage or the webpage itself. (Food for thought: at what point do facets become complex enough to be treated as an inheritance tree? What's the significance of that?)

So it looks like it's time for OO-tagging. With OO-tagging will come defining relationships between tag objects. I've also been itching to add modifiers between tags and their tagged subjects (either with a preposition or verb). Perhaps I can kill object relationships and modifiers with one coding stone. Then again, maybe "W is respected abroad":http://uk.youtube.com/watch?v=OM3Z_Kskl_U .
35 changes: 35 additions & 0 deletions _posts/2009-01-21-block-to-hash-conversion-ruby.textile
@@ -0,0 +1,35 @@
---
layout: post
title: Block to Hash Conversion for Ruby Config Blocks
---

While I was busy scratching "an irb itch":http://github.com/cldwalker/alias, I came up with a handy technique for converting a method's block definition into a hash. Here's an example of using such a method:

{% highlight ruby %}
Alias.init do |a|
a.verbose = true
a.constant = {'Array' = 'A'}
a.instance_method = {'String'=>{'downcase'=>'dc' },'Array'=>{'select'=>'s'}}
end
{% endhighlight %}

What I wanted was a quick but _clean_ way to convert the data structure described in the method's block to a hash. So knowing about OpenStruct, I peered into its internals and saw that it stores its attributes as a hash in <notextile>@table. Since there isn't a public method for @table, I realized I was going to have to use instance_variable_get(:@table)</notextile>. Now if I only wanted to be quick, I could simply have used that. But wanting code clarity (ie not have to read OpenStruct's internal variables each time) and to avoid monkeypatching (I have been bitten), I came up with:

<script src="http://gist.github.com/50171.js"></script>

Using it is simple. Pass your method's block to ConfigStruct.block_to_hash() and you'll get back a hash with whatever was defined in the block:

{% highlight ruby %}
def init(*args, &block)
config = ConfigStruct.block_to_hash(block)
#process your config ...
end

init do |c|
c.some = "config"
c.info = "goes here"
end
# In init(), config = {:some=>'config', :info=>'goes here'}
{% endhighlight %}

If you decide to not pass your method a block? No worries. You get back an empty hash. To see this idea in my ruby gem, see "here":http://github.com/cldwalker/alias/blob/master/lib/alias.rb.
63 changes: 63 additions & 0 deletions _posts/2009-01-31-share-extensions-without-monkey-patching.textile
@@ -0,0 +1,63 @@
---
layout: post
title: Can We Share Our Extensions Without Monkey Patching?
---

As Ruby programmers, I think we enjoy the ease and power of being able to extend any core Ruby class. As our ruby-fu grows, we pick up some tricks to have Hash's and Struct's to do our bidding, monkeypatched or not. So naturally we start collecting extensions. Sometimes they're cool enough to blog about, sometimes you find out a week later that "Ruby's stdlib":http://www.ruby-doc.org/stdlib/ or "activesupport":http://as.rubyonrails.com/ already does it better. Eventually collecting enough of them, you decide to "gem":http://rubyforge.org/ or "github":http://github.com them because you want to share what you've learned. You want others to use it. Heck, maybe even get feedback on them. So when releasing them, why do we force monkeypatching?

{% highlight ruby %}

class Object
def awesome_instance_method
end
def self.awesomer_class_method
end
end
{% endhighlight %}

Why do this when it's easy to do the same without monkeypatching?

{% highlight ruby %}
module Awesome
module Object
def awesome_instance_method
end

module ClassMethods
def awesomer_class_method
end
end
end
end

# In a separate file that you will require:
Object.send :include, Awesome::Object
Object.send :extend, Awesome::Object::ClassMethods
{% endhighlight %}

No, I'm not trying to reignite "monkeypatch debates":http://www.ruby-forum.com/topic/143732. Rather, just hoping that as a community, we can release monkeypatch-agnostic extensions and let the programmer decide when to monkeypatch.

So why do I think everybody monkeypatches their extensions? Take a look at some of the Ruby extension libraries out there:
* "activesupport":http://as.rubyonrails.com
* "facets":http://facets.rubyforge.org/
* "extlib":http://github.com/sam/extlib/tree/master
* "merb-extlib":http://github.com/wycats/merb-extlib/tree/master
* "extensions":http://extensions.rubyforge.org/rdoc/index.html
* "awesomeness":http://github.com/collectiveidea/awesomeness/tree/master
* "hubahuba":http://github.com/github/hubahuba/tree/master
* "quality_extensions":http://github.com/TylerRick/quality_extensions/tree/master
* "ruby-nuggets":http://github.com/blackwinter/ruby-nuggets/tree/master
* "my.rb":http://github.com/elliottcable/my.rb/tree/master
* "mini_facet":http://github.com/webmat/mini_facet/tree/master

And there's still more on "github":http://github.com/search?type=Repositories&amp;language=rb&amp;q=description%3A%28%2Bruby+%2Bextensions%29&amp;repo=&amp;langOverride=&amp;x=0&amp;y=0&amp;start_value=1 ...
Of the above extensions, ActiveSupport is the **ONLY** one that doesn't force monkeypatching:

{% highlight ruby %}
gem 'activesupport'
require 'active_support/core_ext/array/access'
class My; class Array < ::Array; end; end
My::Array.send :include, ActiveSupport::CoreExtensions::Array::Access
{% endhighlight %}

So can we share our extensions without monkeypatching?
Expand Up @@ -3,15 +3,15 @@ layout: post
title: Local Gem Loads Your Current Code
---

The other day while actively "developing a gem":http://github.com/cldwalker/core/tree/master, I got tired of rake reinstalling it to test its effect in irb with some other gems. I wanted to use the edge version of my gem, version **now. So I hacked up $LOAD_PATH:
The other day while actively "developing a gem":http://github.com/cldwalker/core/tree/master, I got tired of rake reinstalling it to test its effect in irb with some other gems. I wanted to use the edge version of my gem, version **now**. So I hacked up @$LOAD_PATH@:

{% highlight ruby %}
$LOAD_PATH.unshift '/my/path/to/gem/lib'
{% endhighlight %}

This effectively made my live gem directory a gem, as far as requiring files is concerned. However once I did this in irb a couple of times and even in a file, it started to feel dirty and repetitious. Why couldn't I just require my local gem just like I do when it's installed in my gem directories? So I hacked on it later and out came "LocalGem":http://github.com/cldwalker/local_gem/tree/master.

LocalGem simply maps names to file paths and when given a name, adds its corresponding path to $LOAD_PATH like above. You can setup the name-path mapping via a yaml config file or a method call.
LocalGem simply maps names to file paths and when given a name, adds its corresponding path to @$LOAD_PATH@ like above. You can setup the name-path mapping via a yaml config file or a method call.

{% highlight ruby %}
require 'local_gem'
Expand All @@ -20,7 +20,7 @@ LocalGem simply maps names to file paths and when given a name, adds its corresp
end
{% endhighlight %}

LocalGem then provides two methods, local_gem() and local_require() to act like gem() and require() but with knowledge of your local gems. You can use these two methods in one of three ways, depending on how much you want LocalGem to invade your namespace:
LocalGem then provides two methods, @local_gem()@ and @local_require()@ to act like @gem()@ and @require()@ but with knowledge of your local gems. You can use these two methods in one of three ways, depending on how much you want LocalGem to invade your namespace:

Peace time:
{% highlight ruby %}
Expand Down
4 changes: 2 additions & 2 deletions blog.html
@@ -1,7 +1,7 @@
---
layout: master
title: Blog
full_posts: 5
full_posts: 1
---

<a href='http://cldwalker.github.com/atom.xml' class='float-right'><img src='/images/subscribe.png' alt='Subscribe to XML Feed'/></a>
Expand All @@ -19,7 +19,7 @@ <h1><a href='{{post.url}}'>{{post.title}}</a></h1>
</div>
{% else %}
{% if forloop.index == page.full_posts %}
<h3>Older Posts</h3>
<h3>All Posts</h3>
<table class='post-list'>
{% endif %}
<tr>
Expand Down
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -17,7 +17,7 @@ <h1><a href='{{site.posts.first.url}}'>{{site.posts.first.title}}</a></h1>
</div>
<div class='home_box home_right'>
<h2>Available for Hire</h2>
Interested in hiring me? See my <a href="http://docs.google.com/Doc?id=dhjdhqhp_4sdt4jmhp">resume</a>.
Interested? See my <a href="http://docs.google.com/Doc?id=dhjdhqhp_4sdt4jmhp">resume</a>.
</div>
<div class='home_box home_right'>
<h2>Projects (<a href='/projects.html'>More</a>)</h2>
Expand Down
18 changes: 12 additions & 6 deletions stylesheets/master.css
Expand Up @@ -120,8 +120,7 @@ div.post {
font-weight: bold;
}

/* for inline use */
code {
code.github {
background-color:#F8F8FF;
border:1px solid #DEDEDE;
color:#444444;
Expand All @@ -130,19 +129,26 @@ code {
padding:2px 5px;
}

pre.code {
code {
background: #fff5dd;
font-size: 14px;
font-family: "Consolas","Courier New",Courier,monospace;
}

pre {
background-color:#F8F8FF;
border:1px solid #DEDEDE;
color:#444444;
padding: 2px;
}

pre.code {
font-size:120%;
overflow:auto;
padding:5px;
}

.highlight pre {
background-color:#F8F8FF;
border:1px solid #DEDEDE;
color:#444444;
margin:1em 0;
overflow:auto;
padding:0.5em;
Expand Down

0 comments on commit 5889bc1

Please sign in to comment.