Search Results

Search found 2601 results on 105 pages for 'condition'.

Page 74/105 | < Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >

  • Shuffle array variables in a pre-specified order, without using extra memory of "size of input array"

    - by Eternal Learner
    Input : A[4] = {0,4,-1,1000} - Actual Array P[4] = {1,0,3,2} - Order to be reshuffled Output: A[4] = {4,0,1000,-1} Condition : Don't use an additional array as memory. Can use an extra variable or two. Problem : I have the below program in C++, but this fails for certain inputs of array P. #include<iostream> using namespace std; void swap(int *a_r,int *r) { int temp = *r; *r = *a_r; *a_r = temp; } int main() { int A[4] = {0,4,-1,1000}; int P[4] = {3,0,1,2}; int value = A[0] , dest = P[0]; for(int i=0; i<4;i++) { swap(&A[dest],&value); dest = P[dest]; } for(int i=0;i<4;i++) cout<<A[i]<<" "; }

    Read the article

  • JBoss 4.0.5 startup takes 15 minutes deploying a single war file

    - by dkblinux98
    This instance of JBoss deploys several war files. The rest of the JBoss startup takes about 5 minutes or less. But when it gets to one particular war file, startup just hangs with no further output to the jboss log. It waits there for about 15 minutes and then suddenly the war starts deploying. The rest of the JBoss startup is then fine. What I want to know is what steps do you recommend I take to diagnose the cause of this condition? It is not possible to upgrade this site to a newer version of JBoss nor java (currently 1.5.0.7). It is running on 32-bit CentOS 5.3 Linux on 3 xen-based virtual servers in a load balanced configuration. The code is common to all three servers via an nfs share. This same issue was seen, however, when the 3 servers were physical and the code was local to each server. The servers are each 2 cpu, 4GB RAM servers.

    Read the article

  • Header files in C++

    - by user269037
    Hi, I am making a simulator and have written lots of files and headers. The problem is whenever I include a file I give the relative path of the particular file. For example a typical code in my application would begin like ifndef AI_H define AI_H include include "../world/world.h" include "pathPlan.h" include "skills/tryskill.h" include "../info/condition.h" include "dataStructures/destination.h" include "../params/gamePlay.h" include "../modules/controlModule.h" class ai { public: etc etc I want to avoid using the relative paths. For example I want to directly include "tryskill.h" and "destination.h" without giving the absolute paths. That way I wont need to bother if I change the location of any particular file. I am using Ubuntu 9.10. Any help would be highly appreciated.

    Read the article

  • How to perform dynamic formatting with perl during write?

    - by Bee
    I have a format which is defined like below: format STDOUT = ------------------------------------ |Field1 | Field2 | Field3 | ------------------------------------ |@<<<<<<<<<<| @<<<<<<<<<<<| @<<<<< |~~ shift(@list1),shift(@list2),shift(@list3) ------------------------------------ . write STDOUT; So the questions are as below: Is it possible to make the list of values printed dynamic? e.g. If list 1 contains 12 elements, and if $flag1 is defined, then print only elements 0..10 instead of all 12. I tried doing this by passing $flag as a parameter to the sub which generates the report. However, the last defined FORMAT seems to always take precedence and the final write when it happens, applies the last format no matter what the condition is. Is it possible to also add/hide fields using the same process. e.g. If $flag2 is defined, then add an additional field Field4 to the list?

    Read the article

  • Php inside javascript function

    - by jasminder
    What i am trying to do is inside script tags run javascript inside the php loops. For example: <script> $('#mydiv').mouseover(function(){ time(); function time(){ <?php $secs = 45; $secs--; if($secs <= 25){ ?>//javascript code here } }); </script> My main purpose is when the user mouseover a div, a javascript function runs and inside that javascript function there is php if conitions. If the time is less then 25 then do a specified javascript code. then another condition if the time is less that 10 then do another javascript function.Any type of help will be appreciated. THanks

    Read the article

  • MySQL AND alternative for eatch table in a join

    - by Scott
    I have a simple join in a query however I need to have a condition on both of the tables "confirmed='yes'" but if one of the tables doesn't have any that match the query returns with no rows. Database: .----------parties----------. | id - party_id - confirmed | |---------------------------| | 1 1 yes | | 1 2 no | | 1 3 no | +---------------------------+ .-----------events----------. | id - event_id - confirmed | |---------------------------| | 1 1 no | +---------------------------+ Query: SELECT p.party_id, e.event_id FROM parties p LEFT JOIN events e ON p.id=e.id WHERE p.id = '1' AND p.party_id IN (1,2,3) AND e.event_id IN (1) AND p.confirmed='yes' AND e.confirmed='yes' It returns nothing but I want it to return party_id 1 with a empty event_id. I hope this make sense and I not missing anything, Thanks for your help!

    Read the article

  • looping and arrays

    - by user1838418
    Hi I'm trying to construct a loop to execute 16 states of the 8 4 2 1 code in (C++) while( condition) { double Bubble[16], Bubble1[16]; Bubble[0] = ( a-2 - (b-2) ) + ( c-2 - (d-2)); // represents 0000 Bubble[1] = ( a-2 - (b-2) ) + ( c-2 - (d+2)); // represents 0001 Bubble[2] = ( a-2 - (b-2) ) + ( c+2 - (d-2)); // represents 0010 Bubble[3] = ( a-2 - (b-2) ) + ( c+2 - (d+2)); //represents 0011 ....... Bubble[15] =(a+2 - (b+2) ) + ( c+2 - (d+2)); //represents 1111 } Is there an easy way of coding using for loops? instead of writing bubble[] every time? 0 stands for -2 and 1 stands for +2. So I have 4 variables and each one need to be incremented and/or decremented. Can this be done using for loop? Appreciate your help

    Read the article

  • typedef to store pointers in C

    - by seriouslion
    The Size of pointer depends on the arch of the machine. So sizeof(int*)=sizeof(int) or sizeof(int*)=sizeof(long int) I want to have a custom data type which is either int or long int depending on the size of pointer. I tried to use macro #if, but the condition for macros does not allow sizeof operator. Also when using if-else, typedef is limited to the scope of if. if((sizeof(int)==sizeof(int *)){ typedef int ptrtype; } else{ typedef long int ptrtype; } //ptrtype not avialble here Is there any way to define ptrtype globally?

    Read the article

  • Using LINQ to filter rows of a matrix based on inclusion in an array

    - by Bob Feng
    I have a matrix, IEnumerable<IEnumerable<int>> matrix, for example: { {10,23,16,20,2,4}, {22,13,1,33,21,11 }, {7,19,31,12,6,22}, ... } and another array: int[] arr={ 10, 23, 16, 20} I want to filter the matrix on the condition that I group all rows of the matrix which contain the same number of elements from arr. That is to say the first row in the matrix {10,23,16,20,2,4} has 4 numbers from arr, this array should be grouped with the rest of the rows with 4 numbers from arr. better to use linq, thank you very much!

    Read the article

  • How should I use try...except while defining a function?

    - by SpawnCxy
    Hi all, I find I've been confused by the problem that when I needn't to use try..except.For last few days it was used in almost every function I defined which I think maybe a bad practice.For example: class mongodb(object): def getRecords(self,tname,conditions=''): try: col = eval("self.db.%s" %tname) recs = col.find(condition) return recs except Exception,e: #here make some error log with e.message What I thought is ,exceptions may be raised everywhere and I have to use try to get them. And my question is,is it a good practice to use it everywhere when defining functions?If not are there any principles for it?Help would be appreciated! Regards

    Read the article

  • Break the limit of threading, segmentation fault

    - by user353573
    use pthread_create to create limited number of threads running concurrently Successfully compile and run However, after adding function pointer array to run the function, Segmentation fault Where is wrong? workserver number: 0 Segmentation fault void* workserver(void arg) { int status; while(true) { printf("workserver number: %d\n", (int)arg); ( job_queue[(int)arg])(); sleep(3); status = pthread_mutex_lock(&data.mutex); if(status != 0) printf("%d lock mutex", status); data.value = 1; status = pthread_cond_signal(&data.cond); if(status != 0) printf("%d signal condition", status); status = pthread_mutex_unlock(&data.mutex); if(status != 0) printf("%d unlock mutex", status); } }

    Read the article

  • How can I avoid explicitly declaring directory paths in C or C++ #include directives?

    - by user269037
    Hi, I am making a simulator and have written lots of files and headers. The problem is whenever I include a file I give the relative path of the particular file. For example a typical code in my application would begin like #ifndef AI_H #define AI_H #include <cstdlib> #include "../world/world.h" #include "pathPlan.h" #include "skills/tryskill.h" #include "../info/condition.h" #include "dataStructures/destination.h" #include "../params/gamePlay.h" #include "../modules/controlModule.h" class ai { public: etc etc I want to avoid using the relative paths. For example I want to directly include "tryskill.h" and "destination.h" without giving the absolute paths. That way I wont need to bother if I change the location of any particular file. I am using Ubuntu 9.10. Any help would be highly appreciated.

    Read the article

  • NSMutableArray of Objects misbehaves ...

    - by iFloh
    I hope someone understands what happens to my NSMutableArray. I read records a, b, c, d from a database, load the fields into an object an add the object to an array. To do this I read the records into an instance of that object (tmpEvent) and add the Object to the target array (NSMutableArray myArray). the code looks like: for (condition) { tmpEvent.field1 = [NSString stringWithUTF8String:(char*)sqlite3_column_text(stmt, 0)]; tmpEvent.field2 = [NSString stringWithUTF8String:(char*)sqlite3_column_text(stmt, 1)]; tmpEvent.field3 = [NSString stringWithUTF8String:(char*)sqlite3_column_text(stmt, 2)]; NSLog(@"myArray: adding %@", tmpEvent.field1); [myArray addObject:tmpEvent]; } The NSLog shows myArray: adding a myArray: adding b myArray: adding c myArray: adding d Subsequent I enumerate the array (this can be in the same or a different method): for (myObject *records in myArray) { NSLog(@"iEvents value %@", records.field1); } The NSLog now shows: myArray value d myArray value d myArray value d myArray value d a mystery .... ??? any thoughts?

    Read the article

  • reterview data from two tables using inner join in cakephp

    - by user3593884
    I two tables from database one as user(id,first_name,last_name) and the second table location(id,country). I need to perform inner join with this two tables and the list should display first_name,last_name,country with condition user.id=location.id I have written sql queries in cakephp $this->set('users',$this->User->find('list', array( 'fields' => array('User.id', 'User.first_name','location.country'), array('joins' => array(array('table' => 'location', 'alias' => 'location', 'type' => 'INNER', 'conditions' => array('User.id = location.id'))))))); i get error -Unknown column 'location.country' in 'field list' Please help!

    Read the article

  • MYSQL to UPDATE table if row with 2 specific columns exist or INSERT new row if it does not exist

    - by user2509541
    I have a MYSQL table that looks as follows: id id_jugador id_partido team1 team2 1 2 1 5 2 2 2 2 1 1 3 1 2 0 0 I need to create a query to either INSERT new rows in the table or UPDATE the table. The condition is based on id_jugador and id_partido, meaning that if I wanted to insert id_jugador = 2 and id_partido = 1, then it should just UPDATE the existing row with the new team1 and team2 values I am sending. And dont duplicate the row. However, if I have an entry id_jugador=2 and id_partido=3, since this combination does not exist yet, it should add the new row. I read about the REPLACE INTO but it seems to be unable to check combination of UNIQUE KEYS.

    Read the article

  • Why use a "do while" loop?

    - by Stanni
    Hi, I've never understood why using a do while loops is necessary. I understand what they do, Which is to execute the code that the while loop contains without checking if the condition is true first. But isn't the below code: do{ document.write("ok"); } while(x == "10"){ document.write("ok"); } The exact same as: document.write("ok"); while(x == "10"){ document.write("ok"); } Maybe I'm being very stupid and missing something obvious out but I don't see the benefit of using do while over my above example.

    Read the article

  • MySQL AND alternative for each table in a join

    - by Scott
    I have a simple join in a query however I need to have a condition on both of the tables "confirmed='yes'" but if one of the tables doesn't have any that match the query returns with no rows. Database: .----------parties----------. | id - party_id - confirmed | |---------------------------| | 1 1 yes | | 1 2 no | | 1 3 no | +---------------------------+ .-----------events----------. | id - event_id - confirmed | |---------------------------| | 1 1 no | +---------------------------+ Query: SELECT p.party_id, e.event_id FROM parties p LEFT JOIN events e ON p.id=e.id WHERE p.id = '1' AND p.party_id IN (1,2,3) AND e.event_id IN (1) AND p.confirmed='yes' AND e.confirmed='yes' It returns nothing but I want it to return party_id 1 with a empty event_id. I hope this make sense and I not missing anything, Thanks for your help!

    Read the article

  • What is the best way to programmatically run javascript when an ASP.net page loads?

    - by Rising Star
    In my global.asax file for my ASP.net project, I am checking for certain conditions. When those conditions are met, I want to automatically execute javascript code when the page runs. This is my code: if condition Then Response.Write("") Response.Write(" // Javascript code to do stuff ") Response.Write("") End If While this appears to work to execute the Javascript code, I don't think it's a best practice because this code will preceed all of the HTML of the page that gets loaded. What is the best way of programmatically tacking on some extra Javascript code to be run when my page loads?

    Read the article

  • Counting values in data frame subject to conditions

    - by unixsnob
    I have been searching around and I cannot figure out how to sumarise the data I have in my data frame (subject to some ranges). I know that it can be done when applying some combination of daaply/taaply or table but I haven't been able to get the exact result I was expecting. Basically I want to turn this: part_no val1 val2 val3 2 1 2 3 45.3 2 1 3 4 -12.3 3 1 3 4 99.3 3 1 5 2 -3.2 3 1 4 3 -55.3 Into this: part_no val3_between0_50 val3_bw50_100 val3_bw-50_0 val3_bw-100_-50 2 1 0 0 1 0 3 0 1 0 1 1 This is dummy data, I got a lot more rows, but the idea is the same. I just want to count the number of values for a participant that meet certain condition. If anyone could explain it sort of step by step, I would really appreciate it. I saw lots of different little posts around, but none do exactly this and my attempts only got me half way there. Like using table, etc. Thanks!

    Read the article

  • How to explain to a developer that adding extra if - else if conditions is not a good way to "improv

    - by Lilit
    Recently I've bumped into the following C++ code: if (a) { f(); } else if (b) { f(); } else if (c) { f(); } Where a, b and c are all different conditions, and they are not very short. I tried to change the code to: if (a || b || c) { f(); } But the author opposed saying that my change will decrease readability of the code. I had two arguments: 1) You should not increase readability by replacing one branching statement with three (though I really doubt that it's possible to make code more readable by using else if instead of ||). 2) It's not the fastest code, and no compiler will optimize this. But my arguments did not convince him. What would you tell a programmer writing such a code? Do you think complex condition is an excuse for using else if instead of OR?

    Read the article

  • Any way to break if statement in PHP?

    - by Usman
    Is there any command in PHP to stop executing the current or parent if statement, same as break or break(1) for switch/loop. For example $arr=array('a','b'); foreach($arr as $val) { break; echo "test"; } echo "finish"; in the above code PHP will not do echo "test"; and will go to echo "finish"; I need this for if $a="test"; if("test"==$a) { break; echo "yes"; // I don't want this line or lines after to be executed, without using another if } echo "finish"; I want to break the if statement above and stop executing echo "yes"; or such codes which are no longer necessary to be executed, there may be or may not be an additional condition, is there way to do this?

    Read the article

  • Can I override a group policy setting as a machine admin?

    - by Max
    Group policy prevents several configuration settings on my Windows 7 / Vista machines. Since my domain account is a member of the local Administrators group on these boxes, is there still a way to override them locally? For instance, GP prevents changing the power management option "Turn off the display" (even changing it from cmd fails: POWERCFG -X -monitor-timeout-ac 60 = "An unexpected error condition has occurred. Unable to perform operation. You may not have permission to perform this operation.") Even when logging on with a local account and not the domain account, it's not possible to change the setting anymore ..

    Read the article

  • Problem with Nulls and an UPDATE statement

    - by Dave
    UPDATE TableA SET Value = a.Value * b.AnotherValue FROM TableA AS a INNER JOIN TableB AS b WHERE (Condition is true); Here is the problem. The Value field for TableA does not allow nulls. If the calculation of a.Value * b.AnotherValue yields a null, an error is thrown. Now the question. Is there any way to tell the UPDATE to ignore the SET phase when the result of the calculation is a null and delete the record rather than updating it. This UPDATE is intended to update hundreds of records at a time but will fail if a single null is encountered. Also, please note that using the ISNULL() function and setting the Value to zero is not acceptable. I would like the record to be dropped if a null is encountered. Many thanks in advance for any help rendered.

    Read the article

  • finding elements in python association lists efficiently

    - by user248237
    I have a set of lists that look like this: conditions = [ ["condition1", ["sample1", "sample2", "sample3"]], ["condition2", ["sample4", "sample5", "sample6"], ...] how can I do the following things efficiently and elegantly in Python? Find all the elements in a certain condition? e.g. get all the samples in condition2. Right now I can do: for cond in conditions: cond_name, samples = cond if cond_name == requested_cond: return samples but that's clunky. Find the ordered union of a list of conditions? E.g. ordered_union(["condition1", "condition2"], conditions) should return: ["sample1", "sample2", "sample3", "sample4", "sample5", "sample6"] How can I do this efficiently in Python? There are probably clever one liners?

    Read the article

  • How to predict result set row count?

    - by Saurabh Kumar
    I have an application where I create a big SQL query dynamically for SQL server 2008. This query is based on various search criteria which the user might give such as search by lastname, firstname, ssn etc. The requirement is that if the user gives a condition due to which the formed query might return a lot of rows(configurable for max N rows), then the application must send back a message instead to the user saying that he needs to refine his search query as the existing query will return too many rows. I would not want to bring back say, 5000 rows to the client and then discard that data just to show the user an error. What is an efficient way to tackle this issue?

    Read the article

< Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >