i like to split a string depending on "," character using JavaScript
example
var mystring="1=name1,2=name2,3=name3";
need output like this
1=name1
2=name2
3=name3
Hi,
In Python script,for every method definition in some C++ code of the form:
return_value ClassName::MethodName(args)
{MehodBody}
,I need to extract three parts: the class name, the method name and the method body for further processing. Finding and extracting the ClassName and MethodName is easy, but is there any simple way to extract the body of the method? With all possible '{' and '}' inside it? Or are regexes unsuitable for such task?
What I am doing that I want to generate a list based on how many items are in an array, so I have counted the items and loop over them, create a number based var and construct a string $var which contains $a1,$a2.... and assigns the $var to list list($var)
and tried to access $a1 but it gives me the error "Undefined variable: a1"
Is there any other way to do it?
Here is my code:
$arr = array('1','2','3');
$listsize = count($arr);
$var='';
for($i=1;$i<=$listsize;$i++){
$var.='$a'.$i;
if($i!=$listsize){
$var.=',';
}
}
list($var) = $arr;
echo $a1;
#include <stdio.h>
#define LENGTH 16
void makeBranches(int, int);
void display(int, int);
int main(){
makeBranches(0, LENGTH-1);
}
void makeBranches(int left, int right){
if(left >= right){
return;
} else{
display(left, right);
makeBranches(left, (right+left)/2);
makeBranches((right+left/2)+1, right);
}
}
void display(int left, int right){
printf("%d, %d", left, right);
int mid = (left+right)/2;
int i;
for(i = left; i <= right; i++){
if(i == mid)
printf("X");
else
printf("-");
}
if(right == LENGTH-1)
printf("\n");
}
The problem that I am having is the second call of makeBranches only executes with the values that caused the first call of makeBranches to return and not the original values that the first call used.
Consider the following code:
class CustomClass
{
public CustomClass(string value)
{ m_value = value; }
public static bool operator==(CustomClass a, CustomClass b)
{ return a.m_value == b.m_value; }
public static bool operator!=(CustomClass a, CustomClass b)
{ return a.m_value != b.m_value; }
public override bool Equals(object o)
{ return m_value == (o as CustomClass).m_value; }
public override int GetHashCode()
{ return 0; /* not needed */ }
string m_value;
}
class G
{
public static bool enericFunction1<T>(T a1, T a2) where T : class
{ return a1.Equals(a2); }
public static bool enericFunction2<T>(T a1, T a2) where T : class
{ return a1==a2; }
}
Now when I call both generic functions, one succeeds and one fails:
var a = new CustomClass("same value");
var b = new CustomClass("same value");
Debug.Assert(G.enericFunction1(a, b)); // Succeeds
Debug.Assert(G.enericFunction2(a, b)); // Fails
Apparently, G.enericFunction2 executes the default operator== implementation instead of my override. Can anybody explain why this happens?
I have this:
var $ul = $(this).children("ul");
$ul.animate({opacity: 0}, 1000);
$ul.delay(1000).css("display", "none")
It's for my dropdown menu, and I want it to fade off before it disappears using the display: none; CSS property. However it appears that the .delay() cannot be used on the .css(); it doesn't work, the $ul just disappears right away.
I can't use $ul.animate({opacity: 0, display: "none"}, 1000); either.
Hi!
I made this script to test the execution of php in background
foreach($tests as $test) {
exec("php test.php ".$test["id"]);
}
to run php in background like suggested in php process background
and How to add large number of event notification reminder via Google Calendar API using PHP? and php execute a background process
But the script do not run faster than when it was all in one script without the addition of test.php.
what I'm doing wrong?
thanks in advance!
What I wanted is printing out 5 dots that a dot printed per a second using time.sleep(), but the result was 5 dots were printed at once after 5 seconds delay.
Tried both print and sys.stdout.write, same result.
Thanks for any advices.
import time
import sys
def wait_for(n):
"""Wait for {n} seconds. {n} should be an integer greater than 0."""
if not isinstance(n, int):
print 'n in wait_for(n) should be an integer.'
return
elif n < 1:
print 'n in wait_for(n) should be greater than 0.'
return
for i in range(0, n):
sys.stdout.write('.')
time.sleep(1)
sys.stdout.write('\n')
def main():
wait_for(5) # FIXME: doesn't work as expected
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print '\nAborted.'
I connected my IOS device to a MAC processor and installed/initialized my app running in xcode or dragged it from itunes folder. Now i physically disconnected my device from the processor and through wifi enabled in the device, sent notifications/messages through APNS to the device. I was able to successfully receive notifications in the device. Now after some time, i reconnected the device to the processor, which lead to a problem of the app launching again and calling 'didFinishLaunchingWithOptions' method again, which is not desirable as the launch/initialization should happen only once. This behaviour is random ie. every time when i disconnect/reconnect, it is not happening, only sometimes. Why is this happening. What could be the reason for this random behaviour.
Any help will be appreciated.Thanks
I'm having a problem with a class like this:
class Sprite {
...
bool checkCollision(Sprite &spr);
...
};
So, if I have that clase, I can do this:
ball.checkCollision(bar1);
But if I change the class to this:
class Sprite {
...
bool checkCollision(Sprite* spr);
...
};
I have to do this:
ball.checkCollision(&bar1);
So, what's the difference?? It's better a way instead other?
Thank you.
I am writed an automated test in Selenium IDE to test one of our applications. Our app throws one of those confirmation dialogs "Are you sure you want to continue."
Click OK or Cancel
Selenium does not support the clicking of these dialog boxes. I have
tried the following SeleniumIDE functions with no success:
chooseOkOnNextConfirmation
chooseOkOnNextConfirmationAndWait
Is there a javascript funtion I can call within SeleniumIDE to do
this, or am I out of luck.
I'm trying to get this expression to work, I'm pretty sure its not the parenthesis because I counted all of them. Perhaps there something I'm doing wrong involving the parameter pow (x,y).
double calculatePeriodicPayment()
{
periodicPaymentcalc = (loan * ((interestRate / yearlyPayment))) / (1-((pow ((1+(interestRate / yearlyPayment)))),(-(yearlyPayment * numOfYearLoan))));
return periodicPaymentcalc;
}
Can Clojure implement (g ° f) constructions like Haskell's g . f? I'm currently using workarounds like (fn [n] (not (zero? n))), which isn't nearly as nice :)
For the jquery form plugin http://jquery.malsup.com/form/#options-object, I see a success callback, but how do I run code if there is a failure like a network issue?
if i use Doctrine_Core::getTable('User')- i will have no auto completion.
isnt it better to just use User:: for autocompletion?
and of course i have to define the methods static
what is the benefit with using getTable except that i can use a non static method?
Under these conditions,
The o/p of the first program is an large array of either integers, doubles or strings.
Best method means the fastest on x86 architecture.
I have a list of sales people and a list of their sale revenues in two separate columns. How do I use an advanced filter or other sorting means to find the max of the sale revenue column and then have the formula output be the corresponding sales person?
I have this snippet of the code
Account& Company::findAccount(int id){
for(list<Account>::const_iterator i = listOfAccounts.begin(); i != listOfAccounts.end(); ++i){
if(i->nID == id){
return *i;
}
}
return 0;
}
Is this right way to return 0 if I didn't find appropriate account?
cause I receive an error:
no match for 'operator!' in '!((Company*)this)->Company::findAccount(id)'
I use it this way:
if(!(findAccount(id))){
throw "hey";
}
thanks in advance
class base {
public:
virtual void doSomething() = 0;
};
class derived : public base {
**private:**
virtual void doSomething(){cout<<"Derived fn"<<endl;}
};
now if i do the following:
base *b=new child;
b->doSomething(); //it calls the derived class fn even if that is private.
Question:
1.its able to call the derived class fn even if that is private.How is it possible?
Now if i change the inheritance access specifier from public to protected/private then i get compilation error as "'type cast' : conversion from 'Derived *' to 'base *' exists, but is inaccessible"
Notes: I am aware on the concepts of the inheritance access specifiers.So in second case as its derived private/protected, its inaccessible. But here it confuses me for the first question. Any input will be highly appreciated
I'm a beginner and I want to write Java code in eclipse. This program takes two LinkedLists of integers (for example, a and b) and makes a LinkedList (for example d) in which every element is the sum of elements from a and b. However, I can't add these two elements from a and b because they are Objects
Example:
a=[3,4,6,7,8]
b=[4,3,7,5,3,2,1]
------
d=[7,7,13,12,11,2,1]