outten.net - random thoughts »

Fast and Friendly Autotest for your Mac

Posted: Jan 09, 2010 21:35:20, by Richard

Autotest, which is part of ZenTest, is a very handy testing application. It runs tests as changes are made to the code. When using it, I would accidentally leave it running and then notice something using up CPU cycles. It would turn out to be the autotest process that was still scanning files for changes every so often. I would then stop autotest only to be bothered to start it up again when I was working on the project again.

Awhile ago, I ran across autotest-fsevent for the Mac. It uses the Mac's FSEvent core service to determine which files have changed (or to be notified when they are). This appears to have really helped the CPU cycles especially when nothing has changed. It is immediately notified when a file has changed.

I would also recommend upgrading to the latest autotest-growl as well. I was using an older version and there have been improvements.

Tags: testing, tech, ruby

Keeping up with CouchDB

Posted: Mar 15, 2009 15:58:30, by Richard

I really like CouchDB and the flexibility it provides. It is currently under heavy development (the last release was an incubating release) and things are changing frequently. Most of the time, this means improvements or new features, but sometimes this leads to breaking backward compatibility. The other night I tried the latest clone of couchrest with this commit. I looked at the breaking changes page (based on the comment on the commit on github). I found the reference to the moved view URLs which was the problem I was having. After reading the discussion on the mailing list, it sounds like it is a good idea and is worth breaking backward compatibility.

To update to the latest version of CouchDB (basically working from the trunk), here are the steps I took:

  1. installed couchdb-python using this script
  2. dumped each database using the couchdb-python dump.py described in breaking changes
  3. shutdown couchdb and make a backup (for example, I tar'ed my /srv/cocuhdb directory)
  4. pull down the latest copy for couch from svn or github
  5. build and install CouchDB
  6. start the new version of CouchDB
  7. go into Futon (for example http://localhost:5984/_utils) and create each database
  8. load each database with load.py from couchdb-python again described in breaking changes

After upgrading CouchDB, I then had to update my application to use the latest couchrest.

Tags: couchdb, ruby

Site Running Ruby 1.9

Posted: Mar 12, 2009 22:40:48, by Richard

This (home grown) blog is now running on Ruby 1.9. Since I wrote it using Sinatra and couch-rest, it was pretty easy to get working. The only real trick was adding a fake JSON gem to fulfill a dependency on JSON (which is now part of Ruby 1.9). I found this reference on the IsItRuby19 which came in very handy in determining which gems work on Ruby 1.9.

Tags: ruby, json, tech

New Blog and New Look

Posted: Mar 01, 2009 14:22:07, by Richard

I have updated the look of the blog as well as the underlying blog software. I have also switched from http://outten.net/weblog to http://blog.outten.net. I had been using a customized version of Typo.

The new blog is running my own combination of Sinatra and CouchDB. I have been using Ruby for a few years now (after starting with Rails). I was curious to see what some of the other Ruby frameworks had to offer. I have tried Camping, Ramaze and Merb. All had some really strong points and I started rewriting my blog in each of these, but did not finish with any of them.

When I first looked at Sinatra, I didn't have a great first impression. I went away and looked at some of the other frameworks mentioned. After dabbling in each, I ran across Sinatra again and really dug it. About the same time I had become interested in CouchDB and really wanted to give it a try. That's when I started playing with a Sinatra and CouchDB combination. They seem to be a nice fit even though I could have written the entire blog in Javascript.

I am planning to release the code in the future in case someone else would like to use it.

Features

  • multiple blogs hosted by the single instance
    • each blog uses its own CouchDB database
  • plug-in for protecting a blog by requiring users to identify themselves
  • admin application separated into a different Rack module
Tags: tech, couchdb, ruby

RPCFN #4 in Erlang

Posted: Mar 04, 2010 20:56:36, by Richard

A few weeks ago I wanted to start learning Erlang. A co-worker pointed out the Ruby Programming Challenge for Newbies that they were completing in Ruby. I decided to try the RPCFN #4, but write it in Erlang. This probably isn’t the most concise or best implementation, but it was a good exercise to encourage me to look at Erlang.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
%% This was inspired from the ruby programming challenge for newbies.
%%   http://rubylearning.com/blog/2009/11/26/rpcfn-rubyfun-4/

-module (polynomials).
%% -compile(export_all).
-export([poly_epr/1]).
-import(string, [concat/2]).
-import(lists, [append/1]).

%% include the test module
-include_lib("eunit/include/eunit.hrl").


%% Create a polynomial expression from an array of numbers
poly_epr(List) when is_list(List), length(List) >= 2 ->
  P = gen_epr([], List),
  case R=join_epr(P) of
    "" ->
      "0";
    _ ->
      R
  end;
poly_epr(_) ->
  {error, "Need at least 2 coefficients"}.


%% generate the polyonmial expression
gen_epr(Poly, []) ->
  case Poly of
    [] ->
      "0";
    _ ->
      Poly
  end;
gen_epr(Poly, [H|T]) ->
  Poly ++ gen_epr([term(H, length(T))], T).


%% join the expressions term together
join_epr([]) ->
  "0";
join_epr([H|T]) ->
  H ++ append([check_neg(X) || X <- T]).


%% add appropreiate sign in front of expression term
check_neg([]) ->
  "";
check_neg(Val="-" ++ _T) ->
  Val;
check_neg(Val) ->
  concat("+",Val).

%% create an expression term
term(1, Expo) ->
  expo(Expo);
term(-1, Expo) ->
  "-" ++ expo(Expo);
term(0, _Expo) ->
  "";
term(Val, 0) ->
  integer_to_list(Val);
term(Val, Expo) when is_number(Val), is_number(Expo)  -> 
  concat(integer_to_list(Val), expo(Expo));
term(_Val, _Expo) ->
  "".


%% create the exponent expression
expo(1) -> 
  "x";
expo(E) ->
  concat("x^", integer_to_list(E)).



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TESTS

%% term tests
term1_test() ->
  "x^2" = term(1,2).

term_negative_value_test() ->
  "-x^2" = term(-1,2).

term0_test() ->
  "" = term(0,5).

term_zero_exponent_test() ->
  "5" = term(5,0).

term_bad_values_test() ->
  "" = term("str","more").

%% poly tests from  the rpcfn
poly_epr1_test() ->
  ?assert("3x^3+4x^2-3" =:= poly_epr([3,4,0,-3])).  

poly_first_negative_test() ->
  ?assert("-3x^4-4x^3+x^2+6" =:= poly_epr([-3,-4,1,0,6])).

poly_simple_test() ->
  ?assert("x^2+2" =:= poly_epr([1,0,2])).

poly_first_minus_one_test() ->
  ?assert("-x^3-2x^2+3x" =:= poly_epr([-1,-2,3,0])).

poly_all_zera_test() ->
  ?assert("0" =:= poly_epr([0,0,0])).

poly_test_error_test() ->
  {error,Msg} = poly_epr([1]),
  ?assert("Need at least 2 coefficients" =:= Msg).

You need to have eunit setup in your code path. Then you can start the Erlang shell and run the tests. Really, they pass!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ erl
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.7.4  (abort with ^G)
1> c(polynomials).
{ok,polynomials}
2> polynomials:test().
  All 11 tests passed.
ok
3> 
Tags: erlang, rpcfn, learning

Word Problems

Posted: Mar 04, 2009 22:41:23, by Richard

Do you remember in school when you used to have the word problems in math? You had to read a paragraph and then pick it apart for certain key words. You might look for "of*" or "times" to indicate multiplication or "more than" for addition. I remembering doing fairly well at these *word problems (not that I enjoyed them), but I didn't really understand how much these were going to apply to me in the future.

It turns out that in the technical field (and probably others) I am constantly dealing with word problems. There are 2 ways that I see them represented:

  1. in general email sent each day (applies to non-technical as well)
  2. in specification, requirement or similar documents
read more...
Tags: tech, agile, random

My 1st Experiences with R

Posted: Jun 12, 2011 21:42:09, by Richard

I decided to take a look at R this weekend between our family events. I had looked at R before when I ran across the R Tutorial. I bookmarked it and decided I would come back later. The other day at work a professor performing big data analysis started a conversation about R and offered to create some examples. He recommended working through the examples and tweaking those as a way to learn R.

Upon further consideration, I decided to go back to R Tutorial and work through the basics of input and data types. I felt like I needed a base before trying some of the examples. This approach seemed to work well-at least for me. I worked through the first 2-3 sections of the tutorial. When I got to the plotting section, things got interesting. Creating plots with the built-in functions seemed very straightforward and powerful. This led me on a quest to find more plotting libraries with subjectively more visually appealing graphs (the default plots aren't too shabby).

googleVis

I had used Google's Charting Tools before and was curious to see if there was an option to use them from R. It turns out there is an excellent library called googleVis. This library creates the HTML, JavaScript and CSS required to create graphs from R. The resulting graphs are visually appealing and interactive. The one downside was, since the rely on the Google Charting Tools, they require an Internet connection to pull down the required JavaScript from Google. I will probably use googleVis in the future for some charts, but it wasn't ideal for my current thought.

ggplot2

The next graphing library I looked at was ggplot2. From the website examples, this library appeared to be exactly what I was looking for. The documentation in the reference manual for each of the functions is well documented. When I started trying to use the library, I had already pulled in my dataset from a CSV file. My initial problem was figuring out how the data was passed to the ggplot function and how this related to the qplot function. The "grammar of graphics" was getting the best of me. After searching the web, I was able to find the R Cookbook which had more examples of scatter plots-not to mention a lot of other good R information. These examples provided the missing link for me: how to supply the data to the graphing functions to get the plots to work. With the combination of ggplot2 and R Cookbook, I was able to create graphs that provided some additional insight into the data.

Sample density graph

Other Thoughts

Some other things I wanted to note:

  • Installing packages available on CRAN are extremely easy and they just worked.
  • After starting with the binary for R, I then found RStudio. It looks like it is in early development, but it quickly became my default environment. With an editor, workspace and console, it was hard to find something better.
  • R has a "batch" processing mode (plus Rscript) which looks interesting for processing data outside the environment.

These were just some of my early experiences with R. Overall, I really enjoyed using R and the ideas started flowing on how I might use it-everything from analyzing spending at home to analyzing data at work. Next, I hope to look at using R with ggplot2 to analyze the results from Apache Bench. If the results turn out interesting, I hope to find time to share them.

Tags: r, learning