Where to define custom error types in Ruby and/or Rails?

For Gems I have seen many times that you define exceptions in this way: gem_dir/lib/gem_name/exceptions.rb and defined as: module GemName class AuthenticationError < StandardError; end class InvalidUsername < AuthenticationError; end end an example of this would be something like this in httparty For Ruby on Rails Put them in your lib/ folder under a file … Read more

Python __str__ versus __unicode__

__str__() is the old method — it returns bytes. __unicode__() is the new, preferred method — it returns characters. The names are a bit confusing, but in 2.x we’re stuck with them for compatibility reasons. Generally, you should put all your string formatting in __unicode__(), and create a stub __str__() method: def __str__(self): return unicode(self).encode(‘utf-8’) … Read more

Is there a standardized method to swap two variables in Python?

Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side. Python docs: Evaluation order That means the following for the expression a,b = b,a : The right-hand side b,a is evaluated, that is to say, a tuple of two elements is created in … Read more

Should I use past or present tense in git commit messages? [closed]

The preference for present-tense, imperative-style commit messages comes from Git itself. From Documentation/SubmittingPatches in the Git repo: Describe your changes in imperative mood, e.g. “make xyzzy do frotz” instead of “[This patch] makes xyzzy do frotz” or “[I] changed xyzzy to do frotz”, as if you are giving orders to the codebase to change its … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)