In which folder should I put “global” shared partial templates? [duplicate]

The standard is placing all shared partials in app/views/shared, and referencing them as render :partial => ‘shared/partial_name’ If you have a standard “row in a list” partial (say, for an index page), you could use a shared partial like: # To render a single object row: render :partial => ‘shared/item’, :locals => { :item => …

Read more

How to reuse beforeEach/afterEach in Jasmine JS?

I think this is partially examined in this blog post and also answered here but i’m adding an adapted answer for your example: Reusable code: function sharedSetup(startPage) { beforeEach(function() { login_as_admin(); browser().navigateTo(startPage); }); afterEach(function() { logout(); }); }; How to use it: describe(‘Services Page’, function() { sharedSetup(‘/services’); it(‘Some test for services page’, function() {}); }); …

Read more

How to reduce code duplication when dealing with recursive sum types

Congratulations, you just rediscovered anamorphisms! Here’s your code, rephrased so that it works with the recursion-schemes package. Alas, it’s not shorter, since we need some boilerplate to make the machinery work. (There might be some automagic way to avoid the boilerplate, e.g. using generics. I simply do not know.) Below, your recurseAfter is replaced with …

Read more

How to specify version in only one place when using pyproject.toml?

After you have installed your project – either in editable mode by poetry install or from the wheel – you can access several metadata via importlib.metadata (importlib_metadata for python < 3.8). So keep the version only in the pyproject.toml and use this in your python code: import importlib.metadata __version__ = importlib.metadata.version(“mypackage”)

DRY Ruby Initialization with Hash Argument

You don’t need the constant, but I don’t think you can eliminate symbol-to-string: class Example attr_reader :name, :age def initialize args args.each do |k,v| instance_variable_set(“@#{k}”, v) unless v.nil? end end end #=> nil e1 = Example.new :name => ‘foo’, :age => 33 #=> #<Example:0x3f9a1c @name=”foo”, @age=33> e2 = Example.new :name => ‘bar’ #=> #<Example:0x3eb15c @name=”bar”> …

Read more