dry

WPF command - called from Window and UserControl, same handlers

How can I have a Command that can be called from both a Window and a UserControl (by hitting a button in either) that uses the same execute and can-execute methods? It seems like if I have the following in my UserControl's XAML, it requires myCommandHandler and canExecuteMyCommand to be in my UserControl class: <CommandBinding Command=...

Replacement for column_names when using Mongoid with rails 3 and dry_crud

I've been doing a spike on Rails 3 and Mongoid and with the pleasant memories of the auto scaffolding in Grails I started to look for a DRY view for ruby when I found: http://github.com/codez/dry_crud I created a simple class class Capture include Mongoid::Document field :species, :type => String field :captured_by, :type => Str...

ASP.NET MVC Ajax/Partial views and DRY

Is there a good convention-based way to avoid repetitive code like the following in my controller action methods?: if (Request.IsAjaxRequest()) { return PartialView("EmployeeList", _service.GetEmployees()); } return RedirectToAction("Index"); ...

Building sharable ASP.NET MVC UI Components

We have two websites that share some business processes and UI elements. Lets focus on a contrived example: we have an apartment rental site and a boat exchange. For instance, on our apartment rental website, we may want to let users bid to buy boats. On our boat website, we may want to let users search for apartments. An obvious s...

How to customize to_json response in Rails 3

I am using respond_with and everything is hooked up right to get data correctly. I want to customize the returned json, xml and foobar formats in a DRY way, but I cannot figure out how to do so using the limited :only and :include. These are great when the data is simple, but with complex finds, they fall short of what I want. Lets say...

"Magic constructor" in Ruby for all attributes

Is there a way to set a default initialize method without writing it down? class DataClass attr_accessor :title, :description, :childs def hasChilds? @childs.nil? end end I Want to initialize this class with standard initial attributes. Something like this: $> a = DataClass.new(:title => "adsf", :description => "test") $> a...

ASP.NET - sharing Columns between GridViews

Is there a way to define a <Columns> outside of a GridView in my .aspx file such that I can use those <Columns> in multiple GridViews in the same page? I have two GridViews that will have the same DataSource type, just with different content, and I'd rather not repeat all my customized TemplateFields in each. This seems simple enough, ...

How to DRY up a ruby conditional structure needed for Rails

I'm finding I often have to use a structure to avoid a Rails error of undefined method 'name' for nil:NilClass. The structure looks like this: if country.state country.state.name end It seems like a classic case of repeating oneself with country.state appearing twice in one simple block. Is there any way to DRY this up? ...

same code in different actions of the controller in rails -- how to make DRY?

I have a controller with two different actions, but both need this same code, which is a little long, how can I allow them access to this same behavior but keep it DRY? @list = Contact.find :all, :select => "companies.name AS co_name, companies.id AS comp_id, COUNT(contact_emails.id) AS ema...

How to DRY in Ruby?

How could I make this shorter and extendable: def overview puts "All As:" for f in @a puts f end puts "\n" puts "All Bs:" for f in @b puts f end end ...

DRY-er Javascript Classes

Hi, Using jQuery, this is the format of most of the classes I write in JS: $.Tabs = function(options){ var self = this; this.defaults = {}; var cfg = $.extend(true, {}, this.defaults, options); this.$elem = cfg.$elem; function _init(){ var dontInit = false; if (!cfg.$elem || !cfg.requiredProperty){ alert('missing para...

C#: inheriting constructors

I know it's not possible to inherit constructors in C#, but there's probably a way to do what I want to do. I have a base class that is inherited by many other classes, and it has an Init method that does some initializing taking 1 parameter. All other inheriting classes also need this initializing, but I'd need to create separate const...

Storing/Calling Repeating Code blocks in MVC

Hey all, Sorry its me again. This time I have a question that I think is fairly general. I am using code that is almost exactly the same over and over again within a controller to set up a viewModel. My question was, is there a way to store this code somewhere within the MVC project, possibly have it return a viewModel, and call it...

Variable value assignment operation duplication

Context From The Pragmatic Programmer: Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. Questions How is that statement reconciled with directly setting a private member variable's value throughout a class in multiple places? Does it matter as there can be no external de...

Keeping DRY between Javascript and CSS.

Say you've got a menu that toggles open and closed with a button. My standard way of going about this would be to write the CSS for a closed menu, and write Javascript that specifies (or animates to) an open menu state. Lately I've gotten into Active.js, a client-side MVC framework. It provides for view classes with builders for making ...

Keep Silverlight DRY with UserControls

I have a DataGrid that is displaying some data at multiple points in my SL 4 app. I would like reduce redundancy. Is the correct way to do this by extracting it into a UserControl? I did this. However, instead of setting dataGrid.ItemsSource in the code behind, I'm setting myDataGridControl.ItemsSource. However, MyDataGridControl doesn'...

Rails Builder::XmlMarkup for Web Service - Repetitive Section

I am using Builder to construct XML messages being sent to a WebService. Each of the different methods require different xml but they all have a set of common elements to start of the request (mostly account authentication stuff). Is there any way to do it in a DRY way? Here is my code for constructing a change pass phrase request: #...

A tension between DRY and performance?

I have a number of pages in my app that are showing partial FOUCs (flashes of unstyled content) upon loading, which occurs because some of them have stylesheets and/or javascript defined at the head of the document rather than in the layout. The fundamental issue is that the DOM is firing before these stylesheets are loaded. In order to...

DRY up LINQ to SQL code (in specific the orderby)

Lets say I have a table called Projects in my SQL server. My dbml file has the Project object, and I use a list of Projects in multiple views of my MVC application. The thing is: Ordering. By default then you use linq the Projects are ordered by ID. lets say I want them ordered by Name and then by Code. _db.Projects.Ordery(q=>q.Name)...

Please help me make this Rails code more dry. I must be missing something very obvious

This rails validation code is so ugly, and there must be a better way to do it. The short story is my user is inputting data from test results. Each specific test has 4 measurements. Usually the user inputs all 5 tests (20 measurements), but it's not always required. I just need to check that if a tester started inputting data for a ...