<?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>Patrick Tulskie &#187; Code</title>
	<atom:link href="http://www.patricktulskie.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.patricktulskie.com</link>
	<description>Building a Better Internet</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:12:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Change ActiveRecord Pool Size on the Fly</title>
		<link>http://www.patricktulskie.com/2010/06/change-activerecord-pool-size-on-the-fly/</link>
		<comments>http://www.patricktulskie.com/2010/06/change-activerecord-pool-size-on-the-fly/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 19:12:25 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[connection_pool]]></category>
		<category><![CDATA[pool]]></category>
		<category><![CDATA[pool size]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=168</guid>
		<description><![CDATA[I have a rake task that runs using the application&#8217;s production environment.  Unlike the production environment though, it is threaded.  In order to make any real use out of that, I need to increase the ActiveRecord connection pool size.  Normally you&#8217;d do this in your database.yml, but in this case I&#8217;d rather [...]]]></description>
			<content:encoded><![CDATA[<p>I have a rake task that runs using the application&#8217;s production environment.  Unlike the production environment though, it is threaded.  In order to make any real use out of that, I need to increase the ActiveRecord connection pool size.  Normally you&#8217;d do this in your database.yml, but in this case I&#8217;d rather not modify the production environment&#8217;s settings for the sake of a single rake task.</p>
<p>Here&#8217;s how you can make the change, on the fly, inside of your rake task:</p>
<pre><code>task :swimming_pool => :environment do
  ActiveRecord::Base.connection_pool.instance_variable_set('@size', 15)
  ActiveRecord::Base.connection_pool.instance_variable_set('@timeout', 10)
  # Do awesome threaded stuff here
end
</code></pre>
<p>The first line of the rake task increases your pool size and the second line changes your timeout when waiting for a connection from the pool.  You can adjust those values to whatever you need.  That just happened to be what I need for this particular task.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2010/06/change-activerecord-pool-size-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby String#Nameize Revised</title>
		<link>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/</link>
		<comments>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 19:10:31 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[irish]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mc]]></category>
		<category><![CDATA[nameize]]></category>
		<category><![CDATA[names]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=102</guid>
		<description><![CDATA[Ruby String class extension to capitalize names properly, including Irish names with Mc, Mac, and O' in them.]]></description>
			<content:encoded><![CDATA[<p>This morning, Kevin Glowacz (<a href="http://twitter.com/kevinglowacz">@kevinglowacz</a>) replied to me a few times on Twitter about Ruby String#Nameize class extension I had posted a while back.  I had done some work to it after posting it here.  Kevin also asked me a few questions about oddities that were in it that have since been resolved.  So thanks to his prodding, you get a slightly updated version&#8230;</p>
<p>The only real &#8220;feature&#8221; is that it will now handle full names just fine. Otherwise, the rest of the stuff was mostly performance related.  Here it is:</p>
<pre><code>class String
  # Extension of the string class to properly handle camel names
  def nameize
    if self.match(/ /)
      # If the name has a space in it, we gotta run the parts through the nameizer.
      name = self.split(' ').each { |part| part.nameize! }.join(' ')
      return name
    elsif self.match(/^[A-Z]/)
      # If they took the time to capitalize their name then let's just jump out.
      return self
    else
      # If there are no spaces and there is no prior
      # capitalization then let's downcase the whole thing.
      name = self.downcase
    end
    # Let's now assume that they were lazy...
    return case
    when name.match(/^mac/)
      name.gsub(/^mac/, "").capitalize.insert(0, "Mac")
    when name.match(/^mc/)
      name.gsub(/^mc/, "").capitalize.insert(0, "Mc")
    when name.match(/^o\'/)
      name.split("'").each{ |piece| piece.capitalize! }.join("'")
    else
      name.capitalize # name is a first name or it's not Irish then capitalize it.
    end
  end

  def nameize!
    replace nameize # BANG!
  end

end</code></pre>
<p>As always &#8211; question, comments, suggestions &#8211; shoot me an email, leave a comment, or hit me on Twitter (@PatrickTulskie).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using Ruby, Git, and Bonjour to Get Through Code Review</title>
		<link>http://www.patricktulskie.com/2008/12/using-ruby-git-and-bonjour-to-get-through-code-review/</link>
		<comments>http://www.patricktulskie.com/2008/12/using-ruby-git-and-bonjour-to-get-through-code-review/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 05:55:38 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=97</guid>
		<description><![CDATA[Every Friday we have our code reviews at BeenVerified and it is definitely a non-trivial event.  Our development team looks through the code all together and offers suggestions and ways to improve what the creator deems near-complete code.  Code reviews have become my favorite part of team based development because they offer me such a [...]]]></description>
			<content:encoded><![CDATA[<p>Every Friday we have our code reviews at BeenVerified and it is definitely a non-trivial event.  Our development team looks through the code all together and offers suggestions and ways to improve what the creator deems near-complete code.  Code reviews have become my favorite part of team based development because they offer me such a badass opportunity to learn more.  Everyone looks a problem differently and so getting insight from other people is huge because you might not consider all of your options when you&#8217;re knee deep in 1000 lines of ruby, CSS, and js all at once.</p>
<p>Yeah it&#8217;s great, except this Friday it didn&#8217;t happen.  Thanksgiving weekend happened instead so we pushed it to Monday.  Being the silly goose I am, I decided to get a new Macbook on Black Friday.  I restored my stuff from Time Machine, installed my Ruby Gems, and thought all was well.  Monday morning, my turn to present code came up and there was a problem with screen sharing.  Crap.  All of my code is in a git branch that is not pushed to a server yet and the time it would have taken to get to a state where we could present it from another machine would have been too much so we postponed my review until my screen sharing would work.  This was most displeasing to me.<span id="more-97"></span></p>
<p><strong>How To Handle It Next Time.</strong></p>
<p>As of late, there has been a lot of talk about bonjour in the ruby world.  There are a lot of really awesome applications that use the technology.  Take for example, gitjour.  It takes an existing git repository and makes it available to machines on the local network through bonjour.  All they would need is the gem and to type &#8220;gitjour list&#8221; in a terminal window to see what&#8217;s available.  That&#8217;s badass.</p>
<p>So if we had to rewind to Monday morning, what we should have done is take a functioning machine on the local network and had that person do a clone of my repository to a new working directory and then we could have screen shared that.  It would have taken a fraction of the time that it would have taken to push it to the server with my own local branch, tell someone to get a copy of my branch from the server and what branch to take.  Gitjour would have cut out all of the steps and it would have been quicker since it&#8217;s on the local network.</p>
<p>This thought alone makes me want to dive deeper into bonjour and figure out how to use it for various things.  If you have any good resources, post them in the comments or hit me up on Twitter. (http://twitter.com/patricktulskie)</p>
<p><strong>What Was The Screen Sharing Problem?</strong></p>
<p>Turns out iChat 4.0.5 doesn&#8217;t know how to view the screen of someone with iChat 4.0.6.  The new Macbook comes with 4.0.6 by default and there is no easy way to upgrade to it.  I downgraded to 4.0.2 from my Blackbook and now all is well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/12/using-ruby-git-and-bonjour-to-get-through-code-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leopard and MySQL Gem</title>
		<link>http://www.patricktulskie.com/2008/11/leopard-and-mysql-gem/</link>
		<comments>http://www.patricktulskie.com/2008/11/leopard-and-mysql-gem/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 18:48:14 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[leopard mysql gem]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby gem mysql rails]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=88</guid>
		<description><![CDATA[Explains how to get the MySQL ruby gem to compile for Macs on OS X Leopard.]]></description>
			<content:encoded><![CDATA[<p>Those of you doing rails development work on Leopard with MySQL have probably seen this error message when starting your app:</p>
<blockquote><p>WARNING: You&#8217;re using the Ruby-based MySQL library that ships with Rails. This library is not suited for production. Please install the C-based MySQL library instead (gem install mysql).</p></blockquote>
<p>Normally I don&#8217;t care, but I figured since I was doing some cleanup today and getting things ready to move on to a longer term it might be good to have a properly working MySQL gem.  I like to run with a system that is close to what we run production.  The closer you get, the less surprises you have when you push it live.</p>
<p><span id="more-88"></span></p>
<p><strong>More Fixing.  Less Talking.</strong></p>
<p>Damn you&#8217;re so pushy sometimes.  Anyhow.  I did a sudo gem install mysql and got another damn error.</p>
<pre><code>Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.
</code></pre>
<p>Oh good.  Another error.  Perfect.  I searched around the interwebs and someone suggested using &#8220;&#8211;with-mysql-lib=/usr/local/mysql/lib&#8221; in the options since that&#8217;s where the libraries are located.  It still barfed on me with that.</p>
<p><strong>A Solution Please.</strong></p>
<p>A few more minutes of hunting and pecking and I found the golden command:</p>
<pre><code>sudo gem install mysql -- --with-mysql-config
Building native extensions.  This could take a while...
Successfully installed mysql-2.7
1 gem installed</code></pre>
<p>Now I don&#8217;t have any errors when starting my rails applications that use MySQL and I&#8217;m closer to what I have in production.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/11/leopard-and-mysql-gem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>String#Nameize</title>
		<link>http://www.patricktulskie.com/2008/10/stringnameize/</link>
		<comments>http://www.patricktulskie.com/2008/10/stringnameize/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 15:50:03 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[capitalize]]></category>
		<category><![CDATA[name]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=79</guid>
		<description><![CDATA[This morning we had an email from someone who wanted us to capitalize their name because they had not done it at signup.  That&#8217;s fine and all, but this is one of those things we&#8217;re going to see again.  Normally you&#8217;d just slap a .capitalize on the string and call it a day.  Unfortunately with [...]]]></description>
			<content:encoded><![CDATA[<p>This morning we had an email from someone who wanted us to capitalize their name because they had not done it at signup.  That&#8217;s fine and all, but this is one of those things we&#8217;re going to see again.  Normally you&#8217;d just slap a .capitalize on the string and call it a day.  Unfortunately with Irish names, you run into a problem because capitalize doesn&#8217;t capitalize those types of names properly.  I wrote a quick function to extend the String class in Ruby that will help get around this problem.</p>
<pre><code>class String
  # Extension of the string class to properly handle camel names
  # Should be used on pieces of names, not full names.
  def nameize
    # If they took the time to capitalize their name then let's just jump out
    if self.match(/\A[A-Z]/)
      return self
    else
      name = self.downcase
    end
    # Let's now assume that they were lazy...
    return case
    when name.match(/^mac/)
      name.capitalize.gsub(/Mac/, "").capitalize.insert(0, "Mac")
    when name.match(/^mc/)
      name.capitalize.gsub(/Mc/, "").capitalize.insert(0, "Mc")
    when name.match(/^o\'/)
      name.split("'").each{ |piece| piece.capitalize! }.join("'")
    else
      name.capitalize
    end
  end
end</code></pre>
<p>I know it&#8217;s not perfect, but it should handle most oddly capitalized names.  Let me know what you think in the comments or on Twitter or whatever and definitely give me any changes you think should be in there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/10/stringnameize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What the heck is REST?</title>
		<link>http://www.patricktulskie.com/2008/08/what-the-heck-is-rest/</link>
		<comments>http://www.patricktulskie.com/2008/08/what-the-heck-is-rest/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 14:39:57 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=40</guid>
		<description><![CDATA[Quite frankly, I&#8217;m tired of about hearing about REST.
&#8230;
So what if I started off my post with a pun?  Look you&#8217;re just going to have to deal with it.  Let&#8217;s move on.  No stop it with the face, it&#8217;s my blog and I can do what I want.
Anyhow &#8211; REST is one of those things [...]]]></description>
			<content:encoded><![CDATA[<p>Quite frankly, I&#8217;m <em>tired</em> of about hearing about REST.</p>
<p>&#8230;</p>
<p>So what if I started off my post with a pun?  Look you&#8217;re just going to have to deal with it.  Let&#8217;s move on.  No stop it with the face, it&#8217;s my blog and I can do what I want.</p>
<p>Anyhow &#8211; REST is one of those things I hear a lot of people talk about as if it is this big mystery.  Then, when you finally find someone to explain it, it turns out they have never actually used it and only understand the theory.  It&#8217;s so frustrating to the beginning Ruby on Rails developer because not everyone has a mini David Hansson in their pocket and it really is one of those things you need to see to understand.</p>
<p><span id="more-40"></span></p>
<p><strong>Ok Patrick.  I&#8217;ll bite.  Let&#8217;s hear more about this.</strong></p>
<p>It&#8217;s a really simple concept that I will explain abstractly at first and then I want you to forget what I said until I compare it to what you&#8217;ve probably already seen.  REST stands for Representational State Transfer.  Technically speaking, REST should be RST but since Roy Fielding coined the term in the year 2000 and he&#8217;s kind of a big deal, people tend to stick with his acronym.</p>
<p>The theory behind it is that your destination |object| is nothing more than a representation of that object at the time you are viewing it.  This plays extremely well into a MVC framework like Ruby on Rails since your controllers and models handle the object and the view is just how you see the object at a given point in time.  Then in the URL, you would just be using nouns to describe what you&#8217;re getting.  Sorta like this:</p>
<p>http://yourdomain.com/noun1/&#8230;/your_object_name</p>
<p><strong>That makes no sense.</strong></p>
<p>I know.  Look, it&#8217;s actually really simple.</p>
<p>Ok so say I have a web application that you would like to pull data from in order to handle however you&#8217;d like with a separate application you are creating.  An example might be a news site &#8211; they provide for you an RSS feed that.  The data is all the same server side but how your web browser sees it is different from how your RSS feed reader sees it so the object (the data) needs to change its form to be readable to the current application.  With me so far?</p>
<p>If I wrote my web application to be RESTful then your application could request the data in RSS or XML or whatever form you prefer to parse, all while maintaining a normal user&#8217;s view in their web browser.  Ah ha!  So we&#8217;re no longer web page builders &#8211; we&#8217;re data providers.  You&#8217;re now actually building page templates and writing more code to handle your data.</p>
<p><strong>I&#8217;m still a little unsure about this Patrick.</strong></p>
<p>I was too, so I sat down and tried it.</p>
<p>On my side project &#8211; www.Twexaminer.com &#8211; I made sure that my controller was pulling data from twitter and storing it into objects instead of just &#8220;building a page.&#8221;  From there I created 2 views.  One is the default HTML view that you see when you view the page from a web browser and the other is a special .xml request that gives you the output of all of the data that the application has collected.</p>
<p>Ex:<br />
http://www.twexaminer.com/examiner/result/patricktulskie<br />
-vs-<br />
http://www.twexaminer.com/examiner/result/patricktulskie.xml</p>
<p>Basically I&#8217;m going to my examiner and saying &#8220;hey, give me a result&#8221; and then clarifying that it should be PatrickTulskie.  In the second example there I tell the examiner to give me the result of PatrickTulskie in XML format.</p>
<p>I could further expand this to make more views or representations for the same data, but for the time being I just have the 2.  In this way, I am now passing on the content using standard looking URLs that a common person can understand.  In addition, if you want to parse the data easily, there is a very intuitive way to get the data without the formatting fluff.  I am effectively passing data to your app, without the use of SOAP or any special hacks, in a format it understands just with a simple GET.  Ah ha!  Simple!</p>
<p>Ok now if I wanted to get fancier then I could add something to my examiner controller to handle updating of a cached result so it would look something like this&#8230; in pseudo code&#8230;</p>
<p>pt_object = new RestResource(http://www.twexaminer.com/examiner/result/patricktulskie)<br />
pt_object.update</p>
<p>&#8230;and then pull off data from that.  This would all be handled through HTTP requests though without needing any additional layers to handle transferring XML to and from client and server.  RestResource is a hypothetical object that one could create that has a simple XML parser to make an easy to use hash out of the data.  XML parsing and generation is easy in Ruby so this just makes sense.</p>
<p><strong>Ah so this is pretty sweet.</strong></p>
<p>Yeah. I know.  It makes things much simpler when you&#8217;re creating something that uses my data now doesn&#8217;t it?  Go, play with it in your project and let me know what you think in the comments or on Twitter, or through email, or through facebook&#8230; or whatever.  Just make sure I get the &#8220;comment&#8221; you&#8217;re trying to convey through some medium.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/08/what-the-heck-is-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons from Twitter: Displaying Content from other Sites on your Own</title>
		<link>http://www.patricktulskie.com/2008/07/lessons-from-twitter-displaying-content-from-other-sites-on-your-own/</link>
		<comments>http://www.patricktulskie.com/2008/07/lessons-from-twitter-displaying-content-from-other-sites-on-your-own/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 15:10:49 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=11</guid>
		<description><![CDATA[I decided to start writing a little series of articles based on the lessons I&#8217;ve learned in writing code the uses twitter, using twitter itself, and just generally getting the most out of it.  This is the first one, and maybe there will be more depending on how I like it.
The Problem &#8211; Why You [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to start writing a little series of articles based on the lessons I&#8217;ve learned in writing code the uses twitter, using twitter itself, and just generally getting the most out of it.  This is the first one, and maybe there will be more depending on how I like it.</p>
<p><strong>The Problem &#8211; Why You Should Care</strong></p>
<p>Other sites that you pull content from are not always going to be reliable.  They could be down, running slow, or some other possible problem.  If you are using something like twitter to display your status on your site but you have a lot of other content you want people to see then it would be wise to use client-side scripting to get the content.  You might be saying in your head &#8220;Oh but I have this sweet PHP script that does that for me.&#8221; but you should tell that voice in your head to shut up and just listen.</p>
<p><span id="more-11"></span></p>
<p><strong>The Solution&#8230;</strong></p>
<p>When you use server-side scripting then the server that is dishing out your website needs to go to the other (possibly) slow website.  If it&#8217;s waiting for this content then your user is waiting for your site to finish being generated server side and then sent to their browser.  This was a problem when twitter was doing its thing with the &#8220;fail whale&#8221; on a regular basis and was generally taking forever to display tweets.  This in turn was making my site very slow.  Realizing the problem, I took out the PHP widget that I had and replaced it with my own little creation that utilizes javascript and a tiny bit of PHP.</p>
<p><strong>Let&#8217;s take a look at how to do that&#8230;</strong></p>
<p>First thing you&#8217;re going to want to do is make a little div with some static text in it that gets killed when your stuff finishes loading.  You can make it kinda like this:</p>
<blockquote><p>&lt;div id=&#8221;twit_text&#8221;&gt;<br />
&lt;ul id=&#8221;twitter_update_list&#8221;&gt;&lt;li&gt;Waiting for Twitter.com to reply.  Please hold.&lt;/li&gt;&lt;/ul&gt;<br />
&lt;/div&gt;</p></blockquote>
<p>The ul in there will be replaced by the script which actually sits right on twitter&#8217;s servers.  This is pretty simple and basic stuff.  It is advisable to put some static content in there so that users know that something else is going to happen and you don&#8217;t have a blank spot on the page.  There is one other piece of magic that actually uses a little bit of PHP but not for the same purpose the other scripts use it for&#8230;</p>
<blockquote><p>&lt;?<br />
$currURL = currPageURL();</p>
<p>if (($currURL == &#8220;http://www.patricktulskie.com/&#8221;) || ($currURL == &#8220;http://patricktulskie.com/&#8221;))<br />
{<br />
echo &#8220;&lt;script type=\&#8221;text/javascript\&#8221; src=\&#8221;http://twitter.com/javascripts/blogger.js\&#8221;&gt;&lt;/script&gt;&#8221;;<br />
echo &#8220;&lt;script type=\&#8221;text/javascript\&#8221; src=\&#8221;http://twitter.com/statuses/user_timeline/PatrickTulskie.json?callback=twitterCallback2&amp;count=1\&#8221;&gt;&lt;/script&gt;&#8221;;<br />
}<br />
?&gt;</p></blockquote>
<p>This goes in the footer of the page to only load the javascript if the page you&#8217;re looking at is the index page.  You can modify the PHP to load on different pages but for my purposes I only want you to see the status on the index.  You can&#8217;t easily do this with a plugin because plugins are loaded entirely as the page loads.  The PHP above is in the very footer of the page and it only kicks off the javascript IF we&#8217;re on the index of the site AND after everything else on the page has already loaded.</p>
<p><strong>One Other Thing&#8230;</strong></p>
<p>I use this function to get the URL of the page.  You can put it in your wordpress theme&#8217;s functions or you can put it wherever you need it on your site.  It&#8217;s fairly reusable too.</p>
<blockquote><p>function currPageURL()<br />
{<br />
$pageURL = &#8216;http&#8217;;<br />
if ($_SERVER["HTTPS"] == &#8220;on&#8221;) {$pageURL .= &#8220;s&#8221;;}<br />
$pageURL .= &#8220;://&#8221;;<br />
if ($_SERVER["SERVER_PORT"] != &#8220;80&#8243;)<br />
{<br />
$pageURL .= $_SERVER["SERVER_NAME"].&#8221;:&#8221;.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];<br />
}<br />
else<br />
{<br />
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];<br />
}<br />
return $pageURL;<br />
}</p></blockquote>
<p><strong>I Hate Twitter</strong></p>
<p>Well thats fine.  I&#8217;m sure it doesn&#8217;t like you much either.  Regardless, this is a really basic usability concept that many people don&#8217;t seem to grasp or even think about when creating a website.  Say you want to pull news feeds from a Digg category using an RSS parser on your page.  You have other stuff on the page but this Digg box is in your sidebar.  If you don&#8217;t think about where the script is going to execute in relation to your page loading, then you&#8217;re going to have problems when Digg is running slow or is down.  For those of you who don&#8217;t want to get into a full blown ajax setup, or simply don&#8217;t know how to then this is a great work around that uses really minimal coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/07/lessons-from-twitter-displaying-content-from-other-sites-on-your-own/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GreaseMonkey for Newbs</title>
		<link>http://www.patricktulskie.com/2008/06/greasemonkey-for-newbs/</link>
		<comments>http://www.patricktulskie.com/2008/06/greasemonkey-for-newbs/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 05:22:52 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=8</guid>
		<description><![CDATA[I won&#8217;t sit here and proclaim myself to be some god of Grease Monkey but I do know a thing or two about Java Script.  Basically, for those of you who are clueless as to what Grease Monkey is, it&#8217;s a plugin for Firefox that allows you to manipulate certain pages you visit using Java [...]]]></description>
			<content:encoded><![CDATA[<p>I won&#8217;t sit here and proclaim myself to be some god of Grease Monkey but I do know a thing or two about Java Script.  Basically, for those of you who are clueless as to what Grease Monkey is, it&#8217;s a plugin for Firefox that allows you to manipulate certain pages you visit using Java Script.  Now that we know what it is and have tons of ideas flowing through our heads, let&#8217;s just do something kinda cool.</p>
<p>Today we&#8217;re going to beat up on certain gallery pages that use images of the format &#8220;imageName.sized.jpg&#8221;.  What I mean by this is &#8211; we&#8217;re going to take the page (which is usually filled with junk) and replace everything with just the full size image and the caption.</p>
<p>Let&#8217;s get some assumptions out of the way:<br />
You know SOME Java Script, the site you&#8217;re visiting also has the non-sized images in the same directory as the sized images, and you don&#8217;t care what else is on the web page.  We&#8217;re also assuming there is only one caption with no &#8220;id&#8221; and we only have a style class to work with.</p>
<p>Ok?  Ok.  Let&#8217;s go.</p>
<p><span id="more-8"></span></p>
<p>Once you&#8217;ve installed GreaseMonkey, set it up, and got it going then you&#8217;ll want to make a new user script.  The namespace isn&#8217;t terribly important right now so just make it the URL for your website or something like that and continue on.  Once you&#8217;ve specified your edittor of choice, it will open up and you&#8217;ll basically have a blank canvas to work with.  The code you enter here will be run when the page is completed.  First thing we&#8217;re going to do is get the caption with this code:</p>
<blockquote><p>function getCaption()<br />
{<br />
var all = document.all ? document.all :<br />
document.getElementsByTagName(&#8217;p');<br />
var theCaption;<br />
for (var e = 0; e &lt; all.length; e++)<br />
{<br />
if (all[e].className == &#8220;pcaption&#8221;)<br />
{<br />
theCaption = all[e];<br />
}<br />
}<br />
return theCaption;<br />
}</p></blockquote>
<p>What we&#8217;re doing there is grabbing all of the elements of the document that are paragraphs (p tags) and then looping through until we find that &#8220;pcaption&#8221; class.  You might need to look at the gallery you&#8217;re visiting to get the exact names but that&#8217;s the basic gist of it.  Now let&#8217;s grab the image and replace the page with it and our caption:</p>
<blockquote><p>var theImage, unSizedImage, unSizedPath;<br />
theImage = document.getElementById(&#8217;galleryImage&#8217;);<br />
theCaption = getCaption();</p>
<p>if (theImage)<br />
{<br />
unSizedPath = theImage.src.replace(/.sized/,&#8221;");<br />
unSizedImage = document.createElement(&#8217;img&#8217;);<br />
unSizedImage.src = unSizedPath;<br />
document.body.innerHTML = &#8220;&lt;center&gt;&#8221; + theCaption.innerHTML + &#8220;&lt;br /&gt;&lt;img src=\&#8221;" + unSizedImage.src + &#8220;\&#8221; /&gt;&lt;/center&gt;&#8221;;<br />
}</p></blockquote>
<p>First we just create some variables and get our caption from before.  Once we have that all setup we say if you find an image with the id of &#8220;galleryImage&#8221; then we&#8217;re gonna do some work.   We grab the src for the image, strip out the .sized portion, and then assign that source to a new blank set of image tags.  Lastly we take the body&#8217;s innerHTML and assign it our caption&#8217;s innerHTML and our newly grabbed image.</p>
<p>In this little exercise we learned how to totally modify the contents of a page with a new image from &#8220;somewhere else.&#8221;  We also learned how to get a set of tags using the class for instances where we don&#8217;t have an id.  We also did some very basic string replacing and innerHTML utilization and manipulation.  Pretty cool huh?</p>
<p>Now you can toy with it anyway you want.  There&#8217;s a lot of fun stuff in there.  For more Grease Monkey tutorials and guides you can visit http://diveintogreasemonkey.org/  Have something you&#8217;re looking to accomplish?  Well, just comment to this post with a suggestion.</p>
<p>Note: Wordpress is really awesome at stripping out whitespace from stuff.  Sorry about the poor code formatting as a result.  I will be looking into a better way to display this stuff so it doesn&#8217;t happen in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/06/greasemonkey-for-newbs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

