Search Results

Search found 834 results on 34 pages for 'looping'.

Page 18/34 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • class method or named_scope?

    - by Hadi
    i would like to have your opinion in a project i am currently working on. class Product has_many :orders end class Order attr_accessor :deliverable # to contain temporary data on how many items can be delivered for this order belongs_to :product end somehow i want to have Order.all_deliverable that will calculate the Product's quantity, subtract from list of Orders until the Product is empty or there is no more Order for this Product to illustrate Product A, quantity: 20 Product B, quantity: 0 Order 1, require Product A, quantity: 12 Order 2, require Product B, quantity: 10 Order 3, require Product A, quantity: 100 so if i call Order.all_deliverable, it will give Order 1, deliverable:12 Order 3, deliverable: 8 #(20-12) i have been thinking on using named_scope, but i think the logic will be too complex to be put in a named_scope. Any suggestion? the pseudo code for all_deliverable will be something like this: go to each orders find the remaining quantity for specific product deduct the product to max amount of order, if product is not enough, add the maximum product add to the order end From what i read around in the web, named_scope deal mostly like find and have not many method calling and looping.

    Read the article

  • Edit Distance in Python

    - by Alice
    I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. I know I need to start by generating a list with an edit distance of one from the invalid word(and then run that again on all the generated words). I have three methods, inserts(...), deletions(...) and changes(...) that should output a list of words with an edit distance of 1, where inserts outputs all valid words with one more letter than the given word, deletions outputs all valid words with one less letter, and changes outputs all valid words with one different letter. I've checked a bunch of places but I can't seem to find an algorithm that describes this process. All the ideas I've come up with involve looping through the dictionary list multiple times, which would be extremely time consuming. If anyone could offer some insight, I'd be extremely grateful. Thanks!

    Read the article

  • [PHP] access array element by value

    - by Brandon
    array( [0] name => 'joe' size => 'large' [1] name => 'bill' size => 'small' ) I think i'm being thick, but to get the attributes of an array element if I know the value of one of the keys, I'm first looping through the elements to find the right one. foreach($array as $item){ if ($item['name'] == 'joe'){ #operations on $item } } I'm aware that this is probably very poor, but I am fairly new and am looking for a way to access this element directly by value. Or do I need the key? Thanks, Brandon

    Read the article

  • Cloning java ArrayList and preventing it from modifications

    - by user222164
    I have a data structure like a database Rowset, which has got Rows and Rows have Columns. I need to initialize a Columns with null values, current code is to loop thru each column for a row and initialize values to NULL. Which is very inefficient if you have 100s or rows and 10s of column. So instead I am keeping a initialized ArrayList of columns are RowSet level, and then doing a clone of this Arraylist for individual rows, as I believe clone() is faster than looping thru each element. row.columnsValues = rowsset.NullArrayList.clone() Problem with this is NullArrayList can be accidentally modified after being cloned, thus sacrificing the integrity of ArrayList at RowSet level, to prevent I am doing 3 things 1) Delcaring ArrayList as final 2) Any elements I insert are final or null 3) Methods thurough this arrayList are passed to other arrays are declared a final. Sounds like a plan, do you see any holes ?

    Read the article

  • Evaluating a regular expression range

    - by Dan Atkinson
    Hi there! Is there a nice way to evaluate a regular expression range, say, for a url such as http://example.com/[a-z]/[0-9].htm This would be converted into: http://example.com/a/0.htm http://example.com/a/1.htm http://example.com/a/2.htm ... http://example.com/a/9.htm ... http://example.com/z/0.htm http://example.com/z/1.htm http://example.com/z/2.htm ... http://example.com/z/9.htm I've been scratching my head about this, and there's no pretty way of doing it without going through the alphabet and looping through numbers. Thanks in advance!

    Read the article

  • SQL bottleneck, how to fix

    - by masfenix
    This is related to my previous thread: http://stackoverflow.com/questions/3069806/sql-query-takes-about-10-20-minutes However, I kinda figured out the problem. The problem (as described in the previous thread) is not the insert (while its still slow), the problem is looping through the data itself Consider the following code: Dim rs As DAO.Recordset Dim sngStart As Single, sngEnd As Single Dim sngElapsed As Single Set rs = CurrentDb().QueryDefs("select-all").OpenRecordset MsgBox "All records retreived" sngStart = Timer Do While Not rs.EOF rs.MoveNext Loop sngEnd = Timer sngElapsed = Format(sngEnd - sngStart, "Fixed") ' Elapsed time. MsgBox ("The query took " & sngElapsed _ & " seconds to run.") As you can see, this loop does NOTHING. You'd expect it to finish in seconds, however it takes about 857 seconds to run (or 15 minutes). I dont know why it is so slow. Maybe the lotusnotes sql driver? any other ideas? (java based solution, any other solution) What my goal is: To get all the data from remote server and insert into local access table

    Read the article

  • Getting clusters of rows close together in time

    - by Mike
    I have a table basically like so ID | ItemID | Start | End | --------------------------------------------------------------- 1 234 10/20/09 8:34:22 10/20/09 8:35:10 2 274 10/20/09 8:35:30 10/20/09 8:36:27 3 272 10/21/09 12:15:00 10/21/09 12:17:00 4 112 10/21/09 12:20:14 10/21/09 12:21:21 5 15 10/21/09 12:22:39 10/21/09 12:24:15 There are two "clusters" of entries here, 1-2 and 3-5 separated by a gap in time, specifically 30 minutes is what I'm interested in. What I would like is the first and last rows of the cluster of entries. This is fairly easy to achieve by retrieving all the rows and looping through them in order of start time, but I'd like to have it in SQL if possible. I'm using SQL Server 2008, thanks.

    Read the article

  • MySqlDataAdapter or MySqlDataReader for bulk transfer?

    - by Jeff Meatball Yang
    I'm using the MySql connector for .NET to copy data from MySql servers to SQL Server 2008. Has anyone experienced better performance using one of the following, versus the other? DataAdapter and calling Fill to a DataTable in chunks of 500 DataReader.Read to a DataTable in a loop of 500 I am then using SqlBulkCopy to load the 500 DataTable rows, then continue looping until the MySql record set is completely transferred. I am primarily concerned with using a reasonable amount of memory and completing in a short amount of time. Any help would be appreciated!

    Read the article

  • XSLT: If Node = A then set B=1 Else B=2

    - by Larry
    I am looping thru looking at the values of a Node. If Node = B, then B has one of two possible meanings. --If Node = A has been previously found in the file, then the value for A should be sent as 1. --If Node = A has NOT been found in the file, the the value for A should be sent as 2. where file is the xml source to be transformed I cannot figure out how to do this. If I was using a programming language that allowed for a variable to have its value reassigned/changed, then it is easy. But, with XSLT variables are set once.

    Read the article

  • jquery hover issue

    - by jay
    hi, i have mouseover issues sometimes when i move my mouse fast over links it loops for quite a while, is there a way to only loop if mouse is stil over and stop if the mouse is not. $('ul.display li').hover(function() { $('ul.display li').find('#details').hide(); // hides all deatils div before showing $('#light').delay('800').fadeIn("fast"); // shows div that fades out all other content. if($.cookie("switch_thumb") =="thumb_view" || $.cookie("switch_thumb") =="null"){//checks for cookie set for display type $(this).find('#details').delay('900').animate({width:'toggle'}); // grow width }else{ $(this).find('#details').delay('900').animate({height:'toggle'}); // grow height } }, function() { $('#light').fadeOut("fast"); // dim the light to show all content $('ul.display li').find('#details').hide(); //hide all details return false; // supposed to stop looping. });

    Read the article

  • getting a date array from a mysql database?

    - by user296516
    Hi guys, I have a database with date field is this format "2010.06.11. | 10:26 13" What is need is a php array that would hold all the different dates, .i.e. array[0] = "2010.06.09." array[1] = "2010.06.10." array[2] = "2010.06.11." Currently I am doing it by selecting the whole table, then looping through the result and adding the date substr to an array if it is not already there. But maybe there is a faster way? Thanks.

    Read the article

  • Handle order dependence in for loops

    - by Matt
    Hey all, I'm making a templating system where I instantiate each tag using a foreach loop. The issue is that some of the tags rely on each other so, I'm wondering how to get around that ordering from the looping. Here's an example: Class A { public $width; __construct() { $this->width = $B->width(); // Undefined! Or atleast not set yet.. } } Class B { private $width; __construct() { $this->width = "500px"; } __tostring() { return "Hello World!"; } } Template.php $tags = array("A", "B"); foreach ($tags as $tag) { $TagObj[$tag] = new $tag(); } echo $TagObj['A']->width; // Nadamundo! I know this has applications elsewhere and I'm sure this has been solved before, if someone could enlighten me or point me in the right direction that'd be great! Thanks! Matt Mueler

    Read the article

  • Drawbacks with reading and writing a big file to or from disk at once instead of small chunks?

    - by Johann Gerell
    I work mainly on Windows and Windows CE based systems, where CreateFile, ReadFile and WriteFile are the work horses, no matter if I'm in native Win32 land or in managed .Net land. I have so far never had any obvious problem writing or reading big files in one chunk, as opposed to looping until several smaller chunks are processed. I usually delegate the IO work to a background thread that notifies me when it's done. But looking at file IO tutorials or "textbook examples", I often find the "loop with small chunks" used without any explanation of why it's used instead of the more obvious (I dare to say!) "do it all at once". Are there any drawbacks to the way I do that I haven't understood?

    Read the article

  • Custom field not showing in Custom Content Type

    - by BeraCim
    Hi all: I created a custom column in a custom content type in a Sharepoint Web manually (e.g. /MySite/MyWeb). I now want to programmatically copy this content type across to another web (e.g. /MySite/MyWeb2). However, upon looping through the custom content type in code, I could only find 2 fields: Content Type and Title (expected: Title and custom column). The custom column was missing. I'm very sure that the content type and field are added at the web level. The custom content type is inherited from Item. When I loop through the web's fields, I can see the custom column, and that was copied to the new web. It is only within the content type that the custom column is not showing up. Any ideas why this is happening? Thanks.

    Read the article

  • iPhone SDK Nested For Loop performance

    - by Skeep
    Hi All, I have a NSArray of string id and a NSDictionary of NSDictionary objects. I am currently looping through the string id array to match the id value in the NSDictionary. There are around 200 NSDictionary objects and only 5 or so string ID. My current code is such: for (NSString *Str in aArr) { for (NSDictionary *a in apArr) { if ([a objectForKey:@"id"] == Str) { NSLog(@"Found!"); } } } The performance of the above code is really slow and I was wondering if there is a better way to do this?

    Read the article

  • is my function correct?

    - by sbsp
    This is part of an assignment so please dont post solutions, just point me in the right direction if possible? I am passing a pointer to a char array to my method, as well as a value for the actual height of the char array. I am looping through to see if all values are 0, if they are then return 0, esle return one The method is used as a test to see if i should free memory or not and set the pointer to null if it is full of 0's. The issue i am having is that the programme should have "some unfree" memory at the end, so i have no idea whether or not its doing it correctly - and gdb i struggle with immensley. Thanks for reading int shouldBeNull(char *charPointer, int sizeOfCharArray) { int isIn = 0; int i = 0; while(i < sizeOfCharArray){ if(*charPointer != '0'){ isIn = 1; break; } i++; charPointer++; } return isIn; }

    Read the article

  • Comparing two collection lists

    - by Eric
    I've been at this for few hors now and can't seem to find a solution. I have 2 invnetory lists, one a spreadsheet and the other data table. I need to match the spreadsheet agains the data table to find out if I have missing inventory. The spreadsheet should match with what I have in the db, ie the spreadsheet is like a master so when I have missing inventory in DB I need to add it an list and build a report. I thought by looping throught the spreadsheet and for each inventory in the spreadsheet loop through the data table I can achieve my goal but that proved to be wrong. Any ideas how I would do this? Thanks, Eric

    Read the article

  • .Remove(object) on a List<T> returned from LINQ to SQL compiled query won't delete the Object right

    - by soldieraman
    I am returning two lists from the database using LINQ to SQL compiled query. While looping the first list I remove duplicates from the second list as I dont want to process already existing objects again. eg. //oldCustomers is a List returned by my Compiled Linq to SQL Statmenet that I have added a .ToList() at the end to //Same goes for newCustomers for (Customer oC in oldCustomers) { //Do some processing newCustomers.Remove(newCusomters.Find(nC=> nC.CustomerID == oC.CusomterID)); } for (Cusomter nC in newCustomers) { //Do some processing } DataContext.SubmitChanges() I expect this to only save the changes that have been made to the customers in my processing and not Remove or Delete any of my customers from the database. Correct? I have tried it and it works fine - but I am trying to know if there is any rare case it might actually get removed

    Read the article

  • Graph - strongly connected components

    - by HardCoder1986
    Hello! Is there any fast way to determine the size of the largest strongly connected component in a graph? I mean, like, the obvious approach would mean determining every SCC (could be done using two DFS calls, I suppose) and then looping through them and taking the maximum. I'm pretty sure there has to be some better approach if I only need to have the size of that component and only the largest one, but I can't think of a good solution. Any ideas? Thanks.

    Read the article

  • Lock HTML select element, allow value to be sent on submit

    - by ILMV
    I have a select box (for a customer field) on a complex order form, when the user starts to add lines to the order they should not be allowed to change the customer select box (unless all lines are deleted). My immediate thought was that I could use the disabled attribute, but when the box is disabled the selected value is no longer passed to the target. When the problem arose a while ago one of the other developers worked around this by looping through all the options and disabling all but the selected option, and sure enough the value was passed to the target and we've been using since. But now I'm looking for a proper solution, I don't want to loop through all the options because are data is expanding and it's starting to introduce performance issues. I'd prefer not to enable this / all the elements when the submit button is hit. How can I lock the input, whilst maintaining the selected option and passing that value to the target script? I would prefer a non-JavaScript solution if possible, but if needed we are running jQuery 1.4.2 so that could be used.

    Read the article

  • Minimizing SQL queries using join with one-to-many relationship

    - by Brian
    So let me preface this by saying that I'm not an SQL wizard by any means. What I want to do is simple as a concept, but has presented me with a small challenge when trying to minimize the amount of database queries I'm performing. Let's say I have a table of departments. Within each department is a list of employees. What is the most efficient way of listing all the departments and which employees are in each department. So for example if I have a department table with: id name 1 sales 2 marketing And a people table with: id department_id name 1 1 Tom 2 1 Bill 3 2 Jessica 4 1 Rachel 5 2 John What is the best way list all departments and all employees for each department like so: Sales Tom Bill Rachel Marketing Jessica John Pretend both tables are actually massive. (I want to avoid getting a list of departments, and then looping through the result and doing an individual query for each department). Think similarly of selecting the statuses/comments in a Facebook-like system, when statuses and comments are stored in separate tables.

    Read the article

  • Searching through Collections in Java

    - by Click Upvote
    I have a java properties file containing a key/value pair of country names and codes. I will load the contents of this file into a Collection like List or HashMap. Then, I want users to be able to search for a country, e.g if they type 'Aus' in a textbox and click submit, then I want to search through the collection I have, containing a key/value pair of country codes/names (e.g AUS=Australia), and return those countries which are found matching. Is there any more efficient way of doing this, other than looping through the elements of the collection and using charAt()?

    Read the article

  • numpy.equal with string values

    - by Morgoth
    The numpy.equal function does not work if a list or array contains strings: >>> import numpy >>> index = numpy.equal([1,2,'a'],None) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: function not supported for these types, and can't coerce safely to supported types What is the easiest way to workaround this without looping through each element? In the end, I need index to contain a boolean array indicating which elements are None.

    Read the article

  • Binary search of unaccesible data field in ldap from python

    - by EricR
    I'm interested in reproducing a particular python script. I have a friend who was accessing an ldap database, without authentication. There was a particular field of interest, we'll call it nin (an integer) for reference, and this field wasn't accessible without proper authentication. However, my friend managed to access this field through some sort of binary search (rather than just looping through integers) on the data; he would check the first digit, check if it was greater or less than the starting value, he would augment that until it returned a true value indicating existence, adding digits and continuing checking until he found the exact value of the integer nin. Any ideas on how he went about this? I've access to a similarly set up database.

    Read the article

  • Adding classes to all form widgets in symfony

    - by rlahay
    Hi everyone, I am trying to find a better way to assign classes to form elements in symfony. Currently, I can't seem to get away from assigning each one manually. ie: $this->widgetSchema['title']->setAttribute("class","fieldInput"); $this->widgetSchema['tag_line']->setAttribute("class","fieldInput"); $this->widgetSchema['description']->setAttribute("class","fieldInput"); // etc Things I tried without success 1) looping through $this-widgetSchema, treating it as an array and setting attributes to each key 2) $this-widgetSchema-setAttribute() but this only applied the class to the label that was generated, not the form element There must be a way to hit all the fields without specifically directing them? Can anyone point me in the right direction?

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >