I have this snippet of the code
char *str = “123”;
if(str[0] == 1) printf("Hello\n");
why I can't receive my Hello thanks in advance!
how exactly compiler does this comparison if(str[0] == 1)?
I'm trying to log the change of a value in the console (Firefox/Firefly, mac).
if(count < 1000)
{
count = count+1;
console.log(count);
setTimeout("startProgress", 1000);
}
This is only returning the value 1. It stops after that.
Am I doing something wrong or is there something else affecting this?
I'm attempting to extract the following data from a table via Android / JSOUP however I'm having a bit of trouble nailing down the process. I think I'm getting close to being able to do this using the code I've provided below - but for some reason I still cannot get my textview to display any of the table data.
P.S.
Live URL's can be provided if necessary.
SOURCE:
public class MainActivity extends Activity {
TextView tv;
final String URL = "http://exampleurl.com";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.TextView01);
new MyTask().execute(URL);
}
private class MyTask extends AsyncTask<String, Void, String> {
ProgressDialog prog;
String title = "";
@Override
protected void onPreExecute() {
prog = new ProgressDialog(MainActivity.this);
prog.setMessage("Loading....");
prog.show();
}
@Override
protected String doInBackground(String... params) {
try {
Document doc = Jsoup.connect(params[0]).get();
Element tableElement = doc.getElementsByClass("datagrid")
.first();
title = doc.title();
} catch (IOException e) {
e.printStackTrace();
}
return title;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
prog.dismiss();
tv.setText(result);
}
}
}
TABLE:
<table class="datagrid">
<tbody><tr>
<th>Item No.</th>
<th>Name</th>
<th>Sex</th>
<th>Location</th>
</tr>
<tr>
<td><a href="redirector.cfm?ID=a33660a3-aae0-45e3-9703-d59d77717836&page=1&&lname=&fname=" title="501207593">501207593 </a></td>
<td>USER1</td>
<td>M </td>
<td>Unknown</td>
</tr>
<tr>
<td><a href="redirector.cfm?ID=edf524da-8598-450f-9373-da87db8d6c84&page=1&&lname=&fname=" title="501302750">501302750 </a></td>
<td>USER2</td>
<td>M </td>
<td>Unknown</td>
</tr>
<tr>
<td><a href="redirector.cfm?ID=a78abeea-7651-4ac1-bba2-0dcb272c8b77&page=1&&lname=&fname=" title="531201804">531201804 </a></td>
<td>USER3</td>
<td>M </td>
<td>Unknown</td>
</tr>
</tbody></table>
I have strings of this type:
text (more text)
What I would like to do is to have a regular expression that extracts the "more text" segment of the string, so far I have been using this regular expression:
"^.*\\((.*)\\)$"
Which although it works on many cases, it seems to fail if I have something of the sort:
text (more text (even more text))
What I get is: even more text)
What I would like to get instead is:
more text (even more text) (basically the content of the outermost pair of brackets.)
Thanks
Good Morning,
I have got the following function:
FUNCTION queryDatabaseCount(sqlStr)
SET queryDatabaseCountRecordSet = databaseConnection.Execute(sqlStr)
If queryDatabaseCountRecordSet.EOF Then
queryDatabaseCountRecordSet.Close
queryDatabaseCount = 0
Else
QueryArray = queryDatabaseCountRecordSet.GetRows
queryDatabaseCountRecordSet.Close
queryDatabaseCount = UBound(QueryArray,2) + 1
End If
END FUNCTION
And the following dbConnect:
SET databaseConnection = Server.CreateObject("ADODB.Connection")
databaseConnection.Open "Provider=SQLOLEDB; Data Source ="&dataSource&"; Initial Catalog ="&initialCatalog&"; User Id ="&userID&"; Password="&password&""
But for some reason I get the following error:
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
/UBS/DBMS/includes/blocks/block_databaseoverview.asp, line 30
Does anyone have any suggestions?
Many Thanks,
Joel
I already have a code with collision but it has check for winners and ontouch method that I don't really need because my bitmaps are moving itself and I just want them to collide if they overlap.
private boolean checkCollision(Grafika first, Grafika second) {
boolean retValue = false;
int width = first.getBitmap().getWidth();
int height = first.getBitmap().getHeight();
int x1start = first.getCoordinates().getX();
int x1end = x1start + width;
int y1start = first.getCoordinates().getY();
int y1end = y1start + height;
int x2start = second.getCoordinates().getX();
int x2end = x2start + width;
int y2start = second.getCoordinates().getY();
int y2end = y2start + height;
if ((x2start >= x1start && x2start <= x1end) || (x2end >= x1start && x2end <= x1end)) {
if ((y2start >= y1start && y2start <= y1end) || (y2end >= y1start && y2end <= y1end)) {
retValue = true;
}
}
return retValue;
}
I am basing my game off the lunarlander example. This is the run loop I am using (very similar to what is used in lunarlander). I am getting considerable performance issues associated with my drawing, even if I draw almost nothing.
I noticed the below method. Why is the canvas being created and set to null each cycle?
@Override
public void run()
{
while (mRun)
{
Canvas c = null;
try
{
c = mSurfaceHolder.lockCanvas();//null
synchronized (mSurfaceHolder)
{
updatePhysics();
doDraw(c);
}
} finally
{
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null)
{
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
Most of the times I have read anything about canvases it is more along the lines of:
mField = new Bitmap(...dimensions...);
Canvas c = new Canvas(mField);
My question is: why is Google's example done that way (null canvas), what are the benefits of this, and is there a faster way to do it?
When my page loads it calls the function like below:
<body onLoad='changeTDNodes()'>
And the code it calls is below:
enter code here
<script src='jquery-1.4.2.min.js' type='text/javascript'></script>
<script>
function changeTDNodes() {
var threshValue = 10;
$(".threshold").each(function(elem) {
if($("b",elem).innerText > threshValue) {
elem.addClass("overThreshold");
}
});
});
}
I have the class setup correctly in CSS
.overThreshold {
td{font-size:72px;}
th{font-size:72px;}
}
But no classes are being changed, whats going on?
Thanks for all your help!
Hey all i am new to XML parsing on VB.net. This is the code i am using to parse an XML file i have:
Dim output As StringBuilder = New StringBuilder()
Dim xmlString As String = _
"<ip_list>" & _
"<ip>" & _
"<ip>192.168.1.1</ip>" & _
"<ping>9 ms</ping>" & _
"<hostname>N/A</hostname>" & _
"</ip>" & _
"<ip>" & _
"<ip>192.168.1.6</ip>" & _
"<ping>0 ms</ping>" & _
"<hostname>N/A</hostname>" & _
"</ip>" & _
"</ip_list>"
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
Do Until reader.EOF
reader.ReadStartElement("ip_list")
reader.ReadStartElement("ip")
reader.ReadStartElement("ip")
reader.MoveToFirstAttribute()
Dim theIP As String = reader.Value.ToString
reader.ReadToFollowing("ping")
Dim thePing As String = reader.ReadElementContentAsString().ToString
reader.ReadToFollowing("hostname")
Dim theHN As String = reader.ReadElementContentAsString().ToString
MsgBox(theIP & " " & thePing & " " & theHN)
Loop
End Using
I put the "do until reader.EOF" myself but it does not seem to work. It keeps giving an error after the first go around. I must be missing something?
David
Hi,
I have this POSIX thread:
void subthread(void)
{
while(!quit_thread) {
// do something
...
// don't waste cpu cycles
if(!quit_thread) usleep(500);
}
// free resources
...
// tell main thread we're done
quit_thread = FALSE;
}
Now I want to terminate subthread() from my main thread. I've tried the following:
quit_thread = TRUE;
// wait until subthread() has cleaned its resources
while(quit_thread);
But it does not work! The while() clause does never exit although my subthread clearly sets quit_thread to FALSE after having freed its resources!
If I modify my shutdown code like this:
quit_thread = TRUE;
// wait until subthread() has cleaned its resources
while(quit_thread) usleep(10);
Then everything is working fine! Could someone explain to me why the first solution does not work and why the version with usleep(10) suddenly works? I know that this is not a pretty solution. I could use semaphores/signals for this but I'd like to learn something about multithreading, so I'd like to know why my first solution doesn't work.
Thanks!
I'm trying to write program calculating average of given numbers stored in an array. Amount of numbers should be not more than 100, and user should input them until a !int variable is given :
#include <iostream>
#include <conio.h>
using namespace std;
double average(int tab[], int i){
int sum=0;
for(int j=0; j<i; ++j){
sum+=tab[j];
}
return (double)sum/i;
}
int main()
{
int tab[100];
int n=0;
int number=0;
do {
if(n < 100){
cout << "Give " << n+1 << " number : ";
cin >> number;
tab[n]=number;
number=0;
++n;
}
else{
break;
}
} while( !isdigit(number) );
cout << average(tab, n) << endl;
getch();
return 0;
}
Why after giving char, it prints me 'Give n number:' for all empty cells of my array ? It should end and use only given numbers.
I need to process this chain using one LoadXML method and one urlLoader object:
ResourceLoader.Instance.LoadXML("Config.xml");
ResourceLoader.Instance.LoadXML("GraphicsSet.xml");
Loader starts loading after first frameFunc iteration (why?) I want it to start immediatly.(optional)
And it starts loading only "GraphicsSet.xml"
Loader class LoadXml method:
public function LoadXML(URL:String):XML
{
urlLoader.addEventListener(Event.COMPLETE,XmlLoadCompleteListener);
urlLoader.load(new URLRequest(URL));
return xml;
}
private function XmlLoadCompleteListener(e:Event):void
{
var xml:XML = new XML(e.target.data);
trace(xml);
trace(xml.name());
if(xml.name() == "Config")
XMLParser.Instance.GameSetup(xml);
else if(xml.name() == "GraphicsSet")
XMLParser.Instance.GraphicsPoolSetup(xml);
}
Here is main:
public function Main()
{
Mouse.hide();
this.addChild(Game.Instance);
this.addEventListener(Event.ENTER_FRAME,Game.Instance.Loop);
}
And on adding a Game.Instance to the rendering queue in game constuctor i start initialize method:
public function Game():void
{
trace("Constructor");
if(_instance)
throw new Error("Use Instance Field");
Initialize();
}
its code is:
private function Initialize():void
{
trace("initialization");
ResourceLoader.Instance.LoadXML("Config.xml");
ResourceLoader.Instance.LoadXML("GraphicsSet.xml");
}
Thanks.
I need to create a script to search through just below a million files of text, code, etc. to find matches and then output all hits on a particular string pattern to a CSV file.
So far I made this;
$location = 'C:\Work*'
$arr = "foo", "bar" #Where "foo" and "bar" are string patterns I want to search for (separately)
for($i=0;$i -lt $arr.length; $i++) {
Get-ChildItem $location -recurse | select-string -pattern $($arr[$i]) | select-object Path | Export-Csv "C:\Work\Results\$($arr[$i]).txt"
}
This returns to me a CSV file named "foo.txt" with a list of all files with the word "foo" in it, and a file named "bar.txt" with a list of all files containing the word "bar".
Is there any way anyone can think of to optimize this script to make it work faster? Or ideas on how to make an entirely different, but equivalent script that just works faster?
All input appreciated!
messagecontroller is nothing but object of initialize nib file.
[self.navigationController pushViewController:messageController animated:YES];
this statement executes in normal condition
this statement also works on state maintainace testing ,
this line executes properly but not open new view ,why?
I'm currently registering my domains through GoDaddy. Does the registrar matter? Any recommendations for registrars you're especially happy with?
(See this very similar question, that requires API support. I need no such support, hence this question is more generic).
I have an array of numbers:
@numbers = 1,2,3,6,8,9,11,12,13,14,15,20
and I want to print it this way:
1-3,6,8-9,11-15,20
Any thoughts? Of course I tried using the most common "looping", but still didn't get it.
PS: My bad, there was not an error. I forgot to upload the latest version to the server...
I have multimedias and images table. I save images in multimedias table with their images table id numbers. Then whenever I need image's url, with a simple function I get it from images table. The problem I am having is when I try to display image's url inside ImageURL, it just does not happen. This is very annoying.
xml output
<?xml version='1.0' encoding='windows-1254' ?>
<rows><row id='1'>
<MultimediaTitle>Hagi Goals</MultimediaTitle>
/FLPM/media/images/5Y2K4T5V_sm.jpg
<ImageURL><![CDATA[]]></ImageURL>
<Videos>
<VideoID id='1'><VideoURL>/FLPM/media/videos/0H7T9C0F.flv</VideoURL></VideoID>
<VideoID id='2'><VideoURL>/FLPM/media/videos/9L6X9G9J.flv</VideoURL></VideoID>
</Videos>
</row>
</rows>
Functionally, the two blocks should be the same
<soapenv:Body>
<ns1:login xmlns:ns1="urn:soap.sof.com">
<userInfo>
<username>superuser</username>
<password>qapass</password>
</userInfo>
</ns1:login>
</soapenv:Body>
-----------------------
<soapenv:Body>
<ns1:login xmlns:ns1="urn:soap.sof.com">
<ns1:userInfo>
<ns1:username>superuser</ns1:username>
<ns1:password>qapass</ns1:password>
</ns1:userInfo>
</ns1:login>
</soapenv:Body>
However, how when I read using AXIS2 and I have tested it with java6 as well, I am having a problem.
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMsg = factory.createMessage(new MimeHeaders(), SimpleTest.class.getResourceAsStream("LoginSoap.xml"));
SOAPBody body = soapMsg.getSOAPBody();
NodeList nodeList = body.getElementsByTagNameNS("urn:soap.sof.com", "login");
System.out.println("Try to get login element" + nodeList.getLength()); // I can get the login element
Node item = nodeList.item(0);
NodeList elementsByTagNameNS = ((Element)item).getElementsByTagNameNS("urn:soap.sof.com", "username");
System.out.println("try to get username element " + elementsByTagNameNS.getLength());
So if I replace the 2nd getElementsByTagNameNS with ((Element)item).getElementsByTagName("username");, I am able to get the username element. Doesn't username have ns1 namespace even though it doesn't have the prefix? Am I suppose to keep track of the namespace scope to read an element? Wouldn't it became nasty if my xml elements are many level deep? Is there a workaround where I can read the element in ns1 namespace without knowing whether a prefix is defined?
If this were raw-SQL, it'd be a no-brainer, but in Django, this is proving to be quite difficult to find. What I want is this really:
SELECT
user_id
FROM
django_comments
WHERE
content_type_id = ? AND
object_pk = ?
GROUP BY
user_id
It's those last two lines that're the problem. I'd like to do this the "Django-way" but the only thing I've found is mention of aggregates and annotations, which I don't think solve this issue... do they? If someone could explain this to me, I'd really appreciate it.
So I have the Ninja model which has many Hovercrafts through ninja_hovercrafts (which stores the ninja_id and the hovercraft_id).
It is of my understanding that this kind of arrangement should be set in a way that the associative table stores only enough information to bind two different classes.
But I'd like to use the associative table to work as a very streamlined authorization hub on my application. So i'd also like this table to inform my system if this binding makes the ninja the pilot or co-pilot of a given hovercraft, through a "role" field in the table.
My questions are:
Is this ugly?
Is this normal?
Are there methods built into rails that would help me to automagically create Ninjas and Hovercrafts associations WITH the role? For exemple, could I have a nested form to create both ninjas and hcs in a way that the role field in ninjas_hovercrafts would be also filled?
If managing my application roles this way isn't a good idea, whats the non-resource heavy alternative (my app is being designed trying to avoid scalability problems such as excessive joins, includes, etc)
thank you
Hi,
I am having trouble parsing self closing XML tags using SAX. I am trying to extract the link tag from the Google Base API.I am having reasonable success in parsing regular tags.
Here is a snippet of the xml
<entry>
<id>http://www.google.com/base/feeds/snippets/15802191394735287303</id>
<published>2010-04-05T11:00:00.000Z</published>
<updated>2010-04-24T19:00:07.000Z</updated>
<category scheme='http://base.google.com/categories/itemtypes' term='Products'/>
<title type='text'>En-el1 Li-ion Battery+charger For Nikon Digital Camera</title>
<link rel='alternate' type='text/html' href='http://rover.ebay.com/rover/1/711-67261-24966-0/2?ipn=psmain&icep_vectorid=263602&kwid=1&mtid=691&crlp=1_263602&icep_item_id=170468125748&itemid=170468125748'/>
.
.
and so on
I can parse the updates and published tags, but not the link and category tag.
Here is my startElement and endElement overrides
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (qName.equals("title") && xmlTags.peek().equals("entry")) {
insideEntryTitle = true;
}
xmlTags.push(qName);
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
// If a "title" element is closed, we start a new line, to prepare
// printing the new title.
xmlTags.pop();
if (insideEntryTitle) {
insideEntryTitle = false;
System.out.println();
}
}
declaration for xmltags..
private Stack<String> xmlTags = new Stack<String>();
Any help guys?
this is my first post here.. I hope I have followed posting rules! thanks a ton guys..
I'm pretty inexperienced with .htaccess so please bear with me.
I have a domain - "http://www.exampletest.com"
which redirects to a folder at a different domain where I have hosting i.e:
"http://www.differenturl.com/exampletest"
Is there an easy mod_rewrite rule where I could have anything at "http://www.differenturl.com/exampletest" show up as "http://www.exampletest.com?" An example would be:
"http://www.differenturl.com/exampletest/user.php" - "http://www.exampletest.com/user.php"
Any assistance is greatly appreciated. I assume this easy so sorry to ask such a basic question.
Thanks
I know this may be the simplest question ever asked on Stack Overflow, but what is the regular expression for a decimal with a precision of 2?
Valid examples:
123.12
2
56754
92929292929292.12
0.21
3.1
Invalid examples:
12.1232
2.23332
e666.76
Sorry for the lame question, but for the life of me I haven't been able to find anyone that can help!
The decimal place may be option, and that integers may also be included.