Friday, April 20, 2012

Why does Nokogiri's to_xhtml create new `id` attributes from `name`?

Consider the following code:



require 'nokogiri' # v1.5.2
doc = Nokogiri.XML('<body><a name="foo">ick</a></body>')

puts doc.to_html
#=> <body><a name="foo">ick</a></body>

puts doc.to_xml
#=> <?xml version="1.0"?>
#=> <body>
#=> <a name="foo">ick</a>
#=> </body>

puts doc.to_xhtml
#=> <body>
#=> <a name="foo" id="foo">ick</a>
#=> </body>


Notice the new id attribute that has been created.




  1. Who is responsible for this, Nokogiri or libxml2?

  2. Why does this occur? (Is this enforcing a standard?)

    The closest I can find is this spec describing how you may put both an id and name attribute with the same value.

  3. Is there any way to avoid this, given the desire to use the to_xhtml method on input that may have <a name="foo">?



This problem arises because I have some input I am parsing with an id attribute on one element and a separate element with a name attribute that happens to conflict.





Type-checking collections with elements with different traits

Is there any way I can enforce a method returning something along the lines of (in regex notation):



(T with A) (T with A with B)+ (T with B)


If I return Traversable[T], it drops the bound traits. Likewise, I can't return Traversable[T with A with B], because this would be inaccurate for the first and last elements.



I'm not sure how to get around this. It introduces some implicit conditions into my program, and I feel like I'm abusing the type system by using .asInstanceOf[] casts. Maybe I'm using the wrong kind of data structure?



Here's a sample of the code I'm writing, for an example of what I mean. I'm looking to enforce the route method. The User class extends type T, I've left out the code because there's a lot.



trait Producer extends User {
def send(file: Data)
}

trait Consumer extends User {
def receive(file: Data)
}

...

def route(sender: T with Producer, receiver: T with Consumer): Traversable[T]

def transfer(sender: T with Producer, receiver: T with Consumer, file: Data) {
val path = route(sender, receiver)
if (!path.isEmpty) {
sender send file

val nextHop = route(sender, receiver).tail.head

nextHop.asInstanceOf[T with Consumer] receive file

if (nextHop != receiver) {
transfer(nextHop.asInstanceOf[T with Producer], receiver, file)
}
}
}




php array still getting white space and nulls

trying to get two word phrases from an array but I keep getting one word phrases with a white space either before or after the word.



$text = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $text);
$textarray = explode(" ", $text);
array_filter($textarray);
$textCount = array_count_values($textarray);
arsort($textCount);
$twoWords = array();
for ($i = 0; $i<=count($textarray); ++$i) {
if ($textarray[$i]<>" ") {
$twoWords[$i] = $textarray[$i]." ".$textarray[$i + 1];
} else {
$twoWords[$i] = "blah";
}
}
foreach ($twoWordsCount as $tey => $val2) {
if ($tey == null || $tey == "" || $tey == "\r\n" || $tey == "\t" || $tey == "\r" || $tey == "\n" || $tey == "&nbsp;" || $tey == " " || $tey == " ") {
//do nothing
} else {
echo $val2."\n";
}
}


and for some reason this just returns values likes whitespace Hello or Test and then a whitespace, but I want it to return hello test





parent and child table foreign key

I currently have a parent table:



CREATE TABLE members (
member_id SERIAL NOT NULL, UNIQUE, PRIMARY KEY
first_name varchar(20)
last_name varchar(20)
address address (compsitie type)
contact_numbers varchar(11)[3]
date_joined date
type varchar(5)
);

CREATE TABLE basic_member (
activites varchar[3]) // can only have 3 max activites
INHERITS (members)
);

CREATE TABLE full_member (
activities varchar[]) // can 0 to many activities
INHERITS (members)
);


I also have another table called



CREATE TABLE planner (
day varchar(9) FOREIGN KEY REFERENCES days(day)
time varchar(5) FOREIGN KEY REFERENCES times(time)
activity varchar(20) FOREIGN KEY REFERENCES activities(activity)
member bigint FOREIGN KEY REFERENCES members(member_id)

ALTER TABLE planner ADD CONSTRAINT pk_planner PRIMARKY KEY (day,time,activity,member);


I am currently trying to add with



INSERT INTO planner VALUES ('monday','09:00','Weights',2);


I have added a set into full_members with



INSERT INTO full_members 
VALUES (Default, 'Hayley', 'Sargent', (12 Forest Road','Mansfield','Nottinghamshire','NG219DX'),'{01623485764,07789485763,01645586754}',20120418,'Full');


My insert is currently not working





Making lexx to read UTF-8 doesn't work

I wrote an xml parser that parses ASCII files, but I need now to be able to read UTF-8 encoded files. I have the following regex in Lexx but they don't match UTF-8 I am not sure what I am doing wrong:



utf_8       [\x00-\xff]*
bom [\xEF\xBB\xBF]


then:



bom             { fprintf( stderr, "OMG I SAW A BOM"); return BOM;}
utf_8 { fprintf( stderr, "OMG I SAW A UTF CHAR", yytext[0] ); return UTF_8; }


I also have the following grammar rules:



program 
: UTF8 '<' '?'ID attribute_list '?''>'
root ...


where UTF8 is:



UTF8



: BOM           {printf("i saw a bom\n");}
| UTF_8 {printf("i saw a utf\n");}
| {printf("i didn't see anything.'\n");}
;


It always comes up with i didn't see anything, my parser works for ASCII files, that is when I copy paste the XML UTF-8 file in a empty document.



Any help would be appreciated.





How to extend an Android button and use an xml layout file

I'm trying to extend the android button class and have it use an xml layout file.



The reason I want to use an xml layout file is that my button needs to use a style and as far as I know, there isn't a way to set style programatically.




public class BuyButton extends Button { ... }




<?xml version="1.0" encoding="utf-8"?>  
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/customButton"
/>


so that I can call:



new BuyButton(activity);


and have it create a button that has the style applied to it.



(I'm also open to other ways of getting the same result)





run order of JavaScript in HTML file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
alert('123');
</script>
</head>
<body>
456
<script type="text/javascript">
alert('789');
</script>
</body>
</html>


As the code above.If I remove alert('789');, the order of appearance would be 123->456.
If I remove alert('123');, the order would be 456->789.
If I don't remove any of the two js statements, the order of appearance would be 123->789->456.
Isn't it a bit strange?





.Net 4 causes DLLImport function to return failure code, .Net 2, 3 or 3.5 does not

I am looking at a sample project from sourceforge for linking to a TSAPI (not TAPI) telephone system - http://tsapi.sourceforge.net/ .



My development environment is 32bit Windows XP and the project is set to target x86.



This works fine as provided to run against .Net 2 but I need to run against .Net 4. When I change the framework and run the 1st function returns -1 indicating failure.



The function definition is:



[DllImport("csta32.dll")]
public static extern int acsOpenStream(ref UInt32 acsHandle, int invokeIDType, UInt32 invokeID, int streamType, char[] serverID, char[] loginID, char[] passwd, char[] applicationName, int acsLevelReq, char[] apiVer, ushort sendQSize, ushort sendExtraBufs, ushort recvQSize, ushort recvExtraBufs, ref PrivateData_t priv);


The c# code (extracted from sample project) for calling this function is:



    // The public method to open the ACS stream
public bool open(string strLoginId, string strPasswd, string strServerId)
{
// Convert the parameters to character arrays
char[] serverId = strServerId.ToCharArray();
char[] loginId = strLoginId.ToCharArray();
char[] passwd = strPasswd.ToCharArray();

// Define the initial set of variables used for opening the ACS Stream
int invokeIdType = 1;
UInt32 invokeId = 0;
int streamType = 1;
char[] appName = "Mojo".ToCharArray();
int acsLevelReq = 1;
char[] apiVer = "TS1-2".ToCharArray();
ushort sendQSize = 0;
ushort sendExtraBufs = 0;
ushort recvQSize = 0;
ushort recvExtraBufs = 0;

// Define the mandatory (but unused) private data structure
Csta.PrivateData_t privData = new Csta.PrivateData_t();
privData.vendor = "MERLIN ".ToCharArray();
privData.length = 4;
privData.data = "N".ToCharArray();

// Define the event buffer pointer that gets data back from the TServer
ushort numEvents = 0;
Csta.EventBuf_t eventBuf = new Csta.EventBuf_t();
ushort eventBufSize = (ushort)Csta.CSTA_MAX_HEAP;

// Open the ACS stream
try
{
int openStream = Csta.acsOpenStream(ref acsHandle, invokeIdType, invokeId, streamType, serverId, loginId, passwd, appName, acsLevelReq, apiVer, sendQSize, sendExtraBufs, recvQSize, recvExtraBufs, ref privData);


A C++ sample application is also provided in which the function call is:



m_nRetCode = acsOpenStream(&m_lAcsHandle            // Handle for ACS Stream 
, APP_GEN_ID // APP_GEN_ID indicates Application generated invokeID's
, (InvokeID_t)m_ulInvokeID // By default 1
, ST_CSTA
, (ServerID_t *)(serverID) // AE Server Name
, (LoginID_t *)(loginID) // CTI LoginID
, (Passwd_t *)(password) // CTI LoginID password
, (AppName_t *)"TSAPI_AgentView"
, ACS_LEVEL1
, (Version_t *) "TS1-2" // private Data version in use 8 in our case
, 10
, 5
, 50
, 5
, (PrivateData_t *)&m_stPrivateData); // private Data.


If I change the DLLImport to



[DllImport("csta32.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int acsOpenStream(ref UInt32 acsHandle, int invokeIDType, UInt32 invokeID, int streamType, char[] serverID, char[] loginID, char[] passwd, char[] applicationName, int acsLevelReq, char[] apiVer, ushort sendQSize, ushort sendExtraBufs, ushort recvQSize, ushort recvExtraBufs, ref PrivateData_t priv);


I get the runtime error



PInvokeStackImbalance was detected
Message: A call to PInvoke function 'Mojo!Csta::acsOpenStream' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.



Avaya do not provide the header file - the documentation indicates the function definition to be:



RetCode_t acsOpenStream(
ACSHandle_t *acsHandle, /* RETURN */
InvokeIDType_t invokeIDType, /* INPUT */
InvokeID_t invokeID, /* INPUT */
StreamType_t streamType, /* INPUT */
ServerID_t *serverID, /* INPUT */
LoginID_t *loginID, /* INPUT */
Passwd_t *passwd, /* INPUT */
AppName_t *applicationName, /* INPUT */
Level_t acsLevelReq /* INPUT */
Version_t *apiVer, /* INPUT */
unsigned short sendQSize, /* INPUT */
unsigned short sendExtraBufs, /* INPUT */
unsigned short recvQSize, /* INPUT */
unsigned short recvExtraBufs /* INPUT */
PrivateData_t *privateData); /* INPUT */


Any help would be appreciated





Java RegEx that matches anything BUT literal string 'NIL' or 'nil'

OK, guys. Here's a Java interview-type question that seems to have stumped some very smart people around here. They actually need this for production code, so it's more than just an interview puzzler.



They need a regular expression, in Java, that returns true if a string literal is anything other than the 3-letter word NIL. The test needs to be case insensitive, and the RegEx itself must do all the work.



So, the RegEx should reject NIL, nil, NiL, nIL, and so on.



It should, however, accept: nile, anil, will, zappa-nil-a, and the empty string.



How many Java developers does it take to write a trivial RegEx? Apparently a lot!





using part of RAM as local storage

I'm setting up a virtuoso server on my local machine, the databse is not big (about 2GB)



The application I'm using the server for needs to make a very large number of queries and the results need to come fast.



The HDD I'm using is mechanical, so it's not that fast, I am now trying to find a way to allocate part of my main memory as a local storage so that I can put the database file on it.



is there's an easy way to do that ?





SQL Server - Show Top entries in List

I have to sort, by hour, the number of times someone calls from a specific country. The list of countries increases on a monthly basis, so for example we can add Brazil. I am using SQL Server.



The Data Looks like This



2012-04-02 08:00:59    United States
2012-04-02 08:12:02 United States
2012-04-02 08:13:42 Canada
2012-04-02 08:13:56 United States
2012-04-02 08:14:07 Mexico
2012-04-02 08:18:09 Canada
2012-04-02 08:19:50 United States
2012-04-02 08:34:34 Mexico
etc.


How I would like to list the data is by top 2 countries by hour.



I would like it to display like:



Date                   Country          Calls
2012-04-02 08:00:00 United States 24
2012-04-02 08:00:00 Canada 19
--hidden--
2012-04-02 08:00:00 Mexico 12


The Code that i tried (does not work):



Declare @StartDate datetime, @EndDate datetime
set @StartDate = '20120401 00:00:00'
set @EndDate = '20120430 23:59:59'
SELECT DATEADD(HOUR, DATEPART(HOUR, [date]), DATEDIFF(DAY, 0, [date])) as [date],
(SELECT COUNT([country]) FROM [mytable] WHERE [date] between @StartDate and @EndDate and [country] = 'United States' ) as [United_States]
,(SELECT COUNT([country]) FROM [mytable] WHERE [date] between @StartDate and @EndDate and [country] = 'Canada' ) as [Canada]
,(SELECT COUNT([country]) FROM [mytable] WHERE [date] between @StartDate and @EndDate and [country] = 'Mexico' ) as [Canada]
FROM [mytable]
WHERE [date] between @StartDate and @EndDate
GROUP BY DATEADD(HOUR, DATEPART(HOUR, [date]), DATEDIFF(DAY, 0, [date]))
ORDER BY [date]


Thank You.





PhoneGap Facebook Plugin connect with android

i have problem for use Facebook connect plugin with PhoneGap.



I have add this line to plugins.xml :



<plugin name="com.phonegap.facebook.Connect" value="com.phonegap.facebook.ConnectPlugin" />


And this include on FbDialog.java :



import com.phonegap.helloworld.R;


I have this file on src :



com
/facebook/android/
AsyncFacebookRunner.java
DialogError.java
Facebook.java
FacebookError.java
FbDialog.java
Util.java
/phonegap/
facebook/ConnectPlugin.java
helloworld/HelloPhoneGapActivity.java


The ressources files close and icon is copied.
In html, i include script :



cordova-1.6.1.js
cdv-plugin-fb-connect.js
facebook_js_sdk.js


I use the default html example with my appId.



When i run app on my android phone, a dialog say : " Cordova Facebook connect plugin fail on init! ", and " Cordova Facebook connect plugin fail on auth.status! ".
If i click login bouton, dialog say : " Cordova Facebook connect plugin fail on login!Class not found ".



And this is the eclipse console log : http://dl.dropbox.com/u/5387356/errorfbapp.png



I tri to install this with officiel git readme and this tutoriel :
http://marguspala.com/add-facebook-login-to-phonegap-android-app-easiest-way/comment-page-1/#comment-156963



when i compile app, i don't have error.



Anyone can help me ?





How can I change the width/height of all QDockWidgets in a QDockWidgetArea?

I have a PyQt 4 application that has a QMainWindow with docked QDockWidgets in the left and bottom dock areas. I currently have two widgets docked on the left and 2 on the bottom. I'm trying to figure out how I can programmatically move the boundary between the central widget and the dock areas, effectively changing the dock area's width (in the case of the left or right areas) or height (for the top and bottom dock areas).



I can do this manually with the mouse; when I move the cursor over the boundary between the central widget and the dock areas, I get a resize handle that I can use to stretch the dock area. I have yet to find an interface to allow me to do that from my program. I've tried manually resizing the QDockWidget objects themselves (which the documentation recommends against) and the widgets that they wrap (which should work), but that doesn't seem to work. Any ideas?



Specifically, this sort of approach does not work:



dock1.resize(QSize(width, height))
dock2.resize(QSize(width, height))
dock3.resize(QSize(width, height))


Nor does this:



dock1.widget().resize(QSize(width, height))
dock2.widget().resize(QSize(width, height))
dock3.widget().resize(QSize(width, height))




Xcode: My app crashes when I hit "Run", but when i hit "Stop" it works

My app crashes when I hit "Run", but when i hit "Stop" and then open the app from the simulator it works like a charm. What is wrong?



Thanks in advance!





UIScrollView not working

I have a UIScrollView with a View inside of it. Inside of that view is a bunch of buttons, labels, etc that fit in the View when in Portrait mode...When the iPad is rotated, I want the scrollView to kick in so the user can scroll to the bottom of the view. The app runs, but when I rotate it, the scroller never works...I believe I've wired everything up correctly and I have this code in the viewDidLoad event:



[scrollview addSubview: masterView];
scrollView.contentSize = [masterView sizeThatFits:CGSizeZero];



Is there something else I am missing? Do I need to modify the size when the iPad rotates?



thanks





XSD: how can I accept data that matches any of a set of types?

In my schema, I would like to accept an element containing data that is formatted as either date or dateTime.



For example, any of these elements should validate:



<event_ts>2012-04-18</event_ts>
<event_ts>2012-04-18T12:00:00</event_ts>
<event_ts>2012-04-18T12:00:00Z</event_ts>
<event_ts>2012-04-18T12:00:00-05:00</event_ts>


If I just use the dateTime type for this element, my first example will not pass validation, as the dateTime spec dictates that the time of day portion must be present.



Does something like an enumeration of types, rather than explicit strings, exist in XML Schema?



I would really rather avoid reinventing the ISO 8601 wheel with a big regex here.





getting an error in webview on ice cream sandwich

Error is



java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.



I am calling a



webview.loadUrl("javascript:myJavaMethod(" + itemArr + "," + telcoID + ");");


on the



webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {


this is a webview playing a flash video player, all is good on 2.2, 2.3.3 etc, tried it on ice cream sandwich and no visible error (other than its just a black screen nor video playing)



Any thoughts.





find the visible height of my iframed page - (fb page)

My page is displayed in an iframe (facebook page) It is around 2000px tall, but of course only a few hundered are visble at any time.



Is it possible to find out the visible hieght of my page? Using $window.width() is giving me the total height of the page.





Encoding nested python object in JSON

I want to encode objects in JSON. But, I can not figure out how to make the output without the string escaping.



import json

class Abc:
def __init__(self):
self.name="abc name"
def toJSON(self):
return json.dumps(self.__dict__, cls=ComplexEncoder)

class Doc:
def __init__(self):
self.abc=Abc()
def toJSON(self):
return json.dumps(self.__dict__, cls=ComplexEncoder)

class ComplexEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Abc) or isinstance(obj, Doc):
return obj.toJSON()
else:
return json.JSONEncoder.default(self, obj)

doc=Doc()
print doc.toJSON()


The result is (the dumps returns a string representation, that's why the " are escaped)



{"abc": "{\"name\": \"abc name\"}"}


I want something a little bit different. The expected result is



{"abc": {"name": "abc name"}"}


But I don't see how to...
Any hint ?



thanks in advance.





How to configr nutch and solr in ubuntu 10.10?

i m trying to build a search engine for my final year project. I have done lots of research on this topic in last 2 months.
And i found that i will need a crawler to crawl Internet,a parser, a indexer.



i am trying to use Nutch as crawler and solr to index data crawled by nutch. But i am stuck in the installation part of both of them. i m trying to install Nutch and solr in my system with the help of of tutorials on Internet but nothing worked for me.



i need some kind of installation guide or a link where i can find how to install and integrate nutch and solr.



next i m stuck with parser i have no idea of this phase. i need help here, how to do parsing of data before indexing.



I don't want to build Google or something all i need a certain items from certain websites to be searched.



i have Java experience and i can work with it comfortably but i am not a professional like u guys
and please do tell me that whether i am going in the right direction or not ? and what i should do next..?



i am using Ubuntu 10.10 and i have apache tomcat 7





Scrolling content right to left Javascript

I have a page with a horizontal width of 4000px



How would i go about creating an event that starts as soon as the page loads and cycles from the far right to left of the page? I want to show all the content and get the user back to the start if you get me



Ideally coded in javascript but will accept CSS3 (if it can be done)



Thanks Guys,



DIM3NSION





custom config xml setting and storing into dictionary object

I plan to set up configuration keys for FormFields, QueryString parameters etc. In my web.config I have setting as follows:



<WhiteListPaametersGroup>
<WhiteListPaameters>
<FormField1>EVENTVALIDATION</FormField1>
<FormField2>VIEWSTATE</FormField2>
<FormField3>Button1</FormField3>

<QueryString1>firstname</QueryString1>
<QueryString2>lastname</QueryString2>

</WhiteListPaameters>
</WhiteListPaametersGroup>


Then in my code, I read the value as follows:



Dictionary<string, string> parameters = new Dictionary<string,string>();

foreach (XmlNode n in section.ChildNodes)
{
parameters.Add(n.Name, n.InnerText);
}


Is there a better way of storing this. Later on, I want to be able to go through dictionary like object, and be able to get settings for FormFields, Querystrings etc.



Please let me know if I could write it cleaner.



Thanks





Are Asynchronous writes to a socket thread safe?

Consider the Socket.BeginSend() method. If two thread pool threads were to call this method simultaneously, would their respective messages end up mixing with each other or does the socket class keep this from happening?





Pex - testing 'Type' parameters

I have a couple of methods that check for assignablity or interface assignabilty between types. Therefore I have signatures like (Type type1, Type type2).



Pex struggles to generate inputs for these parameters and ends up with some type build something or other type (sorry closed VS already) because Type itself is abstract.



I tried creating a factory that would pick one of four test 'types' based on inputs and then hoped that Pex would work the factory out to generate different inputs, and therefore put different inputs into my test method.




  • typeof(object) and typeof(object)

  • typeof(object) and typeof(string)

  • and so on...



Now it just complains that Sytem.Type is abstract and can't be explored. I'm new to Pex, but I don't know how else to generate varying inputs for the methods.



Any help?



Thanks.





Increase Alphanumeric VARCHAR Entry by Value 1?

On an old project because of not thought through design I have a column which actually should be set to auto_increment, though it cannot be because it are alphanumeric entries as follows:



c01
c02
c03


(c99 would continue to c100 and more), the letter happened in the past and it would require to overhaul the system to take it out, thus I rather prefer this workaround.



Now I need a way to imitate the auto_increment functionality with the SQL statement myself, my own attempt has gotten as far as the following:



INSERT INTO tags (tag_id, tag_name, tag_description, added_by_user_id, creation_date, last_edited) VALUES (SELECT(MAX(tag_id)+1), 

'Love', 'All about love', 7, now(), 0);


This one does not work as is, though the idea was to select the highest entry in the column "tag_id" and then simply increase it by the value 1.



Any ideas how to accomplish this?



By the way I am also not sure if you simply can increase an alphanumeric entry through this way, though I know it can be done, I just don't know how.





Is there something better than Navicat in OSX?

I'm working with postgreSQL and developing a lot of PLPGSQL functions and procedures, and navigation is getting tedious and giving me headaches.



At database level (tables and such) it is fine but developing functions is a pain in the neck.





How to get URL string into PHP variable

Let's start with an example:



So requested URL would be: www.domain.com/product/hdd/samsung



I want to have a rewrite rule to get index.php and save everything after www.domain.com into php varible. So, substituted page would be for example www.domain.com/index.php?query=product/hdd/samsung. But I'am unable to write correct rule.



I tried this:



RewriteRule ^/(.*)$ index.php?query=$1 [NC,L]


The code above isn't working. I want to use the query in PHP code in the index.php:



if(isset($_GET["query"] )) {
$query=$_GET["query"];
}


I find out, there is possibility to get $query via $_SERVER['QUERY_STRING'], am I right?



For my PHP application is varibale $query critical, because it's used for loading templates.



Questions:
What solution would you recomand me? To use $_SERVER variable or mod_rewrite?
If mod_rewrite, how to write correct RewriteRule?



Thank you





Trying to load SQLite database once and persist across views in mobile Flex app

I have created a mobile app that has 3 views.



Each view needs access to a local SQLite database and currently I load the database on each view. What I would like to do is load the database once and use the sqlConnection and sqlStatement between views.



After some research I believe I need to create a Class - This is the 1st time I created a class and I have no errors in my class. I created 2 public variables called



sqlConnection and stmt and made them public. I then call my method that loads the database.



In my views I want to refer to those public variables so I can reuse the sqlconnection and sqlstatement whenever I wish. But I get an error message saying 'access of undefined property stmt' which is my public variable in the Class that is for my sqlstatement.



My class is structered like so:



package com.myDomain.db
{
import flash.data.SQLConnection;
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.display.Sprite;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
import flash.filesystem.File;

public class dbOperations
{
public var sqlConnection:SQLConnection;
public var stmt:SQLStatement = new SQLStatement();
private var isLoaded:Boolean = false;


public function OpenDB():void
{

if(!isLoaded){

isLoaded = true

sqlConnection = new SQLConnection();
sqlConnection.open(File.applicationDirectory.resolvePath("myFile.db"));
stmt.sqlConnection = sqlConnection;
stmt.text = "CREATE TABLE IF NOT EXISTS tblDefault(DefaultID integer primary key, Field1 text, Field2 numeric)";
stmt.execute();
}
}
}


}



Obviously I am doing something wrong but how do I refer to the public variables sqlConnection and stmt from within my views.



cheers,






Never mind people I figured it out.



I removed my public declarations from this class and I created a new class to hold my Global variables and set them as static and refer to my global variables through my global class.



cheers,





MSVC environment variables not showing up in different terminals

I'm using HaXe's HXCPP to generate C++ code and compile it with Microsoft Visual Studio 2010 Express Edition. I'm following this guide and it asks you to run "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat" so that cl.exe (the compiler) is in your build path.



This does allow me to run cl.exe, but only in that terminal. It fails if I attempt to run it from another terminal or within my IDE (Sublime Text 2).



I figured out a workaround: manually copy+paste variable values from the terminal to the GUI enviorment variable editor.



There's gotta be a better way. What am I missing?



build.hxml



-main Test
-cpp bin


Test.hx



class Test {
static function main() {
trace("Hello World!");
}
}


Error message when building



link.exe -out:Test.exe -nologo -machine:x86 -libpath:lib user32.lib -libpath:e:/VS8/PlatformSDK/Lib @all_objs
LINK : fatal error LNK1181: cannot open input file 'user32.lib'
Called from ? line 1
Called from BuildTool.hx line 1246
Called from BuildTool.hx line 554
Called from BuildTool.hx line 591
Called from BuildTool.hx line 710
Called from BuildTool.hx line 796
Called from BuildTool.hx line 285




How to use textbox to show an element in a string array?

I can show text in the textbox with



             textBox2->Text = "sddd";


I have a string array, but I tried



  Both textBox2->Text = sss[0]; and textBox2->Text = ^sss[0];


But both do NOT work



What is the correct way to show the element in the array?