partial

Why doesn't functools.partial return a real function (and how to create one that does)?

*爱你&永不变心* 提交于 2019-12-23 07:28:39
问题 So I was playing around with currying functions in Python and one of the things that I noticed was that functools.partial returns a partial object rather than an actual function. One of the things that annoyed me about this was that if I did something along the lines of: five = partial(len, 'hello') five('something') then we get TypeError: len() takes exactly 1 argument (2 given) but what I want to happen is TypeError: five() takes no arguments (1 given) Is there a clean way to make it work

JAXB partial-unmarshalling Elements without @XMLRootElement

烈酒焚心 提交于 2019-12-23 07:24:15
问题 I am using the partial-unmarshalling example of JAXB , but I am unable to unmarshal XML-Elements which are not on the root-level (cause they don't have an @XmlRootElement tag). In my example I tried to read the shipTo-Element instead of the purchaseOrder-Element. Normally I would work with JAXBElement unmarshal(Source source,Class declaredType) but since the example is using an UnmarshallerHandler and a XMLFilterImpl I don't know where to tell Jaxb which Class it should use. My error message

ElasticSearch: Partial/Exact Scoring with edge_ngram & fuzziness

情到浓时终转凉″ 提交于 2019-12-22 17:11:51
问题 In ElasticSearch I am trying to get correct scoring using edge_ngram with fuzziness. I would like exact matches to have the highest score and sub matches have lesser scores. Below is my setup and scoring results. settings: { number_of_shards: 1, analysis: { filter: { ngram_filter: { type: 'edge_ngram', min_gram: 2, max_gram: 20 } }, analyzer: { ngram_analyzer: { type: 'custom', tokenizer: 'standard', filter: [ 'lowercase', 'ngram_filter' ] } } } }, mappings: [{ name: 'voter', _all: { 'type':

Check array for partial match (PHP) [duplicate]

邮差的信 提交于 2019-12-22 09:10:18
问题 This question already has answers here : Search for partial value match in an Array (3 answers) Closed 4 years ago . I have an array of filenames which I need to check against a code, for example array("120_120_435645.jpg","150_150_312312.jpg","250_250_1232327.jpg"); the string is "312312" so it would match "150_150_312312.jpg" as it contains that string. If there are no matches at all within the search then flag the code as missing. I tried in_array but this seems to any return true if it is

Partial application and closures

自古美人都是妖i 提交于 2019-12-22 04:12:57
问题 I was asked what's the relationship between partial function application and closures. I would say there isn't any, unless I'm missing the point. Let's say I'm writing in python and I have a very simple function MySum defined as follows: MySum = lambda x, y : x + y; Now I'm fixing one parameter to obtain a function with smaller arity which returns the same value that MySum would return if I called it with the same parameters (partial application): MyPartialSum = lambda x : MySum(x, 0); I

Local variable always nil when trying to render partial

与世无争的帅哥 提交于 2019-12-22 04:03:22
问题 I'm getting a really strange issue with a partial when trying to render a collection, I've even tried different approaches. Here is my partial code (for debugging): <pre><%= item.inspect -%></pre> And here are my attempts to use it: <%= render 'item', :collection => @foo.items %> <%= render 'item', :collection => @foo.items, :as => :item %> <% @foo.items.each do |item| %> <%= render 'item', :locals => {:item => item} %> <%= render 'item', :object => item %> <% end %> In each of those

Complex Xpage takes long for partial refreshs

早过忘川 提交于 2019-12-21 20:35:23
问题 I have a complex xpage with lots of nested custom controls. Everytime I execute a partial refresh it takes over 4 seconds to finish. If I remove the complexity it works just fine and is fast as wished. I put a test on this complex Xpage and even with partial execution mode this simple test takes over 4 seconds to finish. <xp:button value="Label" id="button1"> <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="refreshPanel" disableValidators="true" execMode=

Rendering Partial View in code MVC Razor

不打扰是莪最后的温柔 提交于 2019-12-21 06:57:27
问题 I'm using MVC 3 Razor to make a simple CMS for practice purposes, and the idea is that I'm creating a few partial views. I'm wanting to do a database lookup, and see that 3 partial views need rendering to the page. How would I do this? In WebForms, you call the LoadControl(ControlURL), but I don't see an equivalent here. Would it be a client side thing? Edit - I was more thinking of taking a View name from the model, and then rendering that view rather than knowing the name of the view in

Rails 3 - notice and error flash cannot be rendered in a partial

半城伤御伤魂 提交于 2019-12-21 05:02:11
问题 I was trying to clean up application.html.erb , by moving parts of the layout into partials. I had the following code for handling flash errors/notifications: <div id="flash"> <% if flash[:notice] %> <h3 class="info_box"><%= flash[:notice] %></h3> <% end %> <% if flash[:error] %> <h3 class="error_box"><%= flash[:error] %></h3> <% end %> </div> This code worked fine in application.html.erb , until I moved it into a file called " _flash.html.erb " and replaced it with the following: <%= render

Convert a partial to method/block for speed

送分小仙女□ 提交于 2019-12-20 14:43:56
问题 I have a loop that renders a partial 1000.times do |i| render partial: 'test', locals: {i: i} end this is really slow, up to 0.1 ms for foreach render call, even if the partial only prints out i my_partial = render_to_method(partial: 'test') 1000.times do |i| my_partial(locals: {i: i}) end Now this should be doing the same thing way faster right? But I don't know how to do this. update: I've tried the to do it this way: Haml::Engine.new(File.read(File.expand_path File.dirname(FILE)+"/../table