wrote a simple PHP script to get quotes data from yahoo finance and format it into XML format.
sample: http://psalmhundred.net/experiment/stocks.php?s=adbe,goog,aapl,msft
OR
references:
http://www.gummy-stuff.org/Yahoo-data.htm
Monday, July 26, 2010
Sunday, July 25, 2010
Flash & XML: namespace
sample RSS feed: http://weather.yahooapis.com/forecastrss?w=1062605&u=c
to access elements that are using namespace.
eg.:
gotta use the Namespace class and the :: operator
eg.:
to access elements that are using namespace.
eg.:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
...
<item>
...
<yweather:condition text="Partly Cloudy" code="30" temp="31" date="Sun, 25 Jul 2010 7:00 pm SGT" />
...
</item>
...
</channel>
</rss>
gotta use the Namespace class and the :: operator
eg.:
var xml:XML = new XML(loader.data);
var ns:Namespace = xml.namespace("yweather");
trace(xml.channel.item.ns::condition.@text);
Friday, July 23, 2010
Wednesday, July 21, 2010
Novint Falcon used in Flash
Getting x, y, z coordinates and buttons status:
Using Flash to output force feedback to haptic device:
Using Flash to output force feedback to haptic device:
Tuesday, July 20, 2010
winsock 2: recv with select
needed to use recv in synchronous mode. but it is a blocking call.
so google a bit and found select.
code segment:
so google a bit and found select.
code segment:
fd_set sockets;
TIMEVAL waitTime;
void Receive()
{
// gotta call select() to check if there is incoming packet
sockets.fd_count = 1;
sockets.fd_array[0] = ClientSocket;
// time to expire for select call. since it is blocking too.
waitTime.tv_sec = 0; // seconds
waitTime.tv_usec = 100; // micro seconds
// check if any of the listening sockets has incoming data
// returns number of sockets in fd_set that has incoming data
int result = select(NULL, &sockets, NULL, NULL, &waitTime);
int iResult = result;
if(result > 0)
{
// blocking call
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
if(iResult > 0)
{
printf("Bytes received: %d\n", iResult);
printf("Recv: %s\n", recvbuf);
}
else if(iResult == 0)
{
//printf("Nothing received\n");
}
else
{
printf("recv failed: %d\n", WSAGetLastError());
}
}
return iResult;
}
Saturday, July 17, 2010
libxml2: XML parsing using C/C++
http://www.xmlsoft.org/
require some modification:
xmlversion.h
iconv.dll required. got it at: http://www.gnupg.org/download/iconv.en.html
require some modification:
xmlversion.h
/**
* LIBXML_ICONV_ENABLED:
*
* Whether iconv support is available
*/
#if 0 // instead of 1
#define LIBXML_ICONV_ENABLED
#endif
iconv.dll required. got it at: http://www.gnupg.org/download/iconv.en.html
xmlTextReaderPtr reader;
char xml[200] = "<root><child1><child2 attr=\"123\" attr2=\"test\">hello world</child2></child1></root>";
printf("%s\n", xml);
cout << "Read XML from memory...\n";
reader = xmlReaderForMemory(xml, strlen(xml), "", NULL, 0);
if (reader != NULL) {
// loop to read nodes
int ret;
const xmlChar *name, *value;
ret = xmlTextReaderRead(reader);
while(ret == 1)
{
name = xmlTextReaderConstName(reader);
value = xmlTextReaderConstValue(reader);
printf("%s=%s\n", name, value);
// attributes
ret = xmlTextReaderHasAttributes(reader);
if(ret == 1)
{
// has attributes
attrName = xmlCharStrdup("attr");
attrValue = xmlTextReaderGetAttribute(reader, attrName);
int attr = atoi((const char *) attrValue);
printf("attr=%d\n", attr);
}
ret = xmlTextReaderRead(reader);
}
cout << "Freeing XML reader...\n";
xmlFreeTextReader(reader);
}
Subscribe to:
Posts (Atom)