﻿<?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/"
	>

<channel>
	<title>Ryan-H.com</title>
	<atom:link href="http://www.ryan-h.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryan-h.com</link>
	<description>because Ryan Hamilton .com was taken</description>
	<pubDate>Mon, 31 Jan 2011 23:22:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>q-grams for fuzzy string matching in KDB</title>
		<link>http://www.ryan-h.com/kdb/q-grams-for-fuzzy-string-matching-in-kdb/</link>
		<comments>http://www.ryan-h.com/kdb/q-grams-for-fuzzy-string-matching-in-kdb/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 23:19:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[KDB]]></category>

		<category><![CDATA[fuzzy]]></category>

		<category><![CDATA[kx]]></category>

		<category><![CDATA[matching]]></category>

		<category><![CDATA[q]]></category>

		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.ryan-h.com/?p=173</guid>
		<description><![CDATA[To see if two strings are similar we can break the strings up into qgrams and count how many match between the two. Padding at the front and back is done so that start/end letters have a chance to cause a match without the whole start/end needing to match:

"Elvis" -> "##E" "#El" "Elv" "lvi" "vis" [...]]]></description>
			<content:encoded><![CDATA[<p>To see if two strings are similar we can break the strings up into qgrams and count how many match between the two. Padding at the front and back is done so that start/end letters have a chance to cause a match without the whole start/end needing to match:</p>
<p><code><br />
"Elvis" -> "##E" "#El" "Elv" "lvi" "vis" "is%" "s%%"<br />
"Jarvis" -> "##J" "#Ja" "Jar" "arv" "rvi" "vis" "is%" "s%%"<br />
i.e. Three would match here.<br />
<code></p>
<p>What's particularly good about this algorithm is that it easily adapted for use in databases. Here is a <a href="http://www.ryan-h.com/wp-content/uploads/2011/01/qgrams.zip">version in q/SQL</a> . q is a language created by <a href="http://www.kx.com/">KX</a> and is tightly tied to a database called <a href="http://kx.com/Products/kdb+.php">KDB+</a>, a <a href="http://kx.com/Developers/software.php">trial version</a> is available. The code is based on <a href="http://pages.stern.nyu.edu/~panos/publications/deb-dec2001.pdf">this paper</a> . </p>
<p>Using .qgrams.cache[] function in q we can see how it works:</p>

<div class="wp_syntax"><div class="code"><pre class="dos dos" style="font-family:monospace;">q<span style="color: #66cc66;">&#41;</span>a:<span style="color: #66cc66;">&#40;</span>&quot;Donald Knuth&quot;;&quot;Leslie Lamport&quot;;&quot;Ken Thompson&quot;;&quot;Rob Pike&quot;;&quot;Linus Torvalds&quot;;&quot;Richard Stallman&quot;;&quot;Tim Berners-Lee&quot;;&quot;Alan
 Turing&quot;;&quot;John Von Neumann&quot;;&quot;Brian Kernighan&quot;;&quot;Grace Hopper&quot;;&quot;Ada Lovelace&quot;;&quot;Edsger Dijkstra&quot;;&quot;Jon Von Neumann&quot;;&quot;Herb Simo
n&quot;;&quot;Kenneth Iverson&quot;<span style="color: #66cc66;">&#41;</span>;
q<span style="color: #66cc66;">&#41;</span>.qgrams.cache<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span>;a<span style="color: #66cc66;">&#93;</span>
qstr| pid pn
----| --------
##D | ,0  ,0
#DO | ,0  ,<span style="color: #cc66cc;">1</span>
DON | ,0  ,<span style="color: #cc66cc;">2</span>
ONA | ,0  ,<span style="color: #cc66cc;">3</span>
NAL | ,0  ,<span style="color: #cc66cc;">4</span>
ALD | 0 <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">5</span> <span style="color: #cc66cc;">12</span>
LD  | ,0  ,<span style="color: #cc66cc;">6</span>
D K | ,0  ,<span style="color: #cc66cc;">7</span>
KN  | ,0  ,<span style="color: #cc66cc;">8</span>
KNU | ,0  ,<span style="color: #cc66cc;">9</span>
NUT | ,0  ,<span style="color: #cc66cc;">10</span>
UTH | ,0  ,<span style="color: #cc66cc;">11</span>
TH<span style="color: #33cc33;">%</span><span style="color: #448888;"> | ,0  ,<span style="color: #cc66cc;">12</span>
H</span><span style="color: #33cc33;">%%</span> | ,0  ,<span style="color: #cc66cc;">13</span>
##L | <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">4</span> 0 0
#LE | ,<span style="color: #cc66cc;">1</span>  ,<span style="color: #cc66cc;">1</span>
LES | ,<span style="color: #cc66cc;">1</span>  ,<span style="color: #cc66cc;">2</span>
ESL | ,<span style="color: #cc66cc;">1</span>  ,<span style="color: #cc66cc;">3</span>
SLI | ,<span style="color: #cc66cc;">1</span>  ,<span style="color: #cc66cc;">4</span>
LIE | ,<span style="color: #cc66cc;">1</span>  ,<span style="color: #cc66cc;">5</span>
..</pre></div></div>

<p>A list of strings where the first one was &#8220;Donald Knuth&#8221; has been broken up.<br />
qstr - is the string broken up<br />
pid - is which string it originally belonged to<br />
pn - is the position of the qgram within the original string</p>
<p>As you can see if we had two tables with qgrams, we could simply join on the qstr column and count the number of overlaps for given strings (pid&#8217;s). The pn column can be used if we want to use a &#8220;window&#8221;to ensure that strings that match occur near each other.</p>
<p>Functions are provided to do this for you, the results are sorted by matchR a crude similarity scoring system (number of matches / length of shortest string):</p>

<div class="wp_syntax"><div class="code"><pre class="dos dos" style="font-family:monospace;">C:tokyom&gt;q
KDB+ <span style="color: #cc66cc;">2.7</span> 2010.11.30 Copyright <span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1993</span>-<span style="color: #cc66cc;">2010</span> Kx Systems
w32/ <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>core 3036MB Admin anonymous 192.168.178.64 PLAY 2011.02.28
&nbsp;
q<span style="color: #66cc66;">&#41;</span>l qgrams.q
q<span style="color: #66cc66;">&#41;</span>a:<span style="color: #66cc66;">&#40;</span>&quot;Donald Knuth&quot;;&quot;Leslie Lamport&quot;;&quot;Ken Thompson&quot;;&quot;Rob Pike&quot;;&quot;Linus Torvalds&quot;;&quot;Richard Stallman&quot;;&quot;Tim Berners-Lee&quot;;&quot;Alan
 Turing&quot;;&quot;John Von Neumann&quot;;&quot;Brian Kernighan&quot;;&quot;Grace Hopper&quot;;&quot;Ada Lovelace&quot;;&quot;Edsger Dijkstra&quot;;&quot;Jon Von Neumann&quot;;&quot;Herb Simo
n&quot;;&quot;Kenneth Iverson&quot;<span style="color: #66cc66;">&#41;</span>;
q<span style="color: #66cc66;">&#41;</span> / <span style="color: #cc66cc;">3</span> = qgram size     <span style="color: #cc66cc;">5</span> = window size
q<span style="color: #66cc66;">&#41;</span>.qgrams.fuzzyMatch<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span>; <span style="color: #cc66cc;">5</span>; <span style="color: #66cc66;">&#40;</span>&quot;Ken Iverson&quot;;&quot;Jonny Newmann&quot;<span style="color: #66cc66;">&#41;</span>; a<span style="color: #66cc66;">&#93;</span>
matchR    qid pid matches strA            strB
------------------------------------------------------------
<span style="color: #cc66cc;">1</span>         0   <span style="color: #cc66cc;">15</span>  <span style="color: #cc66cc;">11</span>      &quot;Ken Iverson&quot;   &quot;Kenneth Iverson&quot;
<span style="color: #cc66cc;">0.6363636</span> 0   <span style="color: #cc66cc;">2</span>   <span style="color: #cc66cc;">7</span>       &quot;Ken Iverson&quot;   &quot;Ken Thompson&quot;
<span style="color: #cc66cc;">0.6153846</span> <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">13</span>  <span style="color: #cc66cc;">8</span>       &quot;Jonny Newmann&quot; &quot;Jon Von Neumann&quot;
<span style="color: #cc66cc;">0.5384615</span> <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">8</span>   <span style="color: #cc66cc;">7</span>       &quot;Jonny Newmann&quot; &quot;John Von Neumann&quot;
<span style="color: #cc66cc;">0.2</span>       0   <span style="color: #cc66cc;">14</span>  <span style="color: #cc66cc;">2</span>       &quot;Ken Iverson&quot;   &quot;Herb Simon&quot;
<span style="color: #cc66cc;">0.1538462</span> <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">5</span>   <span style="color: #cc66cc;">2</span>       &quot;Jonny Newmann&quot; &quot;Richard Stallman&quot;
q<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Assuming that one table will be extremely large and that you&#8217;ll be checking a small subset against that, the functions also allow for caching of one of the datasets. Here I have used the <a href="http://wiki.dbpedia.org/Downloads36#persondata">person data set from DBpedia</a>. The functions to parse <a href="http://downloads.dbpedia.org/3.6/en/persondata_en.nt.bz2">this file</a> are included in the qgrams.q. In fact all example code is included at the bottom of the qgrams.q file commented out. </p>
<p>e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="dos dos" style="font-family:monospace;">q<span style="color: #66cc66;">&#41;</span>a: distinct value loadDBpeople<span style="color: #66cc66;">&#91;</span>`:persondata_en.nt<span style="color: #66cc66;">&#93;</span>
q<span style="color: #66cc66;">&#41;</span>count a
<span style="color: #cc66cc;">48089</span>
q<span style="color: #66cc66;">&#41;</span>\t .qgrams.fuzzyMatch<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span>; <span style="color: #cc66cc;">2</span>; <span style="color: #66cc66;">&#40;</span>&quot;isac newton&quot;;&quot;albert einstine&quot;<span style="color: #66cc66;">&#41;</span>; a<span style="color: #66cc66;">&#93;</span>;
<span style="color: #cc66cc;">2140</span>
q<span style="color: #66cc66;">&#41;</span>ca:.qgrams.cache<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span>;a<span style="color: #66cc66;">&#93;</span>
q<span style="color: #66cc66;">&#41;</span>\t .qgrams.fuzzyMatchUsingCache<span style="color: #66cc66;">&#91;</span> <span style="color: #cc66cc;">2</span>; <span style="color: #66cc66;">&#40;</span>&quot;isac newton&quot;;&quot;albert einstine&quot;<span style="color: #66cc66;">&#41;</span>; a; ca<span style="color: #66cc66;">&#93;</span>
<span style="color: #cc66cc;">421</span>
q<span style="color: #66cc66;">&#41;</span><span style="color: #cc66cc;">7</span>#.qgrams.fuzzyMatchUsingCache<span style="color: #66cc66;">&#91;</span> <span style="color: #cc66cc;">200</span>; <span style="color: #66cc66;">&#40;</span>&quot;richie feynmann&quot;;&quot;albert einstine&quot;<span style="color: #66cc66;">&#41;</span>; a; ca<span style="color: #66cc66;">&#93;</span>
matchR    qid pid   matches strA              strB                           ..
-----------------------------------------------------------------------------..
<span style="color: #cc66cc;">2.4</span>       <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">14225</span> <span style="color: #cc66cc;">36</span>      &quot;albert einstine&quot; &quot;Nyron nilbert gilbert filbert ..
<span style="color: #cc66cc;">0.8666667</span> <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">8</span>     <span style="color: #cc66cc;">13</span>      &quot;albert einstine&quot; &quot;Albert Einstein&quot;              ..
<span style="color: #cc66cc;">0.8181818</span> <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">35952</span> <span style="color: #cc66cc;">9</span>       &quot;albert einstine&quot; &quot;Albert Lane&quot;                  ..
<span style="color: #cc66cc;">0.7777778</span> <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">4010</span>  <span style="color: #cc66cc;">7</span>       &quot;albert einstine&quot; &quot;Albert II&quot;                    ..
<span style="color: #cc66cc;">0.75</span>      <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">30825</span> <span style="color: #cc66cc;">3</span>       &quot;albert einstine&quot; &quot;Wine&quot;                         ..
<span style="color: #cc66cc;">0.7333333</span> 0   <span style="color: #cc66cc;">860</span>   <span style="color: #cc66cc;">11</span>      &quot;richie feynmann&quot; &quot;Richard Phillips Feynman&quot;     ..
<span style="color: #cc66cc;">0.7272727</span> <span style="color: #cc66cc;">1</span>   <span style="color: #cc66cc;">81</span>    <span style="color: #cc66cc;">8</span>       &quot;albert einstine&quot; &quot;Albert Pike&quot;                  ..</pre></div></div>

<p>I&#8217;d say there are a number of major speed improvements could be made to the code and the matchR scoring system could definitely be improved. If you do have any good code changes or suggestions feel free to contact me and I&#8217;ll post any improved versions here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryan-h.com/kdb/q-grams-for-fuzzy-string-matching-in-kdb/feed/</wfw:commentRss>
		</item>
		<item>
		<title>fast java prime number generation</title>
		<link>http://www.ryan-h.com/uncategorized/fast-java-prime-number-generation/</link>
		<comments>http://www.ryan-h.com/uncategorized/fast-java-prime-number-generation/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 09:40:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ryan-h.com/?p=141</guid>
		<description><![CDATA[So I found some old prime number generation code and decided to spruce it up. I also wanted to benchmark the BitSet vs a boolean array as I had previously had issues with a boolean array. Six methods tried:
Prime Generators - Source Download

Simp - Simply check for all x&#8217;s 0 to maxPrime if x is [...]]]></description>
			<content:encoded><![CDATA[<p>So I found some <a href='http://www.ryan-h.com/wp-content/uploads/2009/06/primefinder.rar'>old prime number generation code</a> and decided to spruce it up. I also wanted to benchmark the <b>BitSet vs a boolean array</b> as I had previously had issues with a boolean array. Six methods tried:</p>
<h3>Prime Generators - <a href='http://www.ryan-h.com/wp-content/uploads/2009/06/primefinder.rar'>Source Download</a></h3>
<ol>
<li><strong>Simp</strong> - Simply check for all x&#8217;s 0 to maxPrime if x is prime. ie check x isn&#8217;t divisible by any number between 2 to x-1.</li>
<li><strong>SimpOdd</strong> - same as above, but add 2 to list of known primes, then check all x&#8217;s between 0 and maxPrime but stepping in 2&#8217;s.  And only check for divisibles between 2 to x/2.</li>
<li><strong>S - Sieve</strong> - <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes</a></li>
<li><strong>SS - SkippingSievePG</strong> - improve speed by taking advantage that even numbers are never prime except 2. Therefore when sieving using the prime 3, instead of sieving 6,9,12,15,18,21 we can actually sieve 9,15,21 ie jump double our prime each time.</li>
<li><strong>OSS - OddSkippingSievePG</strong> - Same as above BUT improve speed/memory making the boolean array represent odd numbers instead of all numbers.</li>
<li><strong>BSOSS - BitSetOddSkippingSievePG</strong> - Same as above but use BitSet instead of boolean array</li>
</ol>
<p><br/></p>
<h2>Seconds taken to generate primes between 0 to 10,000,000</h2>
<p><a href="http://www.ryan-h.com/wp-content/uploads/2009/06/speed.png"><img src="http://www.ryan-h.com/wp-content/uploads/2009/06/speed.png" alt="speed" title="speed" width="550" height="450" class="alignnone size-full wp-image-146" /></a></p>
<p>Speed of simp&#8217;s were so slow as to be unusable for finding large numbers of primes, ie 1000&#8217;s of times slower than sieves.</p>
<p><br/></p>
<h2>Memory required to generate primes between 0 to 10,000,000</h2>
<p><a href="http://www.ryan-h.com/wp-content/uploads/2009/06/memory.png"><img src="http://www.ryan-h.com/wp-content/uploads/2009/06/memory.png" alt="memory" title="memory" width="550" height="450" class="alignnone size-full wp-image-145" /></a></p>
<p>Notice 1,120,000 Bytes needed to store arraylist of integers.</p>
<h3>Size of boolean arrays / BitSets in Java</h3>
<p>boolean arrays in java use 1 byte per true/false value. BitSets use 1 bit per true/false value (may depend on OS/VM). However BitSets are slower to access. This explains why BitSetOddSkippingSievePG was slower than OddSkippingSievePG but required less memory.</p>
<h3>Use a sieve - to generate primes fast</h3>
<h2>Further Improvements</h2>
<p>The idea of reducing the array size by letting the array represent odd numbers could be generalized. Further speed increases are also possible. If you want to know more see <a href="http://en.wikipedia.org/wiki/Wheel_factorization">wheel factorization</a> or <a href="http://www.ieeta.pt/~tos/software/prime_sieve.html">segmented sieves</a>. If you code a quicker prime generator please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryan-h.com/uncategorized/fast-java-prime-number-generation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setup java speech jsapi using FreeTTS</title>
		<link>http://www.ryan-h.com/uncategorized/java-speech-jsapi-freetts/</link>
		<comments>http://www.ryan-h.com/uncategorized/java-speech-jsapi-freetts/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 15:06:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[freetts]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[netbeans]]></category>

		<category><![CDATA[speech]]></category>

		<guid isPermaLink="false">http://www.ryan-h.com/?p=124</guid>
		<description><![CDATA[Getting JSAPI setup to work using freetts seems to be quite difficult as seen by here, here, here&#8230;..
Turns out the install instructions were incomplete. The instructions were:

        1. Go to the FreeTTS/lib directory
	2. Type .\jsapi.exe
        3. If the binary license agreement [...]]]></description>
			<content:encoded><![CDATA[<p>Getting JSAPI setup to work using freetts seems to be quite difficult as seen by <a href="http://forums.sun.com/thread.jspa?threadID=5169043">here</a>, <a href="https://www.linuxquestions.org/questions/linux-newbie-8/freetts-install-help-needed-please-132625/">here</a>, <a href="http://forums.sun.com/thread.jspa?threadID=5210857">here</a>&#8230;..</p>
<p>Turns out the install instructions were incomplete. The instructions were:</p>
<blockquote><p>
        1. Go to the FreeTTS/lib directory<br />
	2. Type .\jsapi.exe<br />
        3. If the binary license agreement is acceptable, accept<br />
	   it by clicking &#8220;I Agree&#8221;. The jsapi.jar file will be unpacked<br />
 	   and deposited into the lib directory.</p></blockquote>
<p>What you actually want to do is:</p>
<ol>
<li><a href="http://sourceforge.net/project/showfiles.php?group_id=42080">Download FreeTTS</a></li>
<li>Unzip the freeTTS binary package and check inside the \lib directory for jsapi.exe</li>
<li>Run Jsapi.exe, say yes, to unpack jsapi.jar</li>
<li>Find your JRE directory, mine was C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext</li>
<li>Copy all the Jars (jsapi.jar, freetts.jar, cmu_time_awb.jar, cmu_us_kal.jar, etc.) to that directory</li>
<li>Check in netbeans your projects properties ie right click on project->properties->libraries->manage platforms and the jars should be listed there. If they are not, restart and hopefully they should now be there.<br />
<div id="attachment_125" class="wp-caption alignnone" style="width: 310px"><a href="http://www.ryan-h.com/wp-content/uploads/2009/04/netbeans-freetts-setup.png"><img src="http://www.ryan-h.com/wp-content/uploads/2009/04/netbeans-freetts-setup-300x284.png" alt="Netbeans Freetts Setup" title="netbeans-freetts-setup" width="300" height="284" class="size-medium wp-image-125" /></a><p class="wp-caption-text">Netbeans Freetts Setup</p></div></li>
<li>Copy speech.properties to the relevant folder. To find out where this is run the HelloWorld example that comes with FreeTTS.  In my case the file was located in C:\Documents and Settings\Username\java.home\lib and contained the following

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java java" style="font-family:monospace;"># Modify <span style="color: #000000; font-weight: bold;">this</span> accordingly...
#
#TextSynthEngineCentral<span style="color: #339933;">=</span>com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">speech</span>.<span style="color: #006633;">engine</span>.<span style="color: #006633;">synthesis</span>.<span style="color: #006633;">text</span>.<span style="color: #006633;">TextEngineCentral</span>
#
FreeTTSSynthEngineCentral<span style="color: #339933;">=</span>com.<span style="color: #006633;">sun</span>.<span style="color: #006633;">speech</span>.<span style="color: #006633;">freetts</span>.<span style="color: #006633;">jsapi</span>.<span style="color: #006633;">FreeTTSEngineCentral</span></pre></td></tr></table></div>

<p>Or you can set the property using</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #003399;">System</span>.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;freetts.voices&quot;</span>, <span style="color: #0000ff;">&quot;com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory&quot;</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

</li>
</ol>
<p>Any problems, post here and I will try to help you out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryan-h.com/uncategorized/java-speech-jsapi-freetts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Symfony sfGuard - Setting up users,groups,permissions</title>
		<link>http://www.ryan-h.com/web-development/symfony-sfguard-setting-up-usersgroupspermissions/</link>
		<comments>http://www.ryan-h.com/web-development/symfony-sfguard-setting-up-usersgroupspermissions/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 20:43:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[web development]]></category>

		<category><![CDATA[sfGuard]]></category>

		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.ryan-h.com/?p=75</guid>
		<description><![CDATA[sfGuard is a Symfony plugin that implements a user management and login system for an application. It supports both groups and individual users… and it saves you from having to ‘roll your own’ user administration system. This guide assumes you have followed the steps given in the readme and that you now want to begin [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.symfony-project.org/plugins/sfGuardPlugin">sfGuard</a> is a Symfony plugin that implements a user management and login system for an application. It supports both groups and individual users… and it saves you from having to ‘roll your own’ user administration system. This guide assumes you have followed the steps given in the <a href="http://www.symfony-project.org/plugins/sfGuardPlugin/3_1_3?tab=plugin_readme">readme</a> and that you now want to begin setting up users/permissions etc.</p>
<h3>1. Create links in the backend menu to the user/group/permissions tables.</h3>
<p> Edit apps/backend/templates/layout.php and add these items to the menu.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;">&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="">'Users'</span><span style="color: #339933;">,</span> <span style="">'@sf_guard_user'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="">'Groups'</span><span style="color: #339933;">,</span> <span style="">'@sf_guard_group'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="">'Permissions'</span><span style="color: #339933;">,</span> <span style="">'@sf_guard_permission'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;</pre></td></tr></table></div>

<h3>2. Create a login/logout link on the frontend.</h3>
<p> Edit apps/frontend/templates/layout.php and add these items to the menu. (Notice the use of $sf_user in the templates.)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sf_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;ul&gt;&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="">'Logout'</span><span style="color: #339933;">,</span> <span style="">'/logout'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;&lt;/ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;ul&gt;&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="">'Login'</span><span style="color: #339933;">,</span> <span style="">'/login'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;&lt;/ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>3. Create some users, groups, permissions </h3>
<p>for us to play with using the backend. Create user-&gt;basicUser, group-&gt;basicGroup, permission-&gt;basicPermission. I will be using a basic setup where users always belong to a group and the group has permissions. I will not assigning permissions to individual users. therefore give basicGroup the basicPermission. and you will have something similar to this:</p>
<div id="attachment_103" class="wp-caption alignnone" style="width: 270px"><a href="http://www.ryan-h.com/wp-content/uploads/2009/01/user.png" rel="lightbox"><img src="http://www.ryan-h.com/wp-content/uploads/2009/01/user-260x300.png" alt="sfGuard user" title="sfGuard user" width="260" height="300" class="size-medium wp-image-103" /></a><p class="wp-caption-text">sfGuard user</p></div>
<h3>4. Restricting access to certain modules/actions</h3>
<p>Similar to how I never set individual permissions for one user I make it standard that I only ever set permissions using credentials. ie. In the application I never restrict security dependent on user or group id only on permission/credentials. This allows greater flexibility in the future. Note sfGuard gets confusing to some people because many documents talk about credentials, well basically credentials are what is called in sfGuard permissions.</p>
<p>If we have a module called &#8220;question&#8221;, inside of apps/frontend/modules/question we create a config folder and a new security.yml. Inside of apps/frontend/modules/question/config/security.yml we would have</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="yml" style="font-family:monospace;">all:
    is_secure: on
    credentials: basicPermission</pre></td></tr></table></div>

<p>To set permissions on an action level we would have something similar to the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="yml" style="font-family:monospace;">all:
    is_secure: on
    credentials: basicPermission
&nbsp;
index:
    is_secure: off
&nbsp;
new:
    is_secure: on
    credentials: basicPermission</pre></td></tr></table></div>

<p>Part 2 will detail setting up user registration</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryan-h.com/web-development/symfony-sfguard-setting-up-usersgroupspermissions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to setup a complete PHP development environment on windows</title>
		<link>http://www.ryan-h.com/web-development/how-to-setup-a-complete-php-development-environment-on-windows/</link>
		<comments>http://www.ryan-h.com/web-development/how-to-setup-a-complete-php-development-environment-on-windows/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 21:21:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[web development]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[netebans]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[wamp]]></category>

		<guid isPermaLink="false">http://www.ryan-h.com/?p=64</guid>
		<description><![CDATA[Why to use an IDE
Code Completion
When you start to type a variable name or reference an object the IDE will present options that would autocomplete what your typing. It also presents the documentation saying which each parameter of a method call is. This is easiest to explain by showing you a picture:
Easy browsing
As you can [...]]]></description>
			<content:encoded><![CDATA[<h3>Why to use an IDE</h3>
<h4>Code Completion</h4>
<p>When you start to type a variable name or reference an object the IDE will present options that would autocomplete what your typing. It also presents the documentation saying which each parameter of a method call is. This is easiest to explain by showing you a picture:</p>
<div id="attachment_65" class="wp-caption alignnone" style="width: 546px"><img class="size-full wp-image-65" title="Netbeans - Code Completion" src="http://www.ryan-h.com/wp-content/uploads/2009/01/code-completion.png" alt="Netbeans - Code Completion" width="536" height="549" /><p class="wp-caption-text">Netbeans - Code Completion</p></div>
<h4>Easy browsing</h4>
<p>As you can see in the image, I have one pane for browsing files, one pane for browsing methods. The central pane showing the code is coloured to tell you which words are variables, functions, constants etc. Notice also that you have multiple files open in tabs like firefox. So I can now browse easily through directories/methods and recently opened files. very Handy.</p>
<div id="attachment_67" class="wp-caption alignnone" style="width: 310px"><a href="http://www.ryan-h.com/wp-content/uploads/2009/01/nb.png"><img class="size-medium wp-image-67" title="Netbeans PHP Support" src="http://www.ryan-h.com/wp-content/uploads/2009/01/nb-300x182.png" alt="Netbeans PHP Support" width="300" height="182" /></a><p class="wp-caption-text">Netbeans PHP Support</p></div>
<h4>No more echo debug_var</h4>
<p>Why waste time echo&#8217;ing some variables, XDEBUG allows you to select a line that your interested in, the program will then stop running at that point and you can step through the code line by line and watch as each variable changes to see where the problem is.</p>
<h3>The Setup</h3>
<h4>Download and install <a href="http://www.netbeans.org/features/php/">Netbeans 6.5 for PHP</a></h4>
<p>Take advantage of syntactic and semantic code highlighting, pop-up documentation, code formating and folding, instant rename, code templates, and automatic code completion (including bracket completion) for PHP. The Editor recognizes PHP code including heredoc notation in PHP projects and in PHTML and PHP files.</p>
<h4>Download and install <a href="http://dev.mysql.com/downloads/gui-tools/">MySQL GUI Tools</a></h4>
<p>Never type &#8220;Select * from &#8230;&#8221; again. With simple clicking you can create/edit/drop/select tables. Far easier and quicker. You might also want to check out mysql workbench on the same site.</p>
<div id="attachment_66" class="wp-caption alignnone" style="width: 310px"><a href="http://www.ryan-h.com/wp-content/uploads/2009/01/mysql-gui-tools.png"><img src="http://www.ryan-h.com/wp-content/uploads/2009/01/mysql-gui-tools-300x218.png" alt="mysql-gui-tools" title="mysql-gui-tools" width="300" height="218" class="size-medium wp-image-66" /></a><p class="wp-caption-text">mysql-gui-tools</p></div>
<h4>OPTIONAL install <a href="http://blogs.vertigosoftware.com/teamsystem/archive/2006/01/16/Setting_up_a_Subversion_Server_under_Windows.aspx">Subversion</a></h4>
<p>If only working indiviually the versioning provided internally by netbeans may be sufficient otherwise checkout installing subversion and tortoise SVN. This allows you to save your project at different points. Later if you find out something has broken, you can revert to any earlier date. But thats the simplest method it offers. You can look back at one particular file and see which lines changed on what date. In a team environment this is essential for seeing who changed what files.</p>
<h4>Download and install <a href="http://www.wampserver.com/en/download.php">WAMP</a></h4>
<p>WampServer is a Windows web development environment. It allows you to create web applications with Apache, PHP and the MySQL database. It also comes with PHPMyAdmin and SQLiteManager to easily manage your databases.</p>
<h5>Environment setting</h5>
<p>At times we will need to call PHP or MySQL from the command line to do this we have to setup the PATH environment. Right-click on My Computer, than Properties. Switch to Advanced tab and click the Environment Variables button. At the end of variable PATH add &#8220;;C:\wamp\bin\php\php5.2.6;C:\wamp\bin\mysql\mysql5.0.45\bin&#8221; (note separated by a semicolon). These paths may be slightly different depending on your version, Have a browse.</p>
<h5>XDebug</h5>
<p>Download the .dll from <a href="http://www.xdebug.org/">XDebug website</a> (last time I checked it was on right hand menu, under windows modules). Save the file &#8220;php_xdebug-2.0.3-5.1.7.dll&#8221; to the &#8220;C:\wamp\bin\php\php5.2.6\ext&#8221; folder. Or the similar folder on your install as your PHP version may be different. Browse to &#8220;C:\wamp\bin\apache\apache2.2.8\bin&#8221; and edit &#8220;php.ini&#8221;. At the bottom of the PHP.ini also add</p>
<p>zend_extension_ts=&#8221;C:/wamp/bin/php/php5.2.6/ext/php_xdebug-2.0.2-5.2.5.dll&#8221;<br />
xdebug.remote_enable=1</p>
<h5>Apache Rewrite</h5>
<p>Apache URL Rewrite Module is needed to allow nicer looking URL&#8217;s, by default its off in WAMP. We need to turn it on - left click on WAMP’s tray icon , then in Apache &gt;&gt; Apache Modules menu select rewrite_module.</p>
<h5>php_xsl extension</h5>
<p>Again left click on WAMP&#8217;s tray icon. Then PHP &gt;&gt;  PHP Extension menu, look for php_xsl and click it. But there is one more php.ini file, which WAMP won’t change (no clue why) - we need to do it by hand, let’s open: C:\wamp\bin\php\php5.2.5\php.ini and remove “;” from the line &#8220;;extension=php_xsl.dll&#8221;. This uncomments it. At the bottom of the PHP.ini also add</p>
<p>zend_extension_ts=&#8221;C:/wamp/bin/php/php5.2.6/ext/php_xdebug-2.0.2-5.2.5.dll&#8221;<br />
xdebug.remote_enable=1</p>
<h5>Restart WAMP</h5>
<p>Again left click on WAMP&#8217;s tray icon then select restart all services. Note: mySQL default <strong>username:&#8221;root&#8221; password:&#8221;"</strong> , thats right BLANK. All documents for the webserver are now located in <strong>c:\wamp\www\</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryan-h.com/web-development/how-to-setup-a-complete-php-development-environment-on-windows/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

