Thursday, April 12, 2012

How can I get all locations in a list that are not equal to a value(without using a for loop)?

okay not sure if there is a better way than I'm already doing. Right now I have a list(int[]) that has a over 10,000 values that equal 0 in it and I'm looking for only the non-zero items.



My current approach is just to do a for loop and capture all the non-zeros but I do this a lot, and profiling shows its taking a large amount of my cpu time(since I'm doing this so often). Is there a way I can get the same results without the expensive cpu process(since out 10,000 items, only less than 100 will be non-zeros)?



Here's an example of my data:



int[] list = {0,0,0,1,0,10 }
int[] list_names = {a,b,c,d,e,f}


All I need to ultimately do is use these two lists to create another two lists with only the non-zero values and their names(so D=1 and F=10). I've seen some solutions where I need to sort the results before it works but thats a problem because if I sort the data list then I cannot identify its name.



Is this possible and is there a faster way compared to a for loop?



Sorry I should mention that this large lists remain in my program for processing and I'm trying to do this to reduce the memory footprint of them. I have a queue of a few hundred million of these lists being stored in their entirety when all I really need is the non-zero values, so doing this to save memory(which seems to be working) but I'm also trying not to take a bit hit on the cpu to get it to that point(since I need the cpu for my processing).





Is it possible to gather the number of bluetooth devices around Android device

I would like to get the number of bluetooth devices located around an android device and then store that number in the SQLite database. Is it possible to easily get that number?





Local Variable Declaration Issue

Im getting the following error:




Cannot use local variable 'dob' before it is declared




Here is my implementation



public class Person
{
...
public string dob { get; set; }
...

public int getAge()
{
DateTime origin = DateTime.Parse(dob);
return DateTime.Today.Year - origin.Year;
}

public string getFormattedDoB()
{
DateTime origin = DateTime.Parse(dob);
string dob = origin.ToString("d");
return dob;
}
}


I am not sure what to make of this because it is complaining about it's use of dob in getFormattedDoB() but not in getAge() which comes before it. If anyone could shed some light on this that would be great





CI 2 - Language class and models

I noticed an odd issue and I can't seem to find anything to explain it.



on one of my models i add an error output message to alert that a record is not available, but when it outputs, i get no text, just a blank page.



Now the language tags are valid, the only thing i can figure is that the language file isn't meant to be used on a model, if thats the case I don't see that being explained anywhere.



I hope someone can help me get in the right direction on this, if i have to just set it to false and handle the message on the ui, I'll do that, but prefer not to.



Thanks.



EDIT:



here is what a quick code snipplet that should help:



//fetch topic data.
$this->db->select('id, Name, Description, Level');
$this->db->from('groups');
$this->db->where('id', $gid);
$query = $this->db->get();
$GroupData = $query->row();

//see if we have any records to show.
if($query->num_rows() > 0) {
$this->setId($GroupData->id);
$this->setName($GroupData->Name);
$this->setDescription($GroupData->Description);
$this->setLevel($GroupData->Level);
} else {
//no record was found, throw an error.
show_error($this->lang->line('invalidgid').'<hr />File:'.__FILE__.'<br />Line:'.__LINE__, 500, $this->lang->line('error'));
log_message('error', 'invalid GroupID was provided.'); //log error in error log.
}




IIS 7 URL Rewrite - 403 Error

I know this question has been asked before, but I haven't found an answer to what I'm running into. I'm trying to redirect a domain (not a sub-domain) to a sub-folder. I'm running IIS 7 and I created a URL rewrite rule like this:



<rule name="subfolder" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(www\.)?domain.com?" />
<add input="{PATH_INFO}" pattern="^subfolder" negate="true" />
</conditions>
<action type="Rewrite" url="/subfolder/{R:0}" />
</rule>


With the rule off, I can navigate to a page like http://domain.com/subfolder/index.htm. With it on, I get a 403 error when I try to navigate to http://domain.com/index.htm.



403 - Forbidden: Access is denied.

You do not have permission to view this directory or page using the credentials that you supplied.


How do I fix this?





Using UIScrollview to access 4 different views

This seems like it should be pretty straight forward but im really stuck. I basically want to start the app and it goes to the center view, where the user can swipe up down left or right to access four different views. the picture pretty much sums it up. I will make the text in the picture "swipe up for view 1" "swipe down for ....." buttons also that achieve the same thing as the swiping but I dont want to ask for too much so if anyone can help me out and show me how to program what Im looking for I would much appreciate it.Main Menu views Of app



I was able to get it to be just one massive view but I realized that I want it to jump to every different view, not scroll and be half way there. and when I tried to make cgrect frames it was very confusing to keep it all in order.





combine js array's

pretty simple question, can't quite fig. it out.



I have 2 js array's that I need to combine into a new array, based on sub_key.



var items = [
Object {
OBJECTID=1,
Name="COMMAND B",
ID="AR0xx",
sub_key="1000"
},
Object {
OBJECTID=2,
Name="95TH PCT",
ID="AR0xx",
sub_key="1001"
},
Object {
OBJECTID=379,
Name="dummy4",
ID="AR0xx",
sub_key="9999"
}
];

var subitems = [
Object {
OBJECTID=787,
ID="AR0xx",
sub_key=1000,
Long_Name = foo
},
Object {
OBJECTID=789,
ID="AR0xx",
sub_key=1001,
Long_Name = "bar"
},
Object {
OBJECTID=1,
ID="AR0xx",
sub_key=1001,
Long_Name="baz"
},
Object {
OBJECTID=788,
ID="AR0xx",
sub_key=1001,
Long_Name="buzzz"
}
];


I'd like to create an array like so, which just combines the above 2, based on sub_key



var data = [
COMMAND B=["foo"],
95TH PCT=["bar","baz","buzz"]
dummy4=[]
];


Here's what I tried but it doesn't work... i think i'm close?? thanks for any help!



data = [];
for (var key in items){
var o = items[key];
//data.push(o.Name);
for (var subkey in subitems){
subo = subitems[subkey];
if (o.sub_key == subo.sub_key){
data[o.Name].push(subo.Long_Name)
}
}
}