Dance and Pivot SQL Style
by: Nathan Fisher
Found myself looking at Open Flash Charts for a reporting system. I wanted to create page views broken down by day. A simplified schema is as follows:
| id | created_at | page |
| Integer | DateTime | Varchar(255) |
I wanted to create a table like the following:
| page | monday | tuesday | wednesday | thursday | friday | saturday | sunday |
| index | 3 | 5 | 2 | 8 | 9 | 30 | 32 |
| contact | 2 | 1 | 4 | 3 | 7 | 12 | 16 |
Simplified TDD with Sinatra autotest
by: Nathan Fisher
General overview of what we’re building;
- Simple autotest compatible directory structure.
- Sinatra application.
- Sinatra unit test.
File setup:
export project=MyApp
mkdir -p $project/{lib,test}
cd $project
cat <<EOT > test/test_app.rb
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
require 'app'
require 'test/unit'
class AppTest < Test::Unit::TestCase
def test_fail
flunk 'Write your App tests!'
end
end
EOT
autotest
This should output something akin to the following, if you don’t get that then somethings amiss that you’ll need to investigate further.
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- app (LoadError) from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' from ./test/test_app.rb:4 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' from -e:2 from -e:2:in `each' from -e:2
Next create a new file named ‘lib/app.rb’.
touch lib/app.rb
Once saved your test should kick to life with one failure:
1) Failure: test_fail(AppTest) [./test/test_app.rb:8]: Write your App tests!.
Dom A Regato, My Tests Are Auto
by: Nathan Fisher
So in my ever increasing commitment to TDD, I’ve started seeking an efficient way to run tests. Call me what you will but, I find running tests breaks my tempo. So how do I keep aware of my testing state, but stay with my head in the code. Some out there might call for NetBeans, I’ve used it and loved it, but I’m drawn to vim like a moth to the proverbial flame.
Mix 1 vertical pinch of NERDTree, 1 horizontal slice of bufexplorer, a gram of FuzzyFinder, rails.vim, and some custom bindings and what do you get? A pimped out ride in vim for rails development. Sure it may look like a Honda with those over-sized spoilers, but its just the way I like it! Long story short, NetBeans is a great package, but I just can’t stay away from vim long. Alas I digress, the goal is to maximize my productivity while staying committed to the Tao of TDD.
About Junction Box
Junction Box is the online blog of Nathan Fisher. I grew up in a little city called St. Catharines near Niagara Falls, Canada. I'm a bit of a geek currently employed as a Web Developer/Programmer in London, England.