<?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>Query7 &#187; code</title>
	<atom:link href="http://query7.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 09 Apr 2010 09:36:13 +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>Working with Google&#8217;s Language API</title>
		<link>http://query7.com/working-with-googles-language-apis</link>
		<comments>http://query7.com/working-with-googles-language-apis#comments</comments>
		<pubDate>Sat, 07 Mar 2009 11:28:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://query7.com/?p=378</guid>
		<description><![CDATA[<p>Google translate is used by millions of people every day. Combine this with the easy reporting of language errors/mistakes makes it one of the most comprehensive and accurate online translators. Google provides an easy to use API to access their&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Google translate is used by millions of people every day. Combine this with the easy reporting of language errors/mistakes makes it one of the most comprehensive and accurate online translators. Google provides an easy to use API to access their large language database, we&#8217;ll be using that today.</p>
<p>It will consist of two textareas, two dropdowns and one button. It will look something like this:</p>
<p><a href="http://query7.com/wp-content/uploads/2009/02/preview.gif"><img class="alignnone size-medium wp-image-379" src="http://query7.com/wp-content/uploads/2009/02/preview-300x273.gif" alt="" width="300" height="273" /></a></p>
<h2>HTML</h2>
<p>The HTML code is fairly straight foward. Notice the dropdown menus have <em>value</em>s. These are essential as this is the language code, it&#8217;s sent to Google.</p>
<pre>&lt;body&gt;
&lt;div class="he"&gt;
&lt;h2&gt;Translate&lt;/h2&gt;
From:
&lt;select id="from"&gt;
&lt;option value=sq&gt;Albanian&lt;/option&gt;&lt;option value=ar&gt;Arabic&lt;/option&gt;&lt;option value=bg&gt;Bulgarian&lt;/option&gt;&lt;option value=ca&gt;Catalan&lt;/option&gt;&lt;option value=zh-CN&gt;Chinese (Simplified)&lt;/option&gt;&lt;option value=zh-TW&gt;Chinese (Traditional)&lt;/option&gt;&lt;option value=hr&gt;Croatian&lt;/option&gt;&lt;option value=cs&gt;Czech&lt;/option&gt;&lt;option value=da&gt;Danish&lt;/option&gt;&lt;option value=nl&gt;Dutch&lt;/option&gt;&lt;option value=en selected&gt;English&lt;/option&gt;&lt;option value=et&gt;Estonian&lt;/option&gt;&lt;option value=tl&gt;Filipino&lt;/option&gt;&lt;option value=fi&gt;Finnish&lt;/option&gt;&lt;option value=fr&gt;French&lt;/option&gt;&lt;option value=gl&gt;Galician&lt;/option&gt;&lt;option value=de&gt;German&lt;/option&gt;&lt;option value=el&gt;Greek&lt;/option&gt;&lt;option value=iw&gt;Hebrew&lt;/option&gt;&lt;option value=hi&gt;Hindi&lt;/option&gt;&lt;option value=hu&gt;Hungarian&lt;/option&gt;&lt;option value=id&gt;Indonesian&lt;/option&gt;&lt;option value=it&gt;Italian&lt;/option&gt;&lt;option value=ja&gt;Japanese&lt;/option&gt;&lt;option value=ko&gt;Korean&lt;/option&gt;&lt;option value=lv&gt;Latvian&lt;/option&gt;&lt;option value=lt&gt;Lithuanian&lt;/option&gt;&lt;option value=mt&gt;Maltese&lt;/option&gt;&lt;option value=no&gt;Norwegian&lt;/option&gt;&lt;option value=pl&gt;Polish&lt;/option&gt;&lt;option value=pt&gt;Portuguese&lt;/option&gt;&lt;option value=ro&gt;Romanian&lt;/option&gt;&lt;option value=ru&gt;Russian&lt;/option&gt;&lt;option value=sr&gt;Serbian&lt;/option&gt;&lt;option value=sk&gt;Slovak&lt;/option&gt;&lt;option value=sl&gt;Slovenian&lt;/option&gt;&lt;option value=es&gt;Spanish&lt;/option&gt;&lt;option value=sv&gt;Swedish&lt;/option&gt;&lt;option value=th&gt;Thai&lt;/option&gt;&lt;option value=tr&gt;Turkish&lt;/option&gt;&lt;option value=uk&gt;Ukrainian&lt;/option&gt;&lt;option value=vi&gt;Vietnamese&lt;/option&gt;
&lt;/select&gt;

To:
&lt;select id="to"&gt;
&lt;option value=sq&gt;Albanian&lt;/option&gt;&lt;option value=ar&gt;Arabic&lt;/option&gt;&lt;option value=bg&gt;Bulgarian&lt;/option&gt;&lt;option value=ca&gt;Catalan&lt;/option&gt;&lt;option value=zh-CN&gt;Chinese (Simplified)&lt;/option&gt;&lt;option value=zh-TW&gt;Chinese (Traditional)&lt;/option&gt;&lt;option value=hr&gt;Croatian&lt;/option&gt;&lt;option value=cs&gt;Czech&lt;/option&gt;&lt;option value=da&gt;Danish&lt;/option&gt;&lt;option value=nl&gt;Dutch&lt;/option&gt;&lt;option value=en selected&gt;English&lt;/option&gt;&lt;option value=et&gt;Estonian&lt;/option&gt;&lt;option value=tl&gt;Filipino&lt;/option&gt;&lt;option value=fi&gt;Finnish&lt;/option&gt;&lt;option value=fr&gt;French&lt;/option&gt;&lt;option value=gl&gt;Galician&lt;/option&gt;&lt;option value=de&gt;German&lt;/option&gt;&lt;option value=el&gt;Greek&lt;/option&gt;&lt;option value=iw&gt;Hebrew&lt;/option&gt;&lt;option value=hi&gt;Hindi&lt;/option&gt;&lt;option value=hu&gt;Hungarian&lt;/option&gt;&lt;option value=id&gt;Indonesian&lt;/option&gt;&lt;option value=it&gt;Italian&lt;/option&gt;&lt;option value=ja&gt;Japanese&lt;/option&gt;&lt;option value=ko&gt;Korean&lt;/option&gt;&lt;option value=lv&gt;Latvian&lt;/option&gt;&lt;option value=lt&gt;Lithuanian&lt;/option&gt;&lt;option value=mt&gt;Maltese&lt;/option&gt;&lt;option value=no&gt;Norwegian&lt;/option&gt;&lt;option value=pl&gt;Polish&lt;/option&gt;&lt;option value=pt&gt;Portuguese&lt;/option&gt;&lt;option value=ro&gt;Romanian&lt;/option&gt;&lt;option value=ru&gt;Russian&lt;/option&gt;&lt;option value=sr&gt;Serbian&lt;/option&gt;&lt;option value=sk&gt;Slovak&lt;/option&gt;&lt;option value=sl&gt;Slovenian&lt;/option&gt;&lt;option value=es&gt;Spanish&lt;/option&gt;&lt;option value=sv&gt;Swedish&lt;/option&gt;&lt;option value=th&gt;Thai&lt;/option&gt;&lt;option value=tr&gt;Turkish&lt;/option&gt;&lt;option value=uk&gt;Ukrainian&lt;/option&gt;&lt;option value=vi&gt;Vietnamese&lt;/option&gt;

&lt;/select&gt;
&lt;/div&gt;

&lt;div class="tebg"&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;textarea rows="10" cols="60" id="or" class="te"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;textarea rows="10" cols="60" id="tr" class="te"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;input type="submit" id="translate" value="Translate" /&gt;
&lt;div id="translation"&gt;&lt;/div&gt;
&lt;/body&gt;</pre>
<p>We&#8217;ll start by including Google&#8217;s Language API and jQuery. We can&#8217;t link directly to a language.js file, instead we need to use Google&#8217;s own <em>load</em> function. jQuery will also be included this way.</p>
<pre>

google.load("language", "1");
google.load("jquery", "1.3.2");
</pre>
<p>We need to use jQuery to get 3 values. The textarea containing the words they want translated, the language it is currently in and the language they want it translated into. We only want to capture these when the user clicks the translate button so we wrap it in the <em>click</em> event.</p>
<pre>
    $(document).ready(function(){

		    $("#translate").click(function(){

		        var from = $("#from").val();
			var to = $("#to").val();

			var orig = $("#or").val();

			    });

	});
</pre>
<p>Now we need to use Google&#8217;s translate function. It takes several parameters &#8211; the text we want translated (<em>orig</em>), the language the text was in (<em>from</em>) and the language we want it translated to (<em>to</em>). We capture the information google sends back to is in <em>result</em>. If there are no errors then we set the textarea to the translated text.</p>
<pre>
google.language.translate(orig, from, to, function(result) {

	if(!result.error)
	{

		$("#tr").val(result.translation);

	}

	});
</pre>
<p>If you have any questions or comments feel free to post them below.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/working-with-googles-language-apis/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git for Source Control</title>
		<link>http://query7.com/git-for-source-control</link>
		<comments>http://query7.com/git-for-source-control#comments</comments>
		<pubDate>Sun, 15 Feb 2009 21:23:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://query7.com/?p=366</guid>
		<description><![CDATA[<p>Source Control is an essential part of the development system that any and every programmer needs to utilize. Simply put it is a repository of source code that keeps track of revisions and is a system that allows multiple programmers&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Source Control is an essential part of the development system that any and every programmer needs to utilize. Simply put it is a repository of source code that keeps track of revisions and is a system that allows multiple programmers to work on one copy of code without issues. There are numerous version control systems (VCS) out there including Subversion, Mercurial and Bazaar. Everyone has their preference, today we will be focusing on git, a VCS that has become more popular in the latest months.</p>
<h2>Git</h2>
<p>A typical programmer&#8217;s workflow would be to:</p>
<ol>
<li><strong>pull</strong> (download) the latest copy of code from the git respository.</li>
<li>Make neccessary changes, modify code etc.</li>
<li><strong>commit</strong> the changed files</li>
<li><strong>push</strong> (upload) the files back to the git repository.</li>
</ol>
<p>If multiple programmers were working on the same project they would all use the same git repository. It&#8217;s good practice to always <strong>pull</strong> the latest copy before you <strong>push</strong> any of your changes to make sure your using the most update-to-date copy of the code (Someone may have <strong>push</strong>ed another change while you were editing your code). You can also branch (fork) a git repository. For example two programmers might be working on the same code but both are implementing different features. Their work flow would be something like:</p>
<ol>
<li>Each of them fork the master (main) copy of code</li>
<li>Make appropriate changes to their branches/forks of code</li>
<li>Merge both forks back into master (Git does this for you)</li>
</ol>
<h2>Installing Git</h2>
<p>Git is very easy to install and use on *nix type operating systems (Linux, Mac, BSD). Using Macports or your package management system, install the package <em>git-core</em>. It&#8217;s a little more complicated on Windows. I use <a href="http://code.google.com/p/msysgit/">msysgit</a>. Download and install that. On Windows git is not integrated into the windows command prompt, instead it has it&#8217;s own *nix like terminal (cygwin?). You use *nix commands rather than windows commands -  <em>ls</em> instead of <em>dir</em>. Fire up the shortcut to &#8216;git bash&#8217; (The git command prompt), you should be able to <em>cd</em> around, viewing your directories, and when you type <em>git</em> it should bring you up a list of available commands.</p>
<h2>Git Basics</h2>
<p>To use Git you must have a repository. You can host one yourself or use one of the numerous Git Hosts out there. I use <a href="http://www.github.com">Github</a>, it allows unlimited repositories for open source projects, and also offers paid plans for private repositories. For the rest of this tutorial I&#8217;ll assume your using github. The first thing you need to do is set your username and email. (In the git shell)</p>
<pre>git config --global user.name "Username Here"</pre>
<pre>git config --global user.email "email@email.here"</pre>
<p>Note that we use <em>&#8211;global</em>, this tells git that we want these details to be applied to all of our projects, you can can override these settings when in the local project directory by calling the command again without the <em>&#8211;global</em> flag.</p>
<p>Now we need to generate an SSH key. Git requires it as it&#8217;s an extra step of authentication. There are numerous ways to generate the key and they are different on all platforms so I advise you read <a href="http://github.com/guides/providing-your-ssh-key">this</a> (github.com) tutorial on setting it up.</p>
<p>The final step is to create the git project itself. On Github, login to an account (that you have created) then head over to the <a href="http://github.com/repositories/new">create a repository page</a>. Enter the information and hit Ok.</p>
<p>Now we can make that project on our local system. Change into the project&#8217;s directory then</p>
<pre>git init</pre>
<p>This generates the .git directory and git will now start &#8216;watching&#8217; deletes, alterations and the like. Now we need to add the files that we want to commit. You can name them individually or to select all we simply use the decimal point.</p>
<pre>git add .</pre>
<p>That will add the entire directory&#8217;s contents and all sub directories. We can then commit our changes/additions. We also provide a commit message, explaining to ourselves/others/repository readers what changes you made in that commit &#8211; eg new features in the code.</p>
<pre>git commit -m 'This is our first commit'</pre>
<p>Now we need to attach our project to the repository, then push the changes we made. Again, this is fairly simple.</p>
<pre>git remote add origin git@github.com:GITHUBUSERNAME/REPOSITORYNAME.git</pre>
<pre>git push origin master</pre>
<p>You can view your project&#8217;s page on github now and you will see that the files have been added. From now on it&#8217;s just a matter of <strong>git add</strong>-ing altered files, <strong>git commit</strong>-ing then finally <strong>git push</strong>-ing to upload the changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/git-for-source-control/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
