<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SlickDev &#187; Code Library</title>
	<atom:link href="http://www.slickdev.com/category/code_lib/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.slickdev.com</link>
	<description>Freelance Web and Software Developer</description>
	<lastBuildDate>Sat, 15 May 2010 02:27:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Google Analytics with Flash Actionscript 2</title>
		<link>http://www.slickdev.com/2009/12/03/google-analytics-with-flash-actionscript-2/</link>
		<comments>http://www.slickdev.com/2009/12/03/google-analytics-with-flash-actionscript-2/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 09:00:42 +0000</pubDate>
		<dc:creator>Chaoz</dc:creator>
				<category><![CDATA[Code Library]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.slickdev.com/?p=106</guid>
		<description><![CDATA[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, [...]]]></description>
			<content:encoded><![CDATA[<p>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. </p>
<p>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&#8217;s already Actionscript 3 but its AS2 that was required for the project <img src='http://www.slickdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  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.</p>
<p>Well&#8230; seems like I was able to login and authenticate using the google account&#8217;s AuthID and retrieve my Profile list as well as used the profile data to retrieve the analytics data from my account =)</p>
<p>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 &#038; pass).</p>
<p>Note this is just a proof of concept and I didn&#8217;t do any clean-up,etc&#8230;<br />
This will also work with Actionscript 3&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> authId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span>;
gProfile = <span style="color: #0033ff; font-weight: bold;">new</span> LoadVars<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
gData = <span style="color: #0033ff; font-weight: bold;">new</span> LoadVars<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
gLogin = <span style="color: #0033ff; font-weight: bold;">new</span> LoadVars<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
gLogin.Email = <span style="color: #990000;">&quot;yourgoogleaccount@email.com.here&quot;</span>;
gLogin.Passwd = <span style="color: #990000;">&quot;password goes here&quot;</span>;
gLogin.service = <span style="color: #990000;">&quot;analytics&quot;</span>; <span style="color: #009900;">// what service your accessing, analytics for google analytics, mail for gmail, and so on...</span>
gLogin.accountType = <span style="color: #990000;">&quot;GOOGLE&quot;</span>; <span style="color: #009900;">// this should be default to GOOGLE</span>
gLogin.<span style="color: #004993;">source</span> = <span style="color: #990000;">&quot;proj-name-0.1&quot;</span>; <span style="color: #009900;">// anything goes heres, just a string for your proj</span>
&nbsp;
gLogin.onLoad = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>success<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>success<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        logs.<span style="color: #004993;">text</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;<span style="">\r</span>yay!&quot;</span>;
&nbsp;
    <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
        logs.<span style="color: #004993;">text</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;<span style="">\r</span>try again&quot;</span>;    
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">//header content type should be of application urlencoded form</span>
headers = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;Content-Type&quot;</span>, <span style="color: #990000;">&quot;application/x-www-form-urlencoded&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
gLogin.onHTTPStatus = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">httpStatus</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
       logs.<span style="color: #004993;">text</span> <span style="color: #000000; font-weight: bold;">+</span>=  <span style="color: #990000;">&quot;<span style="">\r</span>&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">httpStatus</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">//address where to login using the username and pass</span>
gLogin.sendAndLoad<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;https://www.google.com/accounts/ClientLogin&quot;</span>, gLogin, <span style="color: #990000;">&quot;POST&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> myAuthID<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
gLogin.onData = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>ret<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>	
	<span style="color: #6699cc; font-weight: bold;">var</span> auth<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = ret.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Auth=&quot;</span><span style="color: #000000;">&#41;</span>;
	authId = auth<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>;	
	authId = authId.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'<span style="">\n</span>'</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">''</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> auth<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;GoogleLogin auth=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span>  authId;
	logs.<span style="color: #004993;">text</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;<span style="">\r</span>&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> auth;
	myAuthID = authId;
&nbsp;
	<span style="color: #009900;">//for the authentication and profile retrieval, add the &quot;Authorization&quot; header and the google login authid we received </span>
	<span style="color: #009900;">// from google after logging in a few seconds ago. We also add X-HTTP-Method-Override with a value of &quot;GET&quot; to force</span>
	<span style="color: #009900;">// the server to accept our data as GET insted of POST method, if we don't do this, the Authorization fails.</span>
	gProfile.addRequestHeader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;X-HTTP-Method-Override&quot;</span>, <span style="color: #990000;">&quot;GET&quot;</span>, <span style="color: #990000;">&quot;Authorization&quot;</span>, <span style="color: #990000;">&quot;GoogleLogin auth=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> authId<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #009900;">//debugging trace of the customer headers</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_customHeaders = &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> gProfile._customHeaders<span style="color: #000000;">&#41;</span>;		
&nbsp;
	<span style="color: #009900;">//authorization and profile retrieval address</span>
	gProfile.sendAndLoad<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;https://www.google.com/analytics/feeds/accounts/default&quot;</span>, gProfile, <span style="color: #990000;">&quot;POST&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #004993;">String</span>.<span style="color: #004993;">prototype</span>.<span style="color: #004993;">replace</span> = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>searchStr, replaceStr<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>	
    <span style="color: #6699cc; font-weight: bold;">var</span> arr<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span>searchStr<span style="color: #000000;">&#41;</span>;
    <span style="color: #0033ff; font-weight: bold;">return</span> arr.<span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span>replaceStr<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>;
&nbsp;
gProfile.onData = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>ret<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;-----&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> ret<span style="color: #000000;">&#41;</span>;
	<span style="color: #009900;">//everytime you retrieve data/profile from google analytics, always add the Authorization header as this will </span>
	<span style="color: #009900;">// be used to authenticate your account.	</span>
	gData.addRequestHeader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;X-HTTP-Method-Override&quot;</span>, <span style="color: #990000;">&quot;GET&quot;</span>, <span style="color: #990000;">&quot;Authorization&quot;</span>, <span style="color: #990000;">&quot;GoogleLogin auth=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> myAuthID<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_customHeaders = &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> gData._customHeaders<span style="color: #000000;">&#41;</span>;		
&nbsp;
	<span style="color: #009900;">//here is the string to query analytics data from a certain project, ids is the table/proj id to retrieve the metrics</span>
	<span style="color: #009900;">// you can read more from analytics developer api docs on how to manipulate your data retrieval...</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> str<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&amp;ids=ga:1234567&amp;dimensions=ga:source,ga:medium&amp;metrics=ga:visits,ga:pageviews&quot;</span>;
	gData.sendAndLoad<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;https://www.google.com/analytics/feeds/data?start-date=2009-10-01&amp;end-date=2009-10-31&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> str, gData, <span style="color: #990000;">&quot;POST&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
gData.onData = <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#40;</span>ret<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;======&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> ret <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
gProfile.onHTTPStatus = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">httpStatus</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
       logs.<span style="color: #004993;">text</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;<span style="">\r</span>&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">httpStatus</span> ;
    <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Any suggestions and comments are very welcome.</p>
<p><strong>Update:</strong> I&#8217;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 <strong><em>crossdomain.xml</em></strong> from www.google.com to allow your site.</p>
<p><strong>Sources:</strong><br />
<a href="http://meidell.dk/archives/2005/12/30/http-authentication-with-flash/">http://meidell.dk/archives/2005/12/30/http-authentication-with-flash/</a><br />
<a href="http://code.google.com/p/ga-api-http-samples/source/browse/trunk/src/v2/accountFeed.sh">http://code.google.com/p/ga-api-http-samples/source/browse/trunk/src/v2/accountFeed.sh</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.slickdev.com/2009/12/03/google-analytics-with-flash-actionscript-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Java JNI: Unsatisfied Link Error in Library Path</title>
		<link>http://www.slickdev.com/2009/05/05/java-jni-unsatisfied-link-error-in-library-path/</link>
		<comments>http://www.slickdev.com/2009/05/05/java-jni-unsatisfied-link-error-in-library-path/#comments</comments>
		<pubDate>Tue, 05 May 2009 08:29:06 +0000</pubDate>
		<dc:creator>Chaoz</dc:creator>
				<category><![CDATA[Code Library]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Others]]></category>

		<guid isPermaLink="false">http://www.slickdev.com/?p=88</guid>
		<description><![CDATA[I&#8217;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&#8230; I was following the tutorial from Sun in creating my first JNI and calling my compiled C++ library, I was stuck in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;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&#8230;</p>
<p>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</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java HelloWorld</pre></div></div>

<p>the error was&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java.lang.UnsatisfiedLinkError: no HelloWorld <span style="color: #000000; font-weight: bold;">in</span> java.library.path
          at java.lang.ClassLoader.loadLibrary<span style="color: #7a0874; font-weight: bold;">&#40;</span>ClassLoader.java:<span style="color: #000000;">1709</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
          at java.lang.Runtime.loadLibrary0<span style="color: #7a0874; font-weight: bold;">&#40;</span>Runtime.java:<span style="color: #000000;">823</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
          at java.lang.System.loadLibrary<span style="color: #7a0874; font-weight: bold;">&#40;</span>System.java:<span style="color: #000000;">1030</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
          at HelloWorld.<span style="color: #000000; font-weight: bold;">&lt;</span>clinit<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>HelloWorld.java:<span style="color: #000000; font-weight: bold;">&lt;</span>line number<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Could not <span style="color: #c20cb9; font-weight: bold;">find</span> the main class: HelloWorld. Program will exit.</pre></div></div>

<p>one way of fixing this is to include the current location of your newly compiled shared library (ex. HelloWorld.so). I&#8217;m using Ubuntu linux,so to include the current folder where your &#8220;.so&#8221; file is located, invoke&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LD_LIBRARY_PATH</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">export</span> LD_LIBRARY_PATH</pre></div></div>

<p>or you can also do &#8230;<br />
<span id="more-88"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LD_LIBRARY_PATH</span>=.
<span style="color: #7a0874; font-weight: bold;">export</span> LD_LIBRARY_PATH</pre></div></div>

<p>another way is to define the location when running the program&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java -Djava.library.path=. HelloWorld</pre></div></div>

<p>this will instruct java to locate the native library in the current location. Now call your program again and this time it work execute your native program.</p>
<p>It&#8217;s possible that when you execute your program after doing the above steps, another error will come out. This happened to me and the culprit was when I compiled the cpp file. The error would look something like&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java.lang.UnsatisfiedLinkError: <span style="color: #000000; font-weight: bold;">&lt;</span>library location<span style="color: #000000; font-weight: bold;">&gt;</span>: <span style="color: #000000; font-weight: bold;">&lt;</span>library location<span style="color: #000000; font-weight: bold;">&gt;</span>: only ET_DYN and ET_EXEC can be loaded
        at java.lang.ClassLoader<span style="color: #007800;">$NativeLibrary</span>.load<span style="color: #7a0874; font-weight: bold;">&#40;</span>Native Method<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        at java.lang.ClassLoader.loadLibrary0<span style="color: #7a0874; font-weight: bold;">&#40;</span>ClassLoader.java:<span style="color: #000000;">1778</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        at java.lang.ClassLoader.loadLibrary<span style="color: #7a0874; font-weight: bold;">&#40;</span>ClassLoader.java:<span style="color: #000000;">1674</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        at java.lang.Runtime.load0<span style="color: #7a0874; font-weight: bold;">&#40;</span>Runtime.java:<span style="color: #000000;">770</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        at java.lang.System.load<span style="color: #7a0874; font-weight: bold;">&#40;</span>System.java:<span style="color: #000000;">1005</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        at HelloWorld.<span style="color: #000000; font-weight: bold;">&lt;</span>clinit<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>HelloWorld.java:<span style="color: #000000;">16</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>to fix this, include the &#8220;-shared&#8221; option when compiling the cpp file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">g++</span> <span style="color: #660033;">-shared</span> HelloWorld.cpp <span style="color: #660033;">-o</span> HelloWorld.so <span style="color: #660033;">-I</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>java<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>folder<span style="color: #000000; font-weight: bold;">/</span>where<span style="color: #000000; font-weight: bold;">/</span>jni.h<span style="color: #000000; font-weight: bold;">/</span>is<span style="color: #000000; font-weight: bold;">/</span>located <span style="color: #660033;">-I</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>java<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>folder<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Do not include the &#8220;-c&#8221; option, this will skip the linking stage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.slickdev.com/2009/05/05/java-jni-unsatisfied-link-error-in-library-path/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>MySQL: Query Real Values from Delimiter-Separated-String-IDs</title>
		<link>http://www.slickdev.com/2008/09/15/mysql-query-real-values-from-delimiter-separated-string-ids/</link>
		<comments>http://www.slickdev.com/2008/09/15/mysql-query-real-values-from-delimiter-separated-string-ids/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 14:15:37 +0000</pubDate>
		<dc:creator>Chaoz</dc:creator>
				<category><![CDATA[Code Library]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.slickdev.com/?p=54</guid>
		<description><![CDATA[I had a problem in using a string-comma-separated-value returned from a query in an &#8220;IN&#8221; statement. I used the IDs from one table, concat them into a comma separated value and insert them into another table. Baaaad idea&#8230; Now when I query that value, I can&#8217;t use it directly into an &#8220;IN&#8221; statement to retrieve [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem in using a string-comma-separated-value returned from a query in an &#8220;IN&#8221; statement. I used the IDs from one table, <em>concat</em> them into a comma separated value and insert them into another table. Baaaad idea&#8230; Now when I query that value, I can&#8217;t use it directly into an &#8220;IN&#8221; statement to retrieve their real values since its a string being returned from the query, the &#8220;IN&#8221; statement will not compare all the values inside as a set, but it will compare it as a string. </p>
<p>e.g.<br />
<strong>SELECT value FROM my_table WHERE my_id IN (&#8217;1, 2, 3&#8242;)</strong> is NOT equivalent to <strong>SELECT value FROM my_table WHERE my_id IN (&#8217;1&#8242;, &#8217;2&#8242;, &#8217;3&#8242;)</strong></p>
<p>So, if you have a table containing values 1 to 3, the first query will return only <strong>1</strong> while the second query will return all values; <strong>1, 2 and 3</strong>.</p>
<p>I Googled around and found out that MySQL does not have a native equivalent of PHP&#8217;s <em>explode()</em> function. Crap&#8230; I had to do it the hard war and create a MySQL stored function to &#8216;explode&#8217; the values from its delimiter, query the right value from the other table using the exploded IDs, concat them back together and return them as a string.</p>
<p>Below is the function I was able to patch together from different codes I found in the MySQL forum. I added comments below as to make things clearer. I named the function <strong>splitAndTranslate</strong> since that&#8217;s what I was really trying to implement. You can make up your own modifications and function name.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">DELIMITER <span style="color: #66cc66;">//</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`splitAndTranslate`</span> <span style="color: #66cc66;">//</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> splitAndTranslate<span style="color: #66cc66;">&#40;</span>str TEXT<span style="color: #66cc66;">,</span> delim VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">124</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
RETURNS TEXT
DETERMINISTIC
BEGIN
	DECLARE i INT <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #cc66cc;">0</span>;	<span style="color: #808080; font-style: italic;">-- total number of delimiters</span>
	DECLARE ctr INT <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #cc66cc;">0</span>;	<span style="color: #808080; font-style: italic;">-- counter for the loop</span>
	DECLARE str_len INT;		<span style="color: #808080; font-style: italic;">-- string length,self explanatory</span>
	DECLARE out_str text <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">''</span>;	<span style="color: #808080; font-style: italic;">-- return string holder</span>
	DECLARE temp_str text <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">''</span>;	<span style="color: #808080; font-style: italic;">-- temporary string holder</span>
  	DECLARE temp_val VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">''</span>;	<span style="color: #808080; font-style: italic;">-- temporary string holder for query</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- get length</span>
	<span style="color: #993333; font-weight: bold;">SET</span> str_len<span style="color: #66cc66;">=</span>LENGTH<span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span>;	
&nbsp;
	<span style="color: #993333; font-weight: bold;">SET</span> i <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>LENGTH<span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span>LENGTH<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">,</span> delim<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>LENGTH<span style="color: #66cc66;">&#40;</span>delim<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;	
		<span style="color: #808080; font-style: italic;">-- get total number delimeters and add 1</span>
		<span style="color: #808080; font-style: italic;">-- add 1 since total separated values are 1 more than the number of delimiters</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- start of while loop</span>
	WHILE<span style="color: #66cc66;">&#40;</span>ctr<span style="color: #66cc66;">&lt;</span>i<span style="color: #66cc66;">&#41;</span> DO
		<span style="color: #808080; font-style: italic;">-- add 1 to the counter, which will also be used to get the value of the string</span>
		<span style="color: #993333; font-weight: bold;">SET</span> ctr<span style="color: #66cc66;">=</span>ctr<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span>; 
&nbsp;
		<span style="color: #808080; font-style: italic;">-- get value separated by delimiter using ctr as the index</span>
		<span style="color: #993333; font-weight: bold;">SET</span> temp_str <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span>SUBSTRING_INDEX<span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">,</span> delim<span style="color: #66cc66;">,</span> ctr<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> LENGTH<span style="color: #66cc66;">&#40;</span>SUBSTRING_INDEX<span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">,</span> delim<span style="color: #66cc66;">,</span>ctr <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> delim<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">-- query real value and insert into temporary value holder, temp_str contains the exploded ID    		</span>
		<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&lt;</span>real_value_column<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">INTO</span> temp_val <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&lt;</span>my_table<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&lt;</span>table_id<span style="color: #66cc66;">&gt;=</span>temp_str;
&nbsp;
		<span style="color: #808080; font-style: italic;">-- concat real value into output string separated by delimiter</span>
    		<span style="color: #993333; font-weight: bold;">SET</span> out_str<span style="color: #66cc66;">=</span>CONCAT<span style="color: #66cc66;">&#40;</span>out_str<span style="color: #66cc66;">,</span> temp_val<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;
	END WHILE;
	<span style="color: #808080; font-style: italic;">-- end of while loop</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- trim delimiter from end of string</span>
	<span style="color: #993333; font-weight: bold;">SET</span> out_str<span style="color: #66cc66;">=</span>TRIM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">TRAILING</span> delim <span style="color: #993333; font-weight: bold;">FROM</span> out_str<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #993333; font-weight: bold;">RETURN</span><span style="color: #66cc66;">&#40;</span>out_str<span style="color: #66cc66;">&#41;</span>;	<span style="color: #808080; font-style: italic;">-- return </span>
&nbsp;
END<span style="color: #66cc66;">//</span></pre></td></tr></table></div>

<p>After creating the stored function, you can now use it normally like any MySQL function inside a query. So what I now do with the new function is&#8230;</p>
<p><strong>SELECT splitAndTranslate( g.comma_separated_ids ) real_values FROM my_group_table g;</strong></p>
<p>Thanks to Chris Stubben in the <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html">MySQL Forum</a>, I used and modified his code to fit my need.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.slickdev.com/2008/09/15/mysql-query-real-values-from-delimiter-separated-string-ids/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Java 5 JDK and Jakarta Tomcat 5.5 in Ubuntu Server Installation</title>
		<link>http://www.slickdev.com/2008/09/13/java-5-jdk-and-jakarta-tomcat-55-in-ubuntu-server-installation/</link>
		<comments>http://www.slickdev.com/2008/09/13/java-5-jdk-and-jakarta-tomcat-55-in-ubuntu-server-installation/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 04:19:33 +0000</pubDate>
		<dc:creator>Chaoz</dc:creator>
				<category><![CDATA[Code Library]]></category>
		<category><![CDATA[Mods]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.slickdev.com/?p=23</guid>
		<description><![CDATA[These are the steps I took to install Jakarta Tomkat 5.5 in conjunction with Java 2 SDK in Ubuntu server. Login as root, you can also use &#8220;su&#8221; though I prefer to login as root. apt-get install sun-java5-jdk This will install Java 2 SDK (1.5), ubuntu will start downloading packages that are not found in [...]]]></description>
			<content:encoded><![CDATA[<p>These are the steps I took to install Jakarta Tomkat 5.5 in conjunction with Java 2 SDK in Ubuntu server.</p>
<ol>
<li>Login as root, you can also use &#8220;<strong>su</strong>&#8221; though I prefer to login as root.</li>
<li><strong>apt-get install sun-java5-jdk</strong></li>
<ul>
<li>This will install Java 2 SDK  (1.5), ubuntu will start downloading packages that are not found in your system.</li>
</ul>
<li><strong>apt-get install tomcat5.5 tomcat5.5-admin tomcat5.5-webapps</strong></li>
<ul>
<li>Of course jakarta-tomcat 5.5, I&#8217;m using 5.5 since this supports java 1.5</li>
</ul>
<li>Now here&#8217;s the tricky part, location for Java and jakarta-tomcat</li>
<ul>
<li>Java&#8217;s location is in <strong>/usr/lib/jvm/java-1.5.0-sun</strong></li>
<li>Jakarta-Tomcat&#8217;s location is in <strong>/usr/share/tomcat5.5</strong></li>
<ul>
<li>We will need these location for the export configurations to be written in the <strong>.bashrc</strong></li>
</ul>
</ul>
<li>Now, open <strong>.bashrc</strong> in your favorite text editor, I used <strong>vim</strong></li>
<li>At the end of the file add these:<br />
<code><br />
export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun<br />
export CLASSPATH="/usr/share/tomcat5.5/common/lib/jsp-api.jar;/usr/share/tomcat5.5/common/lib/servlet-api.jar"<br />
export CATALINA_HOME=/usr/share/tomcat5.5<br />
</code></li>
<li>Now save the file and exit, then log back in. This is required for the export script to be set.</li>
<li>Before starting the server, the default port the installer set is 8180 instead of the 8080 port that Tomcat uses. To change this, go to <strong>/usr/share/tomcat5.5/conf/</strong> and open the file <strong>server.xml</strong>. Locate the line:<br />
<code><br />
...Connector port="8180" maxHttpHeaderSize="8192"...<br />
</code><br />
and change <strong>8180 </strong>to<strong> 8080</strong>. Save and exit. Now your ready to test the server.</li>
<li>Now try the server if it starts, <strong>/usr/share/tomcat5.5/bin/startup.sh</strong>  You should see  something like this:<br />
<code><br />
Using CATALINA_BASE:   /usr/share/tomcat5.5<br />
Using CATALINA_HOME:   /usr/share/tomcat5.5<br />
Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp<br />
Using JRE_HOME:       /usr/lib/jvm/java-1.5.0-sun<br />
</code></li>
<li>Shutting down the server is just <strong>/usr/share/tomcat5.5/bin/</strong><strong>shutdown.sh</strong></li>
<li>Now, during installation of tomcat, Ubuntu automatically adds a startup and shutdown script for ubuntu to use as it starts up or shutsdown in <strong>/etc/init.d/</strong> folder. Filename is <strong>tomcat5.5</strong>. As the server finishes starting up, you will notice tomcat isn&#8217;t running at all. One possible problem is that the script didn&#8217;t use the correct path for the java 2 sdk.  You can check the boot log in <strong>/var/log/</strong>. Check if during boot up, tomcat5.5 encountered problems. For the problem stated above, you can fix this by going to <strong>/etc/default/</strong> and edit the <strong>tomcat5.5</strong> file. Locate the line: <strong><br />
</strong><br /><code><strong>#JAVA_HOME=/usr/lib/j2sdk1.4-sun</strong></code></p>
<p>remove the <strong>&#8216;#&#8217;</strong> and change it to&#8230;<br />
<br /><code><strong>JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun</strong></code></p>
<p>or wherever your java directory is.After that, restart the server and see if tomcat was successfully started. <strong><br />
</strong><br /><code><strong>/etc/init.d/tomcat5.5 status</strong></code></li>
</ol>
<p><strong>Edit: Problem encountered:</strong></p>
<ul>
<li><strong>Tomcat does not load in Ubuntu 8.04</strong></li>
</ul>
<ul>
	Found a little problem loading Tomcat 5.5 under Ubuntu 8.04, it either fails or white screen just appears. I don&#8217;t know what happened from 6.04 to 8.04 but once I compared the <em>init.d/tomcat5.5</em> startup script from 6.04 and 8.04, there WERE changes to the scripts. I replaced the new tomcat5.5 script in 8.04 with the old one from 6.04 and the server started properly after a server restart. I don&#8217;t know why but this may have something to do with permissions and I have yet to trace the script.</p>
</ul>
<ul>
<li><strong>java.lang.ClassNotFoundException: org.apache.jasper.tagplugins.jstl.If</strong></li>
</ul>
<ol>
<ul>
<li>The problem here is that the above name is incomplete&#8230; what it should have been is  <strong>org.apache.jasper.tagplugins.jstl.core.*</strong></li>
<li>Now, to fix the problem, locate <span style="color: #000000"><code></span><strong><span style="color: #000000">/var/lib/tomcat5.5/webapps/jsp-examples/WEB-INF/tagPlugins.xml</span></strong></code> and open it with your text editor&#8230; I used <em>vim</em>. Now edit each line of code that has  <em><strong>org.apache.jasper.tagplugins.jstl</strong></em> in it and add &#8220;<strong>.core</strong>&#8221; after <strong>jstl</strong>. What you will see after editing the code will be&#8230;</li>
<p><code></p>
<p>org.apache.taglibs.standard.tag.rt.core.IfTag</p>
<p>org.apache.jasper.tagplugins.jstl.core.If</p>
<p>org.apache.taglibs.standard.tag.common.core.ChooseTag</p>
<p>org.apache.jasper.tagplugins.jstl.core.Choose</p>
<p>org.apache.taglibs.standard.tag.rt.core.WhenTag</p>
<p>org.apache.jasper.tagplugins.jstl.core.When</p>
<p>org.apache.taglibs.standard.tag.common.core.OtherwiseTag</p>
<p>org.apache.jasper.tagplugins.jstl.core.Otherwise</p>
<p>org.apache.taglibs.standard.tag.rt.core.ForEachTag</p>
<p>org.apache.jasper.tagplugins.jstl.core.ForEach</p>
<p></code>
</ul>
</ol>
<ul>
<li><strong>SEVERE: The scratchDir you specified: [folder_path] is unusable. </strong></li>
</ul>
<ul>
<ul>
<li>Sidenote: took me 2 days to figure out why this was happening (X_x)</li>
<li>Based from the Catalina logs, the folders under <em>webapps</em> was not accessible by tomcat5.</li>
<li>Now looking under all processes running ( ps command ), most bootup services were running under root (mysql, apache, etc ) but tomcat5 was not.</li>
<li>If I start tomcat5 when I logged into the console as root, the problem disappears. This lead me to believe this might have been the Tomcat5 user was not given the correct privileges.</li>
<li><strong>Work-around 1:</strong> Elevate Tomcat5 user to root access level.</li>
<li><strong>Work-around 2: </strong>Go to <em><strong>/etc/init.d/ </strong></em>and open <strong>Tomcat5.5</strong> under any text editor ( I used vim ). Locate the line <strong>TOMCAT5_USER=tomcat55</strong> and change it to <strong>TOMCAT5_USER=<em>root</em></strong> . Restart your server or you can also execute the restart command for <em><strong>Tomcat5.5</strong></em> in <strong><em>init.d</em></strong> folder</li>
</ul>
</ul>
<p><span style="color: #000000" />sources:</p>
<ul>
<li><a target="_blank" href="http://wiki.oss-watch.ac.uk/UbuntuDapper/Remaster">Ubuntu/Drapper Remaster</a></li>
<li><a target="_blank" href="http://www.linuxjournal.com/article/4576">linux journal</a></li>
<li><a target="_blank" href="http://doc.gwos.org/index.php/Install_tomcat_5.5">Ubuntu Install Tomcat</a></li>
<li><a target="_blank" href="http://www.netadmintools.com/art340.html">Net Admin Tools</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.slickdev.com/2008/09/13/java-5-jdk-and-jakarta-tomcat-55-in-ubuntu-server-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
