jasondew's accumulated writings http://jasondew.com Most recent posts at jasondew's accumulated writings posterous.com Mon, 23 Jan 2012 15:20:00 -0800 Clathrus ruber http://jasondew.com/clathrus-ruber http://jasondew.com/clathrus-ruber

While walking in the woods this afternoon, I came across this red, tubular plant growing on some decaying wood.  Upon further investigation, I found that inside was a nice green mucous with lots of flies inside.  Then, the smell hit me.  It was definitely the most foul smelling plant I've ever encountered.  Interestingly enough, according to Wikipedia, its actually an invasive species brought over from Europe.  There's always something cool in the woods.

References:

http://en.wikipedia.org/wiki/Clathrus_ruber

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Thu, 15 Jul 2010 12:21:35 -0700 Useless (but nifty) Ruby code http://jasondew.com/useless-but-nifty-ruby-code http://jasondew.com/useless-but-nifty-ruby-code

Here's a nifty little piece of useless Ruby code:

and the result is:

require "quine"
this.that.and.something_else

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Mon, 12 Jul 2010 14:57:00 -0700 coded_options: A new Ruby gem for coded fields http://jasondew.com/codedoptions-a-new-ruby-gem-for-coded-fields http://jasondew.com/codedoptions-a-new-ruby-gem-for-coded-fields

I recently started a couple new projects (Rails 3 + mongoid) and I've noticed a pattern in the way I handle coded fields.  My key example is something like the following: you have a field, say status, that can have several values, say active, closed, and invalid.  Obviously you could store those as strings in the database or you can code them, say 0, 1, and 2.  Normal database practice is to code them as integers to save space but a far more important concern is that clients change their mind about what you call things.  So its much easier to just change the string values in some code than it is to go changing every string in the database.

Anyway, the usage is something like this (yanked directly from the README):

Here line 4 (the coded_options call) basically gets mapped into lines 6 through 14.  Nothing spectacular but it's really cleaned up my code quite a bit so maybe it will be useful to some other folks.  The code is up on github (http://github.com/jasondew/coded_options) and the gem is on gemcutter (http://rubygems.org/gems/coded_options).

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Fri, 09 Jul 2010 18:15:27 -0700 The importance of a good algorithm http://jasondew.com/the-importance-of-a-good-algorithm http://jasondew.com/the-importance-of-a-good-algorithm

I'm studying for the computer science Ph.D. qualifying exam and so I've started going back through my algorithms book (Intro to Algorithms by Cormen, Leiserson, Rivest, and Stein).  The first chapter was, of course, about motivating the study of algorithms.  One exercise that made an impression on me was the one that had you generate a table giving the largest problem you could solve in different amounts of time given different asymptotically complex algorithms.

Since I take every opportunity to make progress learning Haskell, I coded it up:

What the table shows is the largest value of n you could process given an algorithm of certain complexity and a certain amount of time:

f(n) 1 sec. 1 min. 1 hour 1 day 1 month 1 year 1 century
lg(n) 2.7e43 ∞* ∞* ∞* ∞* ∞* ∞*
sqrt(n) 10000 3.6e8 1.3e11 7.5e13 6.7e16 9.7e18 9.7e22
n 100 6000 3.6e5 8.6e6 2.6e8 3.1e9 3.1e11
n lg(n) 29 884 34458 6.5e5 1.6e7 1.6e8 1.3e10
n^2 10 77 600 2939 16099 55770 5.6e5
n^3 4 17 68 194 597 1357 6203
2^n 6 12 18 23 27 31 38
n! 4 7 8 10 11 12 14

* The values here aren't really infinity but they are over 300 digits!

So the lesson here?  Having an algorithm with a good asymptotic complexity makes a huge difference in the amount of data it is feasible to process.  Just look at the difference between linear complexity (n) and logarithmic complexity (lg n): 41 orders of magnitude!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Thu, 08 Oct 2009 12:00:00 -0700 Named instances for ActiveRecord http://jasondew.com/named-instances-for-activerecord http://jasondew.com/named-instances-for-activerecord

For a project that I'm working on at my day job, we have a governmental client for which we are building a pretty large and complicated online/offline Ruby on Rails application. As part of this app there are tons of data-specific rules. For example, if a client with HIV is being assessed then certain fields may have to be displayed/hidden and there are rules that get applied differently. So lets say you have the following setup:

http://gist.github.com/205241

Now, somewhere in your code you want to be able to do take a specific action only if that client has a particular diagnosis. Without named_instances you might do something like:

http://gist.github.com/205250

With named_instances you can do the following faster and more concise code:

http://gist.github.com/205253

We've been using this functionality for about 6 months now and its been great. The gem is out on GemCutter (which rocks) and the repo is at GitHub. Hopefully it will be useful in your projects. Comments, criticisms, and patches welcome.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Thu, 17 Sep 2009 12:00:00 -0700 Weirdest test failure ever... http://jasondew.com/weirdest-test-failure-ever http://jasondew.com/weirdest-test-failure-ever

So based on some customer feedback on a project I'm currently working on, I added a validation requiring that one of the dates be in the past. The validation is pretty straightforward:

http://gist.github.com/188474

After re-running the test suite though, I got a couple of failures. After digging into the code, it turns out that the following code snippit evaluates to true!

http://gist.github.com/188475

Of course this makes no sense. What's more is that I tried the code again while writing this blog post and now its false. So I did some digging into the Ruby internals and it turns out that Time#< is implemented in C in the following method:

http://gist.github.com/189385

The best I can come up with is that there's an problem with the GetTimeval method since its just a macro that pulls out some data from a time struct -- but the Date class is implemented in pure Ruby. Anyone come across this or can explain better?

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Fri, 13 Feb 2009 12:00:00 -0800 Profiling Darwin, Functionality added to Haskell GD bindings http://jasondew.com/profiling-darwin-functionality-added-to-haske http://jasondew.com/profiling-darwin-functionality-added-to-haske

So I've been working on the Darwin hobby project again recently and decided to find out where the program is spending all of it's time. It turns out that there are some really nice profiling tools in Haskell (GHC to be specific). Armed with that, I found out rather quickly that the bottleneck was the getPixel function I added to the GD bindings.

http://gist.github.com/470216

My first thought was that it would be nice to grab all of the pixels at once instead of repeated (slow) calls to getPixel. So I read up on Haskell FFI and the GD documentation and churned out the following:

This code returns a nice Haskell array of arrays with the color information. This improved the speed from 1 minute per 10 iterations to 1 second per 10 iterations -- about a 60x improvement!

However, this only works with true color images at this point; no indexed palette support since that information gets stored elsewhere in the GD image struct. All in all, it was a very pleasant and rewarding experience into Haskell. Next on the list is (Erlang-style maybe?) parallelization.

BTW, the GD binding code is under the dependencies folder here.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Sun, 01 Feb 2009 12:00:00 -0800 Pseudo Genetic Programming in Haskell http://jasondew.com/pseudo-genetic-programming-in-haskell http://jasondew.com/pseudo-genetic-programming-in-haskell

Monalisa
Had some fun this weekend writing Haskell in response to this blog post. Code is on GitHub. It has some performance issues and its really my first real program in Haskell, so its a little rough around the edges, I'm sure. I think I'll rewrite it in Erlang to see if I can't speed it up a good bit by parallelizing the fitness function and increase the generation pool.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Fri, 08 Aug 2008 12:00:00 -0700 August AITP Presentation http://jasondew.com/august-aitp-presentation http://jasondew.com/august-aitp-presentation

Here are the slides from the talk I gave on Wednesday. Enjoy!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Thu, 31 Jul 2008 12:00:00 -0700 POSScon Talk http://jasondew.com/posscon-talk http://jasondew.com/posscon-talk

Awesome conference. Met lots of great people and the roundtable and ensuing conversation at the end were the best part. We need more of these kinds of conferences. Here are the slides from my talk:

I'm looking forward to next year!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Fri, 11 Jul 2008 12:00:00 -0700 POSScon: Palmetto Open Source Software Conference http://jasondew.com/posscon-palmetto-open-source-software-confere-0 http://jasondew.com/posscon-palmetto-open-source-software-confere-0

Posscon
I'll be speaking at the new South Carolina OSS conference in Columbia, SC on July 30th -- more details at their website. I plan to talk about the open-source technologies that we use at the SC Budget and Control Board -- mostly Ruby on Rails and mySQL. I'm pretty excited about the conference as its the first of its kind here in Columbia. Should be worth coming to check it out -- oh, and did I mention its free to attend? See you guys there!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Tue, 20 May 2008 12:00:00 -0700 ActiveRecord Bug Squashed http://jasondew.com/activerecord-bug-squashed http://jasondew.com/activerecord-bug-squashed

Rails
So we decided to use the new dirty record feature of Edge Rails to record the history of records in our new app at work. Turns out that nullable integer fields are always dirty if their current value is NULL. So, I submitted a patch and I'm honored to report that it was accepted and committed into Rails. Its nice to be able to give back to the community.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Sat, 15 Mar 2008 12:00:00 -0700 learnSTAT is now open source http://jasondew.com/learnstat-is-now-open-source http://jasondew.com/learnstat-is-now-open-source

I've been teaching a Statistics course at USC for a few years now and so, being the geek that I am, I decided a couple of semesters ago to write some course management software in Rails. I've worked on it on and off since then and I would consider it to be in a semi-usable state at this point. I've used it in my last two semesters without major problems.

The features at this point are

  • course announcements
  • course documents
  • ability to assign multiple choice quizzes
  • quiz statistics, including per question
  • ability to add exam grades

The source is available at http://github.com/jasondew/learnstat. Please send any bug reports or feature requests to jason.dew at gmail.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Mon, 11 Feb 2008 12:00:00 -0800 Calculating IRR http://jasondew.com/calculating-irr http://jasondew.com/calculating-irr

So I decided to give the latest Ruby Quiz a shot. I created an Algebra module to deal with finding the root of a function -- using Newton's method.

and here is the more specific code to calculate the IRR:

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Wed, 07 Nov 2007 12:00:00 -0800 My new favorite website http://jasondew.com/my-new-favorite-website-10 http://jasondew.com/my-new-favorite-website-10

Screen-capture

I know its geeky, but I love it.  Its great practice -- http://refactormycode.com/.  The general idea is: people post code that they think could be written better and then other people refactor it and get rated on it.  How cool!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Sun, 04 Nov 2007 11:00:00 -0800 Cowboys and Farmers http://jasondew.com/cowboys-and-farmers http://jasondew.com/cowboys-and-farmers

Cowboy
I can't take credit for this idea and I can't remember the blog post where I read it... but the idea goes something like this: most development groups have cowboys and farmers.

Cowboys live on the bleeding edge of technology and, therefore, tend to bleed at times (normally in the form of overtime). Of course, with risk comes reward. In software development this is increased productivity, more robust products, and programmer happiness.

Farmers, on the other hand, represent stability. They are willing to use the same tools, year after year, and normally produce steady results. They are the risk averse -- willing to do twice the amount of work with a tool that is comfortable rather than try a tool that is more specialized and/or capable.

Obviously, we need some sort of a balance between the cowboys and the farmers. Too much of either type is a recipe for destruction. However, I'm certainly a cowboy. I love learning new tools, especially when they get the job done better than the old tool.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew
Fri, 02 Nov 2007 12:00:00 -0700 Common Beginnings http://jasondew.com/common-beginnings http://jasondew.com/common-beginnings

147px-yukihiro_matsumoto
Its funny what a hobby can turn into. Listening to Matz at RubyConf 07 made me reminisce about how I got started programming. He was asked "do you consider yourself to be a scientist or an artist?" to which Matz responded: "a hobbyist." Ruby was just a hobby to him, something he found to be fun and fulfilling. Its kind of the same way I made it into full-time web development. Its what I did on the side because I enjoyed it. Now I feel privileged that I have a job where I can do what I love most of the time. It's nice to find commonalities with people that you respect.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/522451/profile.jpg http://posterous.com/users/5fdzKmwyYb0R Jason Dew Jason Jason Dew