Beholddy, easily monitor youtube for new videos of specific subjects

On this last weekend, me and a couple friends hacked together a beautiful UI for a tool that I built to scratch my own itch: monitor youtube for new videos on specific subjects. Meet Beholddy:

This cute beholder, with its unique features, will monitor youtube for every new video uploaded and let you know as soon as a new that meets your criterias comes out!

I currently use it to find out:

  • videos of huge channels of a topic that I could take advantage on (by getting into their “similar videos”, for example);
  • discover smaller channels talking about subjects similar to mine and maybe propose a partnership;
  • monitor competitors;
  • new tips about videogames I enjoy 😜

But hey, this is me! Try it and maybe you will find other uses for it and don’t worry cause it has a free plan!

And please, give me some feedback on how you are using it and I will even add a couple more alerts to your free plan 😉

Someone coding

How to delete local git branches after the merge

From time to time we all get annoyed by the git branch autocomplete, which used to be so useful, but now makes us practically write the whole branch name! 😡

Why it keeps happening? Because we are awesome developers who use feature branch flow and now, after working so hard, we have dozens of branches on our local machine.

Yogo, can you tell me an easy way to clear these branches? I don’t wanna delete each one manually! 😩

I sure can, my friend! Here is an alias that I use to delete all my merged branches:

alias clear_merged_branches="git branch --merged | egrep -v '(^\*|master|production)' | xargs git branch -d"

It will only leave the “master” and “production” branches, which you can easily change on that code. Besides the branches that haven’t been merged into master, of course.

Remember to use this alias while you are on the “master” branch 😉

Update

As lpmusix pointed out, you can also use it as a git alias. Add to the alias section of your ~/.gitconfig:

cb = "!git branch --merged | egrep -v '(^\\*|master|production)' | xargs git branch -d"

Ruby already has its own regular expression to validate emails

I’ve searched and written a lot of regular expressions to validate email on our models and forms but recently I’ve found out that Ruby already has a good one and its easy to access and use.

All you have to do require uri library and use its constant:

require 'uri'
'user@gmail.com'.match(URI::MailTo::EMAIL_REGEXP).present?

It’s also easy to use on an Active Record format validation:

validates :email, format: { with: URI::MailTo::EMAIL_REGEXP, message: "only allows valid emails" }

It even accepts emails with “+” as gmail enables.

 

How to solve rails 4 UndefinedTable Error when creating namespaced models

In a given rails 4 application, I have two namespaced models with a has_many association between them:

# models/review/asset_type.rb
module Review
  class AssetType < ActiveRecord::Base
    belongs_to :review_asset_category, class_name: Review::AssetCategory
  end
end

# models/review/asset_category.rb
module Review
  class AssetCategory < ActiveRecord::Base
    has_many :review_asset_types, class_name: Review::AssetType,
             foreign_key: 'review_asset_category_id'
  end
end

With migrations as:

class CreateReviewAssetCategories < ActiveRecord::Migration
  def change
    create_table :review_asset_categories do |t|
      t.string :name
      t.timestamps null: false
    end
  end
end

The migrations ran well but everytime I ran the tests I received the error:

Failure/Error: it { is_expected.to respond_to(:name) }
     ActiveRecord::StatementInvalid:
       PG::UndefinedTable: ERROR:  relation "asset_categories" does not exist
       LINE 5:                WHERE a.attrelid = '"asset_categories"'::regc...
                                                 ^
       :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                            pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                       FROM pg_attribute a LEFT JOIN pg_attrdef d
                         ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                      WHERE a.attrelid = '"asset_categories"'::regclass
                        AND a.attnum > 0 AND NOT a.attisdropped
                      ORDER BY a.attnum

The solution is simple, just add this class method to each model or to the module that is namespacing the models:

module Review
  def self.table_name_prefix
    'review_'
  end
end

I hope this simple advice will save some time for other developers 🙂

Exercism – Practice your dev skills

A week ago I  was trying to find some algorithm exercises and I found exercism.io, a website that helps you practice your developer skills using your terminal, your favorite IDE and TDD 🙂

Captura de Tela 2015-12-28 às 18.12.33

Besides the TDD approach, what I really liked about it is that it encourages you to solve problems iteratively, one test at a time and when all tests are passing, refactor your code for a better solution.

It also lets you discuss each others solutions and I’ve already received some nice advices. Some exercises also made me learn some new methods that I’ve never used before like reducetr and learn that count can receive a block!

I’m practicing Ruby but they have exercises for a lot of other languages like: PHP, Lua, Lisp, F#, Javascript and Elixir.

I suggest you try it and then let me know if you liked it or not and if you did, comment here your profile so we can try to help you improve your coding skills 🙂

ps: you can also see my answers and help me improve mine

When you’re the senior in junior/senior pair programming, the measure of your success is how much the junior learns.

Kent Beck on twitter.

I guess that’s also true on a daily basis on a project where there are some people with way more experience than others 🙂

Useful RSpec matchers that you may not be using

Just sharing a couple RSpec matchers that I think are very useful but people doesn’t seem to know they even exist 🙂

all matcher

When I wanted to make sure that every element of an Enumerable, for example, should be an instance of Course, I would write:

it 'populates @catalog_courses only with courses' do
  assigns(:catalog_courses).each do |course|
    expect(course).to be_a(Course)
  end
end

But with the all matcher, its just:

it 'populates @catalog_courses only with courses' do
  expect(assigns(:catalog_courses)).to all( be_a(Course) )
end

I used the be_a matcher inside the all but you could use any other like: be_truthy or eq.

contain_exactly matcher

When I wanted to make sure that an Array should include a and b elements but in any order I would write something like:

it 'populates @courses with courses a, b and c' do
  courses = assigns(:courses)

  expect(courses).to include(a)
  expect(courses).to include(b)
  expect(courses).to include(c)
end

Now, using the contain_exactly matcher:

it 'populates @courses with courses a and b' do
  expect(assigns(:courses)).to contain_exactly(a, b, c)
end

Hope you learned something new here. Leave in the comments any other awesome matcher that you think other people may not be using 😀