jeudi 23 avril 2015

Tracing through a recursive function

For the following code segment, I am having trouble tracing through it (which I need to be able to do for my upcoming test.

public int question(int x, int y)
    if (x ==y)
        return 0;
        return question(x-1, y) + 1;

I am also confused as to what the + 1 is doing. What is 1 being added on to. I know the result is five, but I need to be able to better understand the concept. Thanks for your help.

Finding a document in RethinkDB that meets multiple criteria

I want to create a wrapper function that accepts an array of requirements. This wrapper function will ask rethinkDB for any documents that meet all criteria. The values will be numerical and I want anything returned which has >= the asked for value.

The syntax supplied in the API is like this:

).run(conn, callback);

But that doesn't allow me to query for an arbitrary amount of conditions.

Is there a feature that I am missing, or is the solution to: 1. build a string and eval it - or - 2. pass a function to the RethinkDB server with my array of requirements included ?

An example that might make more sense: I have a database of monster trucks. I want to allow someone to say "show me trucks with a power score of at least 5 and with a speed of at least 10". Here is a failed attempt at passing a function:

var fail = 0, 
    arr = [{attr: "speed", val: 5}, {attr: "power", val: 10}];
for(var i = 0; i < arr.length; i++){
return fail ? false : true;

Calling a func from one class in another class - swift

I have a class viewcontroller. In another class, SigViewController, I have a function which captures an image of a signature. I would like to call the function in the viewcontroller class (specifically in an IBAction).

In viewcontroller I have the following.

@IBAction func sigsave(sender: AnyObject) {

In SigViewController the function is...

func getSignature() ->UIImage {
    var signature: UIImage = UIGraphicsGetImageFromCurrentImageContext()
    println("saved image")
    return signature

The viewcontroller is returning the error `Use of unresolved identifier SigViewController.

Thanks for any help.

How can I create a function in MySQL for add elements in a table?

I would like to add elements in a table like this:

Codigo  Name   Lastname   Date    Sex    Salary
1       name1  lastname1  random  random random
2       name2  lastname2  random  random random
3       name3  lastname3  random  random random
4       name4  lastname4  random  random random

Date is a date random betweem years 2000 - 2015

Sex is random boolean 1 or 0

Salary is a random float between 500.00 and 5000.00

is that possible? How can I do that?

jQuery. Pass a variable from a function to an .each inside

I want to pass a variable, either '1' or '2' and run a function depending on available size. How can i ensure that the var can get pass through another function? Thanks!

$(function() {
    function newFunc(varNum){
        $('.listing__item .item__details').each(function() {
            var ul = $('ul.item__authors', this);
            var authors = $('.item__authors-info', this);
            if(ul.children('').size() <= varNum) return;

            var hiddenElements = ul.children('li:gt(varNum)', this).hide(),
                showCaption = '+ ' + hiddenElements.size() + ' others';

            authors.append($('<span class="other-authors">' + showCaption + '</span>'));

Method 'setChecked' with Objective-C selector 'setChecked:' conflicts with setter for 'checked' with the same Objective-C selector

I have created custom class that inherits from UIButton.

In that class I have created a function defined as:

  func setChecked(checked:Bool){
        self.checked = checked
        if checked {
            buttonImageView.image = UIImage(named: "radioSelected.png")
        } else {
            buttonImageView.image = UIImage(named: "radioUnselected.png")

which was working fine until I updated my xCode to 6.1.3.

Now I keep getting the error message on the function definition line:

Method 'setChecked' with Objective-C selector 'setChecked:' conflicts with setter for 'checked' with the same Objective-C selector

I already tried to make a override it but then I get a error saying that "Method does not override any method from its superclass".

Anyone know how can I correctly solve it?

(I don't want to change the name of my function.)

when code is executed execution won't move inside a excel vba function

For VBA functions and most programming in general i understand general program execution to occur something like this...

Inside a sub procedure if you call a function (it should return a value), in this case it would return a value to variable num.

To expand this means that execution reaches the line where I call the function, and should then skip down to where the function is written, and go through executing each line inside that function.

This is how it has worked for me previously when I use the F8 key to highlight and follow the code execution line by line.

The problem The problem is when execution reaches the line inside the sub procedure where the function is called the function is just skipped over and execution doesn't go inside the function and run each line inside it.

(and I should say when this happened I had 95% of a working program, and i've tried re-writing the function, calling other functions).

But whenever a function is called execution of the code doesn't go into the function itself it just skips over it, and the variable that holds the result of the function therefore is left empty.

I've tried creating breakpoints at the beginning of the function and when the function is called in the sub procedure however this hasn't worked.

At the very least execution should get to the definition of the function (Function FirstRow() etc) and throw and error but it's not doing that.

Sub Main

    Dim num as double

    Dim sheet_name as string

    num = FirstRow(sheet_name)

End Sub

Function FirstRow(sheet as string) as double

    select case sheet '<<----- execution never gets inside the function

    case "sheet"
        FirstRow = 8
    case "sheet2"
        FirstRow = 12

    end select

End Function