function

PHP Function with Optional Parameters

I've written a PHP function that can accepts 10 parameters, but only 2 are required. Sometimes, I want to define the eighth parameter, but I don't want to type in empty strings for each of the parameters until I reach the eighth. One idea I had was to pass an abstracted function with an array of parameters which passes it along to the r...

How should I comment partial Python functions?

say I have the following code: def func(x, y = 1, z = 2): """ A comment about this function """ return x + y + z another_func = partial(func, z = 4) What would be the correct or Pythonic way of documenting the another_func function? ...

Difference between AddLoadEvent and function load of jQuery

Hi everyone, I'm trying find an explanation to the following question, I looked around and haven't found any awnser so far: What is the the difference between the Simon Willison's code for the AddLoadEvent function and the load function from jQuery? Here are the links: 1 ) AddLoadEvent code : http://simonwillison.net/2004/May/26/addL...

Implement generic swap macro in C

Possible Duplicate: is there an equivalent of std::swap() in c Hi folks, I was attempting a problem to write a generic swap macro in C and my macro looks like this: #define swap(x,y) { x = x + y; y = x - y; x = x - y; } It works fine for integers and floats but I am unsure if there is any catch in it. What if by generic ma...

How to pass long value to javascript function

I have javascript function: function someAction(thisTd,text){ alert(text); thisTd.innerHTML=text; ... } And html-file: <td onclick="someAction(this,<?echo 'Long-long text with <b>html-formatting</b>'?>)"/> When I use such code function someAction doesn't call (because alert doesn't show) and in the error console in Opera no e...

PHP recursive function to delete all child nodes causes stackoverflow

My MySQL looks like this: (the name of the table is category) 'id', 'content', 'parent' where: id = the id of the category content = some-text-we-dont-care-about parent = the id of the parent category this is what I'm trying right now: function remrecurs($id) { $qlist=mysql_query("SELECT * FROM category WHERE parent='$id'"); ...

Python: Run function from the command line

Say in my file i have: def hello(): return 'Hi :)' How would I run this from the command line? ...

Test for functions names in javascript script (SpiderMonkey engine)

I am embeding SpiderMonkey (mozila javascript) interpreter/engine in my C/C++ application. i programatically loading a javascript script and want to test (from my C/C++ code) if a certain function exist/defined in this script. is there a way to do that ? maybe a way to list all functions in a given script ? Tnx, Vertilka ...

Get number of arguments for a class function.

Hi, Is there a way to detect the number of arguments a function in a class has? What I want to do is the following. $class = 'foo'; $path = 'path/to/file'; if ( ! file_exists($path)) { die(); } require($path); if ( ! class_exists($class)) { die(); } $c = new class; if (num_function_args($class, $function) == count($url_segment...

Java static method can't compile

Hi, the following messege appears when I compile this code. ExtractChars(java.lang.String,int) in Question2 cannot be applied to () What should I fix? Thanks. import java.util.Scanner; public class Question2 { public static void main (String[] args) { ExtractChars(); } public static String ExtractCha...

C++ inline member function in .cpp file

I know that inline member functions by definition should go into the header. But what if it's not possible to put the implementation of the function into the header? Let's take this situation: File A.h #pragma once #include "B.h" class A{ B b; }; File B.h #pragma once class A; //forward declaration class B{ inline A getA(...

C function calling

So this program is supposed to estimate hourly temperatures throughout a day after being given the daily high, low and the hour which the low is expected. I am having problems calling up my functions inside the main function. I don't really understand how I am supposed to get specific information from the functions, and use it in place o...

php's preg_replace() versus(vs.) ord() .

What is quicker, for camelCase to underscores; using preg_replace() or using ord() ? My guess is the method using ord will be quicker, since preg_replace can do much more then needed. <?php function __autoload($class_name){ $name = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $class_name)); require_once("some_dir/".$nam...

C++ call back system. Pointers to member functions.

Hi, Im trying to create a call back by passing a pointer to member functions but am running into all types of issues. How can i go about implementing such a thing template<class T> class A{ void (T::*callBackFunction)(int); public: void addCallBack(void (T::*callBackFunction)(int)){ void (T::*callBackFunction...

I am trying to make my input strings lower case using Dojo

I have this security question answer input field validate function where I want to make sure the string are converted to lowercase just in case a user enter a answer in caps in the first field and in small case in the second field: validate : function(){ //check if both input fields are not blank //if not blank, check to see if they m...

how to return a dynamic result set in Oracle function

I found a string tokenizer query on the net and packaged it into the below function, which return the dynamic set of tokens. The function compiles successfully but somehow I get the error "ORA-00933: SQL command not properly ended". Can someone please help me debug this? Thank you. CREATE OR REPLACE TYPE KEY_VALUE_TYPE is object (k varc...

what's meaning that sign of assignment.

hi, i don't understand assignment in the following line. i think, setBit is a function but it's assigned a value. bool setBit(const unsigned int which) = 0; ...

Editable text functionality using jQuery

I have an image button and when I click it I want an specific field to go from text to an editable textfield, kinda like a dynamic edit button. So I have the plain text with certain id (ie. id="text1") and when I click the button, the text changes to an editable field, maybe something like $("#text1").hide(); and then $("#field1").show...

PHP: Calling a class method from another class..

Hi all, basically I have two classes Inventory and Character. During the construct of the inventory I am trying to determine the characters gender however this just doesn't seem to be working for me at all.. I haven't really used static functions before so if somebody could point out what I'm doing wrong it would be much appreciated.. F...

Returning value from a function

const char *Greet(const char *c) { string name; if(c) name = c; if (name.empty()) return "Hello, Unknown"; return name.c_str(); } int _tmain(int argc, _TCHAR* argv[]) { cout << Greet(0) << '\t' << Greet("Hello, World") << endl; return 0; } I see 2 bugs with the above code. Returning c_str from...