dry

Rails 3 DRY Conditional Layout for iframes

自古美人都是妖i 提交于 2019-12-23 05:20:57
问题 I was recently tasked with loading a portion of my Rails application within an iframe on another website. The relevant pages should be using a different layout file, but only if they're being rendered inside of the iframe. There was a solution proposed here Detect iframe request in a rails app that involved passing a query string parameter. For example the requesting website could call my application through an iframe with the src of http://foo.com/bar?iframe=true . Then in our controller we

Rails I18n: Better way of interpolating links?

戏子无情 提交于 2019-12-22 05:52:28
问题 Is there a cleaner, content_tag-ish way of doing this? (I don't want HTML in my YML) en.yml: expert_security_advice: "Go <a href='{{url}}'>here</a> for expert security advice." layout.html.erb: <%= t(:expert_security_advice, :url => "http://www.getsafeonline.org") %> 回答1: The best I could come up with: en.yml: expert_security_advice: "Go *[here] for expert security advice." layout.html.erb: <%= translate_with_link(:expert_security_advice, "http://www.getsafeonline.org") %> application_helper

Using Marshmallow without repeating myself

筅森魡賤 提交于 2019-12-22 03:31:31
问题 According to the official Marshmallow docs, it's recommended to declare a Schema and then have a separate class that receives loaded data, like this: class UserSchema(Schema): name = fields.Str() email = fields.Email() created_at = fields.DateTime() @post_load def make_user(self, data): return User(**data) However, my User class would look something like this: class User: def __init__(name, email, created_at): self.name = name self.email = email self.created_at = created_at This seems like

Using Marshmallow without repeating myself

不羁的心 提交于 2019-12-22 03:31:09
问题 According to the official Marshmallow docs, it's recommended to declare a Schema and then have a separate class that receives loaded data, like this: class UserSchema(Schema): name = fields.Str() email = fields.Email() created_at = fields.DateTime() @post_load def make_user(self, data): return User(**data) However, my User class would look something like this: class User: def __init__(name, email, created_at): self.name = name self.email = email self.created_at = created_at This seems like

What duplication detection threshold do you use? [closed]

可紊 提交于 2019-12-21 20:52: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 . We all agree that duplication is evil and should be avoid (Don't Repeat Yourself principle). To ensure that, static analysis code

AngularJS DRY controller structure

我的梦境 提交于 2019-12-21 20:18:51
问题 The code below represents a situation where the same code pattern repeats in every controller which handles data from the server. After a long research and irc talk at #angularjs I still cannot figure how to abstract that code, inline comments explain the situations: myApp.controller("TodoCtrl", function($scope, Restangular, CalendarService, $filter){ var all_todos = []; $scope.todos = []; Restangular.all("vtodo/").getList().then(function(data){ all_todos = data; $scope.todos = $filter(

Circular dependencies versus DRY

谁说我不能喝 提交于 2019-12-21 12:42:11
问题 I'm designing a re-usable class library that contains 2 assemblies (amongst others) named core.xml.dll and core.string.dll. The xml assembly references the string assembly in order to use some string helper methods. However now there is an string method that would be benefit from using a method contained in the xml assembly. If I reference the xml assembly from the string assembly I will have created a circular dependency and will be unable to build both assemblies from source code. (ie

DRY user-input validation (clientside, serverside) using JSON-schema

无人久伴 提交于 2019-12-20 10:58:27
问题 As part of a extensive test-case, I'm building an ajax-based CMS-like application which provides CRUD-functionality on various documenttypes, e.g: articles, tags, etc. on the server and client-side I'm considering to use JSON-schema ( http://json-schema.org/ ) as a way to do user input validation in a DRY way (i.e: 1 validation-schema, to be used both on the server and client-side, no duplicate-code and all that) . This seems great, because: JSON-schema is both implemented in JS and Java, so

How to extend or override BeginForm to include a AntiForgeryToken field

天大地大妈咪最大 提交于 2019-12-20 10:37:00
问题 I was reading this article (http://weblogs.asp.net/dixin/archive/2010/05/22/anti-forgery-request-recipes-for-asp-net-mvc-and-ajax.aspx) about how to prevent CSRF attacks. It seems like the solution is to create a tag inside each form. <%: this.Html.AntiForgeryToken(Constants.AntiForgeryTokenSalt)%> However, I really don't want to copy and paste that code inside of each form. I would like to extend or override the BeginForm to create a BeginSecureForm that automatically adds the

sed command in dry run

感情迁移 提交于 2019-12-20 09:56:10
问题 I am not able to find out if and how it is possible to make a dry run with sed. So i have this command: find ./ -type f | xargs sed -i 's/string1/string2/g' But before I really substitute in all the files, i want to check what it WOULD substitute. Copying the whole directory structure to check is no option! Thanks for any feedback (negative or positive :) ) 回答1: Remove the -i and pipe it to less to paginate though the results. Alternatively, you can redirect the whole thing to one large file