Inspecting what facebook is doing in my navigator, I see this code:
for (;;);{"t":"refresh"}
If you try to evaluate it, you can figure what happens (infinite loop).
Do you Know what it is?
I'm getting data from a database and I need to add the string field value and the record id.
However, I need this to work with some existing code...
I'm replacing this (see code below) and getting data from my database.
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.allCategories = dict;
[dict release];
But needs to work with these key and value search functions.
- (void)resetSearch {
NSMutableDictionary *allCategoriesCopy = [self.allCategories mutableDeepCopy];
self.Categories = allCategoriesCopy;
[allCategoriesCopy release];
NSMutableArray *keyArray = [[NSMutableArray alloc] init];
[keyArray addObject:UITableViewIndexSearch];
[keyArray addObjectsFromArray:[[self.allCategories allKeys]
sortedArrayUsingSelector:@selector(compare:)]];
self.keys = keyArray;
[keyArray release];
}
.
- (void)handleSearchForTerm:(NSString *)searchTerm {
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];
for (NSString *key in self.keys) {
NSMutableArray *array = [Categories valueForKey:key];
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (NSString *name in array) {
if ([name rangeOfString:searchTerm
options:NSCaseInsensitiveSearch].location
== NSNotFound)
[toRemove addObject:name];
}
if ([array count] == [toRemove count])
[sectionsToRemove addObject:key];
[array removeObjectsInArray:toRemove];
[toRemove release];
}
[self.keys removeObjectsInArray:sectionsToRemove];
[sectionsToRemove release];
[table reloadData];
}
Keep getting an error from this code...
NSDictionary *arrayTmp= [[NSDictionary alloc] init];
... loop records
int cid = sqlite3_column_int(statementTMP, 0);
NSString *category = [[NSString alloc]
initWithUTF8String:(char *)sqlite3_column_text(statementTMP, 1)];
[arrayTmp setObject:category forKey:[NSString stringWithFormat:@"%i", cid]];
Error caused by line above
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString count]: unrecognized selector sent to instance 0x4d4c500' * Call stack at first throw *
... end loop
self.allCategories = arrayTmp;
[arrayTmp release];
hello i have a issue and i want your help i have a table which is called citylink[10][2]
and i want to make a check before i move on in my code if it's full to continue if it's not to break!!i know that i should use an if loop but i don't know what to put inside it!!
i have a code like
res = doc.evalute(xpathExpr,doc,function(prefix) { return namespaces[prefix] || null;}, XPathResult.ANY_TYPE,null );
here doc is DOM document node
when i run for loop like this
for(i in doc)alert(i);
it gives evalute method
but when i tried to use this method on dom node it giving me error like
xpathResult not defined...
i'm working in android browser
thanks in advance....
I have a class variable called attributes which lists the instance variables I want to update in a database:
attributes = ['id', 'first_name', 'last_name', 'name', 'name_url',
'email', 'password', 'password_salt', 'picture_id']
Each of the class attributes are updated upon instantiation.
I would like to loop through each of the attributes and build a MySQL update query in the form of:
UPDATE members SET id = self._id, first_name = self._first name ...
Thanks.
I thought about this: Is there a performance difference in these two practices:
Store the return value of a function in a temporary variable than
give that variable as a parameter to another function.
Put the function into the other function.
Specification
Assuming all classes and functions are written correctly.
Case 1.
ClassA a = function1();
ClassB b = function2(a);
function3(b);
Case 2.
function3(function2(function1()));
I know there aren't a big difference with only one run, but supposed that we could run this a lot of times in a loop, I created some tests.
Test
#include <iostream>
#include <ctime>
#include <math.h>
using namespace std;
int main()
{
clock_t start = clock();
clock_t ends = clock();
// Case 1.
start = clock();
for (int i=0; i<10000000; i++)
{
double a = cos(1);
double b = pow(a, 2);
sqrt(b);
}
ends = clock();
cout << (double) (ends - start) / CLOCKS_PER_SEC << endl;
// Case 2.
start = clock();
for (int i=0; i<10000000; i++)
sqrt(pow(cos(1),2));
ends = clock();
cout << (double) (ends - start) / CLOCKS_PER_SEC << endl;
return 0;
}
Results
Case 1 = 6.375
Case 2 = 0.031
Why is the first one is much slower, and if the second one is faster why dont we always write code that way? Anyway does the second pratice has a name?
I also wondered what happens if I create the variables outside the for loop in the first case, but the result was the same. Why?
I have a DGV with columns "code" and "name".
Depends of lenght of a code I want to add tabulation to the "name" cells, to show structure of a data.
Like that in this picture:
How is it better to do? I think there is a better way then just loop for all rows and add spaces in front of names, right?
i have a string initialized by {'\0'} every time i a loop and store some chars in it ranging from 0 to 9 when i convert atoi(temp) where temp="2" it returns me 20 instead of 2 what i have to do to get the accurate values, help required.
I have 2 perl modules every module use the second one i.e
Module1.pm
use Module2
Module2.pm
use Module1
did i enter infinte loop of loading modules or what happen on the background.
I have a routine that parses text via a loop. At the end of each record I need to clear my string variables but I read that someString = @"" actually just points to a new string & causes a memory leak.
What is the best way to handle this? Should I rather use mutable string vars and use setString:@"" between iterations?
i save a user like this in doctrine:
$user = User();
$user->name = 'peter';
$user->save();
is there a way to save 20 users in one sql query?
or do i have to loop the above code 20 times hence creating 20 sql queries?
thanks
How can I reduce the amount of similar commands into a loop?
Something like
pictureBox7.BackColor = Color.FromArgb(187, 187, 187);
pictureBox9.BackColor = Color.FromArgb(187, 187, 187);
pictureBox10.BackColor = Color.FromArgb(187, 187, 187);
pictureBox11.BackColor = Color.FromArgb(187, 187, 187);
pictureBox12.BackColor = Color.FromArgb(187, 187, 187);
pictureBox13.BackColor = Color.FromArgb(187, 187, 187);
G2g for now, will add on later.
LINQ to SQL .Count takes way to much process time and decreases performances.
I am doing a recursive loop and for one child (lets call it parent) I have to check the number of children under it to make a decision if it should be included or not.
The Count is too slow 8 ms :( for 120 parent records.
Any ideas to make it quicker.
Hi,
I have Ienum which contains number Data inside it.
Attached the snapShot of Viual Studio, Enum that Contains Data:
Just to brief about the above image, eLevelData is the IEnumerable variable, in which I have my data .
Now I want to go to the data at index 4 or 5, but I don't want to use foreach loop. Any suggestions please.
Thanks,
Subhen
These languages do not support mutually recursive functions optimization 'natively', so I guess it must be trampoline or.. heh.. rewriting as a loop) Do I miss something?
UPDATE: It seems that I did lie about FSharp, but I just didn't see an example of mutual tail-calls while googling
Hi, i'm trying to include a number of images in my SWF file not by loading them but by embedding them in the SWF itself. I found the following instruction to do that:
[Embed(source="../graphics/images/ss0.png")]
private var SS0:Class;
Basically, i want to embed a different number of images each time. Is there a way to do that automatically (let's say inside a for loop) or do i have to type manually this instruction for each image i want to include?
So this is a simpler form of my problem.
Lets say I have 2 arrays. A= {1,2} and B={2,4,6}.
If A and B share an element then delete that element from B.
I know you can loop through and compare each element in A to each element in B, but there's got to be a better way!
What's your opinion about using #region folding using application semantic, instead of folding for "syntax".
For example:
#region Application Loop
#region User Management
#region This Kinf of stuffs
instead of
#region Private Routines
#region Public Properties
#region ThisRoutine // (Yes, I've seen this also!)
In this logic, I'm starting fold even routine bodies. I'm starting to love #region directive (even using #pragma region when using C++!).
I am working with MVC 3, Razor views and EditorFor templates.
I have three simple nested models:-
public class BillingMatrixViewModel
{
public ICollection<BillingRateRowViewModel> BillingRateRows { get; set; }
public BillingMatrixViewModel()
{
BillingRateRows = new Collection<BillingRateRowViewModel>();
}
}
public class BillingRateRowViewModel
{
public ICollection<BillingRate> BillingRates { get; set; }
public BillingRateRowViewModel()
{
BillingRates = new Collection<BillingRate>();
}
}
public class BillingRate
{
public int Id { get; set; }
public int Rate { get; set; }
}
The BillingMatrixViewModel has a view:-
@using System.Collections
@using WIP_Data_Migration.Models.ViewModels
@model WIP_Data_Migration.Models.ViewModels.BillingMatrixViewModel
<table class="matrix" id="matrix">
<tbody>
<tr>
@Html.EditorFor(model => Model.BillingRateRows, "BillingRateRow")
</tr>
</tbody>
</table>
The BillingRateRow has an Editor Template called BillingRateRow:-
@using System.Collections
@model IEnumerable<WIP_Data_Migration.Models.ViewModels.BillingRateRowViewModel>
@foreach (var item in Model)
{
<tr>
<td>
@item.BillingRates.First().LabourClass.Name
</td>
@Html.EditorFor(m => item.BillingRates)
</tr>
}
The BillingRate has an Editor Template:-
@model WIP_Data_Migration.Models.BillingRate
<td>
@Html.TextBoxFor(model => model.Rate,
new {style = "width: 20px"})
</td>
The markup produced for each input is:-
<input name="BillingMatrix.BillingRateRows.item.BillingRates[0].Rate" id="BillingMatrix_BillingRateRows_item_BillingRates_0__Rate" style="width: 20px;" type="text" value="0"/>
Notice the name and ID attributes the BillingRate indexes are handled nicely but the BillingRateRows has no index instead '.item.'. From my reasearch this is because the context has been pulled out due to the foreach loop, the loop shouldn't be necessary.
I want to achieve:-
<input name="BillingMatrix.BillingRateRows[0].BillingRates[0].Rate" id="BillingMatrix_BillingRateRows_0_BillingRates_0__Rate" style="width: 20px;" type="text" value="0"/>
If I change the BillingRateRow View to:-
@model WIP_Data_Migration.Models.ViewModels.BillingRateRowViewModel
<tr>
@Html.EditorFor(m => Model.BillingRates)
</tr>
It will throw an InvalidOperationException, 'model item passed into the dictionary is of type System.Collections.ObjectModel.Collection [BillingRateRowViewModel] but this dictionary required a type of BillingRateRowViewModel.
Can anyone shed any light on this?
I am currently using find() and first() method to select the first descendent element from each of the <div> elements that contains the parent class. But I find this quite cumbersome since find() method would produce a set of matched elements before the first element is being picked. The following is the skeleton of my code:
HTML
<div class=parent>
<ul>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
</ul>
</div>
<div class=parent>
<ul>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
</ul>
</div>
<div class=non-parent>
<ul>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
</ul>
</div>
<div class=parent>
<ul>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
<li>random characters</li>
</ul>
</div>
// .....the list continues
Javascript
$('.parent').each(function() {
$(this).find('ul li').first().css('color', 'red');
// do other stuff within each loop
});
I have seen people using $(".parent li:first") selector. But, because I am doing it in a loop, I am not sure how or whether if this could be done and would like some advice. Thanks.
I am trying to delete all worksheet in excel exept last one and save it then move its location. I can not get it took work as it deletes all other worksheets but errors out with and out of range error.
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Open("C:\M-tek 10-31-12_Tony.xlsx")
i = objWorkbook.Worksheets.Count
Do while i = i
i = i - 1
objWorkbook.Worksheets(i).Delete
Loop
Now I use Select and use a criteria which select only new rows. But is there any kind of GetInsertedRows-method. If I remember correctly there is status for each row so naturally one can loop through them all but that's not elegant.
-Cheers -Matti
Hi,
Any ideas on gracefully stopping a windows service with mutli-threaded processing on a timer thread? Is it possible to add some infinite loop logic in the OnStop method to postpone the service shutting down.
i use this javascript syntax for validating a checkbox...
alert(document.getElementById("ctl00_ContentPlaceHolder1_Chkreg").checked);
if (document.getElementById("ctl00_ContentPlaceHolder1_Chkreg").checked == false) {
document.getElementById("ctl00_ContentPlaceHolder1_ErrorMsg").innerHTML = "please select the checkbox";
document.getElementById("ctl00_ContentPlaceHolder1_Chkreg").focus();
return false;
}
My alert showed me false but my if loop is not working... Any suggestion...