<?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>phill84.org &#187; java</title>
	<atom:link href="http://phill84.org/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://phill84.org</link>
	<description>System.out.print</description>
	<lastBuildDate>Sat, 26 Mar 2011 10:21:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>寫了個超級簡單的 chatroom &#8230;</title>
		<link>http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/</link>
		<comments>http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 11:03:48 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[chatroom]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/</guid>
		<description><![CDATA[兩個 class 加兩個 jsp &#8230; 功能極其有限 lol source 在這裡]]></description>
			<content:encoded><![CDATA[<p>兩個 class 加兩個 jsp &#8230;<br />
功能極其有限 lol</p>
<p>source 在<a href="http://code.google.com/p/simplechatroom/source/browse/">這裡</a></p>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to distinguish incoming trunks in asterisk-java</title>
		<link>http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/</link>
		<comments>http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 10:28:52 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[1.6]]></category>
		<category><![CDATA[accountcode]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sip]]></category>
		<category><![CDATA[trunk]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/03/how-to-distinguish-incoming-trunk-in-asterisk-java/</guid>
		<description><![CDATA[Suppose you have asterisk 1.6 with freepbx and you are developing with the latest asterisk-java library. Somehow you wanna perform different tasks based on calls coming through different SIP trunks. When there&#8217;s a new incoming call, asterisk-java will trigger a &#8230; <a href="http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Suppose you have asterisk 1.6 with freepbx and you are developing with the latest asterisk-java library. Somehow you wanna perform different tasks based on calls coming through different SIP trunks.</p>
<p>When there&#8217;s a new incoming call, asterisk-java will trigger a newChannelEvent, but there&#8217;s no information in this event that can be used for distinguish from which trunk this call is coming in.</p>
<p>By default the accountcode in this NewChannelEvent is null, which makes sense because the accountcode is used for billing, and no one, at least not many people, wants to record the charge of SIP trunk because that&#8217;s usually done by the SIP provider to which the trunk is registered to. But since the accountcode is null and useless here, maybe we can use it as an identifier to distinguish the incoming trunk, it may be not the smartest solution, but at least it&#8217;s a working one <img src='http://phill84.org/wp-includes/images/smilies/icon_biggrin.gif' alt="icon biggrin How to distinguish incoming trunks in asterisk java" class='wp-smiley colorbox-563' title="How to distinguish incoming trunks in asterisk java" /> <span id="more-563"></span></p>
<p>The solution is pretty easy. Just open extensions_custom.conf and add<br />
<code>[ext-did-custom]<br />
exten =&gt; &lt;username from your sip provider&gt;,1,Set(CDR(accountcode)=&lt;some account&gt;)</code><br />
et voilà! <img src='http://phill84.org/wp-includes/images/smilies/icon_wink.gif' alt="icon wink How to distinguish incoming trunks in asterisk java" class='wp-smiley colorbox-563' title="How to distinguish incoming trunks in asterisk java" /> </p>
<p>If you try to make a call from outside now, in this NewChannelEvent the accountcode is still null, but there will be a NewAccountCodeEvent and you can see that the accountcode is set in this event, and from the same uniqueid you can tell that both the NewChannelEvent and NewAccountCodeEvent belong to the same call.</p>
<p>*note: Remeber that you should never manually edit extensions_additional.conf, the file is generated by freepbx and all the changes you have done will be overrided the next time you apply some changes in freepbx</p>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>quicksorting with stacks</title>
		<link>http://phill84.org/2008/06/quicksorting-with-stacks/</link>
		<comments>http://phill84.org/2008/06/quicksorting-with-stacks/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 20:55:27 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Hi Lo]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Partition]]></category>
		<category><![CDATA[Public Void]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[Stacks]]></category>

		<guid isPermaLink="false">http://phill84.org/?p=81</guid>
		<description><![CDATA[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 public void quicksort&#40;int&#91;&#93; d, int lo, int hi&#41;&#123; if&#40;lo&#60;hi&#41;&#123; &#8230; <a href="http://phill84.org/2008/06/quicksorting-with-stacks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> quicksort<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> d, <span style="color: #000066; font-weight: bold;">int</span> lo, <span style="color: #000066; font-weight: bold;">int</span> hi<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>lo<span style="color: #339933;">&lt;</span>hi<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> pivotIndex<span style="color: #339933;">=</span>partition<span style="color: #009900;">&#40;</span>d, lo, hi<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		quicksort<span style="color: #009900;">&#40;</span>d,lo,pivotIndex<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		quicksort<span style="color: #009900;">&#40;</span>d,pivotIndex<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>,hi<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> partition<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> d,<span style="color: #000066; font-weight: bold;">int</span> lo, <span style="color: #000066; font-weight: bold;">int</span> hi<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		intStack smaller <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> intStack<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		intStack larger <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> intStack<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> pivot <span style="color: #339933;">=</span> d<span style="color: #009900;">&#91;</span>hi<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>lo<span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>hi<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>pivot<span style="color: #009900;">&#41;</span>
				smaller.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">else</span>
				larger.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>lo<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>smaller.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			d<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>smaller.<span style="color: #006633;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			i<span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
		d<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pivot<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> pivotIndex <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
		i<span style="color: #339933;">++;</span>
		<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>larger.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			d<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> larger.<span style="color: #006633;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			i<span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">return</span> pivotIndex<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2008/06/quicksorting-with-stacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One-way QuickSort implemented in Java</title>
		<link>http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/</link>
		<comments>http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 07:21:08 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[Int Tmp]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Java Codes]]></category>
		<category><![CDATA[Partition]]></category>
		<category><![CDATA[Pivots]]></category>
		<category><![CDATA[Public Static Void]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[Quicksort Java]]></category>

		<guid isPermaLink="false">http://phill84.org/?p=70</guid>
		<description><![CDATA[The codes might be not optimized, and the first elements of all arrays are chosen as the pivots, which will cause a tremendous slow-down when the array is sorted already. 1 2 3 4 5 6 7 8 9 10 &#8230; <a href="http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The codes might be not optimized, and the first elements of all arrays are chosen as the pivots, which will cause a tremendous slow-down when the array is sorted already.</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> swap<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ar, <span style="color: #000066; font-weight: bold;">int</span> a, <span style="color: #000066; font-weight: bold;">int</span> b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">int</span> tmp <span style="color: #339933;">=</span> ar<span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	ar<span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ar<span style="color: #009900;">&#91;</span>b<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	ar<span style="color: #009900;">&#91;</span>b<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> tmp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> partition<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a, <span style="color: #000066; font-weight: bold;">int</span> left, <span style="color: #000066; font-weight: bold;">int</span> right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">int</span> pivot<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>left<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">int</span> m<span style="color: #339933;">=</span>left<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>left<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>right<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>pivot<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			m<span style="color: #339933;">++;</span>
			swap<span style="color: #009900;">&#40;</span>a, i, m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>	
	<span style="color: #009900;">&#125;</span>
	swap<span style="color: #009900;">&#40;</span>a, left, m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> m<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> quicksort<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a, <span style="color: #000066; font-weight: bold;">int</span> left, <span style="color: #000066; font-weight: bold;">int</span> right<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>left<span style="color: #339933;">&gt;=</span>right<span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">int</span> pivotIndex <span style="color: #339933;">=</span> partition<span style="color: #009900;">&#40;</span>a, left, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	quicksort<span style="color: #009900;">&#40;</span>a, left, pivotIndex<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	quicksort<span style="color: #009900;">&#40;</span>a, pivotIndex<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

