Archive for the ‘work’ Category

Compleat Rubyist – Day 1

June 19th, 2010 by Brian | No Comments | Filed in work

Day 1 of 2 of my notes for the Compleat Rubyist training course

Ruby Versions and Implementations  – David

http://ruby-versions.net/ – David’s home for ruby versions & implementations for learning & historical reference

Ruby version manager – http://rvm.beginrescueend.com – lets you install several ruby versions/implementations and easily switch between (including your own custom compiled version). Suggestion – don’t install as root, even though it is allowed.

Notes on a few of the existing options:

  • MacRuby – interacts with Cocoa
  • Rubinius – Ruby in Ruby
  • JRuby – Ruby on JVM
  • REE – optimized – created by Phusion Passenger team
  • MagLev – built in object persistence, repository instead of files, smalltalk-ish
  • IronRuby – Ruby on .NET
  • URABE – ?

rvm allows you to compare performance between versions/implementation:

rvm ruby-1.8.6,ruby1.9.2 benchmark filename.rb

Why does everyone use 1.8 instead of 1.9?

  • Same amount of people are using it as last year (like almost no one)
  • Rails considerations
  • 1.9 is not 100% backwards compatible
  • 1.8.7 backported many of the features of 1.9, so people feel safer

Ruby Enterprise Edition has major memory and speed improvements

Highlights of changes between 1.8 & 1.9

  • Enumerators
  • Method parameters
  • Block variable binding & scope
  • Syntax changes

Discussion

  • “Ruby 1.9 was plenty different enough to be 2.0″ – David
  • 1.9.1 is currently the stable supported version and has been for about a year.
  • 1.8.6 to 1.8.7 was a big jump – major backporting of 1.9 features into 1.8
  • 1.8.7 was a safe harbor for those that wanted 1.9 features but were scared of 1.9
  • rails3 + ruby 1.9.1 = segfaults :(    … works with certain revisions of 1.9.2 HEAD

Enumerator object – 1.9

  • mixes in Enumerable
  • you write the ‘each’ method
    • borrow from another object (can be lazy)
    • or
    • pass in code block on instantiation (via a yielder)
  • once it knows how to ‘each’, it can do select, map, each_cons ….
  • 1.8.6 – require ‘enumerator’ – Enumerable::Enumerator
  • 1.9.x – no require needed – promoted to top level ‘Enumerator’

side bar: each_cons vs each_slice

Note to self: I need to memorize each/select/map/collect

What methods do I get with Enumerator that I don’t get with Enumerable (Array)?

Enumerator.instance_methods - Array.instance_methods
:with_index, :with_object, :next, :rewind

Method argument semantics
required args can now come after optional args
def m(a, b=1, c)
def m(a, *b, c)
def m((a,b),c)
required arguments get filled first

Block variable scope

  • probably the most important/annoying/significant change
  • breaks stuff in surprising ways
  • but if it does break stuff, you were likely doing something buggy before

Example 1:

a = [1,2,3]
a.each {|x| p x}

x gets value of 3 when you are done

|x| literally assigns x ( |x=…| ), so it becomes available outside the block

Example 2:

a = 1
array.each { a = 2 }

does not change the value of a

  • Matz said he wished he had done this from the beginning
  • Unifies the parameter syntax between methods & lambas

1.9 Miscellany

  • no more String#each
    • “Hello”[0] = “H”  #in 1.8 it returns 72
  • new instance_exec is like instance_eval but takes a param to inject

JRuby – ask David about using ArrayList instead of [] in playpoker.rb

The Testing Landscape

Test::Unit is gone in 1.9
Test::Unit::TestCase -> Mini::Test::TestCase
Mini::Test has a new option: refute_match
require ’shoulda’ – makes it more like RSpec without going full RSpec
RSpec is the defacto standard for Behavior-driven testing

Jeremy – wrote ‘context’ and ‘match’
Given/When/Then – cucumber is most popular
“Think in units of features rather than units of code” – Gregory
require ‘could’ – another tool – include feature test right in the same file as tests

Test data

  • YAML/CSV – hard to maintain, csv is kinda nice because you can open in spreadsheet program (or rather your testers can)
  • model_stubbing  http://github.com/technoweenie/model_stubbing
  • Factories is the new hotness
  • mocking/stubbing
    • can extend a class to do it
    • can use OpenStruct to do it require ‘ostrich’
    • Jeremy likes using ‘rr’
    • RSpec has it’s own stubbing
    • flexmock
  • Proxies
    • Proxies are like mocks & stubs & real code combined
    • Proxies are the Ken Jennings of mocks & stubs

Tags: , ,

RailsConf – Day 3 – Lightning talks

June 9th, 2010 by Brian | No Comments | Filed in work

Brian C – DNC

http://github/dnclabs

- client_side_validations – gem that does client side validation for rails
- takes AR validations – serves them via json – used by jquery.validate

how to kill rails
github.com/michel
bad practices by a few rails developers
Don’t reduce yourself to $20/hr, stick to your price, delivery quality
Communication is important!

Democracy.com
Raimond Garcia
Revolutionize Democracy
Parsed Congress web page – created a prototype on heroku in 48 hours
legal palitical party in spain – “partido de internet”

What’s new in RSpec-2
David Chelimsky
in beta right now
Old rspec won’t work with Rails 3
doesn’t work with rails < 3 (yet)

http://github.com/rspec

$rspec spec
modularized, rspec-core is built on micronaut

Surveyor gem
Mark Yoon
Surveys in your Rails app
write surveys in DSL
exmaple Kitchen Sink survey
dates, ranges, plck any, grids, multiple answers
needs: admin ui, validations in UI, Rails3 support

http://github.com/breakpointer/surveyor

MySQL is awesome

@igrigorik
Don’t believe all the NoSQL hype

http://bit.ly/bgi1Wf

more flexibility in the relational model
em-proxy gem – tcp level proxy
- used to rewrite SQL queries on the fly

Michael Hartl
railstutorial.org
Joy of publishing online
goal – write a source file, publish HTML & PDF with syntax highlighting & linking to other sections
PolyyTeXnic
HTML & PDF stay in sync

Jake Scruggs
@jakescruggs
ActiveMQ & ActiveMessaging
Mostly a Java shop, so not Resque, delayed job
sending messages is easy
pass id’s NOT serialized objects
Tips:
- Tell ActiveMessage to not be greedy
- Namespace your queues
- Name your pollers
- Double Kill – Die Poller Die – script/poller run vs script/poller start

Greg Nelson
foreign assistance

http://bit.ly/RwandaOnRails

Jim Rumsick (Big Tiger)- HashRocket
Improv – Comedy to Coding
Programming is about communication

Tags: ,

RailsConf – Day 3 – Persistence Smoothie

June 9th, 2010 by Brian | No Comments | Filed in work

Persistence Smoothie – Blending SQL & NoSQLFlip Sasser (Intridea, Inc.)
@flipsasser

http://github.com/flipsasser/Persistence-Smoothie

NoSQL means no ACID
Keep what you know – don’t throw out your MySQL

DataMapper is the swiss army knife of ORM
- can point different models to different datastores
- Have a lot of refactoring to do

Sample Store App
- Authentication – keep in Reational DB
- Products – store metadata
- Purchases – keep it in RDB
- Activity Stream – denormalize with key/value store

mongofy – gem for moving data from mysql to mongo

Drawbacks
- DataPortability is lowered
- Lot more moving parts
- Say goodbye to all your fun AR mixins

Tags: , , ,

RailsConf – Day 3 – Introduction to Cassandra and CassandraObject

June 9th, 2010 by Brian | No Comments | Filed in work

Introduction to Cassandra and CassandraObjectMichael Koziarski (Koziarski Software Limited)

Scales linearly – increases not only read access, but also write access

A ColumnFamily per query

CassandraObject
- Mostly AR compatible
- In flux
- taking patches

Tags: , ,

RailsConf – Day 3 – Redis, Rails and Resque

June 9th, 2010 by Brian | No Comments | Filed in work

Redis, Rails, and Resque – Background Job BlissChris Wanstrath (GitHub)
redis is a key value store for data structures

redis is not use for everything because entire dataset used to have to fit into RAM – would have to shard across machines

github – uses redis for routing, can add, remove.modify routes quickly & easily – can determine what server to put new users on, etc

Old – HAProxy sending to mongrels
New – Unicorn – instead of receiving requests, it asks for one using ’select’, pooled, forks similar to passenger

Used 6 or 7 different bg – SQS, DelayedJob
Used Delayed job for 2 years

resque is built on redis, jobs are serialized to json and workers can be in any language http://github.com/defunkt/resque

resque has a plugin API – 15 or so plugins already exist – http://wiki.github.com/defunkt/resque/plugins

has admin interface

github has 35 types of background jobs

Notes: lightning fast talker! Lots of good information though. I’d have a beer with this guy!

Tags: , ,