Skip to content

Instantly share code, notes, and snippets.

View cavalle's full-sized avatar

Luismi Cavallé cavalle

View GitHub Profile
channels = [
["TV3+ Denmark", "3PD"],
["Viasat Film Action", "TV1A"],
["TV10", "TV10"],
["Viasat Film Classic", "TV1C"],
["Viasat Film Family", "TV1F"],
["Viasat Film Comedy", "TV1N"],
["Viasat Film Premiere", "TV1S"],
["TV3 Norway", "TV3N"],
["TV3 Sweden", "TV3S"],
Actian Vectorwise 2.0 or later (Windows only)
Amazon Redshift
Amazon Elastic MapReduce
Cloudera Hadoop Hive and Impala; Hive CDH3u1, which includes Hive .71, or later; Impala 1.0 or later
DataStax Enterprise Edition 2.2 or later (Windows only)
EXASOL 4.2 or later (Windows only)
Firebird 2.1.4 or later
Google Analytics
Google BigQuery
Google Cloud SQL
@cavalle
cavalle / the-problem-with-code-examples.md
Last active December 12, 2015 03:58
The problem with code examples

The problem with code examples

Anyone who writes or speaks at conferences about software knows that it's not easy to put together the right code examples. On one side, you want to illustrate just one specific idea or technique, so you try to make your example simple and clear to keep your audience focused. On the other side, if the example is too simple, chances are that it'll fail to justify your point.

This is an issue I come across often in researching resources about big ActiveRecord models. Let's take [this recent post][1] in Victor Savkin's blog. In this writing, the author proposes an alternative way to factor your domain logic in Rails. For that it uses an example which, implemented using a classic Rails way approach, it would have looked like this:

class Order < ActiveRecord::Base
  validates :amount, numericality: true
 has_many :items
@cavalle
cavalle / cohesion-and-big-models.md
Last active December 11, 2015 21:09
Cohesion and Big ActiveRecord Models

Cohesion and Big ActiveRecord Models

One of the problems of big ActiveRecord models is their low cohesion. In Rails we group behaviour around the entities of the domain we're modelling. If we use only ActiveRecord models for that, we'll probably end up with classes full of actions, in most cases, completely unrelated to each other (except for the fact that they act on the same domain entity).

To illustrate the issue let's imagine a big Post AR model of a blog application. In this app, users can add tags to their posts. Since this is the only class with this ability, I decide to put the related logic in the Post model itself. For this, presumably at the beginning of the file, I write a couple of has_many entries for tags and taggings. Then, fifty lines below, along with the rest of scopes, I add one more to find posts by tag name. A couple of hundred lines later, I put a virtual attribute tag_list which will be used to update the associations from a string of tag names separated by commas. Fin

@cavalle
cavalle / strike.md
Last active October 12, 2015 18:48
My reasons to support the general strike in Spain

My reasons to support the general strike in Spain

I think the austerity measures imposed by Europe to Spain will eventually work. But the only possible outcome I personally expect is to get back to where we were before the crisis. An illusion of wealth just waiting for the next crisis to happen.

Politicians seem to have decided that this crisis won't change anything. Probably because the first thing that needs to change are the politicians themselves.

After this crisis, Spain will be as inefficient and as brittle as it was before. Spanish economy will keep depending on the state, on the banks and on a few very big companies to survive. We will keep depending on our King closing big deals with Arab Sheiks while hunting elephants in Africa.

The banks and the big companies, knowing that the consequences of their errors will be assumed by the tax-payers, as they cannot afford to let them down, will keep becoming increasingly more inefficient and incompetent.

@cavalle
cavalle / feature.rb
Created November 7, 2011 16:22
Meatloaf (Just another scam)
require 'meatloaf'
require 'steps'
Feature "Eat candies" do
Scenario "Eat a candy from a jar full of them" do
Given "I have a jar with candies", candies: 10
When "I eat one candy"
Then "the jar won't be empty"
end
@cavalle
cavalle / warden.rb
Created August 25, 2010 10:46
Testing Warden/Devise with Steak
# Create a file `spec/acceptance/support/warden.rb' with the following
# contents:
Spec::Runner.configure do |config|
config.include Warden::Test::Helpers, :type => :acceptance
config.after(:each, :type => :acceptance) { Warden.test_reset! }
end
# Or, if you're using RSpec 2 / Rails 3, the contents should be the following
# instead:
# This works with steak 0.3.x and rspec 1.x
# For steak --pre and rspec 2 see this fork: http://gist.github.com/448487
# Put this code in acceptance_helper.rb or better in a new file spec/acceptance/support/javascript.rb
Spec::Runner.configure do |config|
config.before(:each) do
Capybara.current_driver = :selenium if options[:js]
end