February 13, 2010
Ran into a problem returning an XML data with special characters encoded into it through an AJAX call. The problem was that special characters (i.e. ñ -> ñ) throws an error when being returned through XML and is in the process of being parsed by the browser.
The catch?
XML does not support named entities by default, you have to declare it before hand. Only < > & " and ' are predefined.
Something like:
1
2
3
| <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> |
Got this from here…
The fix…
Instead of using named entities in the XML (I think this also affects JSON, I could be wrong since I didn’t test this is JSON) like ñ, use character references to support special character encoding.
Example:
white space = =  
ñ = ñ = ñ
they are all the same… #160 is referenced/mapped to ” ” and #241 is referenced/mapped to ñ
So when forming your XML before returning it through an AJAX call, form the special characters via character reference.
Hope this helps you out there having this problem.
Related posts
Posted in Tips & Tricks
No Comments »
February 13, 2010
Encountered this problem today while testing an image upload AJAX script in tomcat. Later on I found out that the folder is actually protected Win7 and tomcat couldn’t write the cache or temporary file into the folder.
So anyone having this problem, check the following…
- What OS are you running? Vista/Win7?
- What IDE are you using?
- Was your IDE elevated to admin status?
So, check your OS, I’m using Win7. I was developing this under WinXP a few months back, and now under Win7, the folder is protected since it was under the “Program Files (x86)” folder group. (Argh!)
I closed my IDE, using IDEA IntelliJ 9.0, ran the IDE under “Administrator Level” and the problem disappeared!
So check those out first.
Related posts
Posted in General, Tips & Tricks
No Comments »
December 3, 2009
A little background info, Google Analytics is a free service provided by google to track site statistics, page visits, unique visitors, most visited page, etc.
Now I have been working around with flash actionscript 2 for a few months now and last week I was trying to connect to google analytics using flash actionscript 2, I know there’s already Actionscript 3 but its AS2 that was required for the project
After a few days of trial and error, finally got the stupid code to work, my initial code was not able to properly remove the white spaces from the returned IDs sent by Google. Weird thing is as I googled around the web, people seem to have a problem logging in and authenticating google AuthID through flash AS2 and AS3. As I understand it, there was supposed to be no way of authenticating the AuthID unless google add an option in their crossdomain.xml.
Well… seems like I was able to login and authenticate using the google account’s AuthID and retrieve my Profile list as well as used the profile data to retrieve the analytics data from my account =)
Codes are shown below on how I was able to login and authenticate the AuthID. One note, ALWAYS remove the white spaces (\r and \n) that was returned after initial login process (email & pass).
Note this is just a proof of concept and I didn’t do any clean-up,etc…
This will also work with Actionscript 3…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
| var authId:String = "";
gProfile = new LoadVars();
gData = new LoadVars();
gLogin = new LoadVars();
gLogin.Email = "yourgoogleaccount@email.com.here";
gLogin.Passwd = "password goes here";
gLogin.service = "analytics"; // what service your accessing, analytics for google analytics, mail for gmail, and so on...
gLogin.accountType = "GOOGLE"; // this should be default to GOOGLE
gLogin.source = "proj-name-0.1"; // anything goes heres, just a string for your proj
gLogin.onLoad = function(success) {
if (success)
{
logs.text += "\ryay!";
} else {
logs.text += "\rtry again";
}
}
//header content type should be of application urlencoded form
headers = new Array(["Content-Type", "application/x-www-form-urlencoded"]);
gLogin.onHTTPStatus = function(httpStatus:Number) {
logs.text += "\r" + httpStatus;
}
//address where to login using the username and pass
gLogin.sendAndLoad("https://www.google.com/accounts/ClientLogin", gLogin, "POST");
var myAuthID:String;
gLogin.onData = function(ret:String) {
var auth:Array = ret.split("Auth=");
authId = auth[1];
authId = authId.split('\n').join('');
var auth:String = "GoogleLogin auth=" + authId;
logs.text += "\r" + auth;
myAuthID = authId;
//for the authentication and profile retrieval, add the "Authorization" header and the google login authid we received
// from google after logging in a few seconds ago. We also add X-HTTP-Method-Override with a value of "GET" to force
// the server to accept our data as GET insted of POST method, if we don't do this, the Authorization fails.
gProfile.addRequestHeader(["X-HTTP-Method-Override", "GET", "Authorization", "GoogleLogin auth=" + authId]);
//debugging trace of the customer headers
trace("_customHeaders = " + gProfile._customHeaders);
//authorization and profile retrieval address
gProfile.sendAndLoad("https://www.google.com/analytics/feeds/accounts/default", gProfile, "POST");
}
String.prototype.replace = function(searchStr, replaceStr):String {
var arr:Array = this.split(searchStr);
return arr.join(replaceStr);
};
gProfile.onData = function(ret:String) {
trace("----->" + ret);
//everytime you retrieve data/profile from google analytics, always add the Authorization header as this will
// be used to authenticate your account.
gData.addRequestHeader(["X-HTTP-Method-Override", "GET", "Authorization", "GoogleLogin auth=" + myAuthID]);
trace("_customHeaders = " + gData._customHeaders);
//here is the string to query analytics data from a certain project, ids is the table/proj id to retrieve the metrics
// you can read more from analytics developer api docs on how to manipulate your data retrieval...
var str:String = "&ids=ga:1234567&dimensions=ga:source,ga:medium&metrics=ga:visits,ga:pageviews";
gData.sendAndLoad("https://www.google.com/analytics/feeds/data?start-date=2009-10-01&end-date=2009-10-31" + str, gData, "POST");
}
gData.onData = function (ret:String){
trace("======" + ret );
}
gProfile.onHTTPStatus = function(httpStatus:Number) {
logs.text += "\r" + httpStatus ;
} |
Any suggestions and comments are very welcome.
Update: I’d like to add that this only works on your local machine, if you upload this to a live server or website, you will need a crossdomain.xml from www.google.com to allow your site.
Related posts
Posted in Code Library, Tips & Tricks
5 Comments »
November 17, 2009
I’m now developing in flash actionscript 2…. ok from one language to the other….
Related posts
Posted in General
No Comments »
May 5, 2009
I’m currently playing around with Java Native Interfaces(JNI) and I must say its been too long since I programmed in Java. Its good to be back! Anyway, lets hop to the main topic…
I was following the tutorial from Sun in creating my first JNI and calling my compiled C++ library, I was stuck in the last part where this error popped out whenever I tried to invoke
the error was…
java.lang.UnsatisfiedLinkError: no HelloWorld in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at HelloWorld.<clinit>(HelloWorld.java:<line number>)
Could not find the main class: HelloWorld. Program will exit.
</line></clinit>
one way of fixing this is to include the current location of your newly compiled shared library (ex. HelloWorld.so). I’m using Ubuntu linux,so to include the current folder where your “.so” file is located, invoke…
LD_LIBRARY_PATH=`pwd`
export LD_LIBRARY_PATH
or you can also do …
Read the rest of this entry »
Related posts
Posted in Code Library, Tips & Tricks
4 Comments »
February 27, 2009
Seems like I got caught up with my work again, ah well que sera sera… I’ll be posting some new stuffs later on, one will be mysql replication through SSH tunneling and the other are tips on extjs javascript framework I have been using for over 2 years now. Should have done this a looooong time ago.
Stay tune
Related posts
Posted in General
No Comments »
December 9, 2008
Came across this little bugger in my manager’s pc. The whole thing is that after logging into windows, the windows explorer continuously restart and exits. You can click the start button, open something but will naturally kill itself when explorer exits. You can’t even open the drives and folders normally since it will close sooner or later, anything running under Explorer.exe will die when Explorer.exe dies. Simplest way around the folder and drives is using the good ol’ command prompt. Did this and amazingly it didn’t die, thank God for command prompts. As usual scouring the RECYCLER folder for hidden trojans resulted in a no show, next was the usual system32 and system folder under windows folder. These little buggers get smarter everyday. There weren’t and hidden files so I was already assuming the exe file is there and ran through windows startup using the registry. Using autoruns from sysinternals, found one of the problems, a rogue exe is started everytime the system starts. Deleted the entry from the registry, located the file under system32 folder and also removed it.
That didn’t fixed the problem.
There was something else running when windows starts up. Next target… DLLs. Amazingly, there were dlls that was out-of-placed and curiously named. Example crypt32.dll that wasn’t signed by microsoft. Removed the entry and tried to remove the dll. No luck, its being used. Next tool that was very useful was Unlocker. I ‘unlocked’ the hook for the dll and restarted. Still didn’t fix it but I was getting close. There were two more dlls I found that was very suspicious. I tried to kill one and removed, the other regenerated the dll. I try to unhook the other dll, the whole pc restarts. Smart bugger. Thank goodness for safe mode. Restarted in safe mode and use unlocker again to unhook the dll. Removed one of the dll and its entry in the registry. Good… it didn’t restart… just a countdown for a system shutdown.. freaking dll.
The system restarted and good news is the dll that forced the shutdown wasn’t regenerated. Last dll was a bit simpler. Used unlocker to unhook the dll, deleting was not successful, though unlocker had a feature to delete the dll after a restart. Selected the option and waited. Thankfully, the whole ordeal ended there. All three dlls didn’t regenerate after that.
Note to PC users who watch videos from torrent ( Heroes, Prison break…). If it asks you to download a player to run the video you downloaded.. DON’T!!
Related posts
Posted in Tips & Tricks
No Comments »
November 27, 2008
Well, its been a month… or more? of no updates… been busy for a while cleaning codes and installing some pcs. I was thinking of posting those extjs codes I used that gave me some ‘wtf?!’ or ‘doh!’ moments in the past….we’ll see. I’m also currently compiling the documentations on how I set up a replication master-slaver server on 3 different locations and replicate through SSH. I’ll be posting that later on also.
Related posts
Posted in General
No Comments »
October 20, 2008
This problem is a little tricky, there are possible fixes that MySQL website has stated. Sad to say, the one’s I read in the forum and site didn’t fix my problem. What I encountered was that the relay-bin from my MySQL slave server has already been ‘rotated’, meaning deleted from the folder. This happens when the slave has been disconnected from the master for quite a long time already and has not replicated anything. A simple way to fix this is to flush the logs, but make sure the slave is stopped before using this command…
FLUSH LOGS;
Bring in a fresh copy of the database from the master-server and update the slave-server database. THIS IS IMPORTANT! Since if you don’t update the slave database, you will not have the data from the time you were disconnected until you reset the relay logs. So UPDATE YOUR SLAVE WITH THE LATEST DATABASE FROM THE MASTER!
Now when the logs are flushed,all the relay-bin logs will be deleted when the slave is started again. Usually, this fixes the problem, but when you start the slave and the failed relay log error is still there, now you have to do some more desperate measures… reset the slave. This is what I had to do to fully restore my MySQL slave server. Reseting the slaves restores all the settings to default… password, username, relay-log, port, table to replicate, etc… So better to have a copy of your settings first before actually do a slave reset. When your ready to rest the slave, do the command…
RESET SLAVE;
after which you should restore all your setting with a command something like…
CHANGE MASTER TO MASTER_HOST=.....
now start your server with…
SLAVE START;
check your slave server with…
SHOW SLAVE STATUS\G
look for …
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
both should be YES, if not, check your syslog if there are other errors encountered. I’ll leave this until here since this is what I encountered and I was able to fix it.
Related posts
Posted in MySQL, Tips & Tricks
No Comments »
Recent Comments