Episode #429 - January 3rd, 2014

Posted 8 months back at Ruby5

Writing a Ruby compiler, the Omega universe simulator, RubyGems 2.2.0, debugging with HTTP clients, detecting similarities in images, and the Lotus web framework all in this episode of the Ruby5!

Listen to this episode on Ruby5

This episode is sponsored by New Relic
New Relic is _the_ all-in-one web performance analytics product. It lets you manage and monitor web application performance, from the browser down to the line of code. With Real User Monitoring, New Relic users can see browser response times by geographical location of the user, or by browser type.

Writing a Compiler in Ruby from the Bottom Up
Ever wondered just what goes into writing a compiler? This long running series of blog posts from Vidar Hokstad will take you on a whirlwind tour!

The Omega Simulation Framework
The Omega universe simulation framework lets you create your very own game universe in the cloud!

RubyGems 2.2.0 Released
Happy Festivus, we got a new RubyGems!

Debugging an HTTP Client Library
Avdi gets to the bottom of an HTTP client.

Detect Similar Images
Check out part 1 of a series on detecting similar images.

Lotus
Lotus is a new full-stack web application framework for Ruby.

Phusion Passenger 4.0.33 released

Posted 8 months back at Phusion Corporate Blog


Phusion Passenger is a fast and robust web server and application server for Ruby, Python, Node.js and Meteor. Passenger takes a lot of complexity out of deploying web apps, and adds powerful enterprise-grade features that are useful in production. High-profile companies such as Apple, New York Times, AirBnB, Juniper, American Express, etc are already using it, as well as over 350.000 websites.

Phusion Passenger is under constant maintenance and development. Version 4.0.33 is a bugfix release.

Phusion Passenger also has an Enterprise version which comes with a wide array of additional features. By buying Phusion Passenger Enterprise you will directly sponsor the development of the open source version.

Recent changes

4.0.31 and 4.0.32 have been skipped because an incompatibility problem with very old Ruby versions was found by our build server shortly after tagging the releases. 4.0.32 fixes all those problems. The changes in 4.0.31, 4.0.32 and 4.0.33 combined are:

  • Introduced a new tool: passenger-config restart-app. With this command you can initiate an application restart without touching restart.txt. Unlike touching restart.txt, this tool initiates the restart immediately instead of on the next request.
  • Fixed some problems in process spawning and request handling.
  • Fixed some problems with the handling of HTTP chunked transfer encoding bodies. These problems only occurred in Ruby.
  • Fixed a compatibility problem in passenger-install-apache2-module with Ruby 1.8. The language selection menu didn’t work properly.
  • Fixed the HelperAgent, upon shutdown, not correctly waiting 5 seconds until all clients have disconnected. Fixes issue #884.
  • Fixed compilation problems on FreeBSD 10.
  • Fixed some C++ strict aliasing problems.
  • Fixed some problems with spawning applications that print messages without newline during startup. Fixes issue #1039.
  • Fixed potential hangs on JRuby when Ctrl-C is used to shutdown the server. Fixes issue #1035.
  • When Phusion Passenger is installed through the Debian package, passenger-install-apache2-module now checks whether the Apache module package (libapache2-mod-passenger) is properly installed, and installs it using apt-get if it’s not installed. Fixes issue #1031.
  • The passenger-status --show=xml command no longer prints the non-XML preamble, such as the version number and the time. Fixes issue #1037.
  • The Ruby native extension check whether it’s loaded against the right Ruby version, to prevent problems when people upgrade Ruby without recompiling their native extensions.
  • Various other minor Debian packaging improvements.

Installing or upgrading to 4.0.33

OS X OS X Debian Debian Ubuntu Ubuntu
Heroku Heroku Ruby gem Ruby gem Tarball Tarball

Final

Fork us on Github!

Phusion Passenger’s core is open source. Please fork or watch us on Github. :)

<iframe src="http://ghbtns.com/github-btn.html?user=phusion&amp;repo=passenger&amp;type=watch&amp;size=large&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe><iframe src="http://ghbtns.com/github-btn.html?user=phusion&amp;repo=passenger&amp;type=fork&amp;size=large&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe><iframe src="http://ghbtns.com/github-btn.html?user=phusion&amp;type=follow&amp;size=large&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="190" height="30"></iframe>

If you would like to stay up to date with Phusion news, please fill in your name and email address below and sign up for our newsletter. We won’t spam you, we promise.



Announcing Lotus

Posted 8 months back at Luca Guidi - Home

I’m pleased to announce Lotus: the Open Source project I’ve conceived, hacked and built during the last year.

Lotus is a full stack web framework for Ruby, built with lightness, performances and testability in mind. It aims to bring back Object Oriented Programming to web development, leveraging on stable APIs, a minimal DSL, and plain objects.

Standalone frameworks

It’s composed by standalone frameworks (controllers, views, etc..), each one is shipped as an independent gem, in order to remark the separation of concerns. They can be used with any Rack compatible application for a specific need: for instance, Lotus::Router can be used to dispatch HTTP requests for a pool of Sinatra applications.

Full stack application

The other way to use Lotus is to build a full stack application with it, like Rails does. The Lotus gem is designed to enhance those frameworks’ features with a few specific conventions.

Philosophy

Lotus is based on simplicity, less DSLs, few conventions, more objects, zero monkey-patching of the core language and standard lib, separation of concerns for MVC layers. It suggests patterns, rather than imposing. It leaves all the freedom to developers to build their own architecture, choose the inheritance structure. It simplifies testability, and encourages single, well defined responsibilities between classes.

Roadmap

Lotus is a complex software, it needs to be completed, and to get feedback in order to became production ready. Some of its frameworks already have reached a certain degree of maturity, other still needs to be crafted as a gem yet. A single release day would be hard to meet as expectation, so I would like to suggest an experiment: to open source a component on the 23rd of every month, starting from January with Lotus::Utils and Lotus::Router.

Happy new year!

Defense Wins Championships - Hope for the Trail Blazers

Posted 8 months back at Encytemedia - Home

"Defense Wins Championships." If you're a fan of the NBA (or most major sports), you've likely heard this phrase. I've always considered it fodder for punditry; something you say when you have nothing objective to add to a conversation. Sure, it’s cliché, but is it true?

--

December is almost over and we’re eight weeks into another NBA season. Some great story lines have emerged. Kobe makes a miraculous comeback after tearing his achilles only to promptly injure his knee; Derrick Rose made his return from a season ending injury and tore the meniscus in his right knee, knocking him out for yet another season; First year head coach Jeff Hornacek has the Phoenix Suns, a team people expected to be in the lottery, making a case for the playoffs in a stacked Western Conference. And then there’s the Portland Trail Blazers.

The Blazers, with a record 24-7, are the Cinderella team of the season. A few people expected them to improve, but no one expected them to be sitting near the top of the NBA rankings. The best-case preseason scenario was barely winning enough games to secure the 8th and final playoff spot in the west.

The Blazers area an interesting team. They have the NBAs best offense; One of the best offenses in the NBA in the last 17 years. Taking a look through stats back to the 1996-97 season, this year’s Blazer team ranks #10 in Offensive Rating, behind some dominating Nash-led Phoenix Suns teams.

Offensive Rating- The number of points scored per 100 possessions. By using possessions, you eliminate pace as a factor because some teams play faster, resulting in more possessions.


 rank | season  |       team_name        | wins | losses | advanced_off_rating
------+---------+------------------------+------+--------+---------------------
    1 | 2009-10 | Phoenix Suns           |   54 |     28 |               112.7
    2 | 2004-05 | Phoenix Suns           |   62 |     20 |               111.9
    3 | 2006-07 | Phoenix Suns           |   61 |     21 |               111.4
    4 | 2008-09 | Phoenix Suns           |   46 |     36 |               111.2
    5 | 2007-08 | Phoenix Suns           |   55 |     27 |               111.2
    6 | 1996-97 | Chicago Bulls          |   69 |     13 |               111.1
    7 | 2007-08 | Utah Jazz              |   54 |     28 |               110.8
    8 | 2008-09 | Portland Trail Blazers |   54 |     28 |               110.7
    9 | 1996-97 | Utah Jazz              |   64 |     18 |               110.5
   10 | 2013-14 | Portland Trail Blazers |   24 |      7 |               110.4

While the Blazers offense under Terry Stotts has been humming along, the defense is sitting near the bottom of the league at #23 allowing 105 points per 100 possessions.

Defensive Rating- The number of points allowed per 100 possessions. By using possessions, you eliminate pace as a factor because some teams play faster, resulting in more possessions.


 rank |       team_name        | wins | loses | advanced_def_rating
------+------------------------+------+-------+---------------------
    1 | Indiana Pacers         |   24 |     5 |                93.6
    2 | Oklahoma City Thunder  |   25 |     5 |                97.4
    3 | Charlotte Bobcats      |   14 |    18 |                98.3
    4 | Golden State Warriors  |   19 |    13 |                98.5
    5 | Chicago Bulls          |   12 |    17 |                98.6
    6 | San Antonio Spurs      |   24 |     7 |                98.8
    7 | Los Angeles Clippers   |   21 |    12 |               100.4
    8 | Miami Heat             |   24 |     7 |               100.7
    9 | Toronto Raptors        |   13 |    15 |               101.6
   10 | Phoenix Suns           |   19 |    11 |               101.8
   11 | Boston Celtics         |   13 |    17 |               102.1
   12 | Houston Rockets        |   21 |    12 |               102.4
   13 | Minnesota Timberwolves |   15 |    16 |               102.5
   14 | Orlando Magic          |   10 |    20 |               102.5
   15 | Atlanta Hawks          |   17 |    14 |               102.6
   16 | Denver Nuggets         |   14 |    16 |               102.8
   17 | Washington Wizards     |   14 |    14 |                 103
   18 | Cleveland Cavaliers    |   10 |    20 |               103.9
   19 | Los Angeles Lakers     |   13 |    18 |               103.9
   20 | Dallas Mavericks       |   18 |    13 |               104.4
   21 | Detroit Pistons        |   14 |    19 |               104.8
   22 | Milwaukee Bucks        |    6 |    24 |               104.8
   23 | Portland Trail Blazers |   24 |     7 |                 105
   24 | New Orleans Pelicans   |   14 |    15 |               105.3
   25 | Memphis Grizzlies      |   13 |    17 |               105.5
   26 | New York Knicks        |    9 |    21 |               105.8
   27 | Brooklyn Nets          |   10 |    20 |               106.2
   28 | Sacramento Kings       |    9 |    20 |               106.5
   29 | Philadelphia 76ers     |    9 |    21 |               106.8
   30 | Utah Jazz              |   10 |    24 |               107.7

Does this mean the Blazers can't compete for a title? Conventional wisdom suggests they can't, but there is a chance and that chance is the 2000-01 Lakers.

Take a look at the chart below showing the offensive and defensive ratings of the two teams who competed for the championship back to the 1996-97 season.

The numbers on the outside represent a teams respective regular season rating, while the numbers near the circles represent the teams regular season rank. Shorter bars are better.
Champion Runner-up

<script src="/assets/posts/nba-champions-705b515bd5fa28c7fe2e58fb203c6c6a.js"></script>

Here are some takeaways from the chart:

  • 16 of the last 17 champions had a top 10 defense (94%). The 2000-01 Lakers being the outlier.
  • 14 of the last 17 champions had a top 10 offense (82%).
  • 13 of the last 17 runner-ups had a top 10 defense (76%)
  • 10 of the last 17 runner-ups had a top 10 offense (59%).

In the last 17 years, only one time has a team won the championship without a top 10 defense. That probably isn't the news Blazer fans want to here (I include myself in that group), but the 2000-01 Lakers are the silver lining.

It's ironic that Blazer fans would need to look to the 2000-01 Shaq and Kobe Lakers for hope given how much Blazer fans loathe the Lakers. Especially a Lakers team that swept them in the first round. But if there's reason for hope, this Lakers team is it.

In the 2000-01 season the Lakers had the #19 ranked defense (#21 according to basketball-reference.com) and the #2 ranked offense (similar to this years' Blazer team), but went on to win the title. But, how did they do it?

The 2000-01 Lakers #19 ranked defense allowed 101.7 points per 100 possessions. That defense would be ranked #10 in the 2013-14 season. But, I believe this can almost certainly be explained away by rule changes that have favored offenses. The league PPG average has grown by almost 4 points since hand checking was eliminated in the 2004-05 season.

However, The answer becomes clear when you look at the stats for the 2001 playoffs. The Lakers were motivated in the playoffs, jumping from a regular season rank of #19 to a playoff rank of #1!

The table below shows just how much individual players improved during the playoffs:

      player      | Regular Season Defense | Playoff Defense
------------------+------------------------+-----------------
 Kobe Bryant      |                    105 |              99
 Shaquille O'Neal |                    101 |              96
 Derek Fisher     |                    105 |             101
 Rick Fox         |                    106 |              98
 Horace Grant     |                    106 |              98
 Robert Horry     |                    104 |              95
 Brian Shaw       |                    105 |              99
 Tyronn Lue       |                    108 |              96
 Mark Madsen      |                    107 |             103
 Ron Harper       |                    105 |              91
 Devean George    |                    105 |             106
 Greg Foster      |                    104 |              96

Everyone, save Devean George, who played a total of 27 minutes during the Lakers' playoff run, improved on defense—and pretty drastically.

So the 2013-14 Blazers can win, but they'll need to make drastic improvements on defense. How drastic? I'll leave you with one last table, comparing players who've played at least 300 minutes on the top 5 teams in the NBA.


  rank |      player       | Defense Rating
------+-------------------+----------------
    1 | Roy Hibbert       |             93
    2 | Ian Mahinmi       |             94
    3 | Paul George       |             94
    4 | David West        |             95
    5 | Luis Scola        |             96
    6 | C.J. Watson       |             97
    7 | Tim Duncan        |             97
    8 | George Hill       |             98
    9 | Kevin Durant      |             98
   10 | Kawhi Leonard     |             98
   11 | Steven Adams      |             98
   12 | Serge Ibaka       |             98
   13 | Lance Stephenson  |             98
   14 | Danny Green       |             99
   15 | Jeff Ayres        |            100
   16 | Russell Westbrook |            100
   17 | Orlando Johnson   |            100
   18 | Kendrick Perkins  |            101
   19 | Thabo Sefolosha   |            101
   20 | Tiago Splitter    |            101
   21 | Chris Andersen    |            101
   22 | Manu Ginobili     |            101
   23 | Nick Collison     |            102
   24 | Reggie Jackson    |            102
   25 | Jeremy Lamb       |            102
   26 | Dwyane Wade       |            102
   27 | Chris Bosh        |            102
   28 | Patrick Mills     |            102
   29 | Derek Fisher      |            103
   30 | Marco Belinelli   |            103
   31 | LeBron James      |            103
   32 | Mario Chalmers    |            103
   33 | Rashard Lewis     |            103
   34 | Michael Beasley   |            104
   35 | Boris Diaw        |            104
   36 | LaMarcus Aldridge |            105
   37 | Thomas Robinson   |            106
   38 | Ray Allen         |            106
   39 | Shane Battier     |            106
   40 | Tony Parker       |            106
   41 | Norris Cole       |            106
   42 | Joel Freeland     |            107
   43 | Nicolas Batum     |            107
   44 | Robin Lopez       |            107
   45 | Wesley Matthews   |            109
   46 | Dorell Wright     |            109
   47 | Damian Lillard    |            110
   48 | Mo Williams       |            110

Defense Wins Championships - Hope for the Trail Blazers

Posted 8 months back at Encytemedia - Home

“Defense Wins Championships.” If you’re a fan of the NBA (or most major sports), you’ve likely heard this phrase. I’ve always considered it fodder for punditry; something you say when you have nothing objective to add to a conversation. Sure, it’s cliché, but is it true?

--

December is almost over and we’re eight weeks into another NBA season. Some great story lines have emerged. Kobe makes a miraculous comeback after tearing his achilles only to promptly injure his knee; Derrick Rose made his return from a season ending injury and tore the meniscus in his right knee, knocking him out for yet another season; First year head coach Jeff Hornacek has the Phoenix Suns, a team people expected to be in the lottery, making a case for the playoffs in a stacked Western Conference. And then there’s the Portland Trail Blazers.

The Blazers, with a record 24-7, are the Cinderella team of the season. A few people expected them to improve, but no one expected them to be sitting near the top of the NBA rankings. The best-case preseason scenario was barely winning enough games to secure the 8th and final playoff spot in the west.

The Blazers area an interesting team. They have the NBAs best offense; One of the best offenses in the NBA in the last 17 years. Taking a look through stats back to the 1996-97 season, this year’s Blazer team ranks #10 in Offensive Rating, behind some dominating Nash-led Phoenix Suns teams.

Offensive Rating- The number of points scored per 100 possessions. By using possessions, you eliminate pace as a factor because some teams play faster, resulting in more possessions.


 rank | season  |       team_name        | wins | losses | advanced_off_rating
------+---------+------------------------+------+--------+---------------------
    1 | 2009-10 | Phoenix Suns           |   54 |     28 |               112.7
    2 | 2004-05 | Phoenix Suns           |   62 |     20 |               111.9
    3 | 2006-07 | Phoenix Suns           |   61 |     21 |               111.4
    4 | 2008-09 | Phoenix Suns           |   46 |     36 |               111.2
    5 | 2007-08 | Phoenix Suns           |   55 |     27 |               111.2
    6 | 1996-97 | Chicago Bulls          |   69 |     13 |               111.1
    7 | 2007-08 | Utah Jazz              |   54 |     28 |               110.8
    8 | 2008-09 | Portland Trail Blazers |   54 |     28 |               110.7
    9 | 1996-97 | Utah Jazz              |   64 |     18 |               110.5
   10 | 2013-14 | Portland Trail Blazers |   24 |      7 |               110.4

While the Blazers offense under Terry Stotts has been humming along, the defense is sitting near the bottom of the league at #23 allowing 105 points per 100 possessions.

Defensive Rating- The number of points allowed per 100 possessions. By using possessions, you eliminate pace as a factor because some teams play faster, resulting in more possessions.


 rank |       team_name        | wins | loses | advanced_def_rating
------+------------------------+------+-------+---------------------
    1 | Indiana Pacers         |   24 |     5 |                93.6
    2 | Oklahoma City Thunder  |   25 |     5 |                97.4
    3 | Charlotte Bobcats      |   14 |    18 |                98.3
    4 | Golden State Warriors  |   19 |    13 |                98.5
    5 | Chicago Bulls          |   12 |    17 |                98.6
    6 | San Antonio Spurs      |   24 |     7 |                98.8
    7 | Los Angeles Clippers   |   21 |    12 |               100.4
    8 | Miami Heat             |   24 |     7 |               100.7
    9 | Toronto Raptors        |   13 |    15 |               101.6
   10 | Phoenix Suns           |   19 |    11 |               101.8
   11 | Boston Celtics         |   13 |    17 |               102.1
   12 | Houston Rockets        |   21 |    12 |               102.4
   13 | Minnesota Timberwolves |   15 |    16 |               102.5
   14 | Orlando Magic          |   10 |    20 |               102.5
   15 | Atlanta Hawks          |   17 |    14 |               102.6
   16 | Denver Nuggets         |   14 |    16 |               102.8
   17 | Washington Wizards     |   14 |    14 |                 103
   18 | Cleveland Cavaliers    |   10 |    20 |               103.9
   19 | Los Angeles Lakers     |   13 |    18 |               103.9
   20 | Dallas Mavericks       |   18 |    13 |               104.4
   21 | Detroit Pistons        |   14 |    19 |               104.8
   22 | Milwaukee Bucks        |    6 |    24 |               104.8
   23 | Portland Trail Blazers |   24 |     7 |                 105
   24 | New Orleans Pelicans   |   14 |    15 |               105.3
   25 | Memphis Grizzlies      |   13 |    17 |               105.5
   26 | New York Knicks        |    9 |    21 |               105.8
   27 | Brooklyn Nets          |   10 |    20 |               106.2
   28 | Sacramento Kings       |    9 |    20 |               106.5
   29 | Philadelphia 76ers     |    9 |    21 |               106.8
   30 | Utah Jazz              |   10 |    24 |               107.7

Does this mean the Blazers can’t compete for a title? Conventional wisdom suggests they can’t, but there is a chance and that chance is the 2000-01 Lakers.

Take a look at the chart below showing the offensive and defensive ratings of the two teams who competed for the championship back to the 1996-97 season.

The numbers on the outside represent a teams respective regular season rating, while the numbers near the circles represent the teams regular season rank. Shorter bars are better.
Champion Runner-up

<script src="/js/posts/nba-champions.js" type="text/javascript" charset="utf-8"></script>

Here are some takeaways from the chart:

  • 16 of the last 17 champions had a top 10 defense (94%). The 2000-01 Lakers being the outlier.
  • 14 of the last 17 champions had a top 10 offense (82%).
  • 13 of the last 17 runner-ups had a top 10 defense (76%)
  • 10 of the last 17 runner-ups had a top 10 offense (59%).

In the last 17 years, only one time has a team won the championship without a top 10 defense. That probably isn’t the news Blazer fans want to here (I include myself in that group), but the 2000-01 Lakers are the silver lining.

It’s ironic that Blazer fans would need to look to the 2000-01 Shaq and Kobe Lakers for hope given how much Blazer fans loathe the Lakers. Especially a Lakers team that swept them in the first round. But if there’s reason for hope, this Lakers team is it.

In the 2000-01 season the Lakers had the #19 ranked defense (#21 according to basketball-reference.com) and the #2 ranked offense (similar to this years’ Blazer team), but went on to win the title. But, how did they do it?

The 2000-01 Lakers #19 ranked defense allowed 101.7 points per 100 possessions. That defense would be ranked #10 in the 2013-14 season. But, I believe this can almost certainly be explained away by rule changes that have favored offenses. The league PPG average has grown by almost 4 points since hand checking was eliminated in the 2004-05 season.

However, The answer becomes clear when you look at the stats for the 2001 playoffs. The Lakers were motivated in the playoffs, jumping from a regular season rank of #19 to a playoff rank of #1!

The table below shows just how much individual players improved during the playoffs:


      player      | Regular Season Defense | Playoff Defense
------------------+------------------------+-----------------
 Kobe Bryant      |                    105 |              99
 Shaquille O'Neal |                    101 |              96
 Derek Fisher     |                    105 |             101
 Rick Fox         |                    106 |              98
 Horace Grant     |                    106 |              98
 Robert Horry     |                    104 |              95
 Brian Shaw       |                    105 |              99
 Tyronn Lue       |                    108 |              96
 Mark Madsen      |                    107 |             103
 Ron Harper       |                    105 |              91
 Devean George    |                    105 |             106
 Greg Foster      |                    104 |              96
   

Everyone, save Devean George, who played a total of 27 minutes during the Lakers’ playoff run, improved on defense—and pretty drastically.

So the 2013-14 Blazers can win, but they’ll need to make drastic improvements on defense. How drastic? I’ll leave you with one last table, comparing players who’ve played at least 300 minutes on the top 5 teams in the NBA.


  rank |      player       | Defense Rating
------+-------------------+----------------
    1 | Roy Hibbert       |             93
    2 | Ian Mahinmi       |             94
    3 | Paul George       |             94
    4 | David West        |             95
    5 | Luis Scola        |             96
    6 | C.J. Watson       |             97
    7 | Tim Duncan        |             97
    8 | George Hill       |             98
    9 | Kevin Durant      |             98
   10 | Kawhi Leonard     |             98
   11 | Steven Adams      |             98
   12 | Serge Ibaka       |             98
   13 | Lance Stephenson  |             98
   14 | Danny Green       |             99
   15 | Jeff Ayres        |            100
   16 | Russell Westbrook |            100
   17 | Orlando Johnson   |            100
   18 | Kendrick Perkins  |            101
   19 | Thabo Sefolosha   |            101
   20 | Tiago Splitter    |            101
   21 | Chris Andersen    |            101
   22 | Manu Ginobili     |            101
   23 | Nick Collison     |            102
   24 | Reggie Jackson    |            102
   25 | Jeremy Lamb       |            102
   26 | Dwyane Wade       |            102
   27 | Chris Bosh        |            102
   28 | Patrick Mills     |            102
   29 | Derek Fisher      |            103
   30 | Marco Belinelli   |            103
   31 | LeBron James      |            103
   32 | Mario Chalmers    |            103
   33 | Rashard Lewis     |            103
   34 | Michael Beasley   |            104
   35 | Boris Diaw        |            104
   36 | LaMarcus Aldridge |            105
   37 | Thomas Robinson   |            106
   38 | Ray Allen         |            106
   39 | Shane Battier     |            106
   40 | Tony Parker       |            106
   41 | Norris Cole       |            106
   42 | Joel Freeland     |            107
   43 | Nicolas Batum     |            107
   44 | Robin Lopez       |            107
   45 | Wesley Matthews   |            109
   46 | Dorell Wright     |            109
   47 | Damian Lillard    |            110
   48 | Mo Williams       |            110

Rendering Collections in Rails

Posted 8 months back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

Partials are a great way to break down complex view into more manageable chunks as well as keeping view code DRY. However, rendering a partial for each item in a collection looks ugly:

<% @user.comments.each do |comment| %>
  <%= render partial: 'comments/comment', locals: { comment: comment } %>
<% end %>

to_partial_path

Luckily, Rails gives us this beautiful shorthand syntax:

render @user.comments

How does this magic work? Under the hood, render calls to_partial_path on each our objects to determine which partial to render. Models that inherit from ActiveRecord::Base will return a partial name based on the model's name by default. For example:

User.new.to_partial_path
# => 'users/user'

You can override this:

class User < ActiveRecord::Base
  def to_partial_path
    'users/profile'
  end
end

POROs

This works with plain old Ruby objects too. Here's a Null Object Pattern example.

class Guest
  def name
    'Guest'
  end

  def to_partial_path
    'users/user'
  end
end

@dashboard.users_online is a mix of ActiveRecord User objects and non-persisted Guest objects

  <h1>Users online:</h1>
  <%= render @dashboard.users_online %>

The same partial is used for both guests and registered users.

  <%= user.name %>

Heterogeneous collections

It gets even better. The objects in the collection can be of different types, each with their own partial.

@user.favorites can contain any combination of Article, Comment, and Image objects

<h1><%= @user.name %>'s Favorites</h1>
<%= render @user.favorites %>

app/views/articles/_article.html.erb

<h1><%= article.name %></h1>
<p><%= article.content %></p>

app/views/comments/_comment.html.erb

  <div class="comment">
   <em>Last updated: <%= comment.updated_at %></em>
   <p><%= comment.content %></p>
  </div>

app/views/images/_image.html.rb

  <h1><%= image.title %></h1>
  <%= image_tag image.url %>

The beauty of this polymorphic approach is that we don't have to write any conditional code. As long as all the objects in the collection define to_partial_path, it all just works.

What's next?

If you found this useful, you might also enjoy:

Metis Info Session in Boston

Posted 8 months back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

We’ll be hosting a Metis and Ruby on Rails info session at our Boston office on January 9th from 7pm to 8pm. You can RSVP here.

The session will introduce you to Ruby on Rails and show you just how easy it is to quickly prototype websites. You'll also learn more about our upcoming 12 week Bootcamp Ruby on Rails, and how it can get you started in the world of web development.

The session will be led by Josh Steiner and Matt "Goose" Mongeau, the two instructors of the Metis bootcamp. It will be a great chance to meet Goose and Josh and ask them any questions you might have about the Metis program or Ruby on Rails in general. The session is free and food and beverages will be provided.

Currently the growth rate of web development jobs is one of the highest for any job in the United States. What better way to ring in the new year than to start learning web development!

If Metis isn’t right for you, but someone you know may be interested in Metis, we’d love for you to pass this event onto them.

If Metis is right for you, or you’re not sure it is yet, we’ll see you there!

Let it snow with Zepto—again!

Posted 8 months back at mir.aculo.us - Home

Updated with the latest and greatest Zepto.js… Let it snow!

<iframe src="http://zeptojs.com/let-it-snow/" width="100%" height="400"></iframe>

If you’re interested how this works, grab the source. Except for Zepto.js (built with detect & fx support) there’s no external dependencies (not counting the Twitter and analytics).

Happy Holidays!

P.S. Because it was so popular, I’ve started another flash sale of my ebook Retinafy your web sites and app—use coupon “hiresholidays” for 15% off, but only on December 24th and 25th!

Changelog 12/9 - 12/20

Posted 8 months back at entp hoth blog - Home

Happy Friday,

We have been a little quiet lately, mostly because we have been busy. We are in the process of upgrading a lot of our infrastructure: we bought shiny new servers, with lots of RAM, SSDs and myriad of other goodies, and we are installing them in our datacenter, configuring them, and slowly moving our different services to them. All of this takes time, as we are also upgrading our deployment process (we’re moving to Docker, for those interested). So there are a lot of balls in the air and this work will continue way into January. This slows down the development of new features and bug fixes, but it’s all for the best, I promise!

With that being said, we haven’t been idle on Tender proper either.

Elastic Search

We recently spent a few days optimizing our search cluster. There were a couple of low hanging fruits and we got a 100% improvement: not too shabby!

Graph of the performance improvement

Assignments

Some teams are really busy, with dozens of agents buzzing and humming at any time. If that’s your case, distributing workload can be challenging. So today, we are introducing a small change that should bring happiness and joy to those hard workers: in the assignment dropdown, next to the name, you will now see the number of discussions open assigned to this supporter. This way, if Tom is under water, but Marry ahead of schedule, you know who to give the next one too. It is a small improvement, but it should definitely help.

Screenshot of the new dropdown

Spam

We also deployed a couple of improvements to our spam engine that should reduce false positives.

While we are on the subject of spam, I have a couple of public announcements:

  • If you have issues with spam or false positives on your site, please let us know. We have full control over our spam engine and we can usually improve things for you. Sometimes it’s just bad configuration, but sometimes a rule needs to be tweaked, and we can do that too. Many people contact us after months of suffering, when we could have fixed their problem the day it happened.

  • If your spam folder has grown to unspeakable proportions, we can empty it for you. The best way to keep spam in check and customer happy is an empty spam folder. We recommend that you go through it regularly (every day if you can), restoring false positives and deleting the rest. By keeping it empty, you can make sure you never miss anything. You can also get a better idea as to whether the spam engine is doing its job correctly or not, which leads back to point 1. So if your spam folder is not empty, contact us: we’ll empty it for you and you can start fresh and renewed. You know 2014 is coming: let this be your new year resolution! (Well, one resolution at least. Enjoying life a little more should be on top of your list).

Happy Holidays.

Ho Ho Ho

Episode #428 – December 20th, 2013

Posted 8 months back at Ruby5

Today only! Some Rails 4.1 tidbits, dependency injection drama, a Rails engine for the Dashing framework, and some free tapas from Avdi.

Listen to this episode on Ruby5

This episode is sponsored by New Relic
New Relic is _the_ all-in-one web performance analytics product. It lets you manage and monitor web application performance, from the browser down to the line of code. With Real User Monitoring, New Relic users can see browser response times by geographical location of the user, or by browser type.

Rails 4.1 beta
Rails 4.1 beta is out! A nice summary here: http://coherence.io/blog/2013/12/17/whats-new-in-rails-4-1.html

secrets.yml
Rails 4.1 has a secret! It’s a new config file called secrets.yml intended to hold your sensitive bits out of the gits.

Another post about Dependency Injection
Piotr Solnica adds his own thoughts on DI, and uses a short example of how he practices DI in his own code.

Yield or Enumerate
Avdi Grimm is giving it away! He’s posted another of his brief Ruby Tapas episodes on his site for free. Yield or Enumerate will show you how many of Ruby’s iteration methods return an Enumerator object if not given a block and what you can do with it.

dashing-rails
Dash away, dash away, dash away all! Take a peek at dashing-rails, a Rails Engine for Shopify’s Dashing framework. So handsome.

Clearer Conditionals using De Morgan's Laws

Posted 8 months back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

Ever seen a hard-to-parse conditional like this?

def allow_access_to_site?
  ! (signed_out? && untrusted_ip?)
end

Let's use De Morgan's Laws to clean it up and see who actually has access to our site.

De Morgan's Laws

Whoa, who's this De Morgan guy? Augustus De Morgan, in addition to looking like a 19th-century John C. Reilly, formulated two important rules of logical inference. You can check out the formal definition on the Wikipedia page, but here they are in Ruby code:

# One
!(a && b) == !a || !b
# Two
!(a || b) == !a && !b

Well hey, it looks like we can use these on our gnarly conditional above. Let's try it.

Law-abiding Ruby code

Recall that the original conditional was ! (signed_out? && untrusted_ip?). Let's use the second law and puzzle it out.

# Original
! (signed_out? && untrusted_ip?)
# Conversion using second law. I've added parentheses for clarity.
# a = signed_out?
# b = untrusted_ip?
(! signed_out?) || (! untrusted_ip?)

Here I notice that ! signed_out? and ! untrusted_ip? are double negatives: not signed out, not untrusted IP. Now what they're really trying to say is: signed in, trusted IP. Let's simplify further, using better method names.

# Simplify a: (! signed_out?) == signed_in?
(signed_in?) || (! untrusted_ip?)
# Simplify b: !(! untrusted_ip?) == trusted_ip?
(signed_in?) || (trusted_ip?)
# Remove parentheses
signed_in? || trusted_ip?

These methods, signed_in? and trusted_ip?, might exist and they might not. Creating them is part of this refactoring. You might even end up removing the signed_out? and untrusted_ip? methods in favor of these new, positively-named methods.

And that's it. We took a hard-to-parse conditional and made it clearer and easier-to-read using De Morgan's second Law.

Before:

def allow_access_to_site?
  ! (signed_out? && untrusted_ip?)
end

After:

def allow_access_to_site?
  signed_in? || trusted_ip?
end

What's next?

If you found this useful, you might also enjoy:

Clearer Conditionals using De Morgan's Laws

Posted 8 months back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

Ever seen a hard-to-parse conditional like this?

def allow_access_to_site?
  ! (signed_out? && untrusted_ip?)
end

Let's use De Morgan's Laws to clean it up and see who actually has access to our site.

De Morgan's Laws

Whoa, who's this De Morgan guy? Augustus De Morgan, in addition to looking like a 19th-century John C. Reilly, formulated two important rules of logical inference. You can check out the formal definition on the Wikipedia page, but here they are in Ruby code:

# One
!(a && b) == !a || !b
# Two
!(a || b) == !a && !b

Well hey, it looks like we can use these on our gnarly conditional above. Let's try it.

Law-abiding Ruby code

Recall that the original conditional was ! (signed_out? && untrusted_ip?). Let's use the second law and puzzle it out.

# Original
! (signed_out? && untrusted_ip?)
# Conversion using second law. I've added parentheses for clarity.
# a = signed_out?
# b = untrusted_ip?
(! signed_out?) || (! untrusted_ip?)

Here I notice that ! signed_out? and ! untrusted_ip? are double negatives: not signed out, not untrusted IP. Now what they're really trying to say is: signed in, trusted IP. Let's simplify further, using better method names.

# Simplify a: (! signed_out?) == signed_in?
(signed_in?) || (! untrusted_ip?)
# Simplify b: (! untrusted_ip?) == trusted_ip?
(signed_in?) || (trusted_ip?)
# Remove parentheses
signed_in? || trusted_ip?

These methods, signed_in? and trusted_ip?, might exist and they might not. Creating them is part of this refactoring. You might even end up removing the signed_out? and untrusted_ip? methods in favor of these new, positively-named methods.

And that's it. We took a hard-to-parse conditional and made it clearer and easier-to-read using De Morgan's second Law.

Before:

def allow_access_to_site?
  ! (signed_out? && untrusted_ip?)
end

After:

def allow_access_to_site?
  signed_in? || trusted_ip?
end

What's next?

If you found this useful, you might also enjoy:

Episode #427 - December 17th, 2013

Posted 8 months back at Ruby5

rails-assets.org, Rails Database Info, Callbacks Extraction, Shutterbug, A Deeper Look at Ruby’s Enumerable, Prawn 0.13.0

Listen to this episode on Ruby5

This episode is sponsored by Top Ruby Jobs
If you're looking for a top Ruby job or for top Ruby talent, then you should check out Top Ruby Jobs. Top Ruby Jobs is a website dedicated to the best jobs available in the Ruby community.

rails-assets.org
The team at monterail created a gem host that automatically converts packaged bower components into ruby gems.

Rails Database Info
Vlado Cingel sent us a gem over the weekend called Rails database info. This gem adds an html endpoint to your Rails application which will give you a quick display of your database schema and contents for reference.

Callbacks Extraction
Alex Topalov wrote about how to refactor your app away from callbacks to small easy to understand ruby objects. He does this by moving the callbacks out of their domain classes and into a unitary class.

Shutterbug
Shutterbug is a rack service that sends a JavaScript library to the browser, then makes it simple to send HTML fragments back to the server, which can generate images using PhantomJS.

A Deeper Look at Ruby’s Enumerable
This week the ruby love blog gave some love to some helpful enumerable methods that we might tend to forget about. Methods like any?, all?, none? and each_cons.

Prawn 0.13.0
This week the prawn gem got it’s first official release in 2 years. It’s now at version 0.13.0. There’s lots of new features, bug fixes, and breaking changes so be sure to read the change log before attempting to upgrade.

On Happiness

Posted 8 months back at Luca Guidi - Home

The end of the year is the perfect circumstance to look back and spend some time thinking about life, achievements and all the preeminent aspects of life.

As a naive younger man, I have always been disappointed by how many year resolutions have missed in the past. Mostly because they are a failure by design: the wishful self is delighted to dictate the new agenda of change, where all the lazyness, tiredness, and unforeseen accidents will magically disappear to leave room to a bright, joyful and productive future. This will never happen.

What really works is to plan nothing

If you aim to write more, just find the time and do it. Don’t plan, do it. Todo lists were invented to sit and watch us with disapproval, they always generate a sensation of unfulfillment, we are always inadequate and behind the goal. And if we’re still struggling, we probably have chosen the wrong desire. Better admit the failure, turn it down, than blindly follow somebody else’s dream.

Don’t expect anything, be grateful, instead

Be grateful when an achievement is met, be grateful for your life, for your family. Focus on what you already have, not on what you don’t. What is part of your existence right now, is the ground for happiness, the solid foundation to build a blissful future. When something get lost, like an habit, don’t despair, be thankful to have had that thing in your life, if it’s the case, it will came back.

Strive for long term happiness

I admit that daily routine can be overwhelming, sometimes depressing. Shit happens, and it will forever. Life is like that, and for sure, we easily forget moments, but what we keep are memories. Be sure to create them. That’s why I love photography, it’s the perfect incentive to create memories. Be also sure that your memories will be sunny, it’s what really matters when look back in the past and answer to the ultimate question: was my life happy?

Animating Modals in Angular.js

Posted 8 months back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

Modal dialogs are popular in rich client-side applications. When you have them, it's nice to have transitions between them. We could even take it a step further, and have separate transitions for opening/closing the modal, and another transition when we switch between them.

Fancy Directives

This is surprisingly simple to accomplish with Angular, using a handful of directives, and a service to encapsulate what we're currently displaying. We'll start by creating a "modal view" directive, with two options. One will control whether or not we're displaying the modal, and another will control what templateUrl to display.

modalView = ->
  restrict: 'E'

  scope:
    _modalShow: '&modalShow'
    _modalContent: '&modalSrc'

  templateUrl: '/templates/modal_view.html'

app.directive('modalView', modalView)

Our template would look like this:

.modal-backdrop(ng-if="_modalShow()")
.modal-container(ng-if="_modalShow()")
  .modal-window
    .modal-dialog
      .modal-content(ng-include="_modalContent()")

We make use of two directives that Angular provides. ngIf will remove the element from the DOM if its expression evaluates to false. ngInclude replaces its contents with the template at whatever URL its expression evaluates to.

Angular directives are small reusable snippets of HTML with some logic attached to them. Often times they simply exist to compose the built-in directives provided by Angular, which are incredibly powerful. Combined with Angular's bindings, they allow us to manipulate the DOM in large ways simply by changing a variables.

Next, we need a service to encapsulate what we're displaying, and a controller to expose that service to our application.

class Modal
  isOpen: => !!@src

  open: (src) => @src = src

  close: => @src = ''

app.service('Modal', Modal)

class ModalCtrl
  constructor: ($scope, Modal) ->
    $scope.modal = Modal

app.controller('ModalCtrl', ['$scope', 'Modal', ModalCtrl])

Both of these classes are incredibly simple. Our modal service exists to allow us to share one src variable across the application. Now in our layout, we would add the following.

%div(ng-controller="ModalCtrl")
  %modal-view(modal-show="modal.isOpen()" modal-src="modal.src")

Now we can change the modal's content by calling Modal.open('/whatever.html'). If the modal isn't already open, it'll place it on the DOM. If it is open, it'll change the content. Because these happen on different elements, we can apply separate animations depending on which element enters the page.

I'm basically a designer now.

Adding the animations requires the ngAnimate module. Once we've added that to our dependencies, we just need to use a little CSS to make the animations happen. In this example, we're using Sass and Bourbon to eliminate vendor prefixes, and structure things nicely. First, let's fade in the backdrop.

@mixin fade($opacity) {
  opacity: $opacity;

  &.ng-enter, &.ng-leave.ng-leave-active {
    opacity: 0;
  }
}

.modal-backdrop {
  @include fade(0.5);
  @include transition(0.15s linear all);
}

Next, we'll both fade and slide the modal container.

@mixin slide($x, $y) {
  @include transform(translate(0, 0));

  &.ng-enter, &.ng-leave.ng-leave-active {
    @include transform(translate($x, $y));
  }
}

.modal-container {
  @include fade(1);
  @include slide(0, -25%);
  @include transition(0.3s ease-out all);
}

Finally, we'll define a flip animation for changes in the content. This one is a bit more complex than the others.

@mixin flip-hidden {
  @include transform(rotateY(190deg) scale(1));
}

@mixin flip($time) {
  @include backface-visibility(hidden);

  &.ng-enter {
    @include animation($time flipIn);
    @include flip-hidden;
  }

  &.ng-leave {
    @include animation($time flipOut);

    &.ng-leave-active {
      @include flip-hidden;
    }
  }
}

@include keyframes(flipOut) {
  0% {
    @include transform(rotateY(0) scale(1));
    @include animation-timing-function(ease-out);
  }

  80% {
    @include transform(rotateY(170deg) scale(1));
    @include animation-timing-function(ease-out);
  }

  100% {
    @include flip-hidden;
    @include animation-timing-function(ease-in);
  }
}

@include keyframes(flipIn) {
  0% {
    @include flip-hidden;
    @include animation-timing-function(ease-in);
  }

  60% {
    @include transform(rotateY(360deg) scale(0.95));
    @include animation-timing-function(ease-in);
  }

  100% {
    @include transform(rotateY(360deg) scale(1));
    @include animation-timing-function(ease-in);
  }
}

.modal-dialog {
  @include perspective(1000);
  @include transform-style(preserve-3d);
}

.modal-content {
  @include flip(0.6s);
}

We'll skip the styles that actually make the modals into modals. It should be noted that the .modal-content needs to be position: absolute, or they will pop down to the bottom of the screen when the flip occurs (both the old modal and the new modal will be on the DOM at the same time)

And that's all there is to it. The end result is a beautiful transition, and 0 conditionals in our code to determine which one occurs.

modal transitions