anonymous

Invoking Actions from Moq

北城余情 提交于 2020-01-01 06:43:13
问题 I've got a service with a method that takes two Action s, one for success and one for failure. Each Action takes a Result parameter that contains additional information... void AuthoriseUser(AuthDetails loginDetails, Action<AuthResult> onSuccess, Action<AuthResult> onFailure); I'm writing a unit test for a class that is dependant on that service, and I want to test that this class does the correct things in the onSuccess(...) and onFailure(...) callbacks. These are either private or anonymous

How can an anonymous class have arguments?

时光怂恿深爱的人放手 提交于 2019-12-31 03:17:05
问题 I'm not a java guy but I've inherited some code I need to patch up. I pulled the source into netbeans and I'm getting the error: Anonymous class implements interface; cannot have arguments. Here's the code: Executor background = Executors.newSingleThreadExecutor(); Runnable mylookupThread = new Runnable(FilePath, SearchIndex) { public void run() { MainWindow.this.processFile(this.val$FilePath); Thread t = new Thread(new lookupThread(MainWindow.arrFile, true, false, this.val$SearchIndex)); t

Global const string& smells bad to me, is it truly safe?

ⅰ亾dé卋堺 提交于 2019-12-30 17:20:20
问题 I'm reviewing a collegue's code, and I see he has several constants defined in the global scope as: const string& SomeConstant = "This is some constant text"; Personally, this smells bad to me because the reference is referring to what I'm assuming is an "anonymous" object constructed from the given char array. Syntactically, it's legal (at least in VC++ 7), and it seems to run, but really I'd rather have him remove the & so there's no ambiguity as to what it's doing. So, is this TRULY safe

Identifying anonymous users

ε祈祈猫儿з 提交于 2019-12-30 10:06:27
问题 If I had a poll on my site, and I didn't want to require a registration to vote, but I only wanted each visit one, how might I do this? Let's say a visitor from IP 123.34.243.57 visits the site and votes. Would it then be safe to disallow anyone from 123.34.243.* from voting? Is this a good strategy? What's another one? 回答1: This is a fundamental challenge with all voting sites on the Internet, and you're just breaking the surface of the problem. The way you've phrased it, you "only want to

How to create an instance of anonymous interface in Kotlin?

有些话、适合烂在心里 提交于 2019-12-28 03:32:04
问题 I have a third party Java library which an object with interface like this: public interface Handler<C> { void call(C context) throws Exception; } How can I concisely implement it in Kotlin similar to Java anonymous class like this: Handler<MyContext> handler = new Handler<MyContext> { @Override public void call(MyContext context) throws Exception { System.out.println("Hello world"); } } handler.call(myContext) // Prints "Hello world" 回答1: Assuming the interface has only a single method you

Cellfun with Structfun as function?

╄→гoц情女王★ 提交于 2019-12-25 10:02:18
问题 My data are in the form of a cell array of structs. I am trying to implement a cellfun call that takes structfun as its function that, at the end of the day, will resize all of the vectors in the struct to the passed-in size. E.g. I have a 4-cell array each with a struct that contains one vector (going to be multiple vectors once I figure this out), and I want to resize each vector from index1 to index2 fun = function(foo, index1, index2) cellfun(@structfun(@(x) x(index1:index2), foo,

Jade Parser: “Anonymous blocks are not allowed unless they are part of a mixin” Error

混江龙づ霸主 提交于 2019-12-25 04:22:14
问题 I've got this error: "Anonymous blocks are not allowed unless they are part of a mixin" with this Jade file: html body style(type='text/css', media='screen') div#div_name display: block height: 300px obviously the problem is with display: block - any ideas \ solutions? 回答1: The following Jade style(type='text/css', media='screen') div#div_name display: block height: 300px will not compile. <style type="text/css" media="screen"></style> <div id="div_name"> <display><block></block></display>

Django anonymous user in model

[亡魂溺海] 提交于 2019-12-24 12:06:27
问题 I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other = models.CharField(max_length=100) The problem is Django refuses to assign django.contrib.auth.models.AnonymousUser directly to Example.user as null field so everytime I have to check if request.user.is_authenticated() ans assign Example.user = None manually. Is there a default value for AnonymousUser to use in a model field? 回答1: Only users actually in django.contrib.auth.models.User

How do I restrict the creation of an anonymous subclass (Java)

孤人 提交于 2019-12-24 00:58:29
问题 Sorry the question wasn't properly stated by me earlier. I try to implent the Factory Pattern. A better example: It is an abstract class Human with a function create. Based on the arguments that is passed to create it decides whether to return an instance of its subclass Man or an instance of subclass Woman. So you call create with: Human john = Human.create("Man"); The subclasses Man and Woman are inherited from the abstract class Human and are defined in the same file as Human. I don't want

matlab symfun vs anonymous function

一笑奈何 提交于 2019-12-24 00:31:29
问题 What is the difference between using a symfun and an anonymous function in Matlab? Which one is better i.e. faster? It seems like, I can use both for symbolic and real numbers. Here they discuss the difference between inline and anonymous functions, but don't mention symfun. 回答1: Basic MATLAB functionality is designed for numerical calculations, i.e. working with floating-point numbers. By default MATLAB variables and functions are numeric, and this is why in your linked discussion only