dry

Can I make this CSS simpler to avoid repeating the parent selector?

[亡魂溺海] 提交于 2019-11-29 18:16:43
A common pattern I come across is the following: form.request input { /* ... */ } form.request input[type="text"] { /* ... */ } form.request select { /* ... */ } form.request br { /* ... */ } I have several lines beginning with the same selector ( form.request ), and I want to select various children. Can I do this in a neater way without the repetition (and preferably without additional dependencies like LESS)? Related question - if all the above comments contain the same styles, can I do better than: form.request input, form.request input[type="text"], form.request select, form.request br {

DRY arithmetic expression evaluation in Prolog

坚强是说给别人听的谎言 提交于 2019-11-29 15:46:24
I wanted to write evaluating predicate in Prolog for arithmetics and I found this : eval(A+B,CV):-eval(A,AV),eval(B,BV),CV is AV+BV. eval(A-B,CV):-eval(A,AV),eval(B,BV),CV is AV-BV. eval(A*B,CV):-eval(A,AV),eval(B,BV),CV is AV*BV. eval(Num,Num):-number(Num). Which is great but not very DRY. I've also found this : :- op(100,fy,neg), op(200,yfx,and), op(300,yfx,or). positive(Formula) :- atom(Formula). positive(Formula) :- Formula =.. [_,Left,Right], positive(Left), positive(Right). ?- positive((p or q) and (q or r)). Yes ?- positive(p and (neg q or r)). No Operator is here matched with _ and

How can these XSLT documents be DRY-ed

﹥>﹥吖頭↗ 提交于 2019-11-29 08:53:04
I have made two pages and now I wonder if I can DRY them. Here the XSLT: Frontpage: http://pastebin.com/yuZL913W dagboek-page: http://pastebin.com/6FGYvpvf (Edited) Roelof Sorry one of the links is wrong. I edited this. My question is how to DRY these so I can reuse parts. Only the <div id="posts"> is different. I think I understand the fill in the blanks but it is one big xslt file. Is this possible without named templates and call-templates Here is one way -- what I call " Fill-in-the-blanks " to separate content from processing and to parameterize processing : Rendering file (c:/temp/delete

Render without layout when format is JS (needs drying) [duplicate]

本秂侑毒 提交于 2019-11-29 07:23:49
This question already has an answer here: Never render a layout in response to xhrs 3 answers I have this in my controllers: respond_to do |format| format.html format.js { render :layout => false } end Which outputs without layout when the request is Ajax. I'm replicating this in many actions and controllers. How do I DRY this? I use this in my application controller: class ApplicationController < ActionController::Base layout proc{|c| c.request.xhr? ? false : "application" } end Which covers .js, .json, etc. for me. Well, this answer is a few years late, but you can also create your layout as

How to “DRY up” C# attributes in Models and ViewModels?

别等时光非礼了梦想. 提交于 2019-11-29 06:57:30
问题 This question was inspired by my struggles with ASP.NET MVC, but I think it applies to other situations as well. Let's say I have an ORM-generated Model and two ViewModels (one for a "details" view and one for an "edit" view): Model public class FooModel // ORM generated { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string EmailAddress { get; set; } public int Age { get; set; } public int CategoryId { get; set; } } Display

Using async await when implementing a library with both synchronous and asynchronous API for the same functionality

可紊 提交于 2019-11-28 23:45:16
I've got a few questions about how to provide both synchronous and asynchronous implementation of the same functionality in a library. I am gonna ask them first and then provide the example code below (which is actually quite a bit, but in fact it's quite simple). Is there an approach to avoid violating the DRY principle? Consider the implementations of JsonStreamReader.Read , JsonStreamWriter.Write , JsonStreamWriter.Flush , ProtocolMessenger.Send , ProtocolMessenger.Receive and their asynchronous versions. Is there an approach to avoid violating the DRY principle when unit testing both

Reducing code duplication between operator= and the copy constructor

与世无争的帅哥 提交于 2019-11-28 21:25:21
I have a class that requires a non-default copy constructor and assignment operator (it contains lists of pointers). Is there any general way to reduce the code duplication between the copy constructor and the assignment operator? There's no "general way" for writing custom copy constructors and assignment operators that works in all cases. But there's an idiom called "copy-&-swap": class myclass { ... public: myclass(myclass const&); void swap(myclass & with); myclass& operator=(myclass copy) { this->swap(copy); return *this; } ... }; It's useful in many (but not all) situations. Sometimes

Rails 3 - Restricting formats for action in resource routes

有些话、适合烂在心里 提交于 2019-11-28 17:26:19
问题 I have a resource defined in my routes. resources :categories And I have the following in my Category controller: def show @category = Category.find(params[:id]) respond_to do |format| format.json { render :json => @category } format.xml { render :xml => @category } end end The controller action works fine for json and xml. However I do NOT want the controller to respond to html format requests. How can I only allow json and xml? This should only happen in the show action. What is the best

How much duplicated code do you tolerate? [closed]

人走茶凉 提交于 2019-11-28 16:59:45
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . In a recent code review I spotted a few lines of duplicated logic in a class (less than 15 lines). When I suggested that the author

Best practice for reusing python code [closed]

我的梦境 提交于 2019-11-28 15:58:50
问题 I have write a python library app(which contains several *.py files). And several of my python projects need to reuse the code in the library app. What's the recommended best practice for reusing python code? Currently I have thought out three options: Copy and paste. This is far away from best practice. It violates the DRY principle.(Don't repeat yourself.) Add the folder of the library app to the environment variable PYTHONPATH: export PYTHONPATH=/path/to/library/app . Then every projects