inject

Using `inject`, `unless`, and `next` to determine the minimum value

柔情痞子 提交于 2019-12-24 21:48:07
问题 I have this code: def test(vertices, distances) until vertices.empty? nearest_vertex = vertices.inject do |a, b| p "a = #{a}: b = #{b}" p "distances[a] = #{distances[a]}, distances[b] = #{distances[b]}" next b unless distances[a] #next b if distances[a] == true next a unless distances[b] #next a if distances[b] == true next a if distances[a] < distances[b] p "b = #{b}" b end p "nearest_vertex = #{nearest_vertex}" vertices.delete nearest_vertex end end vertices = [1, 2, 3, 4, 5, 6] distances =

Call to iterating object from iterator

≡放荡痞女 提交于 2019-12-24 10:04:44
问题 How can I call for iterating object from iterating block? # "self" is an Object, and not an iterating object I need. MyClass.some.method.chain.inject{|mean, i| (mean+=i)/self.size} I mean I need to do this: @my_object = MyClass.some.method.chain @my_object.inject{|mean, i| (mean+=i)/@my_object.size} 回答1: This answer is a copy of James Kyburz's answer to a similar question There is no this in ruby the nearest thing is self. Here are some examples to help you on your way #example 1 not self

Where are scripts in injectScripts injected in TestCafé tests?

假装没事ソ 提交于 2019-12-24 03:56:05
问题 I am setting up TestCafé tests programmatically and I use the injectScripts config on the Runner class to inject functions. According to the documentation, these scripts are added to the header of the tested page. Is it possible to invoke the functions from the test itself? I haven't found a way to do it. I can see that the scripts map is accessible inside the test and I can log out the content by doing console.log(t.testRun.opts.clientScripts) But it would be utterly ugly to parse this map

Butterknife 8.4.0 - Plugin with id 'android-apt' not found

萝らか妹 提交于 2019-12-23 08:57:22
问题 I keep getting the error Plugin with id 'android-apt' not found . What's going wrong here? plugins { id "me.tatarka.retrolambda" version "3.2.5" } apply plugin: 'com.android.application' apply plugin: 'android-apt' android { compileSdkVersion 24 buildToolsVersion '23.0.3' dexOptions { javaMaxHeapSize "6g" } defaultConfig { applicationId "com.yitter.android" minSdkVersion 15 targetSdkVersion 24 multiDexEnabled true // Enabling multidex support. renderscriptTargetApi 23

Java injection inside @Asynchronous bean

徘徊边缘 提交于 2019-12-22 18:34:24
问题 I have 2 beans that use Injection to "pass" UserData info that is extracted from HttpRequest . If I remove @Asynchronous from WorkerBean then its all working and WorkerBean can access UserInfo thats injected down. However if I use @Asynchronous on WorkerBean then injection stops working. What is the best way to manually create/pass UserInfo into WorkerBean if it has to be asynchronous? // resource class @Stateless class MainRs { @Context protected HttpServletRequest request; @Inject protected

@Dependent @javax.ejb.Singleton versus @ApplicationScoped @javax.ejb.Singleton?

拥有回忆 提交于 2019-12-22 13:55:29
问题 In essence, what is the difference between these two classes: @ApplicationScoped @Singleton class A {} @Dependent @Singleton class B {} Contextual EJB instances I prefer not to use @Inject when looking for EJB:s, unless the EJB is a @Stateful and I want the CDI container to manage the stateful's life-cycle which could be very convenient. Otherwise, using @Inject to retrieve a contextual EJB instance is a bit dangerous. For example, a @Remote client-view cannot be retrieved using CDI unless we

How to test implementations of Guice AbstractModule?

随声附和 提交于 2019-12-22 03:55:29
问题 How to test implementations of Guice AbstractModule in a big project without creating fake implementations? Is it possible to test bind() and inject() methods? 回答1: Typically the best way to test Guice modules is to just create an injector in your test and ensure you can get instances of keys you care about out of it. To do this without causing production stuff to happen you may need to replace some modules with other modules. You can use Modules.override to selectively override individual

CDI @Produces with multiple properties files

时间秒杀一切 提交于 2019-12-21 21:32:42
问题 Thanks to this post, https://stackoverflow.com/a/28047512/1227941 I am now using CDI to make msg available in my @Named beans like this: @RequestScoped public class BundleProducer { @Produces public PropertyResourceBundle getBundle() { FacesContext context = FacesContext.getCurrentInstance(); return context.getApplication().evaluateExpressionGet(context, "#{msg}", PropertyResourceBundle.class); } } With Injection like: @Inject private PropertyResourceBundle bundle; The question: What should I

CDI @Produces with multiple properties files

筅森魡賤 提交于 2019-12-21 21:26:00
问题 Thanks to this post, https://stackoverflow.com/a/28047512/1227941 I am now using CDI to make msg available in my @Named beans like this: @RequestScoped public class BundleProducer { @Produces public PropertyResourceBundle getBundle() { FacesContext context = FacesContext.getCurrentInstance(); return context.getApplication().evaluateExpressionGet(context, "#{msg}", PropertyResourceBundle.class); } } With Injection like: @Inject private PropertyResourceBundle bundle; The question: What should I

how can i use a chrome extension content script to inject html into a page at startup

妖精的绣舞 提交于 2019-12-20 17:29:31
问题 i want to create an extension to inject html into every page as soon as it loads up. I am familiar with teh manifest.json rules for this as well as how to run a content script. The problem I'm currently having is the content script injects the html after the web page has loaded which is a bit disruptive. I would like to load it as soon as the window is open so it is injected and then the webpage loads as well. Can you help? 回答1: Just to be clear here, "loads up" means "starts loading," right?