Posts

Showing posts with the label Programming

Ye Olde Scala Presentation to Honolulu Coders

I presented the wonderfully named " Scala: Java, Erlang, and Ruby’s Hot Three Way Love Child " Scala presentation to the Honolulu Coders back in 2007. I went looking for the actual presentation online, and I'm not sure I ever posted it. I had a brief fling with Scala as I was looking for multi-core friendly environments to build data processing frameworks. I came away being very impressed and look forward to deploying Scala in a future project. After Erlang and Scala, I started programming in a functional style back over in my Ruby code. I consider the experiments a win for that fact along. This post is to prove that I knew Scala before it was cool. :P

Extending Hadoop Pig for Hierarchical Data

I've been playing with Hadoop Pig lately, and having a fun time.  Pig is an easy to use language for writing Map Reduce jobs against Hadoop. Our data is very hierarchical, and we calculate a lot of aggregates for self nodes, their children nodes, and self plus children.  We have a few tricks up our sleeves for SQL for handling these types of aggregates, but of course with Map Reduce an entirely new way of thinking is required. Luckily, Pig allows for easily created User Defined Functions (UDFs) that extend the Pig language.  I was able to take an existing Pig UDF, TOKENIZE, and alter it to suite my needs. Specifically, our data looks like this: 111,/A/B/C 222,/A/B 333,/A/B/C We need to answer questions such as "How many records for A and all of its children?" In this case, the answer is three. We also need to answer "How many records for just A?" which is zero, or "for just C?" which is two. Our strategy is to take the path (eg /A/B/C )...

Mac OS X, Hadoop 0.19.1, and Java 1.6

Image
If you're excited, like I am, about Amazon's recent announcement that they are now offering Elastic Map Reduce you probably want to try a quick Hadoop MapReduce application to test the waters. I found out quickly that if you are on a Mac (as I am) you'll need to perform a few quick configurations before things work correctly. Below is what I needed to do to get Hadoop running on my Mac with Java 1.6. This post assumes you are running the latest Mac OS X 10.5 with all updates applied. Enable Java 1.6 Support To enable Java 1.6, open up the Java Preferences application. This can be found in /Applications/Utilities/Java Preferences. You will need to drag Java 1.6 up and place at the top of both the applet and application versions. Open up a terminal and type java -version and you should see something like the following: java version "1.6.0_07" Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07...

What If We Ran an Iron Coder?

I've been a fan of Iron Chef America for a while. Fast paced and some very interesting dishes, it's entertaining and even a bit educational (for the epicurean viewer). Being a geek at heart, it leaves me wondering what it would take to create an Iron Coder competition. With the right "ingredients" it just might work. First, we'd need a play-by-play announcer and a color commentator . On Iron Chef America, this single role is played by Alton Brown . We might be able to get away with a single person, but I often like the banter of two announcers. It is, of course, their job to explain what is going on and provide insight and entertainment during the battle. There is, of course, the Secret Requirement. This brings us to the question of what type of code are the two Iron Coders creating? I come from a web application background, so this is my first assumption. You can't pit an X-Box programmer against a Perl script kiddie. For now, let's stick with b...

QOTD

Coding Horror: Size Is The Enemy Java is like a variant of the game of Tetris in which none of the pieces can fill gaps created by the other pieces, so all you can do is pile them up endlessly.

Beautiful Programs

If you've been reading Beautiful Code , and I hope you have, you should also read Donald Knuth's Computer Programming as an Art . It actually makes you feel better about writing all that code and always trying to get it right. The possibility of writing beautiful programs, even in assembly language, is what got me hooked on programming in the first place.

Calculating Combinations In Ruby From Erlang

Well, thanks to the many people ( here and here ) that provided their versions of an erlang way to calculate combinations , I've really begun to open my mind to how to think functionally. To help me understand what is going on, I've converted the basic idea into a Ruby version of calculation combinations. This uses recursion like the erlang versions do. class Array def head_tail [self.first, self.tail] end def tail self[1,self.size-1] end end def combos(list) return [[]] if list.empty? h, t = list.head_tail t_combos = combos(t) t_combos.inject([]) {|memo, obj| memo << [h] + obj} + t_combos end c = combos([1,2,3,4]) require 'pp' pp c As you can see, I added a bit of erlangism to the Array class, by adding a method to get the head and tail of an array. Let's run through this. On the first call to combos([1,2,3,4]) we jump over the first line (the exit in our recursion). We generate the head and tail, which in this case is 1 and [2,3...

Calculating Combinations the Erlang Way

If you recall, I wrote some Ruby code to calculate combinations of values in lists . I needed to create a list of all combinations of values, where each combination had between 0 and N number of values, where N is equal to length of the source list. (I'm not sure I'm explaining that correctly, but refer to my previous post for examples). Here's my first shot at how to do this in erlang . It look longer to find math:pow and how to convert a float to an integer in erlang than to write the actual code. -module(s). -export([combos/1]). combos(L) -> combos(L, bit_masks(length(L))). combos(L, [BH|BT]) -> [mask_list(L, BH)|combos(L, BT)]; combos(_, []) -> []. mask_list([H|T], [BH|BT]) -> case (BH) of 1 -> [H|mask_list(T, BT)] ; 0 -> mask_list(T, BT) end; mask_list([], []) -> []. bit_masks(NumColumns) -> bit_masks(0, round(math:pow(2, NumColumns))-1, NumColumns). bit_masks(Max, Max, NumColumns) -> [padl(NumColumns, bl(Max))]; bit_ma...

Performance with Scala Arrays and Lists

As I continue to tinker with Scala , I was wondering about the performance differences between an Array and List. This post will detail what I've found, but as always YMMV and I could be doing it all wrong. If there's a better (in this case, better == faster) way to do this in Scala, please let me know. My application performs a lot of collection iteration as it combines the values of two collections into a new collection by addition. For instance, I need to combine [1,2] and [3,4] into [4,6] . I wanted to find out if the collections should be an Array or List. Intuition tells me that the Array will perform better, but this is Scala, and Lists reign supreme. So we'll go head to head. For each test, I wanted to write a function that combined the two collections using tail recursion. Test One - Two Lists Into a Third First up, I am adding two lists together while forming a third. One problem here is, due to the way the algorithm is structured, the resulting list is bu...

Creating Combinations of Sets/Arrays/Things in Ruby

I was looking for a way to create combinations of things in Ruby and I found an article by Uncle Bob detailing his attempt at writing a combination generator in Ruby. I modified it slightly to use an array of items, instead of simple indexes. require 'pp' def choose(n, k) return [[]] if n.nil? || n.empty? && k == 0 return [] if n.nil? || n.empty? && k > 0 return [[]] if n.size > 0 && k == 0 c2 = n.clone c2.pop new_element = n.clone.pop choose(c2, k) + append_all(choose(c2, k-1), new_element) end def append_all(lists, element) lists.map { |l| l << element } end all = [:a, :b, :c, :d] pp choose(all,3) The above code prints out: [[:a, :b, :c], [:a, :b, :d], [:a, :c, :d], [:b, :c, :d]] If you don't want these types of combinations, there is a Ruby library for calculating Permutations which will give you all the different permutations, or orderings, of a set of things.

ModelViewController.mp3 (audio/mpeg Object)

ModelViewController.mp3 (audio/mpeg Object) should be on everyone's playlist.