dry

Django - Tips to avoid repeating code in views

I'm moving from a PHP background into Django development via python, mostly for the sake of tackling a MVC (or MVT) that I feel makes the most sense, although in this pattern I've started to notice a lot of repeated code in my views. For example, when logged in I have information regarding the user that I would like to appear on every p...

Sharing a fabfile across multiple projects

Fabric has become my deployment tool of choice both for deploying Django projects and for initially configuring Ubuntu slices. However, my current workflow with Fabric isn't very DRY, as I find myself: copying the fabfile.py from one Django project to another and modifying the fabfile.py as needed for each project (e.g., changing the w...

How do you keep your business rules DRY?

I periodically ponder how to best design an application whose every business rule exists in just a single location. (While I know there is no proverbial “best way” and that designs are situational, people must have a leaning toward one practice or another.) I work for a shop where they prefer to house as much of the business rules as p...

How to overcome an apparent REST vs. DRY dilemma in rails?

A rails app I'm working on features examples of quadratic equations. Obviously, these are all of a common structure: ax^2 + bx + c = 0. I don't want to store every single example of these. I'd rather generate them from a template. Storing hundreds of possible versions of this structure seems highly wasteful and un-DRY. On the other h...

Re-using aggregate level formulas in SQL - any good tactics?

Imagine this case, but with a lot more component buckets and a lot more intermediates and outputs. Many of the intermediates are calculated at the detail level, but a few things are calculated at the aggregate level: DECLARE @Profitability AS TABLE ( Cust INT NOT NULL ,Category VARCHAR(10) NOT NULL ,Income DECIMAL(10, ...

What's the DRY version of the following Makefile targets?

I don't know how to execute a command stored as a variable or how to use ifeq inside of a target, so I have a very redundant Makefile at the moment! Ideally I'd like to have just one target (all) which would run the stored command on Mac and run it twice on Linux, once with -m32 and once with -m64. all: echo PLEASE SELECT OS, e.g. ...

Rails: DRY in views

Hy, I have a layout in the views/layout that has 2 cols and then in every view i have content_for :main_col and content_for :side_col. The problem is that i have more than 5 views with the same content in the content_for :side_col You have a better idea on how to do this?thanks ...

DRYing repeated specs in RSpec

In the test below, the Bar and Baz blocks contain identical specs. Leaving aside why such repetition was necessary in the first place, I'm wondering how one could dry this up. I tried turning the blocks into objects and calling them under Bar and Baz, but possibly because I did not get the scopes right, I have not been able to make it ...

What CSS compiler do you use (SASS, Less, HSS, etc)?

I've been looking to make my web development a little more DRY. SASS+HAML seem to have a degree of popularity within the Ruby/Rails community, but, do those outside of that community generally use these as well? Do they opt for other solutions, or do they stick with plain HTML+CSS, and if so, what is the reason? ...

Pythonic reading from config files

Hi, I have a python class which reads a config file using ConfigParser: Config file: [geography] Xmin=6.6 Xmax=18.6 Ymin=36.6 YMax=47.1 Python code: class Slicer: def __init__(self, config_file_name): config = ConfigParser.ConfigParser() config.read(config_file_name) # Rad the lines from the file ...

DRY Validation with MVC2

Hi All, I'm trying to figure out how I can define validation rules for my domain objects in one single location within my application but have run in to a snag... Some background: My application has several parts: - Database - DAL - Business Logic Layer - SOAP API Layer - MVC website The MVC website accesses the database via the SOAP...

How do I DRY up business logic between sever-side Ruby and client-side Javascript?

I have a Widget model with inheritance (I'm using Single-Table Inheritance, but it's equally valid for Class-per-Table). Some of the subclasses require a particular field; others do not. class Widget < ActiveRecord ALL_WIDGET_TYPES = [FooWidget, BarWidget, BazWidget] end class FooWidget < Widget validates_presence_of :color end cl...

How to make this C++ code more DRY?

I have these two methods on a class that differ only in one method call. Obviously, this is very un-DRY, especially as both use the same formula. int PlayerCharacter::getAttack() { int attack; attack = 1 + this->level; for(int i = 0; i < this->current_equipment; i++) { attack += this->equipment[i].getAttack(); } ...

DRY Ruby Initialization with Hash Argument

I find myself using hash arguments to constructors quite a bit, especially when writing DSLs for configuration or other bits of API that the end user will be exposed to. What I end up doing is something like the following: class Example PROPERTIES = [:name, :age] PROPERTIES.each { |p| attr_reader p } def initialize(args) ...

An exception to avoid copy and paste code?

There are many files in our project that would call a Facebook api. And the call is complicated, spanning usually 8 lines or more, just for the argument values. In this case, we can make it into a function, and place that function in a common_library.php, but doing so would just change the name of the function call from the Facebook AP...

DRY URL's in Django Javascript

I'm using Django on Appengine. I'm using the django reverse() function everywhere, keeping everything as DRY as possible. However, I'm having trouble applying this to my client-side javascript. There is a JS class that loads some data depending on a passed-in ID. Is there a standard way to not-hardcode the URL that this data should come...

I would like to access certain-resolution files within a multiresolution .ico from javascript (or html, for that matter)

I have created a nice multiresolution favicon.ico containing 16x16, 32x32, & 48x48 resolution icons. These load up all pretty-like within browsers or when the site is saved to the desktop. However, the same image is also being used on the website (specifically, as an icon within a toolbar). Currently, the 16x16 icon is also saved as a p...

Django DRY Feeds

I'm using the Django Feeds Framework and it's really nice, very intuitive and easy to use. But, I think there is a problem when creating links to feeds in HTML. For example: <link rel="alternate" type="application/rss+xml" title="{{ feed_title }}" href="{{ url_of_feed }}" /> Link's HREF attribute can be easily found out, just use rev...

PHP: MVC and DRY

Hello! Question about controllers. Can controller call it`s own class methods inside an action? EDIT: Oh sorry. I meant I dont want to repeat myself. :) ...

How can I implement CRUD operations in a base class for an entity framework app?

I'm working a simple EF/MVC app and I'm trying to implement some Repositories to handle my entities. I've set up a BaseObject Class and a IBaseRepository Interface to handle the most basic operations so I don't have to repeat myself each time: public abstract class BaseObject<T> { public XA.Model.Entities.XAEntities db; ...