Doug Bryant

Tech thoughts and notes

OSCON 2005 - Firefox Extension Development

Tools – XPIStubs (pronounced Zippy Stubs) Use this and forget half of what you need to know. Still needs some work.

Speaker looks like Hani (bileblog)

Looks like this tool stubs out everything you need to develop firefox extensions. Run the program to stub out program, do a ./configure make and it installs a plugin into firefox that pops up a window “Test”.

All you need to know to get started developing firefox extendsions are

  • XPIStubs to get quickly stubbed out
  • XUL and javascript for UI
  • XulPlanet.com for reference

Extensions allow you to add new features to existing applications and add new functionality to browsers.

Why user firefox:

  • Cross platform applications
  • add content to the users browser
  • provide the user w/ a better experience through client side customization
  • easier than many alternatives
  • b/c it’s cool

XUL
The xml interface language for mozilla/firefox

It provides

  • layout and base widget set
  • uses css for styling
  • event handling via javascript command sets
  • overlays

And… it may be loaded remotely or locally.

Command Event

  • trap events like button clicks and key presses and allow you to respond to those events.

Broadcasters

  • like command but can push out

Controllers

  • Command sets can call on controllers to respond to events (like focus)
  • Controllers are javascript classes that update state for commands

RDF and Templates

  • allows you to define a template for displaying RDF data
  • Difficult to use but very cool

XBL Bindings

  • XML binding language
  • allows ou to create new widgets or modify existing widgets

XPCOM

  • cross platform components
  • in C++, XBL or javascript. Also support scripting languages (PyXPCOM)
  • Components are global to all chrome packages
  • possibly the most important part of GRE

XPI: Cross platform Installer

  • packaged in a jar file
  • handles cross platform installs

Dev Tools

  • typically use text based tools (vim, emacs, notepad??)
  • Dom Inspector
  • cview (XPCOM inspector)
  • Venkman (javascript debugger)

Not Bad – rest seems like it will be demos, so shutting down to save batter power.

Update – ACK! It almost looks like jelly – programming in XMLWAY WAY Verbose

OSCON 2005 Keynote

Over the keynote was just OK. Not terribly exciting.

Tim O’Reilly is an awsome speaker as always. He seemed to keep it short this time for some reason. one thing he said that struck a chord, was once you create an standard, values moves up the stack. He believes opensource is doing this now, moving up the stack of standards (hardware).

Next up was Kim Polase (think I got her last name right). Good speaker but did not need to be delivering something as part of the keynote. Her talk seemed to be a plug for Spikesource.

Next up was Andrew Morton, linux kernel hacker extradonaire for OSDN. Difficult to understand b/c of how he spoke into the mic. Definitely a developer. Spoke a little in a drone about the integration of opensource and the commercial world.

Lastly was an interview with Jonathan Schwartz. Says he is happy to see an opensource implementation of Java (apache harmony project) but license for Java will not be open b/c they don’t want it to fork. Of opensolaris, says there is now no need ot compare big, bad closed source solaris to open linux. Can now compare the features of one to the other since they are both open. And to show that he was not 100% full of shit (maybe that is a little strong) said netbeans has the features it has today because of eclipse.

I think I would have rather have seen Tim give the entire keynote. I did not get much from any of the other speakers.

Update: Introduced myself to David HH (Rails) after keynote. Nice guy. Awsome framework.

OSCON 2005 - Learning XSLT

This update is late since my server was down during the track. Also my notes were pretty shoddy since there was so much info I was trying to digest plus I was getting sick during the track. My ribs ached and I my teeth were chattering b/c I was so cold. I believe I had a fever. Must have been some kind of virus.

The last time I tried using XSLT, I really, really did not like it. Lots of frustration and curse words. But given that I have to work with XSLT in my current project (to transform word xml templates) I decided to attend. I was going to attend Eric Hatchers Opensource gems, but that talk seemed to be mostly about Lucene and using a few opensource java projects. Interesting but given ruby has changed my interest in java and I need to use XSLT, well…

I’ll spare you my shoddy notes. Have a look at the speakers slides from the class. My notes mostly copied much of what was in the slides anyway. Plus the slides mirror much of what is going to be in the speakers upcoming Oreilly book.

Evan Lenz did an excellent job at presenting XSLT in a clear, very understandable way. I walked away feeling brain overload but feel like I learned something that I can apply.

Background on speaker, Evan Lenz

  • Recommends Michael Kay’s XSLT Programmers Reference
  • Participated on the XSL Working Group for a couple of years
  • Wrote XSLT 1.0 Pocket Reference
  • Preparing for PhD program in Digital Arts and Experimental Media

Bidwell Down (AGAIN!)

Well it was yesterday during OSCON and prevented me from blogging.

This is getting nuts. Seems to be occurring 2-3 times/week lately.

I really like textdrive but the downtime is getting really annoying. Particularly since I am trying to blog OSCON and the server goes down right in the middle of a track.

They are using FreeBSD, which I really like, but when you look at the status of bidwell when it is down (status.textdrive.com) it seems to be __fsck__ing for a long long time. Why doesn’t BSD have journaling file systems like linux. I understand why they can’t use linux’ but seems like they would have started development on one. On the linux boxes I use, it is so nice not to have to go through the fsck.

OSCON 2005 - Learning Ajax

Demos and slides

You’ll walk away with

  • Enought code to be dangerous

Damn. I thought I was already dangerous. Crap.

Demo Life in a text area
Interesting – autosave in a textarea – much like autosave in a text editor or something like MS Word.

What is ajax

  • still being defined – good portion still up to you
  • No page refreshes – Don’t make me blink
  • don’t make users and developers learn new idioms.
  • Technology should not slow you down – ajax does not fundamentally change what you have been doing.
  • Better interfaces without redesigning from ground up.

Should turn browser into a client for your protocol/api

Good, Bad, Ugly

  • Good – more responsive, more intuitive interfaces
  • Bad – Inaccessible by default (google web accellerator)
  • ugly – debugging takes a village

When is ajax the answer

  • give advantages of desktop apps in a web browser.
  • when you need to do things that traditional request/refresh can not accomplish
  • when the competition does it (you gotta do it too)
  • when it makes the users experience better, not worse

Ajax basically manipulates the DOM. Everything is a node.

It’s moving a little slow at the moment. Talking about the javascript api for manipulating the dom and about how not everything is a node (text for example)

Easiest thing to make code portable is use getDocumentById() call

The speaker is sick! a big chunk of custom javascript for moving around paragraphs on a page. Glad there are toolkits for this. It would sound like a turrets party if I had to do it.

Did not know this – can set style propery of any node and can access css styles using CamelCase names.

Mozilla and MSDN have good dhtml references and speaker thinks MSDN has the best.

Limitations can’t request resources which are not on the same domain (XMLHttpRequests). you could proxy if needed

~4k is the usual typical upper and lower limit of what you can store in client cache (cookies) on a per domain level

Browser incompatibilities – write to the spec and use http://quirksmode.org as a reference for cross platform incompatibilities.

IE has conditional comments – block of code is commented out, but runs in appropriate browser. For example would only run in IE5 or IE5.5, or IE6, etc. Conditional Comments are not used very often, but very useful for determining which one of the many xmlhttprequest objects to load.

.innerHtml is a read/write attribute which modifies the dom. Should uses sparingly but is very useful.

.innerHTML example
precode
var fooNode = document.getElementById(“foo”);
var parentContents = node.innerHTML; // where innerHTML = ‘div id=’foo’/’
node.innerHTML = parentContents;
// fooNode is no longer a valid reference here
/code/pre
Point is if your program depends on a node being there, like an onclick handler, it may be going if you do not use innerHTML judiciously.

What to return

  • html
    • easy to insert into document (fast)
    • can return a string – easy to debug
    • difficult to make portable
    • implies replacement, not updates
  • xml
    • usually supported, MUST use “text/xml” document type
    • doesn’t tie your server to your rendering
    • you’ll need to buildUI on the client
    • xml is typically not fast b/c you have to traverse the document (usually w dom)
  • Plain text
  • javascript
    • fastest for large data sets
      • eval() is the fastest parser available
    • native language of you scripting environment
    • skips the xml-to-data structure step
    • app more likely to speak xml or html
    • JSON helps (standard proposed by ?? – a lightweight subset of what can be descript in javascript literal)

You could send back javascript for large data sets where the javascript you send back would have something like a large dataset in an array. Smaller in size and faster to render than xml/html.

Engineering for ajax

  • Server-side design principals
    • ajax-style UIs should call the REST APIs you apps already expose – example Flickr
    • multiple points of entry
    • Single request, single action
    • more requests, smaller requests
  • When retro-fitting existing apps, wrap at the module level, don’t write new code

Back from break – talking about autosaving

  • xmlhttp for moving data back and forth. Use HTTP POST verb, idempotence matters.
  • serInterval() for occasional execution
  • event handlers wired to Nodes, IDs
  • brittle – hard to maintain or reuse

XMLHTTP Basics

  • synchronous or async communications (most calls will be asynchronous)
  • simple callback scheme for status
  • some verbs problematic (Safari KHTML)
    • HEAD
    • PUT
  • File upload not available cross-browser
    • can be handled with iframes and form hacks

Now covering different ajax toolkits

Prototype by Sams Stevenson Ajax framework baked into Rails http://prototype.conio.net/

Dojo Ajax framework written by speaker, Alex Russell http://dojoframework.org

The toolkits (showing Dojo) have built-in graphics for UI display, example a progress indicator or spinner.

Whoa…. Dojo is pretty impressive. As I understand it, it’s sorta like tapestry but for ajax. you create widgets for say an autosaving text area. You can drop a widget on any part of your app and override default values by providing a dojo widget html fragment (div with some specific elements). Not tied to dom id, node, etc.

Debugging Tools

  • Mozilla JS console
  • Safari JS console
  • Opera JS console
  • IE Script Debugger
  • Rhino or WSH – command line JS

Rhino command line example
java -jar js.jar

brings you into a javascript shell (like irb or python shell) poor interactive command line

example.js
precode
function foo() { print(“BAR”) };
/code/pre

java -jar js.jar example.js
precode
js foo()
BAR
js
/code/pre

Advanced Tools

  • LiveHTTPHeaders – Mozilla/FF – Mozilla extension
  • Venkman – Mozilla/FF JS debugger
  • Squarefree JS Console bookmarklet
  • MSE JS debugger for IE
  • Konqueror
  • VirtualPC/VMWare (for testing different browsers)
  • Ethereal (w00t!)
  • your tenaciousness

The talk was pretty good. Did not find myself getting bored through alot of it. I’m just glad someone else develops the JS libraries so I don’t have to.

Update Did not get to finish blogging while in the class b/c the server where I host netinlet.com went down (pretty much until the end of the conference that day). Was able to save all the content offline though and updated that. This is the repost of original + additional content.

OSCON 2005 - Day 2

On the agenda for today is “Learning Ajax” with Alex Russell and probably the XSLT track with Lentz. As much as I hate XSLT, I should probably go because I am having to use it for my current project. Perhaps I’ll learn something.

Was just looking over my blog from yesterday, and they pretty much suck as compared to this and this
Mine seem more like notes.

OSCON 2005 - Day 1 (Rails W/ DHH)

Kickoff – should be a code heavy presentation…

Install ruby dated 12/25/2004

gem install rails to install rails (requires ruby gems)

Demo based around creating a blog app.

David is giving a detailed explanation of directory structure and built in webserver. Seems to be standard stuff in docs. Major point is that everything is layed out for you so you can get started more quickly and do not have to make those decisions.

… Speaks about the ./script/generate program which stubs out controllers, models, etc.

if a rhtml file is named the same as a method on the appropriate controller, that rhtml file will be rendered by default as the return from the action method.

precoderedirect_to :action = “method_name”/code/pre will jump to another action method on controller.

./script/destroy can remove models/controller/etc just like it can generate them.

Rails has extended the to_s method to include parameters (for date) so you can say my_date.to_s(:long) or my_date.to_s(:short)

foreign key names are not plural – should be same as model name. fk or comments to posts is post_id not posts_id (sorry if that one is not in context of anything else)

can specify foreign keys when defining the relationship
precodehas_many :comments, :foreign_key = “crazy_dba_convention_id”/code/pre

with ./script/console you can interact directly with your model.

Pass in :locals { :variable = my_variable } you can render specific to what ever scope you are in.

Foreign key collections have extra convience methods such as create and build.
@post.comments.create(blah) where comments is a collections of comments on post.

layout the reverse of jsp include. view maps to controller name and is used as a template for any html that needs to be rendered for that controller.

Use ApplicationController which was generated as part of generating your project for extension points such as authentication (ApplicationController is a base class of all other generated Action Controllers)

Unit tests with fixtures, fixtures load the entire fixture file for that db class and loads the values into instance variables by their name.

precode
def test_fixtures_work
assert_equal “FooBarBaz”, @my_first_post[‘title’]
end
/code/pre
Where there is a fixture entry with the title my_first_post with the title of ‘FooBarBaz’

Unit tests usually only useful for testing your methods and the domain model.

Functional Testing Mocks already built for simulating gets and posts. Used for testing controllers and workflow of controllers. Can assert things such as responses (assert_response :success assert_template ‘foobar’)

When functional testing, you can test create or update methods similar to this: (code may make no sense, but methods will be like this)
precode
def test_create_post
post :create, :post = { :title = “foo”, :body = “bar” }
assert_response :redirect
assert_kind_of Post, Post.find_by_title(“This is my title”)
post :create, :post = { :title = "", :body = “bar” }
assert_response :success
assert_equal “don’t leave me out”, assigns(:post) .errors_on(:title)
end
/code/pre

AJAX
In template do
precode
%= javascript_include :defaults %
/code/pre
damnit, think the javascript_include is correct but may be wrong – DHH moved on.

use the remote call replacement (linkto_remote instead of link_to for example) and pass in parameters (controller, id of element in html, etc)

can call precoderender :nothing = true/code/pre in action if nothing needs to be rendered for ajax call

can distinguish ajxx from non ajax by using the method request.xml_http_request?

DHH must be tired – he’s ajaxing the wrong files and it’s getting slightly confusing.

Need to clear input fields when ajaxing a form. Example if you have inputs for name and address, you will have to clear the name and address input boxes.

OSCON 2005 - Day 1 (Ruby W/ Dave Thomas)

Finally…, it’s here. And the line up for today is Intro to ruby w/ Dave Thomas and Rails with DHH.

Dave Thomas is one of my most favorite technical authors – this should be good…

Introduction to Ruby

Is programming still fun? in and of itself it is fun – it’s the language and the tools. Rise of scripting language make it more fun b/c less time to run program.

Ruby born in japan 1994 – Mats

Ruby passes the 5 minute test.

Wait – this is funny – Dave is presenting in socks.

Ruby removes alot of the inherited cruft of other languages – no need to put () around method and class definitions – don’t need to put ; at the end of a line. These things are unnecessary -the compiler/interpreter can figure it out.

new is not a keyword. It is built into the object. Makes overriding the functionality of creating the object more flexible (perhaps by using class level variables?)

attributes begin w/ @

Attributes and methods are one and the same. Makes for universal access
precode
@my_var
attr_reader :my_var
/code/pre

is the same as

precode
def my_var=(x)
@a = x
end
def myvar
return @a
end
/code/pre

Blocks and iterators are pervasive in Ruby
The santa clause theory: precode3.times { puts “Ho!” }/code/pre

variable

is called a block parameter

yield inside a method definition looks at code and stores in your “back pocket” which it executes later. (Thats a pretty crappy writeup…)

Ruby convention for iterators. Block should test for params. If block is not given , code should store in an array and return at the end of the method/iterator call.

Blocks as callbacks – use callback syntax as argument to initialize. If block not given, nil is stored. Can use later like
precode
callback.execute if callback
/code/pre

Resource management w/ blocks. Use block with resources to ensure resources are closed afterwards.

precode
File.open(‘/etc/passwd’) do
#… do something
end
/code/pre

File will be closed automagically at the end of the block.

Did not know this. Per-statement exception handling
precode
def x(name)
f = File.open(name)
yield f ensure f.close
end
/code/pre
where yield f ensure f.close is the per statement exception handling

Transparent block passing
precode
def x(name, callback)
File.open(name, callback)
end
/code/pre

Duck typing. Ruby has strongly-typed objects but untyped variables and methods. Type is determined by object protocol (by what object can do) Just have to make sure the types you are passing in support the methods that the object needs. If it walks like a duck and talks like a duck, it must be a duck.

Ruby community differentiates the type and class of an object

  • type: what it can do
  • class: what generated it (who created this object)

Metaprogramming mini DSL’s within you classes
How do we get there:

  • Classes are open and can be extended – ex: can add stuff to string. ex – could add an encryption method to string so you could say cat.encrypt. yes it is dangerous to redefine core class methods like overriding the + method on Fixednum, but just b/c some idiot might do it doesn’t mean it should not be there. I you do something stupid, take ourself out to the parking lot and beat self w/ rubber hose.
  • Definitions are active Add to classes with things such as adding tomorrow and yesterday methods to the Time class. One thing that was really driven home for me is that you can execute arbitrary code in you classes (functional). For ex. Caching. in one of your classes, you could read a file and store it in a string as part of the definition. Then methods on the call would have ready acccess to the string or array. Put another way, you can write code that executes during class definitions.
  • All methods calls have a receiver “ruby”.length “ruby” is the receiver.

This is very powerful for metaprogramming
precode
class Doug
end
class Bryant
end

variable = day.even? Doug: Bryant
variable.do_something
/code/pre

Learned you can use the “inherited(subclass)” method on base classes and will automagically be called when you extend the base class.

Other stuff
Object space can tell you about objects at runtime. ex. give me all the strings in my program. Useful for such things as debugging – why is that person object still hanging around

Dave Thomas is an excellent speaker. I was very impressed. If you ever get a chance to hear him speak, do it. He has a very clear and concise way of explaining things. Not to mention a good sense of humor. He keeps things technical and assumes the audience are not all dumbasses – he knows we have all done some sort of software development before and does not stick on the syntax of the language.

OSCON 2005

I just got signed up for OSCON 2005 in Portland. I’m totally stoked. There is a great line up this year.

Some of the tracks I intend to attend… (Very Ruby Heavy)

  • Intro to Ruby w/ Dave Thomas
  • Ruby on Rails: Enjoying the Ride of Programming
  • Learning Ajax
  • Integrate: Building a Site from Open Source Gems
  • Application Development With Firefox and Mozilla
  • WebWork vs. Spring MVC Smackdown
  • States of the Databases
  • Open Office Xml Doc Format
  • SiteMesh: A Simple Approach to Web Site Layout
  • Tapestry In Action
  • Ruby Blocks
  • Pragmatic Project Automation with Ruby
  • Metaprogramming Ruby
  • Dependency Injection: irrelevant?

Holy Cow! I knew it was ruby heavy, but did did not realize how heavy it was until I saw it listed here.