
MyConfPlan allows conference attendees to view conference sessions, pick which ones they are attending, see what everyone else is attending, and share what they are attending via personal URLs and cool widgets. Its written in Rails, currently uses Hobo, and a nice slab of Javascript for the cool bits.
And it could all be yours, with an auction on eBay. The auction starts at $1 with NO RESERVE.
But, I’d like to think it could raise $75.
Why? Because all the money paid by the winner is going to the Chad Fowler and Marcel Molina Jr fund for all-things Humanitarian, and so I can go to their Testing Training Day on the 17th of September in Berlin. Minimum donation is $75.
That’s right, the winner’s money could be entirely tax-deductible as its all going to charity. (You get the site’s code base and the myconfplan.com domain (cost of transfer is yours) are yours. I get entry to the workshop.
If it raises $500 then you are donating $500. If it raises $2,000,000 then you are donating $2×10^6.
The site needs an owner/occupier/developer. It needs support leading to upto RailsConf Europe, for example.
At some time in the future, it probably needs to be rewritten. I never wrote (m)any tests. It was built with Hobo, and I built it so fast I crossed the line of “playing with Hobo” and “developing and launching an app with Hobo” very quickly. If you don’t know Hobo, you’ll probably feel more confortable starting some parts from scratch, writing your tests, writing normal Rails controllers and views, etc.
Cool things you can do to MyConfPlan (please add more in the comments if can think of them):
- For the users:
- Let users have “friends” – Show their friends’ on the main session page so they can see immediately which sessions their friends are going to
- Allow Speakers to “own” their session, and allow them to update their session descriptions etc.
- Allow uploading of slides, audio, etc after a session has been completed.
- Give each session a forum before and after the session so people can discuss the session
- Internally:
- Allow re-importing of conference sessions from their source. Conferences keep changing/adding sessions.
- Import hCalendar HTML pages directly. O’Reilly conferences post their sessions in hCalendar microformat, so the data should be directly accessible without the ugly rake task I wrote
- Caching – its got none where it counts
So, get bidding, and own yourself a very cool website.
The New Gem Generator (0.13.0)’s newgem command now behaves like the rails command thanks to RubiGen – a new project that is an extraction of the rails_generator.
Developing a RubyGem? You can now have a script/generate command, just like Rails. Other projects, say like Merb, can do this too.
Awesomeness with a Gold Star. (disclosure: Dr Nic awarded this Gold Star to himself)
Warning
This article can get confusing.
Especially around the heading “Generating Generators”.
Plus, this article talks about two projects – an update to New Gem Generator (0.13.0) and the new RubiGen project.
So, give yourself time to digest it all, and then perhaps come back and read it again.
And then perhaps re-write the article for me.
“A generator that can provide generators to your projects, so that you can write generators for your other projects.”
Re-write it – I dare you.
Background
One of the killer features of Rails is the Rails Generator.
It does three things:
- generates an entire scaffold for your application, thus sharing with you its conventions (over configuration) methodology; and
- it then allows you to generate more stuff, like models, controllers, plugins etc. Things that are relevant to a Rails app. Finally,
- it allows you to write your own generators for Rails apps.
Now you can do all this with New Gem.
Killer Feature #1 – upgrade path
Never before have you been able to run ‘newgem’ on top of an existing RubyGem. Why? It used to blow away the entire folder, and then start writing new files… not very friendly.
Now, just like the rails command, you can go into your RubyGem development directory, and run newgem . and you will be asked which files to override.
NOTE: Copy your Rakefile to Rakefile.old, and after running newgem . copy the configuration information into the new file config/hoe.rb.
If you’re using newgem already, I dare you to upgrade as above. (Ok, perhaps make a backup copy of your work first…)
Killer Feature #2 – script/generate
Once you’ve upgraded, or create a new RubyGem (using newgem gemname), you’ll now have two scripts: script/generate and script/destroy, just like Rails has. (and matching generate.cmd and destroy.cmd for Windows users)
Try them out:
script/generate
...
Installed Generators
Rubygems: application_generator, component_generator, executable, install_jruby, install_rspec, install_website
Builtin: test_unit
Oh yeah, I’ve had some fun extracting things into generators.
- Install the dubious-looking NewGem website –
script/generate install_website.
- Install RSpec support –
script/generate install_rspec.
- Make the RubyGem a JRuby gem –
script/generate install_jruby (the generated gem will have -jruby.gem in its name)
- Create an executable Ruby app –
script/generate executable appname
These generators are also reused via the newgem commands various options (Run newgem to see them.)
Killer Feature #3 – generate generators
I’ll post more about RubiGen later, but you can create a new rails-like command-line app that generates a whole stack load of directories and files using script/generate application_generator appname.
There is a large USAGE rundown if you run script/generate application_generator.
Want to create your own generators for developing RubyGems? (similar to creating a generator for a Rails app, but for RubyGems)
script/generate component_generator foobar rubygems
create rubygems_generators/foobar/templates
exists test
create rubygems_generators/foobar/foobar_generator.rb
create test/test_foobar_generator.rb
create test/test_generator_helper.rb
create rubygems_generators/foobar/USAGE
readme readme
Firstly, note test/test_generatorname_generator.rb – that’s right, you get a test stub for your new generator. Start there, write tests, then write your generator. There’s inline help for useful assertions.
Secondly, note rubygems_generators folder. This folder is the “scope” of the generator. As it starts with “rubygems” the generator will only be available when you are developing rubygems. It will not show up in Rails, nor Merb or Camping or any other place that may support RubiGen one day.
Similarly, if you want to write a Rails generator using the component_generator then specify the scope as rails.
script/generate component_generator booya rails
create rails_generators/booya/templates
exists test
create rails_generators/booya/booya_generator.rb
create test/test_booya_generator.rb
identical test/test_generator_helper.rb
create rails_generators/booya/USAGE
readme readme
In Edge Rails (and any Rails version after 1.2.3), the script/generate command in Rails will search all RubyGems for /rails_generator/* folders in addition to the existing search paths (ticket).
Thanks goes to Rails Generator
I’ve long been in love with the Rails Generator for what it does, the beautiful syntax for specifying a generator, etc. I don’t know who wrote what bit, e.g. if DHH wrote all of it, or others wrote nice chunks, but its awesome. Thanks DHH and co. Thanks to Jeremy Kemper
RubiGen is 95% Rails Generator code, with extensions to support scoping. Setting Rails Generator free of its Rails constraints is a tribute to it.
Now RubyGems can use generators, and any other frameworks can integrate generators and their developers can write and distribute additional generators for those frameworks.
I award myself 2 gold stars, and a scratch-n-sniff
In the last 20 days, 43 people have used OpenID to leave comments. That’s very cool.
Corollary: add OpenID login to your blog.
Even cooler – Dynamic counter
The screen shot comes from the Comments form.
If you look at the comments form in a week, month, year, the counter above have be changed from its original value 43.
No fancy WordPress plugins (I don’t do PHP)
No Apache tricks. (I don’t know any Apache tricks)
Instead with Javascript/HTML attached to JSON attached to a RubyCGI script attached to my WordPress database via ActiveRecords and some magic.
I call it MagicCGI. I also call it Frigging Scary.
Try the following:
$ curl -v "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_openid_identities&action=count&format=json"
< Content-Type: txt/json
<
43
Or some XML?
$ curl -v "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_openid_identities&action=count&format=xml"
< Content-Type: txt/xml
<
<?xml version="1.0" encoding="UTF-8"?>
<result>
<count type="integer">43</count>
</result>
Raw data?
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_posts&field=post_title&limit=5&order=post_title"
[{"attributes": {"post_title": "OpenID count"}},
{"attributes": {"post_title": "MagicCGI shows OpenID user count"}},
{"attributes": {"post_title": "map_by_method now works with ActiveRecord associations"}},
{"attributes": {"post_title": "Feedburner"}},
{"attributes": {"post_title": "One year on the InterTubes"}}
]
Getting kinda scary now, I think.
Ooh, just how much magic?
Want a list of available tables to play with?
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?meta=tables"
[{table_name: 'wp_users'},...]
- add
&format=xml to XML output; JSON is default
- add
&meta=columns to include the column schema definitions
- add
&table_name=wp_posts for each table you want (instead of all the tables)
E.g. to see the columns for wp_posts and no other table, in XML:
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?meta=tables&meta=columns&table_name=wp_posts&format=xml"
A list of all urls and internal user_ids for users/OpenID users/registered commenters?
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_users&field=user_url&field=id"
[{"attributes": {"id": "1", "user_url": "http://drnicwilliams.com"}}, ...
So, now we know Dr Nic = user id 1.
Oh oh oh, how about a list of comments for a specific user?
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_comments&user_id=1"
...comments by Dr Nic...
or
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_comments&user_id=1&action=count"
232
Dr Nic’s commented in his own blog 232 times? Out of how many comments?
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_comments&action=count"
963
Where are the user emails? Where are their passwords?
Hidden! See below.
Callbacks?
JSON URLs support callback=someCallbackMethod and/or variable=someLocalVariable.
$ curl "http://drnicwilliams.com/cgi-bin/wp_drnicwilliams.cgi?table=wp_comments&action=count&callback=someMethod"
someMethod(963);
What does wp_drnicwilliams.cgi look like?
Something a little like this…
#!/usr/local/bin/ruby
require 'magic_cgi' # loads the render magic, model magic, and meta-model magic
include Render
require 'magic_cgi/config/wordpress' # connect to DB using WordPress installation (wp-config.php)
MagicCGI::Config::Wordpress.establish_connection "/path/to/drnicwilliams/web/public"
# The following is defaulted for WordPress connections:
MagicCGI::Config.hidden_tables |= %w[wp_openid_nonces wp_openid_associations wp_usermeta wp_tla_rss_map wp_tla_data]
MagicCGI::Config.hidden_columns['wp_users'] = %w[user_email user_pass user_activation_key]
MagicCGI::Config.hidden_columns['wp_openid_identities'] = %w[hash]
MagicCGI::Config.hidden_columns['wp_comments'] = %w[comment_author_email comment_author_IP]
MagicCGI::Config.hidden_columns['wp_posts'] = %w[post_password]
render do |params|
data = DbTable.from_params(params)
data ||= begin
table_name = params['table'].first || 'wp_users'
model_name = ActiveRecord::Base.class_name(table_name)
klass = MagicCGI::MagicModel.create_class(model_name, ActiveRecord::Base)
klass.find_or_count_by_params(params)
end
data
end
Can I write my own CGI scripts for my own DBs?
Sure. Its a library called MagicCGI.
What is MagicCGI?
Coming soon.