partial

Python functools partial efficiency

有些话、适合烂在心里 提交于 2019-11-28 09:04:28
I have been working with Python and I set up the following code situation: import timeit setting = """ import functools def f(a,b,c): pass g = functools.partial(f,c=3) h = functools.partial(f,b=5,c=3) i = functools.partial(f,a=4,b=5,c=3) """ print timeit.timeit('f(4,5,3)', setup = setting, number=100000) print timeit.timeit('g(4,5)', setup = setting, number=100000) print timeit.timeit('h(4)', setup = setting, number=100000) print timeit.timeit('i()', setup = setting, number=100000) I get the following as a result: f: 0.181384086609 g: 0.39066195488 h: 0.425783157349 i: 0.391901016235 Why do

Rails AJAX: My partial needs a FormBuilder instance

£可爱£侵袭症+ 提交于 2019-11-28 07:35:38
So I've got a form in my Rails app which uses a custom FormBuilder to give me some custom field tags <% form_for :staff_member, @staff_member, :builder => MyFormBuilder do |f| %> [...] <%= render :partial => "staff_members/forms/personal_details", :locals => {:f => f, :skill_groups => @skill_groups, :staff_member => @staff_member} %> [...] <% end %> Now, this partial is in an area of the form which gets replaces by an AJAX callback. What I end up doing from the controller in response to the AJAX request is: render :partial => "staff_members/forms/personal_details", :locals => {:skill_groups =>

Avoid precompiling asset partials in Rails (blacklist by Regex)

 ̄綄美尐妖づ 提交于 2019-11-28 06:17:41
问题 I've seen a few questions/answers around avoiding precompiling various assets while using the Rails pipeline; however, I want to effectively blacklist via an array of Regex's for pathname matches to exclude from precompilation. Most often for me, this is often a set of partials that will fail precompilation anyway. 回答1: First off -- keithgaputis has expertly answered a part of this here but it's not quite an answer to the above question. Read and vote up his answer and then see my additions

Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml

我怕爱的太早我们不能终老 提交于 2019-11-28 06:11:27
I am using MVC 3 with the Razor view engine. I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml. For example, when you setup a default ASP.NET MVC 3 project you get a _Layout.cshtml file in the "/Views/Shared" folder. In that _Layout.cshtml the Page Title is set like this: <title>@ViewBag.PageTitle</title> Then in "/Views/Home/About.cshtml" view the contents of the ViewBag are modified: @{ ViewBag.Title = "About Us"; } This works fine. When the About view is rendered the page title is "About Us". So, now I want to render a Partial

Stop ActiveRecord saving a serialized column even if not changed

六月ゝ 毕业季﹏ 提交于 2019-11-28 04:00:20
问题 This is very similar to Rails partial updates problem with hashes , but the question has not really been answered IMHO. The problem is this: I have a model with a serialized column: class Import < AR::Base serialize :data In my case, this data will, and should, not change after the first save/creation of the model. So I want to disable the feature of AR that always saves serialized columns (which is normally a good idea, as it can't detect those changes). I want to disable the saving because

Rails: Should partials be aware of instance variables?

妖精的绣舞 提交于 2019-11-28 03:15:02
Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %> new.html.erb <%= render :partial => 'form' %> _form.html.erb <%= form_for @some_object_defined_in_action %> That hidden state makes me feel uncomfortable, so I usually like to do this edit.html.erb <%= render :partial => 'form', :locals => { :object => @my_object } %> _form.html.erb <%= form_for object %> So which is better: a) having partials access instance variables or b) passing a partial all the variables it needs? I've been opting for b) as of late, but I did run into a little pickle:

how to do partial page rendering (center content) with jsf2 templating via ajax (from menu)

六眼飞鱼酱① 提交于 2019-11-28 02:09:11
问题 i have been struggling getting this to work for 2 weeks, I am trying to merge info from BalusC from these 2 posts to (link1 link2) to achieve partial page rendering of a center content area via a menu on the left. So the links on the left would update the center content via partial page rendering using <f:ajax> or maybe <a4j:ajax> via richfaces ------------------------------------------------------ | include1 link | | | include2 link | center content like include1.xhtml | | include3 link | |

MVC: Dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1

隐身守侯 提交于 2019-11-27 19:00:53
问题 I am getting this error and I'm not sure if I am able to do this, here is my code.. Application controller public ActionResult AppView() { List<Application> apps; using (ISiteDbContext context = _resolver.GetService<ISiteDbContext>()) { apps = context.Applications.ToList(); } return PartialView("AppView", apps.OrderBy(a => a.Name).ToList()); } Render partial - this is within a view which is in the home controller. @{Html.RenderPartial("~/Views/Application/AppView.cshtml", new Example.Services

AngularJs Include Partial Template

寵の児 提交于 2019-11-27 18:41:15
I've this in my main layout file <body> <header id="header" ng-controller="HeaderController"></header> <div class="container" ng-view></div> I've a header.html partial template in my directory structure. How to include this template in my app? I thought angular automatically includes the template after processing the controller, but it doesnt work. The header node should be replaced with the content of this file. Suvi Vignarajah One way of including templates/html fragments from external files is to use the ng-include directive ( doc ). <ng-include src="'/path/to/the/header.html'"></ng-include

Setting attributes of a property in partial classes

佐手、 提交于 2019-11-27 17:16:38
问题 I have an employee class generated by Entity Framework (EF). public partial class employee { private string name; public string Name { get{return name;} set{ name = value;} } } Now I want to put a required attribute in the name property to use in for MVC3 validation in another employee partial class which is written by me in order to extend the one which is generated by EF so that I don't have to rewrite my code if I refresh the model generated by EF. My written partial class is in the same