Search Results

Search found 35086 results on 1404 pages for 'return on investment'.

Page 5/1404 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Using Lambdas for return values in Rhino.Mocks

    - by PSteele
    In a recent StackOverflow question, someone showed some sample code they’d like to be able to use.  The particular syntax they used isn’t supported by Rhino.Mocks, but it was an interesting idea that I thought could be easily implemented with an extension method. Background When stubbing a method return value, Rhino.Mocks supports the following syntax: dependency.Stub(s => s.GetSomething()).Return(new Order()); The method signature is generic and therefore you get compile-time type checking that the object you’re returning matches the return value defined by the “GetSomething” method. You could also have Rhino.Mocks execute arbitrary code using the “Do” method: dependency.Stub(s => s.GetSomething()).Do((Func<Order>) (() => new Order())); This requires the cast though.  It works, but isn’t as clean as the original poster wanted.  They showed a simple example of something they’d like to see: dependency.Stub(s => s.GetSomething()).Return(() => new Order()); Very clean, simple and no casting required.  While Rhino.Mocks doesn’t support this syntax, it’s easy to add it via an extension method. The Rhino.Mocks “Stub” method returns an IMethodOptions<T>.  We just need to accept a Func<T> and use that as the return value.  At first, this would seem straightforward: public static IMethodOptions<T> Return<T>(this IMethodOptions<T> opts, Func<T> factory) { opts.Return(factory()); return opts; } And this would work and would provide the syntax the user was looking for.  But the problem with this is that you loose the late-bound semantics of a lambda.  The Func<T> is executed immediately and stored as the return value.  At the point you’re setting up your mocks and stubs (the “Arrange” part of “Arrange, Act, Assert”), you may not want the lambda executing – you probably want it delayed until the method is actually executed and Rhino.Mocks plugs in your return value. So let’s make a few small tweaks: public static IMethodOptions<T> Return<T>(this IMethodOptions<T> opts, Func<T> factory) { opts.Return(default(T)); // required for Rhino.Mocks on non-void methods opts.WhenCalled(mi => mi.ReturnValue = factory()); return opts; } As you can see, we still need to set up some kind of return value or Rhino.Mocks will complain as soon as it intercepts a call to our stubbed method.  We use the “WhenCalled” method to set the return value equal to the execution of our lambda.  This gives us the delayed execution we’re looking for and a nice syntax for lambda-based return values in Rhino.Mocks. Technorati Tags: .NET,Rhino.Mocks,Mocking,Extension Methods

    Read the article

  • wget return downloaded filename

    - by Matthew
    I'm using wget in a php script and need to get the name of the file downloaded. For example, if I try <?php system('/usr/bin/wget -q --directory-prefix="./downloads/" http://www.google.com/'); ?> I will get a file called index.html in the downloads directory. The page will not always be google though, so I need to find out the name of the file that was downloaded. I'd like to have something like this: <?php //Does not work: $filename = system('/usr/bin/wget -q --directory-prefix="./downloads/" http://www.google.com/'); //$filename should contain "index.html" ?>

    Read the article

  • Python print statement prints nothing with a carriage return

    - by Jonathan Sternberg
    I'm trying to write a simple tool that reads files from disc, does some image processing, and returns the result of the algorithm. Since the program can sometimes take awhile, I like to have a progress bar so I know where it is in the program. And since I don't like to clutter up my command line and I'm on a Unix platform, I wanted to use the '\r' character to print the progress bar on only one line. But when I have this code here, it prints nothing. # Files is a list with the filenames for i, f in enumerate(files): print '\r%d / %d' % (i, len(files)), # Code that takes a long time I have also tried: print '\r', i, '/', len(files), Now just to make sure this worked in python, I tried this: heartbeat = 1 while True: print '\rHello, world', heartbeat, heartbeat += 1 This code works perfectly. What's going on? My understanding of carriage returns on Linux was that it would just move the line feed character to the beginning and then I could overwrite old text that was written previously, as long as I don't print a newline anywhere. This doesn't seem to be happening though. Also, is there a better way to display a progress bar in a command line than what I'm current trying to do?

    Read the article

  • Pick Return Values of Stored Procedure

    - by Juergen
    Hi, I have a stored procedure that returns a result with 250!!! columns. But I only need 3 out of the 250. I want to call the SP and put only the 3 column values in a temp table. I don't want to define a temp table with 250 columns! This is how I would like to do it, but this doesn't work of course: create #myTempTable (id int, value1 int, value2 int) insert into #myTempTable exec myBigFatStoredProc Can it be done anyhow? Bye Juergen

    Read the article

  • Returning superclass of return type from remote EJB method

    - by fish
    Let's say I have remote interface A: @Remote public interface A { public Response doSomething(); } And implementation: @Stateless public class B implements A { public BeeResponse doSomething() {...} } Where: BeeResponse extends Response. Response is located in the EJB-API jar and BeeResponse is in the implementation jar. Response and BeeResponse have different serialVersionUID. My assumption is that the unmarshalling of the response from B will fail, am I correct?

    Read the article

  • Rails 4 json return on API

    - by El - Key
    I'm creating an API on my application. I currently overrided the as_json method in my model in order to be able to get attached files as well as logo from Paperclip : def as_json( options = {} ) super.merge(logo_small: self.logo.url(:small), logo_large: self.logo.url(:large), taxe: self.taxe, attachments: self.attachments) end Then within my controller, I'm doing : def index @products = current_user.products respond_with @products end def show respond_with @product end The problem is that on the index, I don't want get all the attachments. I only need it on the show method. So I tried it : def index @products = current_user.products respond_with @products, except: [:attachments] end But unfortunately it's not working. How can I do to not send :attachments? Thanks

    Read the article

  • multiple return values from PHP with jQuery AJAX

    - by benhowdle89
    I'm using this jQuery code: $.ajax ({ type: "POST", url: "customerfilter.php", data: dataString, cache: false, success: function(html) { $(".custName").html(html); } }); How can i do something like this: $(".projDesc").html(html1); So i can split the returned results into two html elements? echo "<p>" .$row['cust_name']. "</p>"; thats the PHP i'm using and i want to echo another statement which i can put into another HTML element Does this make sense?

    Read the article

  • How to return a value into webpage

    Hello: I have a simple webpage that displays the credit balance for calling cards. So far without any problems, with HTML, PHP and mysql, I was able to retrieve the balance from a data base. But I have to display the result in ANOTHER PAGE, wich looks akward because the page must reload. Can I just load this value into a pre-drawed field under the input fields that collect the data from the customer? Such as : Account Number: 134556 PIN: * |send| Balance is: $12.36 Thanks in advanced

    Read the article

  • Scala return type for tuple-functions

    - by Felix
    Hello Guys, I want to make a scala function which returns a scala tuple. I can do a function like this: def foo = (1,"hello","world") and this will work fine, but now I want to tell the compiler what I expect to be returned from the function instead of using the built in type inference (after all, I have no idea what a (1,"hello","world") is) I thought I remembered the classname being something like Tuple3[Int,String,String] but that doesnt work for me. Suggestions? :D (ps: I love stack overflow!)

    Read the article

  • SQL Server Stored Procedure that return processed records number

    - by Ras
    I have a winform application that fires a Stored Procedure which elaborates several records (around 500k). In order to inform the user about how many record have been processed, I would need a SP which returns a value every n records. For example, every 1000 row processed (most are INSERT). Otherwise I would be able only to inform when ALL record are processed. Any hints how to solve this? I thought it could be useful to use a trigger or some scheduled task, but I cannot figure out how to implement it.

    Read the article

  • PowerShell function won't return object

    - by Dan
    I have a simple function that creates a generic List: function test() { $genericType = [Type] "System.Collections.Generic.List``1" [type[]] $typedParameters = ,"System.String" $closedType = $genericType.MakeGenericType($typedParameters) [Activator]::CreateInstance($closedType) } $a = test The problem is that $a is always null no matter what I try. If I execute the same code outside of the function it works properly. Thoughts?

    Read the article

  • Rails how to return a list of answers with a specific question_id

    - by mytwocentsisworthtwocents
    Let's say I have two Models, Answers and Questions (there are others, but irrelevant to the question). The models are as follows: Answer.rb class Answer < ActiveRecord::Base attr_accessible :description, :question_id has_one :question, :through => :user, :dependent => :destroy validates :description, :presence => true end Question.rb class Question < ActiveRecord::Base attr_accessible :budget, :description, :headline, :user_id, :updated_at, :created_at belongs_to :user has_many :answers validates :headline, :description, :user_id, :presence => true end I'd like to display on a page a list of all answers associated with a question, and only those questions. I got this far. I believe this variable finds all the questions in the database by the question_id (foreign key): @findanswers = Answer.all(params[:question_id]) And this one grabs the the id of the current question (this code will reside as an ERB on the page where the current question is located): @questionshow = Question.find(params[:id]) And now I'm stuck. How do I put the two together so that I list all the answers with the current question id?

    Read the article

  • Prolog returns Out = _G431 when it suppose to return a list of lists

    - by Mandah
    createSchedule([[math109]], fall, Out). [[cs485, cs485], [cs355, cs355, cs462, cs462, cs462], [cs345, cs345, cs352, cs352, cs352, cs362, cs362, cs362, cs396, cs396, cs396], [cs330, cs330, cs330], [cs255, cs255, cs255, cs268, cs268], [math114, cs245, cs245], [math112, cs145, cs146], [math109]] Out = _G431 this is what prolog returns and the list of lists is shown by using write(Out) in prolog. Any ideas why it is showing this? Thanks

    Read the article

  • Java 7 API design best practice - return Array or return Collection

    - by Shengjie
    I know this question has be asked before generic comes out. Array does win out a bit given Array enforces the return type, it's more type-safe. But now, with latest JDK 7, every time when I design this type of APIs: public String[] getElements(String type) vs public List<String> getElements(String type) I am always struggling to think of some good reasons to return A Collection over An Array or another way around. What's the best practice when it comes to the case of choosing String[] or List as the API's return type? Or it's courses for horses. I don't have a special case in my mind, I am more looking for a generic pros/cons comparison.

    Read the article

  • Do out-of-office replies get sent to the return-path header?

    - by Brian Armstrong
    I always thought that the return-path header was used for bounced messages, so I have my email newsletter software setup to unsubscribe anyone whose email address replies back to the return-path email address. But recently some users started telling me their out-of-office replies where unsubscribing them. Do out-of-office replies get sent to the return-path on some email servers? I could check all emails to that address and see if they have the "message/delivery-status" content-type in one of the parts, but I wasn't sure if this was necessary.

    Read the article

  • How can a Perl force its caller to return? [closed]

    - by JS Bangs
    Possible Duplicate: Is it possible for a Perl subroutine to force its caller to return? I want to write a subroutine which causes the caller to return under certain conditions. This is meant to be used as a shortcut for validating input to a function. What I have so far is: sub needs($$) { my ($condition, $message) = @_; if (not $condition) { print "$message\n"; # would like to return from the *parent* here } return $condition; } sub run_find { my $arg = shift @_; needs $arg, "arg required" or return; needs exists $lang{$arg}, "No such language: $arg" or return; # etc. } The advantage of returning from the caller in needs would then be to avoid having to write the repetitive or return inside run_find and similar functions.

    Read the article

  • How to name a method that both performs a task and returns a boolean as a status?

    - by Limbo Exile
    If there is a method bool DoStuff() { try { // doing stuff... return true; } catch (Exception ex) { return false; } } should it rather be called IsStuffDone()? Both names could be misinterpreted by the user: If the name is DoStuff() why does it return a boolean? If the name is IsStuffDone() it is not clear whether the method performs a task or only checks its result. Is there a convention for this case? Or an alternative approach, as this one is considered flawed? For example in languages that have output parameters, like C#, a boolean status variable could be passed to the method as one and the method's return type would be void.

    Read the article

  • Single or multiple return statements in a function [on hold]

    - by Juan Carlos Coto
    When writing a function that can have several different return values, particularly when different branches of code return different values, what is the cleanest or sanest way of returning? Please note the following are really contrived examples meant only to illustrate different styles. Example 1: Single return def my_function(): if some_condition: return_value = 1 elif another_condition: return_value = 2 else: return_value = 3 return return_value Example 2: Multiple returns def my_function(): if some_condition: return 1 elif another_condition: return 2 else: return 3 The second example seems simpler and is perhaps more readable. The first one, however, might describe the overall logic a bit better (the conditions affect the assignment of the value, not whether it's returned or not). Is the second way preferable to the first? Why?

    Read the article

  • What is the best way to return two values from a method?

    - by Edward Tanguay
    When I have to write methods which return two values, I usually go about it as in the following code which returns a List<string>. Or if I have to return e.g. a id and string, then I return a List<object> and then pick them out with index number and recast the values. This recasting and referencing by index seems inelegant so I want to develop a new habit for methods that return two values. What is the best pattern for this? using System; using System.Collections.Generic; using System.Linq; namespace MultipleReturns { class Program { static void Main(string[] args) { string extension = "txt"; { List<string> entries = GetIdCodeAndFileName("first.txt", extension); Console.WriteLine("{0}, {1}", entries[0], entries[1]); } { List<string> entries = GetIdCodeAndFileName("first", extension); Console.WriteLine("{0}, {1}", entries[0], entries[1]); } Console.ReadLine(); } /// <summary> /// gets "first.txt", "txt" and returns "first", "first.txt" /// gets "first", "txt" and returns "first", "first.txt" /// it is assumed that extensions will always match /// </summary> /// <param name="line"></param> public static List<string> GetIdCodeAndFileName(string line, string extension) { if (line.Contains(".")) { List<string> parts = line.BreakIntoParts("."); List<string> returnItems = new List<string>(); returnItems.Add(parts[0]); returnItems.Add(line); return returnItems; } else { List<string> returnItems = new List<string>(); returnItems.Add(line); returnItems.Add(line + "." + extension); return returnItems; } } } public static class StringHelpers { public static List<string> BreakIntoParts(this string line, string separator) { if (String.IsNullOrEmpty(line)) return null; else { return line.Split(new string[] { separator }, StringSplitOptions.None).Select(p => p.Trim()).ToList(); } } } }

    Read the article

  • Multiple returns: Which one sets the final return value?

    - by DR
    Given this code: String test() { try { return "1"; } finally { return "2"; } } Do the language specifications define the return value of a call to test()? In other words: Is it always the same in every JVM? In the Sun JVM the return value is 2, but I want to be sure, that this is not VM-dependant.

    Read the article

  • When does a const return type interfere with template instantiation?

    - by Rimo
    From Herb Sutter's GotW #6 Return-by-value should normally be const for non-builtin return types. ... Note: Lakos (pg. 618) argues against returning const value, and notes that it is redundant for builtins anyway (for example, returning "const int"), which he notes may interfere with template instantiation. While Sutter seems to disagree on whether to return a const value or non-const value when returning an object of a non-built type by value with Lakos, he generally agrees that returning a const value of a built-in type (e.g const int) is not a good idea. While I understand why that is useless because the return value cannot be modified as it is an rvalue, I cannot find an example of how that might interfere with template instantiation. Please give me an example of how having a const qualifier for a return type might interfere with template instantiation.

    Read the article

  • Is it advisable to have an interface as the return type?

    - by wb
    I have a set of classes with the same functions but with different logic. However, each class function can return a number of objects. It is safe to set the return type as the interface? Each class (all using the same interface) is doing this with different business logic. protected IMessage validateReturnType; <-- This is in an abstract class public bool IsValid() <-- This is in an abstract class { return (validateReturnType.GetType() == typeof(Success)); } public IMessage Validate() { if (name.Length < 5) { validateReturnType = new Error("Name must be 5 characters or greater."); } else { validateReturnType = new Success("Name is valid."); } return validateReturnType; } Are there any pitfalls with unit testing the return type of an function? Also, is it considered bad design to have functions needing to be run in order for them to succeed? In this example, Validate() would have to be run before IsValid() or else IsValid() would always return false. Thank you.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >