How to elegantly symbolize_keys for a ‘nested’ hash

There are a few ways to do this There’s a deep_symbolize_keys method in Rails hash.deep_symbolize_keys! As mentioned by @chrisgeeq, there is a deep_transform_keys method that’s available from Rails 4. hash.deep_transform_keys(&:to_sym) There is also a bang ! version to replace the existing object. There is another method called with_indifferent_access. This allows you to access a hash … Read more

Can I inherit constructors?

You don’t need to create loads of constructors, all with the same code; you create only one, but have the derived classes call the base constructor: public class Base { public Base(Parameter p) { Init(p) } void Init(Parameter p) { // common initialisation code } } public class Derived : Base { public Derived(Parameter p) … Read more

Java error: Implicit super constructor is undefined for default constructor

You get this error because a class which has no constructor has a default constructor, which is argument-less and is equivalent to the following code: public ACSubClass() { super(); } However since your BaseClass declares a constructor (and therefore doesn’t have the default, no-arg constructor that the compiler would otherwise provide) this is illegal – … Read more

How to repeat a “block” in a django template

Use the Django template macros plugin: https://gist.github.com/1715202 (django >= 1.4) or http://www.djangosnippets.org/snippets/363/ (django < 1.4) django >= 1.4 # base.html {% kwacro title %} {% block title %}My Cool Website{% endblock %} {% endkwacro %} <html> <head> <title>{% usekwacro title %}</title> </head> <body> <h1>{% usekwacro title %}</h1> </body> </html> and # blog.html {% extends ‘base.html’ … Read more

Is duplicated code more tolerable in unit tests?

Readability is more important for tests. If a test fails, you want the problem to be obvious. The developer shouldn’t have to wade through a lot of heavily factored test code to determine exactly what failed. You don’t want your test code to become so complex that you need to write unit-test-tests. However, eliminating duplication … Read more

What’s the recommended way to extend AngularJS controllers?

Perhaps you don’t extend a controller but it is possible to extend a controller or make a single controller a mixin of multiple controllers. module.controller(‘CtrlImplAdvanced’, [‘$scope’, ‘$controller’, function ($scope, $controller) { // Initialize the super class and extend it. angular.extend(this, $controller(‘CtrlImpl’, {$scope: $scope})); … Additional extensions to create a mixin. }]); When the parent controller … Read more

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