<?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>Tony&#039;s Place</title>
	<atom:link href="http://blog.tonycode.com/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.tonycode.com</link>
	<description>Random thoughts</description>
	<lastBuildDate>Thu, 10 May 2012 21:37:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How often do my Rackspace Cloud servers have issues?</title>
		<link>http://blog.tonycode.com/archives/436</link>
		<comments>http://blog.tonycode.com/archives/436#comments</comments>
		<pubDate>Fri, 20 Apr 2012 22:09:00 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.tonycode.com/?p=436</guid>
		<description><![CDATA[I have about 6 cloud server instances running and they seem to have problems too often. But I never actually listed them out, so going back through my cloudkick and rackspace emails here&#8217;s what I have for the past 6 months or so. I have emails going back through Fall of 2009. There is rarely [...]]]></description>
			<content:encoded><![CDATA[<p>I have about 6 cloud server instances running and they seem to have problems too often. But I never actually listed them out, so going back through my cloudkick and rackspace emails here&#8217;s what I have for the past 6 months or so.</p>
<p><iframe width='550' height='700' frameborder='0' src='https://docs.google.com/spreadsheet/pub?key=0AhfTKUaWkiIcdFRvWnNVVXhBQVV2dXNybWhudUJ1QlE&#038;output=html&#038;widget=true'></iframe></p>
<p>I have emails going back through Fall of 2009.  There is rarely a month without an outage.  While most are short, this level of uptime is probably unacceptable to many businesses.   </p>
<p>Oddly enough, my server with the highest level of traffic has not died yet.  I&#8217;m not sure if that is because it is on newer hardware or if something in the OpenStack system doesn&#8217;t like my mostly idle boxes. </p>
<p>One of the failures earlier this year left me with a corrupted filesystem.  While restoring from a backup is simple enough it took a little while to get my Master/Slave replication on Mysql working again.  (Slave was ahead of the master).    The rest of these issues took no work on my part other than pinging the RS team if they weren&#8217;t already working on the issue. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/436/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rack-Cache on Rails 3 &#8211; the unadvertised caching option</title>
		<link>http://blog.tonycode.com/archives/418</link>
		<comments>http://blog.tonycode.com/archives/418#comments</comments>
		<pubDate>Thu, 29 Mar 2012 01:36:31 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://blog.tonycode.com/?p=418</guid>
		<description><![CDATA[Today I was poking around in the rails tmp/cache directory and I saw an entry I did not expect. It appeared that a controller action was being cached but I was not using, page, action or fragment caching. I was setting an expiration header on the action response and as it turns out there is [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was poking around in the rails tmp/cache directory and I saw an entry I did not expect. It appeared that a controller action was being cached but I was not using, page, action or fragment caching.</p>
<p>I was setting an expiration header on the action response and as it turns out there is a handy gem in rails now called <a href="http://rtomayko.github.com/rack-cache/" target="_blank">rack-cache</a>. Rack-cache will create cache entries for items that you set future a expiration for. Since this isn&#8217;t mentioned in the <a href="http://guides.rubyonrails.org/caching_with_rails.html" target="_blank">Rails Caching Guide</a> it took me a little while to track it down.</p>
<p>Here&#8217;s a quick example of it in action</p>
<p>Create a dummy app</p>
<pre>rails new rack-cache
cd rack-cache
bundle exec rails generate controller RackCache cache_this</pre>
<p>Edit the cache_this method</p>
<pre>class RackCacheController &lt; ApplicationController
def cache_this
    render :text =&gt; Time.zone.now.to_s
  end
end</pre>
<p>Fire it up in production mode so caching is enabled</p>
<pre>RAILS_ENV=production bundle exec rails s -p6666</pre>
<p>When you hit the page in the browser and hit reload you&#8217;ll see the time change</p>
<p>http://localhost:6666/rack_cache/cache_this</p>
<pre>2012-03-29 00:40:09 UTC
2012-03-29 00:40:29 UTC</pre>
<p>Now lets change the action slightly</p>
<pre>class RackCacheController &lt; ApplicationController
  def cache_this
    expires_in(5.minutes, :public =&gt; true)
    render :text =&gt; "The time is #{Time.zone.now.to_s}"
  end
end</pre>
<p>Now each time you reload the page you get the same time</p>
<pre>The time is 2012-03-29 00:58:07 UTC</pre>
<pre>The time is 2012-03-29 00:58:07 UTC</pre>
<p>Without a reload the browser won&#8217;t bother asking for the resource for another 5 minutes.  With the reload we get a 304 message.</p>
<p>Normally a simple clear of your browser cache would get you a new time but Rack-Cache also cached this on the server.  So clear all you want, you&#8217;ll not get an update until 5 minutes after the time in the window.   If there are 10 folks hitting this page they will all see the same time.   The 1st person to hit it after expiration will update the time.</p>
<pre>The time is 2012-03-29 01:04:01 UTC</pre>
<p>So where is the output cached?  By default Rails used the <a href="http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-filestore">ActiveSupport::Cache::FileStore</a> which lives in tmp/cache &#8212; configurable via config.cache_store.</p>
<pre>ls -tr tmp/cache/
 assets    B15    2A5    A92    B2C    B31
 # B31 is newest dir
 find tmp/cache/B31
 tmp/cache/B31
 tmp/cache/B31/A20
 tmp/cache/B31/A20/1c4fa8db52f778f10f535fe2253f3a63f92fd87b</pre>
<p>The cached response is in</p>
<p>tmp/cache/B31/A20/1c4fa8db52f778f10f535fe2253f3a63f92fd87b</p>
<pre>cat tmp/cache/B31/A20/1c4fa8db52f778f10f535fe2253f3a63f92fd87b
 o: ActiveSupport::Cache::Entry    :@compressedF:@expires_in0:@created_atf1332983041.303097:
 @value[I"(The time is 2012-03-29 01:04:01 UTC:EF</pre>
<p>This is a pretty powerful caching option that Rails developers should understand and use when appropriate.    In some cases, not knowing this feature was in place has broken applications. Maybe I'll edit the Rails Guide to include this information.</p>
<p>I noticed that rack-cache was filling our apache error log with entries</p>
<pre>cache: [GET /somepath] miss
cache: [GET /anotherpath/logo?1333186605] fresh
cache: [POST /yet/another/path] invalidate, pass</pre>
<p>Turn off the verbose option by adding this to your production.rb</p>
<pre>config.action_dispatch.rack_cache =  {:metastore=&gt;"rails:/", :entitystore=&gt;"rails:/", :verbose=&gt;false}</pre>
<p>To disable rack-cache altogether just do this</p>
<pre>config.action_dispatch.rack_cache =  nil</pre>
<p>Some useful links</p>
<ul>
<li><a href="https://github.com/rails/rails/commit/254ab7d916e579b9300951f5f33d3c5d3ee755a2" target="_blank">First pass at Rack::Cache (github commit)</a></li>
<li><a title="Rack-Cache with Memcached" href="https://devcenter.heroku.com/articles/rack-cache-memcached-static-assets-rails31" target="_blank">Rack-Cache with Memcached</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/418/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple logic problems from interviews</title>
		<link>http://blog.tonycode.com/archives/252</link>
		<comments>http://blog.tonycode.com/archives/252#comments</comments>
		<pubDate>Thu, 30 Jun 2011 18:29:32 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=252</guid>
		<description><![CDATA[I love logic/algorithm problems but during an interview I can sometime just blank out on these questions.   I don&#8217;t feel like taking a lot of time but at the same time some of the problems are quite complex if not approached in the right way. Problem 1: You have an array that contains 0s [...]]]></description>
			<content:encoded><![CDATA[<p>I love logic/algorithm problems but during an interview I can sometime just blank out on these questions.   I don&#8217;t feel like taking a lot of time but at the same time some of the problems are quite complex if not approached in the right way.</p>
<p><strong>Problem 1:</strong></p>
<p>You have an array that contains 0s and 1s.   Order the array.</p>
<p>Now if memory and performance weren&#8217;t a factor this is as simple as doing a ones_and_zeros.sort in ruby (where ones_and_zeros is the array).</p>
<p>You could also build an array of 0s and 1s and then merge them but if the array huge and taking up too much memory this is less than ideal.   You could also add up all the 1s and build a new array but then you are also building a second array and iterating twice.</p>
<p>So the correct answer is to do this inline.</p>
<p>My solution is to loop through the array, replacing any 0 with a 1 and putting 0s on the front of the array.  There is the main loop index and then the zero index that points to the location of the last 0.</p>
<p>&nbsp;</p>
<pre>def sort_it!(ones_and_zeros)
 zero_index = -1
 for i in 0 .. ones_and_zeros.size
   if ones_and_zeros[i] == 0
     zero_index +=1
     unless zero_index == i
       ones_and_zeros[zero_index]=0
       ones_and_zeros[i] = 1
     end
   end
 end
 return ones_and_zeros
end</pre>
<p>This works fine but I got stuck and came back to this problem later.  :-\   I should probably google this and see if there is a better way.</p>
<p><strong>Problem 2:</strong></p>
<p>Next problem was..  you have 5 bottles of pills,  1 has bad pills.  The bad bills weigh 9oz and good pills are 10oz.  You can use the scale once.  You can weigh pills, bottles or any combination but you can only use the scale once.</p>
<p>Now you could weigh pills 3 pills from different bottles and determine narrow down to 2 or 3 which bottle has the bad pills but we need to know which one has the bad pills.</p>
<p>After what seemed like an eternity I figured it out.   put 1 pill from bottle #1, 2 from #2, 3 from #3, etc on the scale.   if all the batches are were good these 15 pills would weigh 150oz.  but there are bad pills.  If they were in bottle #1 it would weigh 149oz, in #2 148oz. etc.   Isn&#8217;t this fun!    It is fun unless you are under a the pressure of a interview&#8230;  that said I guess this tests how people react under pressure as well as their logic skills.</p>
<p><strong>Final problem</strong></p>
<p>you need to determine what the highest floor on a 100 story building that you can drop a marble from before it will shatter on the ground.   You have 2 marbles to work with and you need to minimize the number of tries.   You could go floor 1, 2,3,4, etc but then worse case you have made 100 tries.</p>
<p>I immediately started thinking about dividing the problem like a binary tree.  Try floor 50, then 75 if no breakage, then 62 if it broke but you only have 2 marbles so the worse case is 50 tries.  start at 50.  breaks,  go back to 1 and progress to 49.</p>
<p>Now what if I moved up 5 floors at a time.  Worse case is 99 with 24 tries.   5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,96,97,98,99</p>
<p>Ok, how about 10s?  10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 91, 92, 93,94,95,96,97,98,99</p>
<p>19 tries.  better</p>
<p>There must be a formula here..  assuming a fixed increment we have ceiling(floors/increment) + increment -1</p>
<p>This seems to work ceiling(100/10) + 9 = 19 and ceiling(100/5) + 4 = 24 check out.</p>
<p>Ok,  graph this thing and find the lowest point..  turns out with this technique 19 tries is the best by using 10 as the fixed increment.</p>
<p>But the real answer is 14 using an increment that changes.   I&#8217;m out of time for today but I&#8217;ll probably dig into that one while i sleep.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/252/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Is Ubuntu Server winning over CentOS folks?</title>
		<link>http://blog.tonycode.com/archives/244</link>
		<comments>http://blog.tonycode.com/archives/244#comments</comments>
		<pubDate>Tue, 28 Jun 2011 18:35:03 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=244</guid>
		<description><![CDATA[For years I have used Ubuntu for my desktop environment and CentOS in production.  Why?   Ubuntu makes a great desktop distro and since CentOS is basically a copy of Red Hat, it is considered an enterprise OS. The trouble with being an Enterprise OS is you avoid the latest updates to the OS and aggressively [...]]]></description>
			<content:encoded><![CDATA[<p>For years I have used Ubuntu for my desktop environment and CentOS in production.  Why?   Ubuntu makes a great desktop distro and since CentOS is basically a copy of Red Hat, it is considered an enterprise OS.</p>
<p>The trouble with being an Enterprise OS is you avoid the latest updates to the OS and aggressively patch proven packages.   CentOS has worked fine for me up until recently and I suspect all my future deployments will use Ubuntu.  CentOS packages are lagging behind and this lag is causing pain.  Here are some examples of my recent pain points.</p>
<p>Every 3 months on the dot I fail my PCI compliance scan with the following error.</p>
<p><em><strong>OpenSSH 4.3 is vulnerable Severity: Critical Problem</strong></em></p>
<p>OpenSSH is up to version 5.8 but RedHat keeps patching 4.3.  It is totally secure, it has the latest patches but every 3 months I need to contact the scan company and prove that I have a patched release.  Not fun.</p>
<p>CentOS is using gcc 4.1.2.  Gcc 4.1.2 was released in 2007 and many tools are requiring newer versions to work.  Most recently I tried using opscode/chef and while the site says it works with CentOS you&#8217;ll need to update the compiler to 4.2 or higher.  This defeats the purpose of using Chef IMO.</p>
<p>I also find myself building things like git on CentOS that are part of the standard repository on Ubuntu.  Sure, I can start adding random repositories to get these things but I&#8217;d rather work with an OS that has them in the default/supported repository.</p>
<p>I&#8217;ve talking with colleagues at several other companies over the past few weeks and several are using Ubuntu Server or are planning on getting off CentOS in the near future.   A side note on Rails from my talks,  there seems to be little excitement about CoffeeScript or Sass in Rails 3.1 (just learn css and js already) and folks prefer test-unit and shoulda over rspec.    I totally agree with this sentiment.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/244/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting Rails/Nginx installed on Ubuntu 10.10</title>
		<link>http://blog.tonycode.com/archives/240</link>
		<comments>http://blog.tonycode.com/archives/240#comments</comments>
		<pubDate>Mon, 11 Apr 2011 00:15:31 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=240</guid>
		<description><![CDATA[I did a fresh install of Ubuntu today and figured I would share the steps and packages necessary to get Ruby on Rails running.    I always miss a package or 2 and need to go back.   Here is what worked for me today. Rails3 / Ubuntu 10.10 / MySql / Nginx / Ruby 1.9.2 Core [...]]]></description>
			<content:encoded><![CDATA[<p>I did a fresh install of Ubuntu today and figured I would share the steps and packages necessary to get Ruby on Rails running.    I always miss a package or 2 and need to go back.   Here is what worked for me today.</p>
<p>Rails3 / Ubuntu 10.10 / MySql / Nginx / Ruby 1.9.2</p>
<h2 id="internal-source-marker_0.9749695605972857">Core packages</h2>
<pre>  
sudo apt-get install curl # RVM needs it and it is good to have
sudo apt-get install libcurl3-dev  # needed by several gems and nginx i think
sudo apt-get install git # RVM needs it and it is good to have
# Packages needed by rails and some popular Gems (also ssl for nginx)
sudo  apt-get install build-essential bison openssl libreadline6  libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev  libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf  libc6-dev ncurses-dev
# MySql
sudo apt-get install libmysqlclient-dev  sudo apt-get install mysql-server
# needed by nginx
sudo apt-get install libpcre3-dev  #nginx</pre>
<h2>Install RVM</h2>
<p>bash &lt; &lt;(curl -s https://rvm.beginrescueend.com/install/rvm)<br />
#fix .bashrc then<br />
rvm install 1.9.2  # or whatever ruby version you like<br />
rvm &#8211;default use 1.9.2<br />
gem install rails</p>
<h2>Install Passenger/Nginx with SSL</h2>
<p>Grab Nginx tarball</p>
<pre>cd /tmp
wget http://sysoev.ru/nginx/nginx-0.8.54.tar.gz
tar -zxvf nginx-0.8.54.tar.gz

# install the gem
gem install passenger

# build Nginx
rvmsudo passenger-install-nginx-module</pre>
<ul>
<li>Watch Phusion Passenger do its thing and when it asks you “Automatically download and install Nginx?”, answer 2</li>
<li>Specify the directory where you unzipped the nginx source code (Please specify the directory: /tmp/nginx-0.8.54))</li>
<li>Specify the directory where you want to install nginx to (/usr/local/nginx in my case)</li>
</ul>
<p>You&#8217;ll need a init script for nginx.  Get it here and follow directions</p>
<p><a href="http://wiki.nginx.org/Nginx-init-ubuntu">http://wiki.nginx.org/Nginx-init-ubuntu</a></p>
<p>To start Nginx use</p>
<pre>sudo /etc/init.d/nginx start</pre>
<p>Now at this point your nginx.conf needs some changes.  You need to point to your Rails apps and setup passenger.</p>
<p>Here is my http section for /usr/local/nginx/conf/nginx.conf .. this is a dev setup.  don&#8217;t read too much into it.</p>
<p>&nbsp;</p>
<pre>http {
 passenger_root /home/tony/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.6;
 passenger_ruby /home/tony/.rvm/wrappers/ruby-1.9.2-p180/ruby;
 passenger_user_switching on;
include       mime.types;
 default_type  application/octet-stream;

 log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 '$status $body_bytes_sent "$http_referer" '
 '"$http_user_agent" "$http_x_forwarded_for" "$http_host"';

 access_log  /tmp/nginx.access.log  main;
 sendfile        on;
 keepalive_timeout  65;

 server {
 listen       *:80;
 server_name  localhost;
 rails_env development;
 root   /&lt;path to my rails app&gt;/public;</pre>
<pre>  if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
   return 444;  # block requests that Rails doesn't handle
  }
passenger_enabled on;
}
# HTTPS server
server {
  listen       443;
  server_name  localhost;
  rails_env development;
  root   /&lt;path to my rails app&gt;/public;
  if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
    return 444;  # block requests that Rails doesn't handle
  }
  ssl                  on;
  ssl_certificate      local.crt;
  ssl_certificate_key  local.key;
  ssl_session_timeout  5m;
  ssl_protocols  SSLv2 SSLv3 TLSv1;
  ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  ssl_prefer_server_ciphers   on;
  passenger_enabled on;
  }
}</pre>
<p>restart your Nginx if it is already running</p>
<p>sudo /etc/init.d/nginx restart</p>
<p>That&#8217;s all..  hopefully this helps someone.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />    My nginx.conf is much longer so hopefully I didn&#8217;t cut out anything too important.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/240/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up Sunspot/Solr for OR queries, stemming and lower memory usage</title>
		<link>http://blog.tonycode.com/archives/192</link>
		<comments>http://blog.tonycode.com/archives/192#comments</comments>
		<pubDate>Thu, 06 Jan 2011 18:15:04 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=192</guid>
		<description><![CDATA[As I keep finding in Rails 3, the Gems I used in Rails 2 no longer work or have fallen out of favor.   In Rails 2 acts_as_ferret met my searching needs but after submitting some fixes for Rails 3 and Ruby 1.9.2, I was still having issues so I moved on to Sunspot. One of [...]]]></description>
			<content:encoded><![CDATA[<p>As I keep finding in Rails 3, the Gems I used in Rails 2 no longer work or have fallen out of favor.   In Rails 2 <a href="https://github.com/jkraemer/acts_as_ferret" target="_blank">acts_as_ferret</a> met my searching needs but after submitting some fixes for Rails 3 and Ruby 1.9.2, I was still having issues so I moved on to <a href="https://github.com/outoftime/sunspot" target="_blank">Sunspot</a>.</p>
<p>One of the 1st things I wanted to change with Sunspot was to make the default boolean operator OR.   This means when someone searches for &#8220;car window&#8221; they will get results that match car or window.</p>
<p>Not being a Solr expert my 1st thought was that all I needed to do was change</p>
<pre>&lt;solrQueryParser defaultOperator="AND"/&gt;</pre>
<p>to</p>
<pre>&lt;solrQueryParser defaultOperator="OR"/&gt;</pre>
<p>But it didn&#8217;t work.   After some research and digging through the logs I learned that Sunspot is using the dismax request handler.  To make a long story short, dismax ignores the defaultOperator and uses a minimum_match field.   The good news here is that setting this field to 1 in your search query is easy and gives you the same function as  defaultOperator=&#8221;OR&#8221;.</p>
<p>In your controller your search would look something like this.</p>
<pre>@articles = Article.search do
  keywords(actual_search) {minimum_match 1}
end</pre>
<p>Next thing I wanted was for car searches to return results for cars and other stems.   This required a 1 line change in schema.xml</p>
<p>In the &lt;analyzer&gt; block just add &lt;filter class=&#8221;solr.SnowballPorterFilterFactory&#8221; language=&#8221;English&#8221; /&gt;</p>
<pre>      &lt;analyzer&gt;
        &lt;tokenizer class="solr.StandardTokenizerFactory"/&gt;
        &lt;filter class="solr.StandardFilterFactory"/&gt;
        &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
        &lt;filter class="solr.SnowballPorterFilterFactory" language="English" /&gt;
      &lt;/analyzer&gt;
</pre>
<p>Finally, because the model I am searching is small and Java eats quite a bit of memory I wanted to reduce the Solr server&#8217;s memory footprint.  This may come back to bite me as my dataset grows but for now this is working fine.  To adjust the memory parameters used when using rake sunspot:solr:start just edit your sunspot.yml file and add min_memory and max_memory lines.</p>
<pre>development:
  solr:
    hostname: localhost
    port: 8982
    log_level: DEBUG
    min_memory: 64M
    max_memory: 64M
</pre>
<p>This will result in -Xms64M -Xmx64M being sent to java on startup.</p>
<pre id="_mcePaste" style="position: absolute; left: -10000px; top: 434px; width: 1px; height: 1px; overflow: hidden;">      &lt;analyzer&gt;
        &lt;tokenizer class="solr.StandardTokenizerFactory"/&gt;
        &lt;filter class="solr.StandardFilterFactory"/&gt;
        &lt;filter class="solr.LowerCaseFilterFactory"/&gt;
        &lt;filter class="solr.SnowballPorterFilterFactory" language="English" /&gt;
      &lt;/analyzer&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/192/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>My WordPress Notes</title>
		<link>http://blog.tonycode.com/archives/179</link>
		<comments>http://blog.tonycode.com/archives/179#comments</comments>
		<pubDate>Tue, 23 Feb 2010 01:41:32 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=179</guid>
		<description><![CDATA[While I&#8217;ve been using WordPress for my blog for over 5 years I dig into the internals so rarely that I often forget some of the cool things I&#8217;ve learned and done. In addition to my blog I&#8217;ve used it more like a CMS system where there were only pages and no posts, in this [...]]]></description>
			<content:encoded><![CDATA[<p>While I&#8217;ve been using WordPress for my blog for over 5 years I dig into the internals so rarely that I often forget some of the cool things I&#8217;ve learned and done.   In addition to my blog I&#8217;ve used it more like a CMS system where there were only pages and no posts, in this case the site used a static front page.  I haven&#8217;t written any themes from scratch but I&#8217;m pretty comfortable hacking other people&#8217;s themes and adding new features.</p>
<p>I should probably do this on my wiki but I&#8217;m going to try putting some useful notes here.</p>
<h2>Viewing database queries</h2>
<p>Recently I tried out a calendar plugin that allowed you to enter and display future events.  For some reason it only let you show events 99 days in the future. I hacked the code to let me use 3 digits and it took forever to load my events so I added the following to the bottom of my footer.php (before &lt;/body&gt;)</p>
<pre>&lt;?php
if (current_user_can('administrator')){
 global $wpdb;
 echo "&lt;pre&gt;";
 print_r($wpdb-&gt;queries);
 echo "&lt;/pre&gt;";
}
?&gt;</pre>
<p>This dumps all database queries that are made to the bottom of the page.  Turned out that the plugin was querying the database once for each date in the future.  So when I set it to 200 it was making over 200 queries.  Rather than figure out why it was coded tis way I switched to using <a href="http://wordpress.org/extend/plugins/the-events-calendar/" target="_blank">The Events Calendar</a> Plugin.  It lets you specify if a post is an event and then you can add details.  It works well.</p>
<h2>Header and Footer snippets</h2>
<p>I had an application that I wanted to use the header and footer from a live wordpress blog.  Any time the blog header/footer was updated the application would update too.  The idea here is the wordpress and application maintain the same look and feel and  navigation.</p>
<p>To do this I created a header.php and footer.php file in my wordpress root directory (where wp-config.php is).  The files started with</p>
<pre>&lt;?php
require('./wp-blog-header.php');
?&gt;
</pre>
<p>And then I stole code from the theme header.php and footer.php files to build the code snippets needed for the header and footer for my application.  I then did server side pulls of these live files, cached them and displayed them as my application header and footer.</p>
<p>I guess instead of copying the code I should try to factor out the common code between the theme files and these files so I don&#8217;t repeat it.  Has anyone done this?  I haven&#8217;t tried it yet.</p>
<h2>No HTTPS?  Use OpenId</h2>
<p>I hate sending passwords in the clear but often the cost of SSL is more than the cost of hosting your site so we just do without.  Personally I always link my openId to my main account and use that to sign in.  My assumption is this is much more secure than sending credentials in the clear.  I use the <a href="http://wordpress.org/extend/plugins/openid/" target="_blank">OpenID</a> plugin for this.  I&#8217;m happy that Google now has OpenId support via their profiles.</p>
<h2>Caching</h2>
<p><strong>DB Cache Reloaded or WP Super Cache?</strong></p>
<p>I&#8217;ve used both although there are times when I think a database query is faster than building all these local files.  For low traffic sites does the cache help or hurt?  I don&#8217;t have any stats here.  Just thinking out loud.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2><strong>Broken Link Checker</strong></h2>
<p>Some sites have a lot of links.  This plugin lets you know when you&#8217;re pointing to a dead end.  Very handy.  <a href="http://wordpress.org/extend/plugins/broken-link-checker/">http://wordpress.org/extend/plugins/broken-link-checker/</a></p>
<h2>Akismet</h2>
<p>Install this or spend all day deleting spam comments.</p>
<h2>Backups</h2>
<p>Moving my homeowners association web site from static files to wordpress allowed us to have multiple editors but it makes backing up the system much more difficult.  Before the site consisted of about 80 files.   Now there is a database and many more things can go wrong.   I had downloaded a wordpress backup plugin a few months ago but it wasn&#8217;t ready for prime time.   At the moment my backup consists of daily mysqldumps via cron that reside with my wordpress installation.  I then rsync that to my local machine (the wordpress install with db backups).   It&#8217;s not perfect but it works for now. I guess I could share these scripts in another post.</p>
<h2>One more thing</h2>
<p>I forgot what I was going to say,  maybe it will come to me later tonight.   This is why I should have done this on the wiki.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   I hope someone finds this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/179/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Snow removal in Montgomery County Maryland</title>
		<link>http://blog.tonycode.com/archives/150</link>
		<comments>http://blog.tonycode.com/archives/150#comments</comments>
		<pubDate>Sat, 19 Dec 2009 17:36:14 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[snowstorm]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=150</guid>
		<description><![CDATA[Back in February 2003 we got about 2 feet of snow in Montgomery County Maryland.   The snow plows completely ignored the side streets and focused on the primary roads. The result?   3 days after the storm my street looked like this. When the small plows finally came they were unable to deal with the heavy/wet [...]]]></description>
			<content:encoded><![CDATA[<p>Back in February 2003 we got about 2 feet of snow in Montgomery County Maryland.   The snow plows completely ignored the side streets and focused on the primary roads.</p>
<p>The result?   3 days after the storm my street looked like this.</p>
<p><a rel="attachment wp-att-151" href="http://www.tonycode.com/blog/archives/150/snowedin"><img class="size-full wp-image-151 alignnone" title="3 days after the storm" src="http://www.tonycode.com/blog/wp-content/uploads/2009/12/snowedin.jpg" alt="3 days after the storm" width="465" height="312" /></a></p>
<p>When the small plows finally came they were unable to deal with the heavy/wet snow so it took them a while to clear the streets.</p>
<p>I hope this doesn&#8217;t happen again.  It&#8217;s not like I live in the middle of nowhere.  300 ft up my street is 7 Locks Road which was kept clear.  Unfortunately,  &#8220;up&#8221; is the operative word here and no one was able to escape before the plows came.</p>
<p>I&#8217;m still hoping FedEx makes it today,  but the mailman got stuck a few hours ago so I&#8217;m not counting on it.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />    I did make the mailman&#8217;s day by helping him get out.</p>
<h2> Update </h2>
<p>I&#8217;m happy to report that my street was plowed around 4PM on the 20th so we were snowed in for less than 48 hours.   </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/150/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>My experience with Rackspace Cloud Sites</title>
		<link>http://blog.tonycode.com/archives/133</link>
		<comments>http://blog.tonycode.com/archives/133#comments</comments>
		<pubDate>Wed, 04 Nov 2009 18:17:34 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[rackspace]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=133</guid>
		<description><![CDATA[I&#8217;ve been using Rackspace&#8217;s Cloud Servers for months now and I thought moving some of our standard PHP apps (like wordpress) to Cloud Sites would save me some time as a sysadmin/developer.  I also figured I would setup a database there and use it for my Rails application that runs on Cloud servers (instead of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Rackspace&#8217;s Cloud Servers for months now and I thought moving some of our standard PHP apps (like wordpress) to Cloud Sites would save me some time as a sysadmin/developer.  I also figured I would setup a database there and use it for my Rails application that runs on Cloud servers (instead of building my own or using Amazon&#8217;s RDS).</p>
<p>I&#8217;m sorry to say that after a few days of working with Cloud Sites, I think managing the sites myself on Cloud Servers would be easier.   Fortunately, many of the problems I am having can be easily fixed.</p>
<h2>My issues</h2>
<p>1) No rsync or scp access.  Installing a wordpress site via FTP or Rackspaces file manager was just plain painful.  The file manager didn&#8217;t allow me to move files and it always extracted zip files to the root directory.  Maybe it works correctly on IE?   I only run linux so I have no way of knowing.</p>
<p>2) No easy way to do backups.   Cloud Sites allow you to run cron jobs but the example backups build tarballs on the same host that the site is running on.  When I saw they had ruby as a cron shell option I assumed they had the CloudFiles gem installed,  but they didn&#8217;t.  I want my backups off moved off the host.  I don&#8217;t want to log into my account and download them manually.</p>
<p>3) No access to database binary logs.  I like to take a snapshot every 15 minutes or so in case I lose my database but this is not an option with the cloudsites database.  You could do a mysql dump from another host but you probably don&#8217;t want to do this every 15 minutes.</p>
<p>4) For my Cloud Server rails app there was no LAN address to access my Cloud Site database so all my queries incurred bandwidth charges.</p>
<h2>Feature Requests (easy to hard)</h2>
<p>1) Give people a cron job (or simple backup tab like cloud servers has) that can be used to dump their database daily to Cloud Files.  Its a win for everyone.  The user gets automated backup and you get more Cloud Files revenue.   Here is a script I run from a Cloud Server to back up my Cloud Site database nightly (I can not run it as a Cloud Site job as the CloudFiles gem is not installed on the hosts..  as i mentioned above).</p>
<pre>def run(command)
  result = system(command)
  raise("error, process exited with status #{$?.exitstatus}") unless result
end

cf = CloudFiles::Connection.new(@account_name, @cloud_key)
container = cf.container(@directory_name)
cmd = "mysqldump -C --opt -h #{@mysql_host} -u#{@mysql_user}  "
cmd += " -p'#{@mysql_password}'" unless @mysql_password.nil?
cmd += " #{@mysql_database} | gzip &gt; #{@backup_directory}#{@db_file}"
run(cmd)
t = container.create_object(@db_file)
t.load_from_filename "#{@backup_directory}#{@db_file}"</pre>
<p>2) Advertise the LAN address of the Database Hosts&#8230;  of course the address given now is probably a switch that hits several DB machines.</p>
<p>3) Fix the File Manager.   Maybe it&#8217;s just me but on Firefox/Linux moving files doesn&#8217;t work.  A crippled version of rsync may also be nice.  I suspect there are security issues here but shell access sure would be nice.</p>
<p>4) This is probably hard but it would be nice if I could get access to the MySQL binary logs.</p>
<p>Thanks for listening.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/133/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Why I chose The Rackspace Cloud over AWS</title>
		<link>http://blog.tonycode.com/archives/122</link>
		<comments>http://blog.tonycode.com/archives/122#comments</comments>
		<pubDate>Thu, 03 Sep 2009 13:05:40 +0000</pubDate>
		<dc:creator>Tony Primerano</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[rackspace]]></category>

		<guid isPermaLink="false">http://www.tonycode.com/blog/?p=122</guid>
		<description><![CDATA[Last October at BarCamp DC 2 I ran a session called  “To Cloud or Not? AWS, EC2, S3 or build your own“.  Unfortunately the barcamp wiki died and my notes are gone but at the time it seemed that everyone loved Amazon&#8217;s services.   I tried using EC2 in April and while the ablity to select [...]]]></description>
			<content:encoded><![CDATA[<p>Last October at BarCamp DC 2 I ran a session called  <a title="To Cloud or Not? AWS, EC2, S3" href="http://www.tonycode.com/blog/archives/80" target="_blank">“To Cloud or Not? AWS, EC2, S3 or build your own</a>“.  Unfortunately the barcamp wiki died and my notes are gone but at the time it seemed that everyone loved Amazon&#8217;s services.   I tried using EC2 in April and while the ablity to select from several pre-configured AMIs was nice, building your own AMI should have been easier.  I wanted to configure my machine and then push a button to have my image created.   With Amazon you needed to install tools and go through several steps to create an image.</p>
<p>Then I found Slicehost.  It was owned by Rackspace and had servers for as little as $20/month (for a 256MB instance).   A few weeks later I stumbled on Mosso, also owned by Rackspace and it had servers for about $11/month (plus bandwidth).   Since my applications were using very little bandwidth, I moved to Mosso which is now called <a href="http://www.rackspacecloud.com/" target="_blank">The Rackspace Cloud</a>.   With the Rackspace offerings you install your operating system image, <a href="http://cloudservers.mosso.com/index.php/List_of_Articles#CentOS" target="_blank">configure it</a> and then, from their control panel you can then back it up with 1 click.  You can also schedule backups.   This was so much easier than EC2.</p>
<p>Then there is the pricing.  Amazon&#8217;s small instance is a big vitrual machine and at $0.10/hour it runs around $70/month (i think it was 0.12/hour when I 1st started using it).    This is probably a good price if you need that much horsepower.    What could you possibly run from a 256MB instance anyway?  Here&#8217;s what I am running.</p>
<ul>
<li>A full rails app using Apache/Passenger and MySql (I had to remove several unused modules from apache config and my database is small at the moment)</li>
<li>Apache PHP &#8212; I don&#8217;t have a database here but I suspect there is room</li>
</ul>
<p>I suspect a 512MB instance a safe bet for most applications and I will lilely upgrade as my traffic and database size increases.   Depending on the situation, I may just spin up more instances of the same server as redunancy is a good thing.   Sure I could run everything on 1 AWS instance but if it dies I&#8217;m really SOL.</p>
<p>If you ever need a bigger slice you can upgrade in the control panel with 1 click.  All your configurations and IP address are kept the same. I usually make a backup (1 click) before doing this just in case something bad happens.</p>
<p>Rackspace is still making improvements to their APIs and Image Management so while they don&#8217;t offer as many services as Amazon, they have offered all important features to make developer&#8217;s lives easier, IMO.</p>
<p>For the record, I actually backup my Rackspace Databases to Amazon&#8217;s S3, I feel better knowing my backups are in a different datacenter.  <img src='http://blog.tonycode.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>If you sign up (and found this post helpful) please use my referral code when creating your account.  It is REF-TONYCODE</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonycode.com/archives/122/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

