<?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>CodeSanity &#187; Tom Schlick</title>
	<atom:link href="http://codesanity.net/author/Tom/feed/" rel="self" type="application/rss+xml" />
	<link>http://codesanity.net</link>
	<description>PHP, Javascript &#38; Technology Ramblings</description>
	<lastBuildDate>Wed, 07 Jul 2010 00:28:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Day to Day Apps of a Web Developer</title>
		<link>http://codesanity.net/2010/07/day-to-day-apps-of-a-web-developer/</link>
		<comments>http://codesanity.net/2010/07/day-to-day-apps-of-a-web-developer/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 00:28:04 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[billings]]></category>
		<category><![CDATA[coda]]></category>
		<category><![CDATA[evernote]]></category>
		<category><![CDATA[fluidapp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sequelpro]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=280</guid>
		<description><![CDATA[Any good developer has a set of applications that helps them get their job done faster and better. When developing on a mac this is no exception. There are tons of high quality applications from both big name companies to small independent companies. This is a list of some of the applications I find myself using each [...]]]></description>
			<content:encoded><![CDATA[<p>Any good developer has a set of applications that helps them get their job done faster and better. When developing on a mac this is no exception. There are tons of high quality applications from both big name companies to small independent companies. This is a list of some of the applications I find myself using each and every day.</p>
<h2><a href="http://www.panic.com/coda/" target="_blank">Coda</a></h2>
<p><img class="alignright size-full wp-image-285" title="coda_logo" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2010/07/coda_logo.png" alt="" width="143" height="146" /></p>
<p>Out of everything in my arsenal I really do use coda the most. It is the jack of all trades editor from the great people over at Panic. It includes a ton of features such as built in FTP, Terminal, CSS Editor, and Reference Books. The best part about Coda is that it&#8217;s not bloated. Panic has done an awesome job with coda and I can&#8217;t wait to see what they come out with in the next major release. I have tried many other clients including Espresso &amp; TextMate (I do use TextMate for other things) but I always come back to Coda. Coda is $99.00 and is well worth the purchase.</p>
<h2><strong><a href="http://www.sequelpro.com/" target="_blank">Sequel Pro</a></strong></h2>
<p><img class="alignleft size-full wp-image-288" title="sequel pro" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2010/07/appicon-e1278396588977.png" alt="sequel pro" width="143" height="143" />Sequel Pro is a MySQL database management interface. Think PhpMyAdmin but more powerful and desktop based. Sequel Pro allows you to view, create, and manage your databases without having to go through the hassle of using a command line interface. It is an active open source project which means its free to download and use. Once you start using Sequel Pro it will be hard to go back to anything else. (Note: I used to use Navicat but it sucked for mac and sequel pro seems a lot better at not sucking.)</p>
<h2><a href="http://evernote.com" target="_blank">Evernote</a></h2>
<p><img class="alignright size-full wp-image-293" title="evernote-logo" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2010/07/evernote-logo-e1278397562474.jpg" alt="" width="143" height="142" />Evernote is a simple but amazing application. If you are not using it already you should be. Evernote is your digital brain. You can use it to store everything from code snippets to reciepts. I use it all the time to take picture of whiteboard sessions with my phone and send them to evernote where they are scanned and indexed making them searchable.</p>
<h2><a href="http://fluidapp.com/" target="_blank">Fluid</a></h2>
<p><img class="alignleft size-full wp-image-299" title="fluid" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2010/07/fluid.png" alt="" width="128" height="128" />Fluid is  SSB (site specific browser) application for the mac. Similar to Mozilla&#8217;s Prizm, it allows you to create a desktop application from a web app. I use SSB&#8217;s for my personal gmail account, work&#8217;s google apps account, lighthouse ticket tracker, TeuxDeux and google voice. I can have these windows open (or hidden) all the time and when something needs to get my attention such as a new email I get a Dock badge! This makes it a lot easier to use gmail&#8217;s awesomeness 100% of the time without having to use something like MailPlane or the native Mail app.</p>
<h2><a href="http://www.marketcircle.com/billings/" target="_blank">Billings</a></h2>
<p><img class="alignright size-full wp-image-303" title="Billings" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2010/07/Billings.png" alt="" width="143" height="143" />Billings is an invoice tracking application. It makes it easy to track your time, send out estimates / invoices, and helps account for every last penny a client owes you. It is one of the most elegant I have found and provides some very nice invoice templates by default. I know there are some web based ones out there such as FreshBooks, but I prefer billings.</p>
<h2><a href="http://panic.com/transmit">Transmit</a></h2>
<p><img class="alignleft size-full wp-image-309" title="Transmit" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2010/07/Transmit.png" alt="" width="143" height="143" />Transmit is an awesome FTP client from the same great people that make Coda. It is elegant and features FTP, SFTP, Amazon S3 and many other integrations. It is a rock solid client and the recent refresh made it even more powerful and easy to use. FYI: The core of transmit also powers Coda&#8217;s FTP integration. Transmit is $34 and is also well worth the money. (Plus they have a pretty nice truck icon so you can&#8217;t go wrong with Transmit).</p>
<h5>I will add anything new I come across to this list. If you have any suggestions of things I should try out let me know.</h5>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2010/07/day-to-day-apps-of-a-web-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If you&#8217;re smart, don&#8217;t use Smarty</title>
		<link>http://codesanity.net/2010/06/dont-use-smarty/</link>
		<comments>http://codesanity.net/2010/06/dont-use-smarty/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 20:13:12 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[shorthand]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[template engine]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=256</guid>
		<description><![CDATA[Template engines such as Smarty can seem like the way to go when planning your application but that decision can have some bad operational consequences later down the road when you need to scale.]]></description>
			<content:encoded><![CDATA[<p>Today in the world of web frameworks people are looking for the perfect marriage of technology to scale their applications &amp; provide rapid development. Through this time of transition some really great advancements have come out such as CodeIgniter, Ruby on Rails, &amp; jQuery. Unfortunately, some of the things that are popular now seem to be good but can actually hurt your application. I&#8217;m talking about template engines in PHP.</p>
<h2>Why They Are Bad</h2>
<p>Template languages like Smarty are essentially another programming language built on top of PHP. This is a problem because php is what we call an<a href="http://en.wikipedia.org/wiki/Interpreted_language" target="_blank"> interpreted language</a> which means every time you load the page it is parsed on the fly and is outputted. When you add a template language on top of this the template language has to be interpreted, converted to php and then interpreted as php and outputted. This doubles the amount of work that the cpu has to do to return the page the user requested.</p>
<p>At one point in an application I&#8217;ve been working on, I noticed that smarty was accounting for 60% of page load time. The page load time was still under a second but thats a huge amount of the process just for smarty to convert to php.</p>
<h2>What About Designers!?</h2>
<p>Using a template language just because you are working with designers is a poor excuse. Those designers could just as easily learn PHP Shorthand as they could something link Smarty. By teaching your designers small amounts of PHP, your giving them the knowledge to help with other areas of your application without having to learn something new.</p>
<h2>When It&#8217;s Appropriate</h2>
<p>Sometimes a template language is the perfect solution. For instance if you were creating a CMS application where your users would have to edit template code you might want to use a template language. It would allow you to restrict which functions could be executed on the views side so that your application would be more secure. This is ok for CMS type apps like WordPress and Expression Engine, but its usually something you dont need when your app is just something that your company will be editing.</p>
<p>For use with codeigniter views, I have my own template library built and extended off of the initial work of Phil Sturgeon. You can take a look at his library here <a href="http://github.com/philsturgeon/codeigniter-template" target="_blank">http://github.com/philsturgeon/codeigniter-template</a> and I may release mine in the future.</p>
<p><!-- e131a55b1591440881a06e5b69532149 --></p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2010/06/dont-use-smarty/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Using MongoDB for CodeIgniter Logs</title>
		<link>http://codesanity.net/2010/05/mongodb-codeigniter-logs/</link>
		<comments>http://codesanity.net/2010/05/mongodb-codeigniter-logs/#comments</comments>
		<pubDate>Tue, 18 May 2010 06:01:09 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[clusters]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[production]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=229</guid>
		<description><![CDATA[As developers, we like to log everything. Flat file logging is great for single server setups but becomes troublesome to manage on a cluster. We will use MongoDB to fix this in regards to the CodeIgniter error logs.

<br />]]></description>
			<content:encoded><![CDATA[<p>Anyone who has ever worked in a production environment knows that your users will find errors you have not even dreamed of. They will find your broken links, they will find your missing files, and yes they will find every database connectivity issue you hoped would never occur. Thankfully we are all great developers and sysadmins so we log everything we possibly can to find and remove these errors.</p>
<p>This is great at first but after a while log files become enormous and eat up lots of disk space. The problem multiplies when you start getting into a clustered environment (more than 1 server). You now have to read &amp; maintain logs on 2+ machines which will most likely lead to neglecting your error fixing duties. Fortunately MongoDB recently hit the scene.</p>
<h2>MongoDB</h2>
<p><a href="http://www.mongodb.org/" target="_blank">MongoDB</a> is a scalable, high-performance, open source, document-oriented database. It&#8217;s ability to accept huge amounts of data very quickly make it perfect for application logging. It has built in support for auto-sharding &amp; replication so when your application takes off mongodb will scale with you. It uses a JSON based storage system meaning you can give the database an object (from any programming language with support) and when you pull it back out of the database it will be the exact same as when you put it in. No conversion, no hassle, no bullshit.</p>
<h2>Capped Collections</h2>
<p>Mongo uses things called Collections which are essentially tables in mysql. The main difference is these collections are schemaless. I can have 10 fields in one document (row) and 500 in another and they will play nice inside the collection. This allows a huge amount of flexibility to the developer.</p>
<p>These collections also have the ability to be &#8220;Capped&#8221;. This means I can set a max document count of 5000 and only the most recent 5000 documents will be kept. The older documents are deleted as new ones come in. This is awesome for logging because you will never have to rotate your logs in fear that they will become too large and occupy all of your file system space.</p>
<p>Use this command to cap a collection (in a mongo shell):</p>
<blockquote>
<pre><strong>db.createCollection("my_collection", {capped:true, size:5000})</strong></pre>
</blockquote>
<p><a title="More Information on Capped Collections" href="http://www.mongodb.org/display/DOCS/Capped+Collections" target="_blank">More Information on Capped Collections</a></p>
<h2>Use in CodeIgniter</h2>
<p>By default CodeIgniter writes to log files in /system/logs/ . I have created a class that overwrites that default functionality and sends all logs to a mongo db collection. Adding this library to all of your servers will allow all of those servers to write to the same mongo collection. I have also added some more data to the logs that is helpful in a clustered environment such as the server name, server ip, request uri, and a few more. Just place the MY_Log.php in your application/libraries directory and codeigniter should handle the rest.</p>
<p>You can view and fork the class on Github:<br />
<a href="http://github.com/trs21219/codeigniter-mongo-logs/" target="_blank">http://github.com/trs21219/codeigniter-mongo-logs/</a></p>
<p><script src="http://gist.github.com/404697.js?file=MY_Log.php"></script></p>
<p>Feel free to modify data inserted to fit your specific needs. If you find any bugs or have suggestions you can comment below or raise an <a href="http://github.com/trs21219/codeigniter-mongo-logs/issues" target="_blank">issue here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2010/05/mongodb-codeigniter-logs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Avoiding Database Overload with Memcached</title>
		<link>http://codesanity.net/2010/03/avoiding-database-overload-with-memcached/</link>
		<comments>http://codesanity.net/2010/03/avoiding-database-overload-with-memcached/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 06:23:30 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Downloads]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[key pair]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=194</guid>
		<description><![CDATA[As you build out your application, scalability will start become an issue. You will find yourself making queries to the database every page load cost you precious cpu and load time. The trick is to cache frequently used data so that a database query is not necessary, reducing the overhead on your server.]]></description>
			<content:encoded><![CDATA[<h2>Overview</h2>
<p>Probably the biggest challenge for a newly popular site these days is scalability. The most common point of failure in applications seems to always be the database. These days our applications are totally reliant on some sort of relational database to store the information for our website&#8217;s content. Each and every page load brings many queries that read or insert information into this database all while rendering the web page in a timely manner. This isn&#8217;t so much a problem for your Mom &amp; Pop business, but when your website starts to get some real traffic pointed towards it,  your underlying architecture that you thought was impervious to anything will crumble before your eyes. The solution? Stop making so many queries to your database.</p>
<h2>Caching</h2>
<p>Caching is nothing new. Servers have been caching content for many years quite successfully. There are many different ways you can cache data in your application but right now we will just be talking about using <a href="http://memcached.org/" target="_blank">Memcached</a>. Memcached is a high-performance, distributed memory object caching system. So what does this mean? Basically it can store any kind of value that you would normally store in your database and retrieve it much much faster than your database can.</p>
<h2>Memcached Flow</h2>
<p>When you implement memcached you use it along side of your database. Neither takes the place of each other, memcached just takes some of the load off of your database server after your database server has previously done the grunt work. It works on a key pair system. Meaning it has no tables, rows, columns etc. You give memcached a name and pass it data and it stores that data just as you passed to it. You can pass it an object, array, binary, etc and it will output the same way when you go to retrieve it.</p>
<p>So how does this all work with the database? First, you add code that checks to see if the memcached object (blogpost-45 for our example) exists before it checks the database for the data. If it does you return that data and never touch the DB.  If the memcached object does not exist  you retrieve data from your database, take the array that is passed back and store it in  memcached with the key of &#8220;blogpost-45&#8243;. So the next time you try to get the data for blogpost-45 it will return from memcached and not your database. This is where the load savings occurs.</p>
<p>So what happens when I want to change the data? When you change the data in your database you should delete the key in memcached. You shouldn&#8217;t re-add the data after you delete it, let the select query do that to avoid complications.</p>
<h2>CodeIgniter + Memcached</h2>
<p>I have created a CodeIgniter Library that can help you get a jump start on your integration with memcached, its available on my github page and will be updated when I get time.</p>
<p><a href="http://github.com/trs21219/memcached-library" target="_blank">http://github.com/trs21219/memcached-library</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2010/03/avoiding-database-overload-with-memcached/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Making the Switch: SVN to Git</title>
		<link>http://codesanity.net/2010/03/making-switch-svn-git/</link>
		<comments>http://codesanity.net/2010/03/making-switch-svn-git/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 02:25:49 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[environments]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[svn-git]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=175</guid>
		<description><![CDATA[Choosing the right revision control system can make or break your development flow. I found this out the hard way after SVN brought our source migration process to a crawl. We will walk through the problems that most have with SVN and the migration process from SVN to Git.]]></description>
			<content:encoded><![CDATA[<h2>Overview</h2>
<p>Recently at work, we realized that our SVN setup just wasn&#8217;t working anymore for us. Merges were difficult and time consuming, we had weekly release meetings to go file by file through a list of changes to make sure what we were pushing to production was actually quality. This process was severely inefficient and everyone hated it.  So we did what any company that absolutely hates svn does, we moved to <a href="http://git-scm.com/" target="_blank">Git</a> &amp; <a href="http://github.com/" target="_blank">Github</a>. We chose Github for the stability, function, and social coding features. We use freelancers fairly often to contribute to small modules we work on and having a rich GUI is absolutely essential.</p>
<h2>Git-SVN</h2>
<p>Now we had a years worth of commits that we wanted to migrate over to the new git system. I tried using the import tool that Github provides for repositories but due to our unconventional setup it couldn&#8217;t be done. After some searching  I found a command line tool that actually resides inside of the core git install called <a href="http://www.kernel.org/pub/software/scm/git-core/docs/git-svn.html" target="_blank">git-svn</a>. With a few simple commands and about 45 minutes in the case of our repository it had converted every commit to the sha-1 equivalent that git uses.  Git-svn was actually designed so that you have the ability to work with both systems at the same time. So you could use git while your co-worker uses svn and both commit to the same repository. Below is the actual command we used to convert our SVN repo to a git repository. You can find the original tutorial on doing so <a href="http://pauldowman.com/2008/07/26/how-to-convert-from-subversion-to-git/" target="_blank">here</a>.</p>
<p><code>git svn clone  --no-metadata -A authors.txt -t tags -b branches -T trunk </code></p>
<p>This took around 35 &#8211; 45 minutes with our repository which had almost 6,000 commits in it so give yourself some time.</p>
<h2>Git GUI &amp; Bash</h2>
<p>Unfortunately, not everyone in the office is running on a mac. Now this wouldn&#8217;t be so bad if windows had native support for ssh but it doesn&#8217;t so we had to find a third party solution to using git. Good thing for us is that the git gui &amp; bash application is pretty feature rich and has a low learning curve. After you <a href="http://git-scm.com/download" target="_blank">install git via msysGit</a>, head over to the <a href="http://learn.github.com" target="_blank">github learing </a>page or the <a href="http://progit.org/book/" target="_blank">progit book</a> site to get your self acclimated with how git works.</p>
<p>Screencast on using git gui via Vimeo<br />
[vimeo 2111264 400 285]</p>
<h2>Line Endings</h2>
<p>Let me just say this. Line Endings are a nasty bitch.  If you use multiple operating systems with your repository (especially windows) line endings can be a very big problem if you don&#8217;t set them up right from the start. What happens is that when Windows modifies a file and commits it it uses  a different style of line ending than mac or linux. When your mac or  linux machine pulls that down from the central repository, it changes  the line ending thus changing the sha1 which makes git think you edited  the entire file.  This bit us in the ass a week after converting our repo, which just so happened to be over the holidays so troubleshooting the problems it presented turned out to be especially hard. I highly recommend setting your line endings to the spec that <a href="http://help.github.com/dealing-with-lineendings/" target="_blank">this tutorial outlines</a>. Since we did this we have not had line ending problems.</p>
<h2>Workflow</h2>
<p>We experimented with several workflows to see which would work best with Git. We landed on the &#8220;branch per task&#8221; solution. Basically whenever someone is going to complete a task ( a bug fix, feature enhancement, etc) they create a branch with the ticket name and number. They do their work in that branch, committing and pushing often. When their code is ready to be merged back into the master branch its a fairly easy task. We just run git merge origin/branchname and their changes are ported into the current codebase. We have found this best because it keeps developers from stepping on each others toes and its easy to delay a branch from making it into the master codebase if needed.</p>
<h2>Server Deployment</h2>
<p>We use several staging &amp; production environments for alpha/beta testing  as well as our live environment. Pushing the code changes to these servers is actually quite easy. We just SSH right into the server, cd to the directory and run &#8221; git pull &#8220;. Its as simple as that.</p>
<h4>Overall we all like the new system. It took some getting used to and like everyone else we had our own WTF did I just do moments but in the end it works.</h4>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2010/03/making-switch-svn-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why You Should Always Use Active Record</title>
		<link>http://codesanity.net/2010/03/active-record/</link>
		<comments>http://codesanity.net/2010/03/active-record/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 01:52:58 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[escaped]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[queries]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=205</guid>
		<description><![CDATA[Active Record can be a very useful tool in your developer arsenal. It allows you to code faster and helps ensure your queries execute without security issues.]]></description>
			<content:encoded><![CDATA[<p>I recently came across a post over at <a href="http://stackoverflow.com" target="_blank">Stack Overflow</a> about the <a href="http://stackoverflow.com/questions/2394355/is-it-a-good-idea-to-use-codeigniters-active-record-library-to-manipulate-mysql-d" target="_blank">pros and cons of using the active record class</a> that CodeIgniter provides. I outlined to the poster several advantages of using the active record class as well as the disadvantages.</p>
<h2>Security</h2>
<p>Through the development cycle of a web application, you are going to write hundreds if not thousands of queries for each specific thing you want your application to do. That means for each query you write you will have to wrap it with functions that make it safe so that SQL injection and other malicious things cannot take place. Now say if you write 1000 queries through he course of your development and you forget to properly escape them 1% of the time (very very conservative). You will have 10 possible places for your malicious users to bring down your system.</p>
<p>If you had used Active Record you wouldn&#8217;t have had that happen. Active Record doesn&#8217;t forget to escape and filter those queries. You wouldn&#8217;t have a client calling you at 3am because their pride and joy is displaying porn ads or even worse that their customer&#8217;s personal information has been leaked to hackers.</p>
<h2>Performance</h2>
<p>One of his concerns was the performance impact that the Active Record class imposed. Coming from someone who uses the AR class every day in my 9-5, I have never noticed a significant performance impact on any of the queries I write. I dont know the exact benchmarks of it but I would think the most it adds to any query would by around .0001 seconds. I think the small impact it has on your application is well worth the peace of mind that all of your queries are secure from the few malicious users you are bound to cross paths with.</p>
<h2>Complex Queries</h2>
<p>The Active Record class does a pretty good job at 99% of the queries you are most likely to run. It powers through insert/update/select/delete queries with no problem at all. However it is not perfect. If your application demands a few complex queries you can very easily switch back to straight SQL with $this-&gt;db-&gt;query(); . This way you get the best of both worlds. You can be secure in your cookie cutter queries that you write all the time but when you have to do something that is a little more complicated you have the ability to switch very easily.</p>
<h4>In my opinion there isn&#8217;t a real reason not to use CodeIgniter&#8217;s Active Record. The benefits it provides far outweigh the downsides. Unless of course your someone who never makes a mistake in programming, in that case forget everything I have told you.</h4>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2010/03/active-record/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Fix an iSight Camera that is Not Showing Up</title>
		<link>http://codesanity.net/2009/11/fix-isight-camera-showing/</link>
		<comments>http://codesanity.net/2009/11/fix-isight-camera-showing/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 06:09:17 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[isight]]></category>
		<category><![CDATA[macbook pro]]></category>
		<category><![CDATA[malfunction]]></category>
		<category><![CDATA[virtual machine]]></category>
		<category><![CDATA[vmware fusion]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=162</guid>
		<description><![CDATA[After several days of frustrating Google queries and support forums, I found out what was causing the iSight on my 2008 Macbook Pro to stay hidden from the computer.]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">So lately I noticed the iSight web cam on my 2008 Macbook Pro wasn&#8217;t showing up to Photobooth, Skype, or any other program i tried to use it in. I checked on a bunch of forums, read apple support pages, and revised google search queries until I wanted to scream! After trying to remember the last time I used the camera it hit me, the last time I used it was in a virtual machine (Ubuntu on VMWare Fusion). I know I had to connect the camera manually by clicking the camera icon in the virtual machine widow so I thought that could be the culprit. It turns out after 3 days of searching that it was the problem.<br />
<a href="http://codesanity.s3.amazonaws.com/wp-content/uploads/2009/11/VMware-Fusion1.png"><img class="size-large wp-image-163 alignnone" style="margin: 3px;" title="VMware Fusion1" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2009/11/VMware-Fusion1-1024x683.png" alt="VMware Fusion1" width="430" height="287" /></a>
</p>
<p style="text-align: left;">So if you are having trouble with yours make sure to activate and deactivate the camera in any virtual machines you have. Hope this helps!</p>
<p>( i am running Mac OSX 10.6.2 on a 2008 Aluminum Macbook Pro )</p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2009/11/fix-isight-camera-showing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Conditional .Htpasswd for Multi-Environment Setups</title>
		<link>http://codesanity.net/2009/11/conditional-htpasswd-multienvironment-setups/</link>
		<comments>http://codesanity.net/2009/11/conditional-htpasswd-multienvironment-setups/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 08:58:47 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[environments]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[htpasswd]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=125</guid>
		<description><![CDATA[When using a Multi-Environment setup for your development process it is essential to have adequate protection from outside prying eyes, but also allow people to access your public/testing sites. This .htaccess code allows you to do that.]]></description>
			<content:encoded><![CDATA[<p>So a while back i set Chris over at <a href="http://css-tricks.com" target="_blank">CSS-Tricks</a> some code for his ongoing <a href="http://css-tricks.com/snippets/" target="_blank">snippet library</a> project. This is a quick explanation of that code.</p>
<p>You see when you are working with a multi-environment setup that is synced via a version control system such as Git or Subversion, you need a way to keep your development environments locked down while allowing access to your public environment.</p>
<p>Below is some text that you will input into a .htaccess file placed in your webroot</p>
<p>[sourcecode language='php']<br />
#allows a single uri through the .htaccess password protection<br />
SetEnvIf Request_URI &#8220;/testing_uri$&#8221; test_uri</p>
<p>#allows everything if its on a certain host<br />
SetEnvIf HOST &#8220;^testing.yoursite.com&#8221; testing_url<br />
SetEnvIf HOST &#8220;^yoursite.com&#8221; live_url<br />
Order Deny,Allow</p>
<p>AuthName &#8220;Restricted Area&#8221;<br />
AuthType Basic<br />
AuthUserFile /path/to/your/.htpasswd<br />
AuthGroupFile /<br />
Require valid-user</p>
<p>#Allow valid-user<br />
Deny from all<br />
Allow from env=test_uri<br />
Allow from env=testing_url<br />
Allow from env=live_url<br />
Satisfy any<br />
[/sourcecode]</p>
<p>so in the above code the &#8220;testing_uri&#8221; part could be if i only wanted to allow this url through my htaccess protections (useful for paypal pings) ex &#8220;http://mysite.com/paypal/ipn&#8221;</p>
<p>the host part is to allow anyone through if they are requesting the code from a specific domain such as &#8220;testing.yoursite.com&#8221;. if it is &#8220;development.yoursite.com&#8221; it will not allow the user through.</p>
<p><a href="http://css-tricks.com/snippets/htaccess/allow-single-url/" target="_blank">here is the code on css-tricks</a> and <a href="http://gist.github.com/229178" target="_blank">here is the code as a github gist</a></p>
<p>Thanks for reading and as always comments &amp; questions are heavily encouraged!</p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2009/11/conditional-htpasswd-multienvironment-setups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Structure Models in your MVC based Web Application</title>
		<link>http://codesanity.net/2009/11/structure-models-mvc-based-web-application/</link>
		<comments>http://codesanity.net/2009/11/structure-models-mvc-based-web-application/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 05:01:20 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[applications architecture]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=99</guid>
		<description><![CDATA[MVC has defiantly changed the way applications are written over the past few years. It is more organized and developer-friendly, but it comes with a bit of a learning curve. I will cover what models are and how I use them to speed up my application development.]]></description>
			<content:encoded><![CDATA[<h1>MVC</h1>
<p>Ever since I started using <a href="http://codeigniter.com">CodeIgniter</a> about a year and a half ago, I feel that my coding style has drastically improved as well as the speed, security, and reliability of my applications. This is mostly due to CodeIgniter&#8217;s <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC</a> approach to the structure of the application. It separates your code into three stages:</p>
<ul>
<li>Model &#8211; Used to interact with your database or data source and return the data back to your application</li>
<li>View &#8211; Holds all of the display logic such as html, css and javascript</li>
<li>Controller &#8211; Sort of the middleman, used to coordinate all the actions from Models and Libraries into a View to display to the user&#8217;s browser</li>
</ul>
<h1>CRUD</h1>
<p><a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD (Create, read, update and delete)</a> is a way of structuring your code that interfaces with your database. Those four actions handle 99% of the actions you will do with the data in your database so why should we duplicate functionality every time we need to do something? For my examples I will be using the <a href="http://codeigniter.com/user_guide/database/active_record.html">Active Record Class</a> in CodeIgniter but it would be just as easy for you to use simple SQL statements in your PHP code.</p>
<p>Ok that&#8217;s enough of the vocabulary lesson, lets get into some code.</p>
<h1>Start of the Model</h1>
<p><script src="http://gist.github.com/464047.js?file=gistfile1.php"></script></p>
<p>All we are doing here is declaring the model as &#8220;Blog_model&#8221; and we will save this code in blog_model.php in the models folder in Codeigniter.</p>
<h1>Create</h1>
<p>Creating data is pretty simple, especially in codeigniter. You should only need a single function to create data for each table in your database. This is how i structure my insert functions.</p>
<p><script src="http://gist.github.com/464050.js?file=gistfile1.php"></script></p>
<p>Now what the code above is actually doing is this. When i call $this-&gt;whatever_model-&gt;insert_blog_post($data); , i pass a $data variable which is actually just an array with the index names matching to the database field names. If you are familiar with <a href="http://codeigniter.com/user_guide/database/active_record.html" target="_blank">CodeIgniter&#8217;s Active Record Class</a> this approach is nothing new to you.</p>
<h1>Read</h1>
<p>Reading information from a database is nothing new. You send a select query to a database and it returns results, how could it get any simpler? Well what usually ends up happening over the development of an application is that the developer will create multiple functions that essentially do the same thing. One function will query the database based on the Unique ID # of an item. Another will query checking to see if a particular title in that blog post already exists. So how can these be combined? Well you can create a single function that actually interacts with the database. It is passed a few parameters that tell it what query to run and it does just that. This function is called by other functions that pass those specific parameters. Here is an example.</p>
<p><script src="http://gist.github.com/464053.js?file=gistfile1.php"></script></p>
<h1>Update</h1>
<p>Now updating an row (or many rows) in the database is just as easy as adding a row. The first parameter is your where statement which includes the conditions that the rows must have to be updates. The second parameter is the data that will be inserted into those selected rows.</p>
<p><script src="http://gist.github.com/464055.js?file=gistfile1.php"></script></p>
<p>Pretty simple right? Now all you have to do from anywhere in your application to update a row in blog_posts is $this-&gt;blog_model-&gt;update_blog_post(array(&#8216;ID&#8217; =&gt; 5), array(&#8216;title&#8217; =&gt; &#8216;Getting Started with CRUD&#8217;));</p>
<h1>Delete</h1>
<p>Just as you might suspect, deleting a post is just as simple as adding or updating a post.</p>
<p><script src="http://gist.github.com/464058.js?file=gistfile1.php"></script></p>
<p>Now just run the command $this-&gt;blog_model-&gt;delete_blog_post(array(&#8216;ID&#8217; =&gt; &#8217;223&#8242;));</p>
<h2>Thats it!</h2>
<p>If you have any questions or comments be sure to leave them below!</p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2009/11/structure-models-mvc-based-web-application/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Nambu Twitter Client for Mac and iPhone</title>
		<link>http://codesanity.net/2009/05/nambu-twitter-client-mac-iphone/</link>
		<comments>http://codesanity.net/2009/05/nambu-twitter-client-mac-iphone/#comments</comments>
		<pubDate>Wed, 06 May 2009 00:14:10 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[nambu]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=75</guid>
		<description><![CDATA[Nambu is a great new twitter client out for the Mac and iPhone Platforms. It includes the saved searches, tr.im / pic.im integration, and the ability to group your friends. Its a pretty nice app if you have not tried it yet.]]></description>
			<content:encoded><![CDATA[<p>Recently around the Mac Software ecosystem we have heard alot about twitter clients such as tweetie, tweetdeck and seesmic desktop. Now don&#8217;t get me wrong they are all great twitter clients but they just didn&#8217;t have all the features i was interested in. That is where nambu comes in.</p>
<p>Nambu is a terrific twitter client for the Mac and iPhone. It includes the ability to manage multiple twitter accounts, a mailbox like interface that lets you organize all of your tweets, . You can check out where you are mentioned on twitter, direct messages, sent messages, favorites, and even current trends on twitter! Not to mention the killer ability to organize the people you are following into groups to better manage your tweet stream. I for one use the groups feature very heavily. I have one group for fellow codeigniter people, one for work messages, and another for celebrities such as @aplusk &amp; @grantimahara.</p>
<p><img class="alignleft size-full wp-image-83" title="overview" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2009/05/overview.jpg" alt="overview" width="330" height="275" /></p>
<p>The search feature is pretty nice too. You can save searches and when new entries for those searches appear you will be notified. So if you have an existing search open for &#8220;CodeIgniter&#8221; and someone you dont even know posts &#8220;Man i love Codeigniter!&#8221; you will see that message. A great way to find new friends on twitter with the same interests as you.</p>
<p>Nambu also includes integration with tr.im and pic.im services. Yes i know you are thinking that they are just another set of url shortening services and you are right, but they also have a few tricks up their sleeves. Such as being able to see right from the client how many people have clicked your links and when you visit the tr.im website you can see an analytical breakdown of browsers, countries, bots vs. humans, etc. A pretty powerful feature for anyone who loves to keep track of how traffic is coming to their website.</p>
<p><img class="alignleft size-full wp-image-84" title="search" src="http://codesanity.s3.amazonaws.com/wp-content/uploads/2009/05/search.jpg" alt="search" width="330" height="275" /></p>
<p>Nambu is completely free! No trial periods or annoying ads get inserted into your tweets either. You can download the <a href="http://www.nambu.com/">desktop version for mac here</a> and you can download the <a href="http://itunes.com/apps/nambu">iphone app from the itunes store</a>. So you have no reason to give nambu a shot and save some money while you are at it!</p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2009/05/nambu-twitter-client-mac-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mozenda Data Scraping with CodeIgniter</title>
		<link>http://codesanity.net/2009/04/mozenda-data-scraping-codeigniter/</link>
		<comments>http://codesanity.net/2009/04/mozenda-data-scraping-codeigniter/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 07:23:23 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Downloads]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[mozenda]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=51</guid>
		<description><![CDATA[Mozenda is a very powerful data scraping service. If you have ever found yourself writing scripts or manually copying and pasting data from one website to another then mozenda is for you. They have a very nice, full featured REST API which will be the focus of this article.]]></description>
			<content:encoded><![CDATA[<h1>Overview</h1>
<p>I use Mozenda all the time. When scraping crappy static html pages it is very difficult to find consistency with markup. So thats where Mozenda comes in. I create an agent to scrape a collection of data in a specific order. It can select data between html tags, select data thats supposed to be in one featured place on the page, or it can skip over it if the data you are looking for is not there. It is truely a lifesaving service for anyone that updates mass amounts of data on a regular basis. You cant beat the price of $49/month either (just think how much you would have to pay someone to scrape all of that data for you). I have created a CodeIgniter Library (regular php class compatible) to interact with this api in a easy way. Now lets get to it!</p>
<h1>Download</h1>
<address><a href="http://github.com/trs21219/mozenda-api" target="_blank">http://github.com/trs21219/mozenda-api</a></address>
<h1>Documentation</h1>
<p>First off you need to set your api key and set what format you would like the results to be returned to you in. If you don&#8217;t have an api key then</p>
<p>1. Login to your account at http://Login.Mozenda.com</p>
<p>2. Click the &#8216;Account&#8217; link located in the top right corner of the web page.</p>
<p>3. Look for the &#8216;API Web Service Key&#8217; section under the &#8216;Account Details&#8217; tab, then click &#8216;Generate a New Key&#8217;. You will be required to provide this key in all requests to the API.</p>
<p>If you already have your API key then all you need to worry about is setting your output format. The two options are array (php array) and json.</p>
<h3 style="padding-left: 30px;">Configuring Your Library</h3>
<p style="padding-left: 30px;">[code language='php']<br />
$config_array = array('output_format' =&gt; 'json', 'api_key' =&gt; 'MY-SUPER-SECRET-KEY');<br />
$this-&gt;mozenda_api-&gt;config($config_array);<br />
[/code]</p>
<h3 style="padding-left: 30px;">Collection.GetList</h3>
<p style="padding-left: 30px;">Returns a list of collections for an account</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_get_list();</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Collection.GetViews</h3>
<p style="padding-left: 30px;">Gets a list of views for a particular collection</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_get_views($collection_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Collection.GetFields</h3>
<p style="padding-left: 30px;">Returns a list of fields that are in that collection with their details</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_get_fields($collection_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Collection.AddItem</h3>
<p style="padding-left: 30px;">Adds an item to a collection with the values specified.</p>
<p>[code language='php']</p>
<p>$items = array('Username' =&gt; 'John', 'Phone_Number' =&gt; '555-0123');</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_add_item($collection_id, $items);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Collection.UpdateItem</h3>
<p style="padding-left: 30px;">Updates an item in the collection.</p>
<p>[code language='php']</p>
<p>$items = array('Username' =&gt; 'Peter', 'Phone_Number' =&gt; '555-9876');</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_update_item($collection_id, $item_id, $items);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Collection.DeleteItem</h3>
<p style="padding-left: 30px;">Deletes an item from a collection.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_delete_item($collection_id, $item_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Collection.Clear</h3>
<p style="padding-left: 30px;">Clears the contents of a collection but leaves the collection intact.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_clear($collection_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Collection.Delete</h3>
<p style="padding-left: 30px;">Deletes the collection and all data within it.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;collection_delete($collection_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">View.GetItems</h3>
<p style="padding-left: 30px;">Returns items from a view.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;view_get_items($view_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Agent.GetList</h3>
<p style="padding-left: 30px;">Returns a list of your agents with their ID, Name, Settings, Description, and other important information.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;agent_get_list();</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Agent.GetJobs</h3>
<p style="padding-left: 30px;">Returns a list of your agent&#8217;s jobs with detailed information.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;agent_get_jobs($agent_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Agent.Run</h3>
<p style="padding-left: 30px;">Starts or resumes the Agent.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;agent_run($agent_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Agent.Delete</h3>
<p style="padding-left: 30px;">Deletes an agent and all associated schedules for that agent.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;agent_delete($agent_id)</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Job.Get</h3>
<p style="padding-left: 30px;">Gets the details of a job by the Job ID.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;job_get($job_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Job.Cancel</h3>
<p style="padding-left: 30px;">Cancels a Job in the system. Note, a job must be in a Paused or Error State to cancel a job.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;job_cancel($job_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Job.Pause</h3>
<p style="padding-left: 30px;">Issues the &#8216;Pause&#8217; command for a job currently running in the system.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;job_pause($job_id);</p>
<p>[/code]</p>
<h3 style="padding-left: 30px;">Job.Resume</h3>
<p style="padding-left: 30px;">Resumes a job that is in a Paused or Error state.</p>
<p>[code language='php']</p>
<p>$data = $this-&gt;mozenda_api-&gt;job_resume($job_id);</p>
<p>[/code]</p>
<p>I would really recommend taking a look at the official documentation on the mozenda website <a href=" https://server31.mozenda.com/api" target="_blank">show here.</a></p>
<h2>That&#8217;s It!</h2>
<p>That pretty much wraps it all up. If you have any questions or find a bug please use the comments and ill do my best to fix it.</p>
<p><em>NOTE: The descriptions of what the commands do was copied from the mozenda documentation to make it easier for the end user to understand. I do not take any credit in writing the descriptions.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2009/04/mozenda-data-scraping-codeigniter/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Envato Marketplace API with CodeIgniter</title>
		<link>http://codesanity.net/2009/04/evanto-marketplace-api-codeigniter/</link>
		<comments>http://codesanity.net/2009/04/evanto-marketplace-api-codeigniter/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 04:32:45 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Downloads]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[evanto]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=23</guid>
		<description><![CDATA[Envato recently released an API for thier various Marketplaces. I have taken the various methods of interacting with this data and compiled it into one, easy to use codeigniter library. It can also be used as a standalone php class if you wish. The class is currently PHP5 and requires you have json_encode, json_decode, and curl functions available.]]></description>
			<content:encoded><![CDATA[<h1>Overview</h1>
<p>So I created this library mostly out of boredom. It includes functions to interact with all of the options &amp; functionality that the current version (&#8220;EDGE&#8221;) provides. It was designed to be a CodeIgniter library but it can easily be ported over to php in just a few steps. It allows you to output the data in json, array, or raw (the format that the request was [json, xml]). So lets get to it!</p>
<h1>Download</h1>
<p>[download id="1"]</p>
<h1>Documentation</h1>
<h2 style="padding-left: 30px;">Configuration</h2>
<p style="padding-left: 30px;">There are several options you can set in the configuration that will make the library behave differently.</p>
<ul>
<li>username &#8211; obviously your username for the envato marketplaces</li>
<li>api_key &#8211; your api key for the marketplaces ( you should never set this in view of the public, its sort of like a password ).</li>
<li>api_format &#8211; the format you want the library to request, this can be altered with the next option (output format) &#8211; options incude : json, array, xml (default is json)</li>
<li>output_format &#8211; the format you want the library to return to you. options: array (default), json, raw (unaltered/formatted data straight from the feed) note: to get xml format back you need to set this to raw and set api_format to xml</li>
</ul>
<p style="padding-left: 30px;">This is how you can set the config information with a simple function and array.<br />
[code language='php']<br />
$this->envato_api->config(array('api_format' => 'json', 'output_format' => 'array', 'username' => 'joesmith', 'api_key' => 'MYSUPERSECRETKEY'));<br />
[/code]
</p>
<p style="padding-left: 30px;">Place the configuration code above the functions listed below.</p>
<h2 style="padding-left: 30px;">Public Functions</h2>
<p style="padding-left: 30px;">These are functions that do not require a username and api key to access. They are mostly things such as the latest files on the marketplaces, the most popular threads, etc.</p>
<p style="padding-left: 30px;">
<h3 style="padding-left: 30px;">Blog Posts</h3>
<p style="padding-left: 30px;">A list of blog posts for a particular site. Requires a site parameter.</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_blog_posts('sitename');<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">Active Threads</h3>
<p style="padding-left: 30px;">Threads with the most recent messages activity. Requires a site parameter.</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_threads_active('sitename');<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">Number of Files in Categories</h3>
<p style="padding-left: 30px;">Shows the number of files in the major categories of a particular site. Requires a site paramater.</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_files_number('sitename');<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">Category New Files</h3>
<p style="padding-left: 30px;">New files, recently uploaded to a particular site. Requires site and category paramaters.</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_files_new('sitename', 'categoryname');<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">Popular Files</h3>
<p style="padding-left: 30px;">Returns the popular files for a particular site. Requires a site paramater.</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_files_popular('sitename');<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">New User Files</h3>
<p style="padding-left: 30px;">Shows the newest 10 files a user has uploaded to a particualr site. Requires username and site paramaters.</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_files_user_new('username', 'sitename');<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">Random New Files</h3>
<p style="padding-left: 30px;">Shows a random list of newly uploaded files from a particular site (i.e. like the homepage). Requires a site paramater.</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_files_new_random('sitename');<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">API Releases</h3>
<p style="padding-left: 30px;">Returns Release and Set information for the API (used to generate the documentation).</p>
<p>[code language='php']<br />
$data = $this->envato_api->public_releases();<br />
$this->evanto_api->clear();<br />
[/code]</p>
<p style="padding-left: 30px;">
<h2 style="padding-left: 30px;">Private User Functions</h2>
<p style="padding-left: 30px;">These are functions that DO require a username and API key to access. They include things such as account information, billing statements, etc. <strong>Make sure to set your username &amp; api key inside the script or with the config function above.</strong></p>
<p style="padding-left: 30px;">
<h3 style="padding-left: 30px;">User Vitals</h3>
<p style="padding-left: 30px;">Return a users username and balance.</p>
<p>[code language='php']<br />
$data = $this->envato_api->user_vitals();<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">User Account</h3>
<p style="padding-left: 30px;">Returns the first name, surname, total earnings, total deposits, balance (deposits + earnings), country and current commission rate for sales.</p>
<p>[code language='php']<br />
$data = $this->envato_api->user_account();<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">User Earnings &amp; Monthly Sales</h3>
<p style="padding-left: 30px;">Returns the monthly sales data, as displayed on the user&#8217;s earnings page.</p>
<p>[code language='php']<br />
$data = $this->envato_api->user_earnings();<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">User Statement</h3>
<p style="padding-left: 30px;">Returns the last 100 events as seen on the user&#8217;s statement page.</p>
<p>[code language='php']<br />
$data = $this->envato_api->user_statement();<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">User Recent Sales</h3>
<p style="padding-left: 30px;">Shows the 50 recent sales of the user&#8217;s items.</p>
<p>[code language='php']<br />
$data = $this->envato_api->user_recent_sales();<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h3 style="padding-left: 30px;">User Multiple</h3>
<p style="padding-left: 30px;">This function will return multiple sets of data at once. if you dont supply anything in the parameters it will return all of the results by default. The options inside the array below are the only options you have. You can use as many or as little as you need.</p>
<p>[code language='php']<br />
$data = $this->envato_api->user_multiple(array('account', 'vitals', 'earnings-adn-sales-by-month', 'statement', 'recent-sales'));<br />
$this->evanto_api->clear();<br />
[/code]</p>
<h2>Done!</h2>
<p>We are all done! If you have any questions, suggestions, bugs or just wanna say thanks then reply in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2009/04/evanto-marketplace-api-codeigniter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Started</title>
		<link>http://codesanity.net/2009/04/getting-started/</link>
		<comments>http://codesanity.net/2009/04/getting-started/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 23:23:36 +0000</pubDate>
		<dc:creator>Tom Schlick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[960.gs]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[getting started]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mygov365]]></category>

		<guid isPermaLink="false">http://codesanity.net/?p=1</guid>
		<description><![CDATA[Hello Everyone!

My name is Tom Schlick and I'm a freelance web developer / applications engineer for a company called MyGov365. I absolutely love creating kick ass web applications with php. Lately I've been hooked on CodeIgniter, jQuery, and the 960.gs frameworks as they make my job a hell of a lot easier.]]></description>
			<content:encoded><![CDATA[<p>I plan to use this site to share tutorials, application architecture, and general technology ramblings. Tutorial topics can include such things as CodeIgniter, Site Security, jQuery, and ethical SEO tactics.</p>
]]></content:encoded>
			<wfw:commentRss>http://codesanity.net/2009/04/getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Content Delivery Network via Amazon Web Services: S3: assets.codesanity.net.s3.amazonaws.com

Served from: codesanity.net @ 2010-09-09 19:54:44 -->