dry

MVC 3 and DRY custom validation

≯℡__Kan透↙ 提交于 2019-12-02 02:27:52
问题 Unless I'm missing something (which is very possible), it seems to me that custom validation has always violated DRY. In all the examples I've seen, even with the brand new Unobtrusive Client Validation introduced w/ MVC 3, we have to create .NET code for our server-side validation, and jQuery (or JavaScript code) for client-side validation. I understand that there's no such thing as a .NET-to-jQuery translator that would facilitate DRY server/client validation, and I guess that would be the

MVC 3 and DRY custom validation

一个人想着一个人 提交于 2019-12-02 00:17:48
Unless I'm missing something (which is very possible), it seems to me that custom validation has always violated DRY. In all the examples I've seen, even with the brand new Unobtrusive Client Validation introduced w/ MVC 3, we have to create .NET code for our server-side validation, and jQuery (or JavaScript code) for client-side validation. I understand that there's no such thing as a .NET-to-jQuery translator that would facilitate DRY server/client validation, and I guess that would be the only way to have true DRY validation that works both server and client side. But I would be perfectly

Implementing dry-run in ruby script

回眸只為那壹抹淺笑 提交于 2019-12-01 22:57:35
anybody know how to implement dry-run option in Ruby? I need something like this, but only for ruby https://serverfault.com/questions/147628/implementing-dry-run-in-bash-scripts I've tried this, but part after else doesn't work: DRY_RUN = true def perform(*args) command = args if DRY_RUN command.each{|x| puts x} else command.each {|x| x} end end perform("puts 'Hello'") Thanks for any idea in advance. P.S I don't want use something like system ("ruby -e \"puts 'Hello'\"") This could help: def perform(*commands) commands.each { |x| DRY_RUN ? puts(x) : eval(x)} end It results in: DRY_RUN = true

Access Level to certain class must be public error in PHP

你离开我真会死。 提交于 2019-12-01 16:32:47
I created this class <?php abstract class Validator{ public $_errors = array(); abstract public function isValid($input); public function _addErrors($message){ $this->_errors = $message; } public function getErrors(){ return $this->_errors; } public function getMessage(){ return $this->message; } } class Validator_NoSpaces extends Validator{ public function __construct($value){ $this->isValid($value); } public function isValid($value){ if (preg_match('/\s/', $value)){ $this->_addErrors("Spaces are not allowed"); return false; } return true; } } class Validator_MinimumLength extends Validator{

Access Level to certain class must be public error in PHP

﹥>﹥吖頭↗ 提交于 2019-12-01 15:41:54
问题 I created this class <?php abstract class Validator{ public $_errors = array(); abstract public function isValid($input); public function _addErrors($message){ $this->_errors = $message; } public function getErrors(){ return $this->_errors; } public function getMessage(){ return $this->message; } } class Validator_NoSpaces extends Validator{ public function __construct($value){ $this->isValid($value); } public function isValid($value){ if (preg_match('/\s/', $value)){ $this->_addErrors(

DRYing up a helper: wrap form_for and access local form variable

北城余情 提交于 2019-12-01 13:04:45
问题 I am trying to DRY up a bunch of forms code that has a repeating set of fields appearing at the end of each form. I wrote a helper that wraps around the form_for rails helper. But I'm starting to get lost in all the different scopes that are flying around... My helper goes something like this: def simple_form_helper(record_or_name_or_array, *args, &proc) options = ... # overriding some options, not relevant form_for(record_or_name_or_array, *(args << options.merge(:option => "blah")) , &proc)

d3 v4: merge enter and update selections to remove duplicate code

橙三吉。 提交于 2019-12-01 12:14:05
I understand that merge can be used to combine enter and update selections in d3 v4, as in the simple example here: https://bl.ocks.org/mbostock/3808218 . I have a scatter plot in which multiple variables are displayed on a shared x-axis, for different groups selected by a dropdown box. When a new group is selected, the overall set of datapoints is updated, with points for each variable added like this: .each(function(d, i) { var min = d3.min(d.values, function(d) { return d.value; } ); var max = d3.max(d.values, function(d) { return d.value; } ); // Join new data with old elements var points

If WCF is in a MVC application, should it use the controller to access the database to keep 'DRY'

↘锁芯ラ 提交于 2019-12-01 11:32:19
I have an MVC application that accesses SQL and Windows Azure. The logical flow looks like this: Person <--> View <--> Controller.ConvertPersonHere(x) <--> StorageContext.DoDataAction <--> AzurePersonTableEntity ConvertPersonHere is the answer to this Stack Overflow question and it converts the Model entity to the Storage entity public class Person { public string Name {get;set;} public int ID {get;set;} } public class PersonEntity : TableServiceEntity { public string Name {get;set;} public int ID {get;set;} // Code to set PartitionKey // Code to set RowKey } Now that I'm adding WCF to the mix

Generic http error handling in Angular

坚强是说给别人听的谎言 提交于 2019-12-01 09:58:26
问题 angular2-jwt provides an AuthHttp wrapper for the native Angular http class that automatically includes the http authorization header with each request. In my services I am usually calling a backend api like this getThings(): Observable<Thing[]> { return this.http.get(environment.apiEndpoint + '/things') .map(res => res.json().data) .catch(res => this.handleError(res)); } with an error handler like private handleError(error: Response | any) { let errMsg: string; if (error instanceof Response)

d3 v4: merge enter and update selections to remove duplicate code

我的梦境 提交于 2019-12-01 09:55:27
问题 I understand that merge can be used to combine enter and update selections in d3 v4, as in the simple example here: https://bl.ocks.org/mbostock/3808218. I have a scatter plot in which multiple variables are displayed on a shared x-axis, for different groups selected by a dropdown box. When a new group is selected, the overall set of datapoints is updated, with points for each variable added like this: .each(function(d, i) { var min = d3.min(d.values, function(d) { return d.value; } ); var