function

Compare 2 elements of two arrays in C++

I have two arrays each array has some values for instance: int a[] = {1, 2, 3, 4}; int b[] = {0, 1, 5, 6}; now I need to compare the elements of the array (a) with elements in array (b).. if is there any match the program should return an error or print "error there is a duplicate value" etc.. in the above situation, it should retur...

How to pass a specific argument to a decorator in python

I want to write a python function decorator that tests that certain arguments to a function pass some criterion. For eg, Suppose I want to test that some arguments are always even, then I want to be able to do something like this (not valid python code) def ensure_even( n ) : def decorator( function ) : @functools.wraps( functio...

Any way to improve this python function?

def __number(): # This line returns the number of the latest created object # as a "Factura" object in format "n/year" last = Factura.objects.filter(f_type__exact=False).latest('number') # We convert it into a string and split it to get only the first number spl = str(last).split('/')[0] # Convert it into intege...

Expose __main__

Hi everybody, is this legal in python?. Seems to work ... Thanks # with these lines you not need global variables anymore if __name__ == '__main__': import __main__ as main else: main = __import__(os.path.basename(os.path.splitext(__file__))) var_in_main = 0 # now any var is a global var, you can access any var from every...

Breaking a parent function from within a child function (PHP Preferrably)

I was challenged how to break or end execution of a parent function without modifying the code of the parent, using PHP I cannot figure out any solution, other than die(); in the child, which would end all execution, and so anything after the parent function call would end. Any ideas? code example: function victim() { echo "I shou...

Suppose I want to create a "stored function" for MYSQL. Where do I wrote it? Which file?

Of course, I could go into mysql console and type the Function. But what if I want to store it for future use? What do I do? ...

Javascript function to get the difference between two numbers

I want a Simple Javascript function to get the difference between two numbers in such a way that foo(2, 3) and foo(3,2) will return the same difference 1. ...

Specific functions vs many Arguments vs context dependent

An Example Suppose we have a text to write and could be converted to "uppercase or lowercase", and can be printed "at left, center or right". Specific case implementation (too many functions) writeInUpperCaseAndCentered(char *str){//..} writeInLowerCaseAndCentered(char *str){//..} writeInUpperCaseAndLeft(char *str){//..} and so on... ...

C++ auto call function after change variable

Is there a function in c++ that when a variable got changed it automaticly call a function? ...

Java template question

I have instantiated an object like this: GraphMatrixDirected<String, Integer> g g is passed to a function like this: floyd(g); floyd's signature looks like this: public void floyd(GraphMatrixDirected<V,E> g) Eclipse gives me an error saying: The method floyd(GraphMatrixDirected<V,E>) in the type GraphMatrix<V,E> is not applic...

Fgetcsv initial line reading problem

I'm working with a CSV file and PHP5 however I'm not quite understanding what I am seeing. The file is as follows when I open it in a text editor: "Jun 23,2010 21:40","City1","Location1","0 0 0 " "Jun 23,2010 21:41","City2","Location1","0 0 0 " What I get as output from this code: while (($data = fgetcsv($handle, 1000, ",","\"")) !=...

c++ const member function question

I am reading a book called 'Effective C++, Second Edition' and its talking about const member functions and how you have bitwise const-ness and conceptual const-ness. It says most compilers will go with bitwise const-ness, which is that you cannot alter data members of an object inside a const member function. Then there's an example o...

How can I ignore first results from a function in Lua ?

Lua functions can return multiple results : a, b, c = unpack({'one', 'two', 'three'}) If I'm not interested in the third return value, I can choose to ignore it when calling the function : a, b = unpack({'one', 'two', 'three'}) Is there a similar way to ignore the X first elements when calling the function ? I could write this cod...

How to return additional fields based on aggregate function ?

I have two tables, jobcli client_id job_id jobs job_id jobTitle startDate projectmgr What I am having trouble with is to display client_id, job_id, jobTitle, startDate, and projectmgr in a query, where the results are grouped by client_id and have max of date. So far I can get a list that's groupped by client_id with their c...

PHP - cooler function parameter

Hi I have this: function boo($show_one = false){ if(!show_one) return 1; else return 2; } how can I call boo like this: boo(SHOW_ALL); instead of boo(false). I see some native php function have parameters like that which make the code more easy to read ...

Dynamic Functions

Ok, well I have sorta of an odd situation. I have a two applications. One is the main application and the other is a helper bundle that is loaded during run time. What I want to do is to call a function defined within the main application from the bundle so that code does not have to be copied over. I have tried setting the header declar...

Parser expression for comma-separated function call parameters

Im writing a parser than can parse expressions like myfunc1(), myfunc2(param1) and myfunc3(param1, param2) (with an unknown amount of parameters). Now I'm trying to get my parse expressions right. I'm using the Lemon Parser Generator. Here is what I've come up with: application(res) ::= APPLICATIONNAME(a) BRACE_OPEN params BRACE_CLOSE. ...

Easiest way to repeatedly call a custom function in Jquery while hovering?

I have a function called goRight() which does some stuff when I click a div called "goright". I want to make it so that when I hover over the div "goright" it will call the function repeatedly (with a small delay) for as long as I'm hovering, and then do nothing and stop once i move the mouse away. I have experimented with setInterval ...

c++ Function pointer declaration causes program to crash on exit.

I declare the following two function pointers in my class: void (*ptrFunc)(void *); bool (*ptrValid)(char *); Now for some reason, the second pointer (ptrValid) causes the program to crash on exit. When I comment out the declaration the program exits fine, but when I un-comment it, it crashes. Nothing is being assigned to it, it isn...

Flash, ActionScript 3: using get/set properties to get values from other classes creates much duplicate code can it different?`

hi, i am using get and setters in my as3 code to edit values of an other class (because those variables are shared) i dont like to put stage.sharedVar.isScrabble in my code every time to change a variable so i used get/set functions see below private function get isScrabble(){return stage.sharedVar.isScrabble;} private function set i...