Monday, September 21, 2009
Enhancing Forms
http://www.jankoatwarpspeed.com/post/2008/07/27/Enhance-your-input-fields-with-simple-CSS-tricks.aspx
Wednesday, August 19, 2009
third-order associations using nested :include
Friday, August 7, 2009
Securing the Data
Thursday, August 6, 2009
Shaving response times and adding progress with spawn
One of the reasons that lds.org is such a hassle is that their server responds so slowly.
I want this application to be user-friendly. The problem is, how do I make an abstracted layer faster than the original?
I don't.
But I do fake it as best I can and I'll make up for it later with HIJAX. The idea is that I'll use spawn to fork blocks of code into the background (like the generator I created in the last post) so that the rendered page returns sooner and I can do a little ajax polling in the background on the client-side to update the client page as needed. In the meantime, I'll allow the user to take care of things which aren't on the 'critical path', like grouping and formatting options.
Installing spawn in railssudo apt-get git-core
cd ~/Code/TheWardMenu
./script/plugin install git://github.com/tra/spawn.git
#app/controller/directory.rb
...
spawn do
while record = @photo_directory_generator.next
member = Member.new(record)
member.ward = @ward
member.save end
end
Using links2 as a quick test for transfer speeds from lds.org here's a way that things could go
- 4s - TheWardMenu.com responds
- 5s - User enters credentials
- 1s - twm receives request
- 3s - Lds.org has responded
- 1s - Update Profile page parsed
- 0s - spawned the block of code that gets the directory
- 1s - response sent
- 4s - the text-only directory is now in the database
- 0s - the photo downloading process is spawned
- 2m - the photos are downloading
Generator (like an Iterator) in Ruby on Rails
class Contacts
def import_directory
@records = []
#... get names and photo urls
@records << [:name => 'abc']
@records << [:name => 'jkl']
@records << [:name => 'xyz']
return true
end
def next_contact
if not @gen
create_generator
end
return @gen.next
end
private
def create_generator
require 'generator'
@gen = Generator.new do |g|
for record in @records
g.yield record
end
g.yield nil
end
end
end
contacts = Contacts.new
if not contacts.import_directory
abort 'Invalid Import'
end
while record = contacts.next_contact
puts record
end
