<?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>Jeff Beard &#187; Computing</title>
	<atom:link href="http://jeffbeard.org/category/computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeffbeard.org</link>
	<description>Blog.blog</description>
	<lastBuildDate>Sun, 01 Jan 2012 17:51:29 +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>Netalyzr &#8211; Network debugging tool</title>
		<link>http://jeffbeard.org/2012/01/netalyzr-network-debugging-tool/</link>
		<comments>http://jeffbeard.org/2012/01/netalyzr-network-debugging-tool/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 17:51:29 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Infrastructure Management]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=440</guid>
		<description><![CDATA[I&#8217;ve had a transient issue with my Internet access randomly &#8220;going away&#8221;. It&#8217;s annoying but generally clears up within a minute or two. I came across a tool called Netalyzr by a group within UC Berkeley. Netalyzr is a Java application available as either an in-browser Applet or a command line utility. It runs a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a transient issue with my Internet access randomly &#8220;going away&#8221;. It&#8217;s annoying but generally clears up within a minute or two. I came across a tool called <a href="http://netalyzr.icsi.berkeley.edu/index.html">Netalyzr</a> by a group within UC Berkeley. Netalyzr is a Java application available as either an in-browser Applet or a command line utility. It runs a number of network connectivity tests and provides a detailed report hosted on their web site that uses a simple red/yellow/green motif to show problems and their relative importance.</p>
<p>While Netalyzr didn&#8217;t clearly show what was going on with my Internet connection it did raise a red flag about network buffers that might be the issue. Unfortunately, that&#8217;s a router configuration issue on the part of my ISP so I&#8217;m not hopeful for a resolution. But I can always gather data then open a trouble ticket with the vendor. </p>
<p>Regardless, Netalyzr looks like a great tool for troubleshooting connectivity issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2012/01/netalyzr-network-debugging-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prey Project, ping and Cygwin</title>
		<link>http://jeffbeard.org/2011/09/prey-project-ping-and-cygwin/</link>
		<comments>http://jeffbeard.org/2011/09/prey-project-ping-and-cygwin/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 16:08:48 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Personal Computing]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=411</guid>
		<description><![CDATA[File this with the obscure issue department&#8230; The Prey Project looked like a nice system for tracking stolen devices and has gotten a lot of good press recently. I decided to try it out. After getting everything setup and working I noticed a lot of Cygwin bash shells running the ping command. The commands accumulated [...]]]></description>
			<content:encoded><![CDATA[<p>File this with the obscure issue department&#8230;</p>
<p>The <a href="http://www.preyproject.com" title="Prey Project">Prey Project</a> looked like a nice system for tracking stolen devices and has gotten a lot of good press recently. I decided to try it out. After getting everything setup and working I noticed a lot of <a href="http://www.cygwin.com" title="Cygwin">Cygwin</a> bash shells running the ping command. The commands accumulated eventually degrading system performance which is when I noticed.</p>
<p>Prey has a partial UNIX environment (<a href="http://www.mingw.org/" title="MingW">MingW</a>) contained in it and consists of shell scripts wrapping a number of UNIX utilities compiled for Windows. I say partial because it doesn&#8217;t include the &#8220;ping&#8221; command which is a dependency for the software. And the shell scripts apparently don&#8217;t take into account the potential for a user having other UNIX-like environments installed (Cygwin also has a bash shell and the ping command but there are <a href="http://www.mkssoftware.com/products/">others</a> <a href="http://unxutils.sourceforge.net/">as well</a>.) So what was happening is that script (<a href="https://github.com/tomas/prey/blob/master/core/pull">pull</a>) naively looks at what operating system it is installed on and for a ping command and issue what it believes are the correct command line arguments. For Windows it&#8217;s this:</p>
<pre class="brush: bash; title: ; notranslate">
ping -n 1 www.google.com
</pre>
<p>This doesn&#8217;t work because Cygwin&#8217;s ping.exe doesn&#8217;t have a &#8220;-n&#8221; switch. But for some reason doesn&#8217;t fail when it encounters an invalid option. Rather, it tried to ping the IP address 0.0.0.1. This doesn&#8217;t work, of course, but the ping command tries forever thus respawning new instances of the bash shell and ping until it kills your computer.</p>
<p>Anyway, I hard coded a change to the script on my system and filed a <a href="https://github.com/tomas/prey/issues/216">bug</a> with the Prey developers. </p>
<p>I also submitted an email to the Cygwin mailing list describing the Cygwin ping issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/09/prey-project-ping-and-cygwin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick-n-dirty git getting started guide</title>
		<link>http://jeffbeard.org/2011/09/quick-n-dirty-git-getting-started-guide/</link>
		<comments>http://jeffbeard.org/2011/09/quick-n-dirty-git-getting-started-guide/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 21:24:17 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=404</guid>
		<description><![CDATA[As a git neophyte I approve of this post: http://news.ycombinator.com/item?id=2970637 UPDATE: I also found this helpful site: gitref.org]]></description>
			<content:encoded><![CDATA[<p>As a git neophyte I approve of this post:</p>
<p><a href="http://news.ycombinator.com/item?id=2970637">http://news.ycombinator.com/item?id=2970637</a></p>
<p>UPDATE: I also found this helpful site: <a href="http://gitref.org/">gitref.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/09/quick-n-dirty-git-getting-started-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lighting a fire under WordPress</title>
		<link>http://jeffbeard.org/2011/09/lighting-a-fire-under-wordpress/</link>
		<comments>http://jeffbeard.org/2011/09/lighting-a-fire-under-wordpress/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 17:30:08 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Infrastructure Management]]></category>
		<category><![CDATA[9 million hits per day]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=317</guid>
		<description><![CDATA[Learn how to light a fire under Wordpress and sustain 9 million hits a day with nginx, PHP-FPM, memcached and varnish. ]]></description>
			<content:encoded><![CDATA[<p>Since I moved my personal web site from <a title="Apache Roller" href="http://rollerweblogger.org/project/">Roller </a> to <a title="Wordpress" href="http://www.wordpress.org">WordPress</a> a couple of years ago, my web site had been a dog. After reading an <a title="9 Million Hits per day with 120 megs RAM" href="http://tumbledry.org/2011/08/31/9_million_hits_day_with_120">article</a> about a PHP-based web site configured to support 9 millions hits per day, and knowing through experience that my site should be significantly faster, I decided it was time to light a fire under WordPress.</p>
<p><strong><em>(Note that I&#8217;ve included gists at the bottom of the article with the important configuration files.)</em></strong><br />
<span id="more-317"></span><br />
I was using a <a title="Slicehost" href="http://www.slicehost.com">Slicehost</a> slice with a typical Apache/mod_php configuration but there wasn&#8217;t enough memory so it would start swapping with a little use which caused frequent outages. But rather than upgrade to the next sized Slice, I found that I could double my RAM for the same money simply by moving to <a title="Linode" href="http://www.linode.com/">Linode</a>. So that was the first change I made. (FWIW, I&#8217;m not suggesting this as a performance enhancement but it&#8217;s definitely a better value.)</p>
<p>Next was a series of changes, some of which were noted in the Tumbledry article, some not. The Tumbledry article was thin on details so I did the research myself and came up with a number of articles with the best being this <a title="Running WordPress with nginx, php-fpm, apc and varnish" href="http://www.cryptkcoding.com/2011/08/running-wordpress-with-nginx-php-fpm-apc-and-varnish/">article</a> on setting up nginx, PHP-FPM, APC, memcached and the W3 Total Cache WordPress plugin. The cryptkcoding article shows how to setup an <a title="Ubuntu" href="http://www.ubuntu.com">Ubuntu</a> Linux system for seriously fast WordPress performance that consumes incredible few system resources.</p>
<p>First, an ease of use feature that I discovered: someone did a build of PHP 5.3.8 for Ubuntu 10.04 LTS. Since PHP 5.3 includes PHP-FPM, you can keep everything package based. </p>
<p>To use these packages add these lines to /etc/apt/sources.lst:</p>
<pre>deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main
deb-src http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main</pre>
<p>After updating the sources list, run this command to update the apt cache:</p>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get update
</pre>
<p>(For more details on using these packages, as well as setting up a similar system, checkout <a href="http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian">this</a> HowToForge article. In particular, there are some useful comments at the bottom.)</p>
<p>Anyway, one of the main features of this setup was swapping out the <a href="http://httpd.apache.org">Apache web server</a> for nginx and PHP-FPM. Like most PHP developers, Apache and mod_php has been the default setup for PHP applications for years. However, I can now vouch for the nginx/PHP-FPM combo as both stable and fast production environment. (I will try out this combo for development on my next PHP project to see how it works.) </p>
<p>Importantly, the system now uses a UNIX socket for the connection between the web and application servers rather than TCP/IP. That means that for the core application and web services there are two UNIX sockets used, one between the web server and the application server then again between the the application server and the database server (MySQL clients use the UNIX socket when the &#8220;localhost&#8221; host name is used or the host name is blank.)</p>
<p>Anyway, to really see the difference the architecture changes made, I used a <a href="http://blitz.io">blitz.io</a> Rush to hammer the two instances.</p>
<p>First up was the old Slicehost system. This is the Rush configuration I used (same as Tumbledry):</p>
<pre>--pattern 1-250:60 -T 4000 -r california</pre>
<p>The result: this rendered the system completely unresponsive and required a hard reboot. Here&#8217;s a shot of &#8220;top&#8221; before the system stopped responding. Note all the memory being consumed, load on the way up and lots of Apache processes:</p>
<p><a href="http://jeffbeard.org/wp-content/uploads/2011/09/jeffbeard-top-1.jpg"><img class="alignleft size-full wp-image-327" title="jeffbeard-top-1" src="http://jeffbeard.org/wp-content/uploads/2011/09/jeffbeard-top-1.jpg" alt="" width="595" height="492" /></a></p>
<p>Oh no! The system just died:<br />
<a href="http://jeffbeard.org/wp-content/uploads/2011/09/jeffbeard-org-rush.jpg"><img class="alignleft size-full wp-image-331" title="jeffbeard-org-rush" src="http://jeffbeard.org/wp-content/uploads/2011/09/jeffbeard-org-rush.jpg" alt="" width="540" height="483" /></a></p>
<p>Next was the new Linode hosted solution. The result is that the new architecture sustained the Rush with virtually zero CPU usage (I&#8217;m not kidding) or any changes to memory usage. Varnish takes most of the load.</p>
<p><a href="http://jeffbeard.org/wp-content/uploads/2011/09/jeffbeard-org-rush-1.jpg"><img class="size-full wp-image-323 alignnone" title="jeffbeard-org-rush-1" src="http://jeffbeard.org/wp-content/uploads/2011/09/jeffbeard-org-rush-1.jpg" alt="blitz.io Rush Graph for jeffbeard.org" width="437" height="389" /></a></p>
<p>So as it turns out, I can also serve up 9 million hits per day from a small (512MB RAM), inexpensive ($20 per month) virtual server.</p>
<p>Here are the important configuration files:</p>
<p>nginx.conf:<br />
<script src="https://gist.github.com/1195248.js"> </script></p>
<p>nginx virtual host config:<br />
<script src="https://gist.github.com/1195299.js"> </script></p>
<p>php5-fpm.conf:<br />
<script src="https://gist.github.com/1195269.js"> </script></p>
<p>varnish:<br />
<script src="https://gist.github.com/1195393.js"> </script></p>
<p>wordpress.vcl (varnish site config):<br />
<script src="https://gist.github.com/1195286.js"> </script></p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/09/lighting-a-fire-under-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip for optimizing MySQL data types</title>
		<link>http://jeffbeard.org/2011/06/tip-for-optimizing-mysql-data-types/</link>
		<comments>http://jeffbeard.org/2011/06/tip-for-optimizing-mysql-data-types/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 15:08:48 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[data management]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimizing data types]]></category>
		<category><![CDATA[refactoring databases]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=227</guid>
		<description><![CDATA[This is a tip that I&#8217;ve kept forgetting to write down so here it is: During a system&#8217;s life cycle requirements change and components are refactored. This includes databases as well and particularly as data grows. Decisions and assumptions are made at the beginning of a system&#8217;s life cycle that may or may not hold [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tip that I&#8217;ve kept forgetting to write down so here it is:</p>
<p>During a system&#8217;s life cycle requirements change and components are refactored. This includes databases as well and particularly as data grows. Decisions and assumptions are made at the beginning of a system&#8217;s life cycle that may or may not hold up over years of operation and it&#8217;s good practice to continually analyze how well the initial design is working.<br />
<span id="more-227"></span><br />
When doing analysis in support of refactoring database schemas in MySQL, I&#8217;ve found this little bit of SQL to be invaluable.</p>
<p>Code:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT * FROM TABLE PROCEDURE analyse();
</pre>
<p>(I suggest giving it a try on a small table with few rows.)</p>
<p><a href="http://dev.mysql.com/doc/refman/5.6/en/procedure-analyse.html">PROCEDURE ANALYSE</a> interrogates the values in a table, shows the smallest and largest values and suggests a type for each column. While the results frequently indicate that an ENUM type is the most appropriate you can add arguments to the ANALYSE procedure to get more rational suggestions. However, even with no arguments the results can be useful.</p>
<p>For example, you might see that the max value of a column actually is smaller than the type that it&#8217;s using. I&#8217;ve frequently seen INT(11) columns that would work fine as a MEDIUMINT or even TINYINT. Or your might find that an ENUM type is better since the distribution of values is small in a VARCHAR column. (The benefit of an ENUM is that the data is stored as an integer rather than the string value so its&#8217; footprint on the disk can be significantly smaller).</p>
<p>Anyway, while it&#8217;s not a panacea, PROCECURE ANALYSE() is another helpful tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/06/tip-for-optimizing-mysql-data-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL udf_median on Windows 7 64bit</title>
		<link>http://jeffbeard.org/2011/05/mysql-udf_median-on-windows-7-64bit/</link>
		<comments>http://jeffbeard.org/2011/05/mysql-udf_median-on-windows-7-64bit/#comments</comments>
		<pubDate>Sat, 21 May 2011 16:00:08 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[udf]]></category>
		<category><![CDATA[udf on windows]]></category>
		<category><![CDATA[udf_median]]></category>
		<category><![CDATA[windows 7 64bit]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=290</guid>
		<description><![CDATA[In a minor but ongoing saga of supporting the venerable MySQL UDF function udf_median, I can now add a HOWTO for building it on Windows 7 x64 using Microsoft Visual C++ Express 2010. I should point out my previous article on the subject since there are parts of it that are still applicable. This is [...]]]></description>
			<content:encoded><![CDATA[<p>In a minor but ongoing saga of supporting the venerable MySQL UDF function udf_median, I can now add a HOWTO for building it on Windows 7 x64 using Microsoft Visual C++ Express 2010.<br />
<span id="more-290"></span></p>
<p>I should point out <a href="http://jeffbeard.org/2011/04/mysql-udf_median-on-windows">my previous article</a> on the subject since there are parts of it that are still applicable.</p>
<p>This is likely applicable to other MySQL UDFs as well but I haven&#8217;t tried.</p>
<p>I used the MySQL 5.1.57 x64 version for my system and I downloaded the zip archive rather than the installer. (Note that the server can still be installed as a service but you will need to run the cmd.exe program as an administrator in order to run the command line installation process.)</p>
<p>I also used Microsoft Visual C++ Express 2010 for this and my Windows version is Windows 7 Ultimate x64.</p>
<p>In addition to VS C++, you will also need the Windows SDK for Windows 7 which you can download <a href="http://www.microsoft.com/downloads/dlx/en-us/listdetailsview.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b">here</a>. This addition is critical since it contains the x64 compiler and other tools.</p>
<p>When you have everything installed, follow the instructions on Roland Bouman&#8217;s <a href="http://rpbouman.blogspot.com/2007/09/creating-mysql-udfs-with-microsoft.html">blog post</a> about building UDFs on Windows but stop before building and installing the function then follow these steps to 64bit glory (if you are specifically using udf_median, you might also be interested in <a href="http://www.mooreds.com/wordpress/archives/376">this post</a>):</p>
<ol>
<li>Right-click on the project (not the solution), choose &#8220;Properties&#8221;. At the top of the dialog, from the &#8220;Configuration&#8221; dropdown, select &#8220;All Configurations&#8221;.<br/></li>
<li>Next expand &#8220;Configuration Properties&#8221; then select &#8220;General&#8221;. In the field on the right labeled &#8220;Platform Toolset&#8221; make sure the value &#8220;Windows7.1SDK&#8221; is selected<br/></li>
<li> Now let&#8217;s make it x64. At the top of the dialog box, click on the &#8220;Configuration Manager&#8221; button.<br/></li>
<li>In the resultant grid, select the &#8220;Platform&#8221; dropdown and choose &#8220;New&#8230;&#8221;. When the &#8220;New Project Platform&#8221; comes up, select x64 from the top dropdown then click &#8220;OK&#8221; then &#8220;Close&#8221; then close the Properties dialog.<br/></li>
<li>Now you can try building the project<br/></li>
<li>If the build is successful, you find the .dll, in my case ufd_median.dll, in the &#8220;Debug&#8221; or &#8220;Release&#8221; folder. Put that in the MySQL lib/plugin/ directory<br/></li>
<li>Install the plugin using SQL like this:<br />
           <code><br />
               CREATE AGGREGATE FUNCTION median RETURNS REAL SONAME 'udf_median.dll';<br />
           </code>
        </li>
</ol>
<p>And that should be it. </p>
<p>Here are a few things that I came across while setting up my project that might be helpful:</p>
<ol>
<li>In one instance the linker reported this error:<br />
            <code>1>LINK : fatal error LNK1104: cannot open file 'kernel32.lib'</code><br />
         The fix for this was making sure that the &#8220;Platform Toolset&#8221; in the project configuration properties was set to  &#8220;Windows7.1SDK&#8221;
        </li>
<li>If you get this error:<br />
        <code>ERROR 1126 (HY000): Can't open shared library 'file.dll'</code><br />
        this can sometimes mean that the .dll wasn&#8217;t compiled correctly (i.e. this is what you get when you try to use a 32bit .dll with a 64bit server) or the symbol exports didn&#8217;t work. I used the dumpbin program to make sure that the functions that needed to be exported were. Under the &#8220;Tools&#8221; menu in VC++, select &#8220;Visual Studio Command Prompt&#8221; then navigate to the directory with your .dll file and run this command:<br />
          <code>dumpbin  /exports udf_median.dll</code><br />
You should see the exported functions in the output.
        </li>
<li>I did not have to alter any of the C code to make this work even though I saw some comments on Roland&#8217;s post indicating that might be necessary.
        </li>
</ol>
<p>That&#8217;s about it. Feel free to contact me if you have any questions or if the steps didn&#8217;t work for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/05/mysql-udf_median-on-windows-7-64bit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Intercept HTTP requests with Squid</title>
		<link>http://jeffbeard.org/2011/04/intercept-http-requests-with-squid/</link>
		<comments>http://jeffbeard.org/2011/04/intercept-http-requests-with-squid/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 13:08:53 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Systems Administration]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[log requests]]></category>
		<category><![CDATA[log web traffic]]></category>
		<category><![CDATA[squid]]></category>
		<category><![CDATA[transparent proxy]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=260</guid>
		<description><![CDATA[On one of my projects we had some questions about how much bandwidth was being used by requests to a third party service but we didn&#8217;t have any a view beyond general traffic on the network interface. I hit upon the idea of using a transparent proxy to log requests then use log analysis to [...]]]></description>
			<content:encoded><![CDATA[<p>On one of my projects we had some questions about how much bandwidth was being used by requests to a third party service but we didn&#8217;t have any a view beyond general traffic on the network interface. I hit upon the idea of using a transparent proxy to log requests then use log analysis to break out data transfer amounts per third party service. And since we already had <a href="http://www.squid-cache.org/">squid</a> as part of our infrastructure applications it seemed like a good choice. </p>
<p>The tricky part of this setup is that everything is hosted on the same hardware node and we also have some web services that needed to be left untouched. These requirements implied some network configuration using <a href="http://www.netfilter.org/">iptables</a> to force outbound web requests through the proxy.<br />
<span id="more-260"></span><br />
So the first thing I needed to do was install squid. On this project we use <a href="http://www.centos.org/">CentOS</a> on all our hosts so this was easily accomplished like this:</p>
<p><code>sudo yum install squid</code></p>
<p>Next was adjusting the configuration. The default squid.conf comes with lots of documentation which is helpful but makes the configuration file difficult to read and navigate so the first thing I did was get rid of it like so:<br />
<code><br />
cd /etc/squid &#038;&#038; sudo cp squid.conf squid.conf.orig &#038;&#038; sudo egrep -v'^#' squid.conf > /tmp/squid.conf<br />
</code></p>
<p>This leaves a lot of empty lines in the file which can be removed like this:</p>
<p><code><br />
sudo sed '/^$/d' /tmp/squid.conf > /tmp/squid.clean &#038;&#038; sudo mv /tmp/squid.clean squid.conf<br />
</code></p>
<p>Next up was setting up networking and squid.</p>
<p>The squid site has a great set of examples, <a href="http://wiki.squid-cache.org/ConfigExamples/Intercept/LinuxLocalhost">one of which</a> looked like it suit my purposes nicely. </p>
<p>First I configured squid by adding this directive:</p>
<p><code>http_port 3128 transparent</code></p>
<p>Then I started squid:</p>
<p><code>sudo service squid start</code></p>
<p>I also wanted to make sure squid starts when the system is rebooted:</p>
<p><code>sudo chkconfig --levels 2345 squid on</code></p>
<p>Next up was network configuration. </p>
<p>I needed to setup iptables with some NAT rules to force requests through the proxy server. The first command clears out any existing rules. If you already have a custom kernel network config, use this with caution:</p>
<p><code>sudo iptables iptables -t nat -F </code></p>
<p>The next rule is for a typical transparent proxy setup. In the setup that I was working with I did not need this rule, something I discovered by disabling the existing web sites with this command. So if you have a web server <strong>DO NOT</strong> do this:</p>
<p><code><br />
sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j REDIRECT --to-port 3128<br />
</code></p>
<p>Here is the start of the iptables configuration we implemented. </p>
<p>Apply the rules to force local HTTP traffic through the transparent proxy:</p>
<p><code><br />
gid=`id -g squid`<br />
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner --gid-owner $gid -j ACCEPT<br />
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination HOSTIP:3128<br />
</code></p>
<p>Replace the string &#8220;HOSTIP&#8221; with the IP address of the host you&#8217;re configuring.</p>
<p>At this point I needed to test the setup so I tailed the access log. Or at least I tried to. The default directory permissions on the /var/log/squid directory prevented me from viewing its&#8217; contents. I fixed that with this:</p>
<p><code>sudo chmod 0775 /var/log/squid</code></p>
<p>Then I was able to tail the /var/log/squid/access.log. So I created a request to see if it was logged:</p>
<p><code>wget http://www.google.com</code></p>
<p>I saw the request logged in the squid access log so I was satisfied that it and the networking were functional. However the log format wasn&#8217;t what we needed to feed to <a href="http://awstats.sourceforge.net/">awstats</a>, which is what I going to use to process the log.</p>
<p>Since we already use squid and process its&#8217; logs I grabbed the configuration from our production configuration file:</p>
<p><code><br />
logformat combined %>a %ui %un [%{%d/%b/%Y:%H:%M:%S %z}tl] "%rm %ru HTTP/%rv" %Hs %<st "%{User-Agent}>h" %Ss:%Sh<br />
access_log /var/log/squid/access.log combined<br />
</code></p>
<p>Then I restarted squid and tested again. It looked good so I tested one of our batch processes that makes HTTP requests to make sure that it did what I wanted. It did however I noticed that query strings from the URI were not being logged. A quick google told me that I needed to update the squid.conf with this:</p>
<p><code>strip_query_terms off</code></p>
<p>As it turns out squid squid strips query string after the &#8220;?&#8221; by default. This is apparently to &#8220;protect privacy&#8221; but we needed the query string to identify individual requests more accurately. </p>
<p>At this point I had the system setup and working. It logged all the outbound HTTP requests and the existing web services remained unaffected. All that was left to do was setup awstats to process the logs.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/04/intercept-http-requests-with-squid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL udf_median on Windows</title>
		<link>http://jeffbeard.org/2011/04/mysql-udf_median-on-windows/</link>
		<comments>http://jeffbeard.org/2011/04/mysql-udf_median-on-windows/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 17:22:27 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[udf]]></category>
		<category><![CDATA[udf on windows]]></category>
		<category><![CDATA[udf_median]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=239</guid>
		<description><![CDATA[A few years ago I had to get a MySQL UDF (User Defined Function) working on my Windows workstation for a project I was working on. I had the benefit of a couple of other folks to help me get my environment set up and a .dll compiled. I was recently contacted about my project [...]]]></description>
			<content:encoded><![CDATA[<p>A few years ago I had to get a MySQL UDF (User Defined Function) working on my Windows workstation for a project I was working on. I had the benefit of a <a href="http://rpbouman.blogspot.com/2007/09/creating-mysql-udfs-with-microsoft.html">couple</a> of <a href="http://www.mooreds.com/wordpress/archives/376">other folks</a> to help me get my environment set up and a .dll compiled. I was recently contacted about my project files and realized I had an orphaned link out on the Internet so I thought I&#8217;d better fix that up.</p>
<p><span id="more-239"></span></p>
<p>I&#8217;ve captured the text from my previous post and put it here. I apologize for not having the images available but will see what I can do about that. Anyway, here&#8217;s the text I first published in 2008:</p>
<blockquote><p>
<strong>UDF median on Windows</strong></p>
<p>On my current project we use MySQL as part of our stack and I needed to setup MySQL on my Windows XP workstation for development. A custom feature of the database is the use of a MySQL UDF (User Defined Function), discussed in depth here, here and lots of other places. </p>
<p>We had a pre-compiled Windows binary DLL available that did not work. Dan Moore told me that he needed to recompile on his workstation as well so I set about figuring out how to rebuild on my workstation.</p>
<p>While this is somewhat of a digression, it might be useful information. The error that was returned with our pre-compiled DLL was this:</p>
<p><code>ERROR 1126 (HY000): Can't open shared library 'file.dll'</code></p>
<p>The error message is supposed to indicate that the location of the DLL is incorrect, however that was not the issue in this case. It was in the bin/ directory of the MySQL installation where the recompiled DLL was later found, loaded and made usable by the server. I did not look any further into this issue since recompiling fixed the problem.</p>
<p>Returning to the subject at hand, because I found that there are differences in the process to setup between Visual Studio Express Edition 2005, as described in Roland Bouman&#8217;s blog post, and Visual Studio 2008 Professional, I decided to post a write up describing my process. Most of the changes have to do with the New Project wizard and it&#8217;s ability to take care of most of the configuration of the project. However if you haven&#8217;t already, please stop and read the article on Roland Bouman&#8217;s blog before going through this as it has more detail and includes the all important steps of installing the MySQL header files and development libraries used to compile the UDF code.</p>
<p>    If you are like me and sometimes prefer &#8220;doing&#8221; over reading or you just want a compiled binary, you can find the project files here. You will find the bonus feature of a Makefile and some other niceties for building on Linux and Unix variants too!</p>
<p>    Note that my source file has been modified to work with MySQL 5.0.x and I&#8217;ve only tested it against 5.0.45 since that was the only requirement I had at the time. Please post a comment if you have solutions to problems with other versions.</p>
<p>First, you will want to make sure that you have installed MySQL version 5.0 or later with the header and other development components per the instructions in Roland Bouman&#8217;s post.</p>
<p>Next, install the version of VS08 that you have access to. I use VS08 Professional so there may some differences if you use the Express version. After installing VS, download the source file and put it in it&#8217;s own folder on your hard drive. This will be your project directory. Once you have the project director and the source file, udf_median.cc in my case, you can start VS08 in order to start setting up the project.</p>
<p>Once VS08 is running, go to the &#8220;File&#8221; menu and click &#8220;New&#8221; then &#8220;Project from Existing Code&#8230;&#8221;, as such:</p>
<p>Project from Existing Code&#8230;</p>
<p>The next screen will allow you to choose a C++ project (I also use C# so this step is required):</p>
<p> Choose C++</p>
<p>The next dialog allows you to select the folder that contains your source file. This is what it should look like once you select your project folder and give the project a name:</p>
<p>The next dialog allows you to define the project type. We&#8217;re building a DLL (Dynamically Linked Library) so select the appropriate item from the drop down:</p>
<p>In the next two dialogs, we are configuring properties for the build. There are two builds, Debug and Release. All we are going to add is the path to the MySQL header files.</p>
<p>Because the wizard is so helpful, you don&#8217;t have do anything to setup the Release target. Just make it the same as Debug:</p>
<p>Click the &#8220;Finish&#8221; button and you will be taken to your project. You can try building the DLL at this point by either pressing F6 or choosing it from the &#8220;Build&#8221; menu:</p>
<p>If you used the source I&#8217;ve provided, you should end up with a compiler warning that looks like this:<br />
Command line warning D9035 : option &#8216;Wp64&#8242; has been deprecated and will be removed in a future release</p>
<p>Since I&#8217;m a stickler for clean builds, I decided to fix this. First right-click on your project (not the &#8220;Solution&#8221; at the top level) then select &#8220;Properties&#8221;:</p>
<p>Once in the Properties dialog, expand the &#8220;Configuration Properties&#8221; item in the left pane, then expand the &#8220;C/C++&#8221; item. Select &#8220;General&#8221;. In the right pane, sixth row down you should see the property &#8220;Detect 64-bit Portability Issues&#8221;. Set the property to &#8220;No&#8221;:</p>
<p>To fix the release build, select &#8220;Release&#8221; from the &#8220;Configuration&#8221; drop down at the very top of the dialog and set the same property to &#8220;No&#8221;. Click &#8220;OK&#8221; to close this dialog.</p>
<p>Speaking of the Release build, once you&#8217;ve made it to this point we should try that build as well. At the top of the IDE on the tool bar there is a drop down that should be set to &#8220;Debug&#8221;. Click on this drop down and select &#8220;Release&#8221;, as such:</p>
<p>Press the F6 key to build the release. Again if you are using my source and following these instructions, you should get the following build warnings:</p>
<p><code>warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification<br />
</code><br />
To remedy this, you again want to right-click on the project and select &#8220;Properties&#8221;. Make sure that the &#8220;Release&#8221; configuration is selected at the top of the dialog. This time drill down to the &#8220;Linker&#8221; item and select &#8220;General&#8221;. In the right-hand pane you will find a property labeled &#8220;Enable Incremental Linking&#8221;. Set the value to &#8220;Default&#8221; then click &#8220;OK&#8221; to to close the dialog.</p>
<p>Once you are out of the dialog press F6 to build and you should get a clean build with no errors or warnings. The output DLL will be in a subfolder of the project named &#8220;Release&#8221;. Copy the udf_median.dll file into the bin directory of the MySQL server instance. Start a MySQL client and connect to the database server. From a query window as the root or other user with the appropriate privileges, issue this SQL query:</p>
<p><code>CREATE AGGREGATE FUNCTION median RETURNS REAL SONAME 'udf_median.dll';</code> </p>
<p>You should now be able to use the function in your SQL queries. </p>
<p>You can see example output in one of the web applications udf_median is used in here.</p>
<p>Last and certainly not least, I would like to acknowledge the work of Dan Moore and Roland Bouman without who&#8217;s excellent work I would not have been able to figure this out. Cheers! </p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/04/mysql-udf_median-on-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;select count&#8221; with Generics, Spring and Hibernate</title>
		<link>http://jeffbeard.org/2011/04/select-count-with-generics-spring-and-hibernate/</link>
		<comments>http://jeffbeard.org/2011/04/select-count-with-generics-spring-and-hibernate/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 12:57:44 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=209</guid>
		<description><![CDATA[In a recent project, we introduced Generics and Spring into an application. In developing the Generic DAO implementation I was trying to find a way to get a record count from the database. It&#8217;s a simple enough task with HQL or Spring&#8217;s JdbcTemplate.queryForInt(String sql), however the Generics made it a little tricky. The solution I [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project, we introduced Generics and Spring into an application. In developing the Generic DAO implementation I was trying to find a way to get a record count from the database. It&#8217;s a simple enough task with HQL or Spring&#8217;s <a href="http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/jdbc/core/JdbcTemplate.html">JdbcTemplate</a>.<a href="http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/jdbc/core/JdbcTemplate.html#queryForInt%28java.lang.String%29">queryForInt(String sql)</a>, however the Generics made it a little tricky. The solution I came up with was using <a title="HibernateCallback" href="http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/orm/hibernate3/HibernateCallback.html">HibernateCallback</a>. A reference to the persistent type is a member of GenericDAOHibernate as is the <a href="http://docs.jboss.org/hibernate/core/3.3/api/org/hibernate/SessionFactory.html">SessionFactory</a> and an instance of Spring&#8217;s <a href="http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/orm/hibernate3/HibernateTemplate.html">HibernateTemplate</a>.</p>
<p><span id="more-209"></span></p>
<pre class="brush: java; title: ; notranslate">
public class GenericDAOHibernate&lt;T, PK extends Serializable&gt; implements GenericDAO&lt;T, PK&gt; {

	/** log4j Logger for class GenericDAOHibernate */
	private static Logger logger = Logger.getLogger(GenericDAOHibernate.class.getName());

    private Class&lt;T&gt; persistentClass;

    private HibernateTemplate hibernateTemplate;

    @Autowired(required=true)
    private SessionFactory sessionFactory;

// [...]

@Override
public Class&lt;T&gt; getPersistentClass() {
    return persistentClass;
}

@Override
public int countAll() {

    @SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })
    List results = (List) hibernateTemplate.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            return session.createCriteria(getPersistentClass())
                .setProjection(Projections.rowCount())
                .list();
            }
        });

        // Here I use the Spring DataAccessUtils class to interpret the result set
        int result = DataAccessUtils.intResult(results)

        logger.debug(&quot;count retrieved: &quot; + result;

        return result;
}
</pre>
<p>I also added another convenience method that uses the <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycriteria.html#querycriteria-examples">Example Criteria API</a> so we can generate a count with a pre-configured Entity:</p>
<pre class="brush: java; title: ; notranslate">
@Override
public int countByExample(final T exampleInstance)

    @SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })
    List results = (List) hibernateTemplate.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            return session.createCriteria(getPersistentClass())
                .add(Example.create(exampleInstance))
                .setProjection(Projections.rowCount())
                .list();
            }
        });

        // Here I use the Spring DataAccessUtils class to interpret the result set
        int result = DataAccessUtils.intResult(results)

        logger.debug(&quot;count retrieved: &quot; + result;

        return result;
</pre>
<p>I plan to package up some of the Generics code at some point and will post a link to download it or to a public source code repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2011/04/select-count-with-generics-spring-and-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disabling Google Instant Preview</title>
		<link>http://jeffbeard.org/2010/11/disabling-google-instant-preview/</link>
		<comments>http://jeffbeard.org/2010/11/disabling-google-instant-preview/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 16:20:12 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[The Web]]></category>

		<guid isPermaLink="false">http://jeffbeard.org/?p=182</guid>
		<description><![CDATA[Unlike many people, I&#8217;m not a fan of Google&#8217;s addition of instant previews. I&#8217;m a fidgety clicker and clicking in common areas where I rest my mouse pointer activates the preview. Not only annoying, I found this to be an odd behavior considering there is an icon specifically designed to activate the preview. Why would [...]]]></description>
			<content:encoded><![CDATA[<p>Unlike many people, I&#8217;m not a fan of Google&#8217;s addition of instant previews. I&#8217;m a fidgety clicker and clicking in common areas where I rest my mouse pointer activates the preview. Not only annoying, I found this to be an odd behavior considering there is an icon specifically designed to activate the preview. Why would the text preview be a hotspot too? Regardless, the pop-ups instantly made Google search results a very bad user experience.</p>
<p>An additional aggravation was that turning off the previews is not a configuration option.</p>
<p>Being a web developer, I opened up <a title="Firebug" href="http://getfirebug.com">Firebug</a> and started rooting around for the &#8220;problem&#8221;. After sifting through Google&#8217;s nearly inscrutable code for about 30 seconds, I asked Google directly for a solution. Google pointed me to <a href="http://lifehacker.com/5688543/hide-google-instant-preview-with-an-adblock-filter">this article</a> on Lifehacker about how to use the <a href="http://adblockplus.org">AdBlock Plus </a>browser plugin to do the job. The solution is to add these 3 rules:</p>
<p><code><br />
google.com##.vspi<br />
google.com##.vspib<br />
google.com###vspb<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://jeffbeard.org/2010/11/disabling-google-instant-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached
Object Caching 528/602 objects using memcached

Served from: jeffbeard.org @ 2012-05-20 06:38:08 -->
