<?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>The Original Jelani Harris &#187; Programming</title>
	<atom:link href="http://jelaniharris.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://jelaniharris.com</link>
	<description>The original website of Jelani Harris the original of course</description>
	<lastBuildDate>Sat, 24 Sep 2011 18:58:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to install Paperclip in Rails 3</title>
		<link>http://jelaniharris.com/2011/how-to-install-paperclip-in-rails-3/</link>
		<comments>http://jelaniharris.com/2011/how-to-install-paperclip-in-rails-3/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 18:58:13 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=210</guid>
		<description><![CDATA[Paperclip is a plugin/gem created by the talented folks at ThoughtBot. It will make using attachments and uploads in your rails application ridiculously easy to implement. Let's get started! Things you'll need installed  Before we start there is only one thing that you will need to have installed on your system before we can proceed. [...]]]></description>
			<content:encoded><![CDATA[<p>Paperclip is a plugin/gem created by the talented folks at <a title="Thoughtbot" href="http://thoughtbot.com/" target="_blank">ThoughtBot</a>. It will make using attachments and uploads in your rails application ridiculously easy to implement. Let's get started!</p>
<h3><strong>Things you'll need installed </strong></h3>
<p><strong></strong>Before we start there is only one thing that you will need to have installed on your system before we can proceed.</p>
<p><strong>ImageMagik</strong><br />
<a title="ImageMagick" href="http://www.imagemagick.org/" target="_blank"> ImageMagik</a> is a software suite that is used to edit and create images. Paperclip uses it to resize and modify images. The easiest way to install this is to first make sure that you have <a title="MacPorts Installation" href="http://www.macports.org/install.php" target="_blank">MacPorts installed</a>, and then running:<br />
<code><br />
sudo port install ImageMagick<br />
</code></p>
<p>This is a massive library and it will take a little while to install.</p>
<h3><strong>Installing Paperclip</strong></h3>
<p><strong></strong>So you can install Paperclip as a plugin, or you can install it as a gem.</p>
<p><strong>Install as a Gem</strong><br />
This is the recommended way of installing Paperclip. All you need to do is to add to your <em>config/environment.rb</em><br />
<code><br />
config.gem 'paperclip', :source => 'http://rubygems.org'<br />
</code><br />
Then run:<br />
<code><br />
rake gems:install<br />
rake gems:unpack</code></p>
<p>Or you can add it directly to your Gemfile if you have Bundler:</p>
<p><code> source 'http://rubygems.org'<br />
gem 'paperclip'<br />
</code></p>
<p><strong>Install as a Plugin<br />
</strong>To install it as a plugin you use:</p>
<p><code> ruby script/plugin install git://github.com/thoughtbot/paperclip.git<br />
</code></p>
<h3>Using Paperclip in Your Application</h3>
<p>Lets add the 'has_attached_file' attributes to the model we want to be able to attach files to:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Author <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_attached_file <span style="color:#ff3333; font-weight:bold;">:avatar</span>,
    <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:thumb</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;75x75#&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:small</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;100x100#&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:medium</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;150x150&gt;&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Thankfully attached files do not need to have a separate model. Your attachments are essentially treated like another attribute. The image is not saved until your model is saved (if you desire, there are ways of forcing attachment creation/updates without model involvement - but that's another tutorial)</p>
<p>Now that we have our model paperclip enabled we need to add some database columns to provide full support for it.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> AddAvatarToAuthor <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    add_column <span style="color:#ff3333; font-weight:bold;">:author</span>, <span style="color:#ff3333; font-weight:bold;">:avatar_file_name</span>, :<span style="color:#CC0066; font-weight:bold;">string</span>
    add_column <span style="color:#ff3333; font-weight:bold;">:author</span>, <span style="color:#ff3333; font-weight:bold;">:avatar_content_type</span>, :<span style="color:#CC0066; font-weight:bold;">string</span>
    add_column <span style="color:#ff3333; font-weight:bold;">:author</span>, <span style="color:#ff3333; font-weight:bold;">:avatar_file_size</span>, :<span style="color:#CC0066; font-weight:bold;">integer</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    remove_column <span style="color:#ff3333; font-weight:bold;">:author</span>, <span style="color:#ff3333; font-weight:bold;">:avatar_file_name</span>
    remove_column <span style="color:#ff3333; font-weight:bold;">:author</span>, <span style="color:#ff3333; font-weight:bold;">:avatar_content_type</span>
    remove_column <span style="color:#ff3333; font-weight:bold;">:author</span>, <span style="color:#ff3333; font-weight:bold;">:avatar_file_size</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So the first part of the column name is the same as what we called our attachment attribute in our model. In this case that's <em>photo</em>. Now to update our database we use:</p>
<p><code> rake db:migrate </code></p>
<p>Now that we have our database and our model taken care of, we can start working on our content. So in our view we can add a file field:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> form_for <span style="color:#ff3333; font-weight:bold;">:author</span>, <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:multipart <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:avatar</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;br /&gt;
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= f.<span style="color:#9900CC;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:avatar</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><strong>Displaying Attachments</strong><br />
Now when you want to display your model's attachments all you need to do is use:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= image_tag <span style="color:#0066ff; font-weight:bold;">@author</span>.<span style="color:#9900CC;">avatar</span>.<span style="color:#9900CC;">url</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= image_tag <span style="color:#0066ff; font-weight:bold;">@author</span>.<span style="color:#9900CC;">avatar</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:thumb</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2011/how-to-install-paperclip-in-rails-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery is the best javascript library out there</title>
		<link>http://jelaniharris.com/2008/jquery-is-the-best-javascript-library-out-there/</link>
		<comments>http://jelaniharris.com/2008/jquery-is-the-best-javascript-library-out-there/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 01:43:31 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apparatus complex]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=17</guid>
		<description><![CDATA[I officially declare JQuery to be the best javascript library out there. So much documentation, so many plugins, so many interesting things you can DO with that library. I just lost 7-8 hours, implementing a prototype of a feature for my discussion site, Apparatus Complex. In particular it's a meta-game that I'm developing so that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I officially declare</strong> JQuery to be the best javascript library out there. So much documentation, so many plugins, so many interesting things you can DO with that library. I just lost 7-8 hours, implementing a prototype of a feature for my discussion site, <a title="Apparatus Complex" href="http://www.apparatuscomplex.com">Apparatus Complex</a>. In particular it's a meta-game that I'm developing so that users can compete with each other in a role-playing game  while they wait for the site to update itself with content from other people.</p>
<p><a href="http://jelaniharris.com/blog/wp-content/uploads/2008/07/grauz.jpg"><img class="alignnone size-medium wp-image-18" title="grauz" src="http://jelaniharris.com/blog/wp-content/uploads/2008/07/grauz-300x214.jpg" alt="" width="300" height="214" /></a></p>
<p>So I had a crazy idea of using jquery and ajax to let people drag and drop equipment into slots, and then dynamically update what that piece of equipment would do to their statistics. Doing this in flash is really easy, I first got the drag and drop implemented (so easy with the <a href="http://ui.jquery.com/">Jquery UI</a>), then I set the restrictions on which column each orb could belong in, and then I added the automatic update of the statistics just moments later. It was simply brilliant and it was pretty darn efficient. If you want to play around with this, it's <a href="http://www.apparatuscomplex.com/grauz/">located right here</a>. The equipment orbs are generated randomly and so are the names.</p>
<p>By the way, <a href="http://www.mootools.net">MooTools </a>and <a href="http://www.prototypejs.org/">Prototype </a>and <a href="http://script.aculo.us/">Scriptalicious</a> are okay as well. I'm just <em>really </em>impressed with JQuery right now.</p>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2008/jquery-is-the-best-javascript-library-out-there/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding a delay to JQuery Functions</title>
		<link>http://jelaniharris.com/2008/adding-a-delay-to-jquery-functions/</link>
		<comments>http://jelaniharris.com/2008/adding-a-delay-to-jquery-functions/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 01:19:48 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=14</guid>
		<description><![CDATA[Recently I was working on a few functions that I didn't want to have activated immediately after hovered over a div. I neededthe functions to activate after a half a second of hovering by the user. To do this I created this this piece of code. 1 2 3 4 5 6 7 8 9 [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on a few functions that I didn't want to have activated immediately after hovered over a div. I neededthe functions to activate after a half a second of hovering by the user. To do this I created this this piece of code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> display_timeout <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.orb_space&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>display_timeout <span style="color: #339933;">!=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				clearTimeout<span style="color: #009900;">&#40;</span>display_timeout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// save a reference to 'this' so we can use it in timeout function</span>
		<span style="color: #003366; font-weight: bold;">var</span> this_element <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
                display_timeout <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				display_timeout <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
				<span style="color: #006600; font-style: italic;">// perform things with this_element here buy referencing it like $(this_element)</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span>this_element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'magic'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					performRollinMagic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>display_timeout <span style="color: #339933;">!=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				clearTimeout<span style="color: #009900;">&#40;</span>display_timeout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			performRolloutStuff<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Let's go through line by line to see what's happening here.</p>
<p><strong>Lines 2: </strong>The <a href="http://docs.jquery.com/Events/hover">JQuery hover</a> function has two parameters. The first parameter is for the function to call when the user hovers onto the element, and the second one is for when the user hovers out. Lines 4-16 consist of the first function and lines 19-24 consist of the second.</p>
<p><strong>Lines 4-6:</strong> So if we happen to flash our mouse over the element very fast twice, this will make sure that we only have one timeout function happening.</p>
<p><strong>Line 9:</strong> When we in the <a href="http://www.w3schools.com/js/js_timing.asp">setTimeout</a> function we need to remember a reference to our current element so that we don't have to do some tricky DOM navigation to get the hover activated element with the setTimeout event. It's just easier to just make a variable to remember the element.</p>
<p><strong>Lines 11-15:</strong> First we reset the display_timeout variable, and then we can perform our necessary hover actions in this setTimeout function. The 500 indicates that we want this function to occur after 500ms.</p>
<p><strong>Lines 20-23:</strong> This looks very familiar doesn't it? It's the same thing from lines 4-6. This is so that if the user rolls out of the hover element, the timer countdown will immediately stop and the hoverin functions will not occur.</p>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2008/adding-a-delay-to-jquery-functions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Middleware is your friend</title>
		<link>http://jelaniharris.com/2008/middleware-is-your-friend/</link>
		<comments>http://jelaniharris.com/2008/middleware-is-your-friend/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 21:37:18 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ogre]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=15</guid>
		<description><![CDATA[There's nothing wrong with reinventing the wheel. In fact, sometimes that's the best way to learn how something works. But if you just want to get something done, middleware is your best answer. Here is some that I personally recommend. Blogging Software WordPress - With thousands of plugins and full customization, why would you install [...]]]></description>
			<content:encoded><![CDATA[<p>There's nothing wrong with reinventing the wheel. In fact, sometimes that's the best way to learn how something works. But if you just want to get something done, middleware is your best answer. Here is some that I personally recommend.</p>
<h2>Blogging Software</h2>
<p><a href="http://www.wordpress.org">WordPress </a>- With thousands of plugins and full customization, why would you install anything else? Perhaps if you're the kind of person that sits around wearing black turtle necks and hates something because it's popular. But you're not one of those kind of people? Right? <a href="http://www.expressionengine.com">Expression Engine</a> isn't bad either - but you pay for that kind of quality.</p>
<h2>3d Engines</h2>
<p><a href="http://www.ogre3d.org">Ogre</a> for C++, Python, and C#. A great 3d engine that my friend and I are using to create our games. Ogre has a great community, with a very helpful wiki to get newbies started. However, some of it assumes that you know a little bit about 3d graphics before the intermediate ones seem to be truly helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2008/middleware-is-your-friend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

