<?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>Daniel Pataki &#187; Daniel Pataki</title>
	<atom:link href="http://danielpataki.com/author/danielpataki/feed/" rel="self" type="application/rss+xml" />
	<link>http://danielpataki.com</link>
	<description>Web Developer &#38; Entrepreneur</description>
	<lastBuildDate>Sat, 07 Apr 2012 06:38:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Get Your MeSH On</title>
		<link>http://danielpataki.com/2012/04/get-your-mesh-on/</link>
		<comments>http://danielpataki.com/2012/04/get-your-mesh-on/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 12:24:41 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Datasets]]></category>

		<guid isPermaLink="false">http://danielpataki.com/?p=5</guid>
		<description><![CDATA[MeSH is a database of scientific keywords and synonyms (Cyclomycin is the same as A-23187). Download the 2012 database I prepared in SQL format ]]></description>
			<content:encoded><![CDATA[<p>MeSH is a database of medical subject headings; a medical thesaurus if you will. We are using it in an upcoming project to give people keyword suggestions and to normalize keywords across the project. What does this mean exactly?</p>
<p>Two people visit our site one day and they both upload videos about Vitamin C. One person decides to tag his video with &#8216;Vitamin C&#8217; while the other goes for &#8216;Ascorbic Acid&#8217;. Normally if someone searches our site for one of the terms he would only get the appropriate video. By injecting some MeSH magic we know that Vitamin C is the same thing as Ascorbic Acid so we can serve both results when searching for either term.</p>
<p>There are some more obscure (for me) term equivalencies like &#8216;Calcymycin&#8217; which is the same as &#8216;A-23187&#8242;. The other great feature of MeSH is that it tries to be as complete as can be. In the example above MeSH also has &#8216;A 23187&#8242;, &#8216;A23187&#8242; and for &#8216;Somatostatin receptors&#8217; it contains variations like &#8216;Receptors, somatostatin&#8217;. By storing these directly in our database there is no need to do any advanced matching which would eat up some resources considering the 177,000-ish entries.</p>
<p>The <a title="Medical subject headings main page" href="http://www.nlm.nih.gov/mesh/">MeSH website</a> contains a lot of information about why and how they work. You can also grab the database in various formats. Since I needed an SQL database I parsed the XML file and compiled the results into two tables. The <code>data_mesh_term</code> table contains the MeSH headings which are the &#8216;official&#8217; main terms. The <code>data_mesh_term_synonym</code> table contains all the variations for the terms. Feel free to download the zip file which contains the data in an sql file.</p>
<h2>Downloads</h2>
<ul>
<li><a href='http://danielpataki.com/wp-content/uploads/2012/04/mesh_terms.sql_.zip'>Download the SQL database</a> <small>(1.3MB, 19.8 uncompressed)</small></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://danielpataki.com/2012/04/get-your-mesh-on/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Pagination Links</title>
		<link>http://danielpataki.com/2012/04/wordpress-pagination-links/</link>
		<comments>http://danielpataki.com/2012/04/wordpress-pagination-links/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 12:22:03 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://danielpataki.com/?p=3</guid>
		<description><![CDATA[For years my pagination solution was wp_pagenavi, a popular WordPress plugin. Not long ago I realized that since 2.1 WordPress had a built in function for this!]]></description>
			<content:encoded><![CDATA[<p>For ages and I ages I used a plugin for WordPress pagination when there has been a solution since 2.1 to do this easily in the code! Don&#8217;t get me wrong, <a href="http://wordpress.org/extend/plugins/wp-pagenavi/" title="WordPress pagination plugin">wp_pagenavi</a> is a great plugin but I prefer not to use plugins needlessly. </p>
<p>The <a href='http://codex.wordpress.org/Function_Reference/paginate_links' tutle='WordPress Pagination Function' type='codex'><code>paginate_links()</code></a> function allows you to create very easily customizable pagination which you can use completely out of the loop as well. </p>
<pre class='brush: php'>
$list = new WP_Query($query_args);
$pagination = array(
	'base'       =&gt; str_replace( 99999, '%#%', get_pagenum_link( 99999 ) ),
	'format'     =&gt; '?paged=%#%',
	'current'    =&gt; max( 1, get_query_var( 'paged' ) ),
	'total'      =&gt; $list-&gt;max_num_pages,
	'next_text'  =&gt; 'next',
	'prev_text'  =&gt; 'previous'
);
echo '&lt;div class="pagination primary-links"&gt;' . paginate_links( $pagination ) . '&lt;/div&gt;';
</pre>
<p>Since the function does not use the loop directly you can use it for listing anything as long as you know the current page and the total number of pages. </p>
<pre class='brush: php'>
$list = range(1, 200);
$items_per_page = 12;
$pagination = array(
	'base'       =&gt; get_bloginfo( 'url' ) . '/mypage/%_%',
	'format'     =&gt; '?paged=%#%',
	'current'    =&gt; $_GET['current_page'],
	'total'      =&gt; ceil( max($list) / $items_per_page ),
	'next_text'  =&gt; 'go forth',
	'prev_text'  =&gt; 'go back'
);
echo '&lt;div class="pagination primary-links"&gt;' . paginate_links( $pagination ) . '&lt;/div&gt;';
</pre>
]]></content:encoded>
			<wfw:commentRss>http://danielpataki.com/2012/04/wordpress-pagination-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking Variable Values</title>
		<link>http://danielpataki.com/2012/04/checking-variable-values/</link>
		<comments>http://danielpataki.com/2012/04/checking-variable-values/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 12:21:26 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://danielpataki.com/?p=1</guid>
		<description><![CDATA[A lot of developers don't check for variable existence and emptiness properly. This leads to bugs and all sorts of commotion, let's put a stop to it!]]></description>
			<content:encoded><![CDATA[<p>Improper checking for variables and values is a very frequent error I see among WordPress plugin and theme developers. While their products work fine they produce many PHP notices which will not bring the World to its knees but is an annoyance at the very least (and sloppy work). In less obvious cases it can lead to bugs and weird behavior. </p>
<h2>Sending you home with a note</h2>
<pre class='brush: php'>
if ( $result ) {
    echo 'Your display named has been changed to ' . $result['display_name'];
}
</pre>
<p>So what&#8217;s the problem here? The above will throw a notice if <code>$result</code> is not defined. If notices are not shown this works as intended but is still sloppy. The reason it works is that when a variable is not set it evaluates to false. Hence the statement is echoed above if <code>$result</code> is set otherwise nothing happens. </p>
<h2>Empty Inside</h2>
<p>Similarly as above an unset variable is not the same as an empty variable so the below code will also throw a notice since we are trying to see if an unset variable is empty. </p>
<pre class='brush: php'>
if ( empty( $result ) ) {
    echo 'Your display named could not be changed';
}
</pre>
<p>The proper way to do this</p>
<pre class='brush: php'>
if ( isset( $result ) AND !empty( $result ) ) {
    echo 'Your display named has been changed to ' . $result['display_name'];
}
</pre>
<h2>When Sloppiness Leads To Bugs</h2>
<p>Say you&#8217;re creating a WordPress theme and you want the user to be able to specify a logo. If no logo is specified the site title is shown in heading text. </p>
<pre class='brush: php'>
$logo = get_option( 'my_site_logo' );
if ( isset( $logo ) ) {
    echo '<img src="<?php echo $logo ?>">';
}
else {
    echo '
<h1>' . get_bloginfo() . '</h1>

';
}
</pre>
<p>So let&#8217;s see what a user would do/see. He downloads the theme, activates it and sees his new website with the website title in a nice heading on top. He then decides to use a logo instad so pastes the URL of an image he uploaded. The image shows up, the user is awesome happy and all is well. </p>
<p>Once day he decides to switch back to the text again until all is well so he removes the URL from the input box. He goes back to his where there is now no logo and no title either. He is furious and eats his own arm in sorrow. </p>
<p>In this case the &#8216;my_site_logo&#8217; option is still in the database, it just has an empty value. So when you pull it <code>$logo</code> will be set as if you would have hard coded it like so: <code>$logo = ''</code>. When we get to the if statement <code>$logo</code> is set so the image is output but the source will be empty. </p>
<p>To prevent this you should always use <code>isset()</code> and <code>empty()</code> in conjunction. </p>
<pre class='brush: php'>
$logo = get_option( 'my_site_logo' );
if ( isset( $logo ) AND !empty( $logo ) ) {
    echo '<img src="<?php echo $logo ?>">';
}
else {
    echo '
<h1>' . get_bloginfo() . '</h1>

';
}
</pre>
<h2>Don&#8217;t Trust Yourself</h2>
<p>Many programmers&#8217; first reaction is that this is stupid. When saving the option we always check to make sure the value isn&#8217;t empty. If it is we delete the option from the database which means that the emptiness check isn&#8217;t necessary. </p>
<p>While this is true this is just bad practice and you are opening yourself up to bugs. Even with the best coding practices we get so many bugs it&#8217;s a shame to have to spend time fixing ones we cluld have prevented easily. </p>
]]></content:encoded>
			<wfw:commentRss>http://danielpataki.com/2012/04/checking-variable-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

