<?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>Brian Wigginton</title>
	<atom:link href="http://www.bwigg.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bwigg.com</link>
	<description>Lab and Nerdery</description>
	<lastBuildDate>Mon, 16 Apr 2012 02:07:41 +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>Content Switching with HAProxy</title>
		<link>http://www.bwigg.com/2012/04/content-switching-with-haproxy/</link>
		<comments>http://www.bwigg.com/2012/04/content-switching-with-haproxy/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 16:08:07 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[DevOps]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=339</guid>
		<description><![CDATA[Content Switching Content-switching is an OSI layer 7 application switching technique, which in lamans terms means that it has access to the HTTP requests and responses of your application. By inspecting each request and response, it make decision on where to send those requests and how to handle responses. HAProxy is an open source load [...]]]></description>
			<content:encoded><![CDATA[<h3>Content Switching</h3>
<p>Content-switching is an OSI layer 7 application switching technique, which in lamans terms means that it has access to the HTTP requests and responses of your application. By inspecting each request and response, it make decision on where to send those requests and how to handle responses.</p>
<p>HAProxy is an open source load balancing tool that also has the ability to implement content switching.</p>
<h3>Proxies &amp; Reverse Proxies</h3>
<p>You might be familiar with a Proxy, which is basically something that sits between the client and the server. When the client makes a request it first goes through the proxy then to the server. The response from the server then goes back through the proxy  to the client. These are usually implemented by the client and completely transparent to the server. A great example of this is when someone configures their browser to use a proxy to access the internet, with a tool such as Tor.</p>
<p>A Reverse Proxy is the same thing except it acts on behalf of the server. One example of a Reverse Proxy is a load balancer, which receives requests from a users and usually proxies them to one of several backend servers. This process is completely transparent to the client. Content switching is also a form of Reverse Proxy.</p>
<h2>Content-Switching Scenario</h2>
<p>Let's say you're in charge of a large social bookmarking application, http://delicioso.com. The shelf life for that system has come to and end and you're team has decided to rewrite everything in Rails. It's going to take a long time to migrate everything over to the new application, and you want to reduce the risk involved with a huge release cycle. Instead you want to take an agile approach and roll out bits and pieces over time in the following order:</p>
<ol>
<li>Configure HAProxy as a Reverse Proxy</li>
<li>Phase in user profiles - http://delicioso.com/profile/...</li>
<li>...</li>
</ol>
<p>For the purpose if this example, let's call the current application <em>Legacy</em>. Image your current infrastructure is setup like the following:</p>
<pre>                        +-------------------+
                        |    example.com    |
  User  +----------&gt;    |-------------------|
                        |     legacy:80     |
                        +-------------------+</pre>
<h3></h3>
<h3>Step 1: Configure HAProxy as a Reverse Proxy</h3>
<p>The first step is to setup HAProxy to be reverse proxy for <em>Legacy</em>, so later we can implement content-switching. You'll need to have HAProxy installed.</p>
<pre>                      +-------------------+
                      |    example.com    |
User  +----------&gt;    |-------------------|
                      |    HAProxy:80     |
                      |     legacy:8001   |
                      +-------------------+</pre>
<p>Here's the config file to configure HAProxy in this way:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">global
  <span style="color: #666666; font-style: italic;">#debug                                   # uncomment to enable debug mode for HAProxy</span>
&nbsp;
defaults
  mode http                                <span style="color: #666666; font-style: italic;"># enable http mode which gives of layer 7 filtering</span>
  timeout connect 5000ms                   <span style="color: #666666; font-style: italic;"># max time to wait for a connection attempt</span>
                                           <span style="color: #666666; font-style: italic;">#  to a server to succeed</span>
  timeout client 50000ms                   <span style="color: #666666; font-style: italic;"># max inactivity time on the client side</span>
  timeout server 50000ms                   <span style="color: #666666; font-style: italic;"># max inactivity time on the server side</span>
&nbsp;
backend legacy                             <span style="color: #666666; font-style: italic;"># define a group of backend servers</span>
  server legacy_server 127.0.0.1:<span style="color: #000000;">8001</span>      <span style="color: #666666; font-style: italic;"># add a server to this backend</span>
&nbsp;
frontend app <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span>                          <span style="color: #666666; font-style: italic;"># define what port to listed to for HAProxy</span>
  default_backend legacy                   <span style="color: #666666; font-style: italic;"># set the default server for all request</span></pre></div></div>

<h3></h3>
<h3>Step 2: Phase in User Profiles</h3>
<p>All of your user's profile pages have a URL format as follows: /profile/username. Your team finished implementing this in the new Rails framework and it's time to roll it out. The rails app is running on port 8002.</p>
<pre>                      +-------------------+
                      |    example.com    |
User  +----------&gt;    |-------------------|
                      |    HAProxy:80     |
                      |     legacy:8001   |
                      |      rails:8002   |
                      +-------------------+</pre>
<p>Here's the new config file for content-switching all requests starting with /profile to the new rails application</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">global
  <span style="color: #666666; font-style: italic;">#debug</span>
&nbsp;
defaults
  mode http
  option httpclose                         <span style="color: #666666; font-style: italic;"># close the tcp connection after every request</span>
  timeout connect 5000ms
  timeout client 50000ms
  timeout server 50000ms
&nbsp;
backend legacy
  server legacy_server 127.0.0.1:<span style="color: #000000;">8001</span>
&nbsp;
backend rails                              <span style="color: #666666; font-style: italic;"># define a group of backend servers</span>
  server rails_server 127.0.0.1:<span style="color: #000000;">8002</span>       <span style="color: #666666; font-style: italic;"># add a server to this backend</span>
&nbsp;
frontend app <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span>
  default_backend legacy
  acl rails_path path_beg <span style="color: #000000; font-weight: bold;">/</span>profile         <span style="color: #666666; font-style: italic;"># acl rule for rails supported paths</span>
  use_backend rails <span style="color: #000000; font-weight: bold;">if</span> rails_path          <span style="color: #666666; font-style: italic;"># use rails if the rules match.</span></pre></div></div>

<p>Check out the HAProxy documentation for more keywords your can use to route requests. This was a pretty simple example, this get's more challenging when you need to handle session state across the legacy and new systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2012/04/content-switching-with-haproxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web.config User Specific appSettings</title>
		<link>http://www.bwigg.com/2012/03/web-config-user-specific-appsettings/</link>
		<comments>http://www.bwigg.com/2012/03/web-config-user-specific-appsettings/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 21:27:51 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=364</guid>
		<description><![CDATA[On an MVC.NET project at work, we came across the need to be able to override the web.config's appSettings uniquely on each of our local environments. Turns out there's a very easy way to do just that inside the web.config file. Just add the file attribute to the &#60;appSettings&#62; node in your web.config, and add [...]]]></description>
			<content:encoded><![CDATA[<p>On an MVC.NET project at work, we came across the need to be able to override the web.config's appSettings uniquely on each of our local environments. Turns out there's a very easy way to do just that inside the web.config file.</p>
<p>Just add the file attribute to the &lt;appSettings&gt; node in your web.config, and add a local.config file to the project root.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- WEB.CONFIG --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  ...
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appSettings</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;local.config&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    ...
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  ...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- LOCAL.CONFIG --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;MySQLConnectionString&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;...&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now when your app loads, it will check to see if there's a local.config file relative to the web.config file. If there is a file, then it overrides any web.config settings it finds duplicates for in the local.config. If the local.config file does not exist, then it is ignored.</p>
<p>Pro tip: Keep local.config out of your code repo and boom! Easily manageable local dev environment settings.</p>
<p>See Also:</p>
<ul>
<li><a title="MSDN: appSettings Element (General Settings Schema)" href="http://msdn.microsoft.com/en-us/library/ms228154.aspx" target="_blank">MSDN: appSettings Element (General Settings Schema)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2012/03/web-config-user-specific-appsettings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 11.10 Blank Screen with underline after boot with VMWare Fusion</title>
		<link>http://www.bwigg.com/2012/03/ubuntu-11-10-blank-screen-with-underline-after-boot-with-vmware-fusion/</link>
		<comments>http://www.bwigg.com/2012/03/ubuntu-11-10-blank-screen-with-underline-after-boot-with-vmware-fusion/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 04:36:23 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=358</guid>
		<description><![CDATA[After installing the latest version of Ubuntu Server with VMWare Fusion, I wasn't able to get to a terminal. The machine would boot and then just give me a blank line with a single underscore. Turns out all I needed to do was switch from TTY7. CMD + OPT + CTL + [F1 - F7]]]></description>
			<content:encoded><![CDATA[<p>After installing the latest version of Ubuntu Server with VMWare Fusion, I wasn't able to get to a terminal. The machine would boot and then just give me a blank line with a single underscore. Turns out all I needed to do was switch from TTY7.</p>
<pre>CMD + OPT + CTL + [F1 - F7]</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2012/03/ubuntu-11-10-blank-screen-with-underline-after-boot-with-vmware-fusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Fixtures: JSON Formatting</title>
		<link>http://www.bwigg.com/2012/01/django-json-fixtures/</link>
		<comments>http://www.bwigg.com/2012/01/django-json-fixtures/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 04:25:41 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=318</guid>
		<description><![CDATA[Came across an issue with Django Fixtures using the JSON format. Here was my fixture: Here's the error I was getting: The fix was simple, wrap the object in an array. Found the fix thanks to the following StackOverflow post: http://stackoverflow.com/a/4939147]]></description>
			<content:encoded><![CDATA[<p>Came across an issue with Django Fixtures using the JSON format. Here was my fixture:</p>
<div id="gist-1581086" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">{</span></div><div class='line' id='LC2'>	<span class="nt">&quot;pk&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC3'>	<span class="nt">&quot;model&quot;</span><span class="p">:</span> <span class="s2">&quot;core.wine&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>	<span class="nt">&quot;fields&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC5'>		<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Juan Gil&quot;</span><span class="p">,</span></div><div class='line' id='LC6'>		<span class="nt">&quot;vintage&quot;</span><span class="p">:</span> <span class="mi">2009</span></div><div class='line' id='LC7'>	<span class="p">}</span></div><div class='line' id='LC8'><span class="p">}</span></div><div class='line' id='LC9'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/d71de9702a353ebe37b7/653e9b12959b10c2e73d61190f8645675dcf66d0/initial_data_broken.json" style="float:right;">view raw</a>
            <a href="https://gist.github.com/d71de9702a353ebe37b7#file_initial_data_broken.json" style="float:right;margin-right:10px;color:#666">initial_data_broken.json</a>
            <a href="https://gist.github.com/d71de9702a353ebe37b7">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Here's the error I was getting:</p>
<div id="gist-1581086" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>Problem installing fixture &#39;.../core/fixtures/initial_data.json&#39;: Traceback (most recent call last):</div><div class='line' id='LC2'>&nbsp;&nbsp;File &quot;.../python2.6/site-packages/django/core/management/commands/loaddata.py&quot;, line 169, in handle</div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;for obj in objects:</div><div class='line' id='LC4'>&nbsp;&nbsp;File &quot;...python2.6/site-packages/django/core/serializers/json.py&quot;, line 35, in Deserializer</div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;for obj in PythonDeserializer(simplejson.load(stream), **options):</div><div class='line' id='LC6'>&nbsp;&nbsp;File &quot;...python2.6/site-packages/django/core/serializers/python.py&quot;, line 84, in Deserializer</div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;Model = _get_model(d[&quot;model&quot;])</div><div class='line' id='LC8'>TypeError: string indices must be integers</div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/d71de9702a353ebe37b7/b2396f3796224bb85586ed54e2fbe56e6cca8154/error.txt" style="float:right;">view raw</a>
            <a href="https://gist.github.com/d71de9702a353ebe37b7#file_error.txt" style="float:right;margin-right:10px;color:#666">error.txt</a>
            <a href="https://gist.github.com/d71de9702a353ebe37b7">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The fix was simple, wrap the object in an array.</p>
<div id="gist-1581086" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">[</span></div><div class='line' id='LC2'>	<span class="p">{</span></div><div class='line' id='LC3'>		<span class="nt">&quot;pk&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC4'>		<span class="nt">&quot;model&quot;</span><span class="p">:</span> <span class="s2">&quot;core.wine&quot;</span><span class="p">,</span></div><div class='line' id='LC5'>		<span class="nt">&quot;fields&quot;</span><span class="p">:</span> <span class="p">{</span></div><div class='line' id='LC6'>			<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Juan Gil&quot;</span><span class="p">,</span></div><div class='line' id='LC7'>			<span class="nt">&quot;vintage&quot;</span><span class="p">:</span> <span class="mi">2009</span></div><div class='line' id='LC8'>		<span class="p">}</span></div><div class='line' id='LC9'>	<span class="p">}</span></div><div class='line' id='LC10'><span class="p">]</span></div><div class='line' id='LC11'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/d71de9702a353ebe37b7/c37a0e28892de744bd24bb4bbd49f5e57f5975f7/initial_data_fixed.json" style="float:right;">view raw</a>
            <a href="https://gist.github.com/d71de9702a353ebe37b7#file_initial_data_fixed.json" style="float:right;margin-right:10px;color:#666">initial_data_fixed.json</a>
            <a href="https://gist.github.com/d71de9702a353ebe37b7">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Found the fix thanks to the following StackOverflow post: <a title="Type error trying to load fixtures with Content_type natural keys in Django" href="http://stackoverflow.com/a/4939147" target="_blank">http://stackoverflow.com/a/4939147</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2012/01/django-json-fixtures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Closures</title>
		<link>http://www.bwigg.com/2011/12/javascript-closures/</link>
		<comments>http://www.bwigg.com/2011/12/javascript-closures/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 01:12:19 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=289</guid>
		<description><![CDATA[Javascript closures can be confusing at first. They're not, and hopefully this analogy will help drive home the concept. A Man's Secret - An Analogy A man possess a secret book, which he cannot let anyone else know about. He decides the only way to keep the book truly secret is to memorize the entire [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript closures can be confusing at first. They're not, and hopefully this analogy will help drive home the concept.</p>
<p><strong>A Man's Secret - An Analogy</strong></p>
<p>A man possess a secret book, which he cannot let anyone else know about. He decides the only way to keep the book truly secret is to memorize the entire thing and then bury the book so no one can find it. Later in his years he bears a son. Once his son grows old enough, the father digs up the book and begins having his son commit the entire book to memory. Years later, he has his son rewrite the entire book cover to cover from memory on paper. When the son successfully completes the task, and the father is satisfied that his son truly has the book memorized in it's entirety, the book and the copy of the book the son just wrote are thrown into a fire, completely eliminating any evidence that the book actually existed. A few years later the father dies, leaving the son on his own, with the book committed to memory.</p>
<p>This is similiar to how a javascript closure works. See the following code.</p>
<p><strong>Code Example</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> father <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// this is declared as a private variable</span>
    <span style="color: #003366; font-weight: bold;">var</span> secretBook <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Book of Secrets'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bearSon</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
            whatWasTheBookYourFatherTaughtYou<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>secretBook<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// the father won't tell anyone about the book he has</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>father.<span style="color: #660066;">secretBook</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// undefined</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// the father bears a son</span>
son <span style="color: #339933;">=</span> father.<span style="color: #660066;">bearSon</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// the father dies</span>
father <span style="color: #339933;">=</span> undefined<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// the son still knows the book his father taught him</span>
son.<span style="color: #660066;">whatWasTheBookYourFatherTaughtYou</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Book of Secrets</span></pre></div></div>

<p>secretBook was declared inside the father function and is a private variable, inaccessible to anything outside the father function. The father function <em>closes </em>around the variables declared inside of it. Anything defined inside the father function has access to it, even once the father function has executed and been undefined. The bearSon method returns a new object that contains a function called whatWasTheBookYourFatherTaughtYou.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2011/12/javascript-closures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AccountManager getAuthToken() authTokenType param</title>
		<link>http://www.bwigg.com/2011/04/accountmanager-getauthtoken-authtokentype-param/</link>
		<comments>http://www.bwigg.com/2011/04/accountmanager-getauthtoken-authtokentype-param/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 08:40:20 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=309</guid>
		<description><![CDATA[In trying to connect to a Google api using the builtin AccountManager API for android, I could not figure out what values to use for the authTokenType. Then, finally, I found this link... http://code.google.com/apis/gdata/faq.html#clientlogin]]></description>
			<content:encoded><![CDATA[<p>In trying to connect to a Google api using the builtin AccountManager API for android, I could not figure out what values to use for the authTokenType. Then, finally, I found this link...</p>
<p><a title="Google Data Protocol - FAQ - Client Login Listing" href="http://code.google.com/apis/gdata/faq.html#clientlogin" target="_blank">http://code.google.com/apis/gdata/faq.html#clientlogin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2011/04/accountmanager-getauthtoken-authtokentype-param/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript&#8217;s new Operator</title>
		<link>http://www.bwigg.com/2011/01/javascripts-new-operator/</link>
		<comments>http://www.bwigg.com/2011/01/javascripts-new-operator/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 17:54:58 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=276</guid>
		<description><![CDATA[What is it and how can you use it to create new objects from constructor functions? What's a constructor function. There's really no such thing as a constructor function. There are just functions, that's it, no different than any other function, except that you the programmer has made it so that it initializes a keyword [...]]]></description>
			<content:encoded><![CDATA[<p>What is it and how can you use it to create new objects from constructor functions?</p>
<h3>What's a <em>constructor</em> function.</h3>
<p>There's really no such thing as a <em>constructor</em> function. There are just functions, that's it, no different than any other function, except that you the programmer has made it so that it initializes a keyword called <code>this</code> with methods and properties. Here's the <em>constructor</em> function we will use for the rest of this post.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Computer<span style="color: #009900;">&#40;</span>manufacturer<span style="color: #339933;">,</span> model<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">manufacturer</span> <span style="color: #339933;">=</span> manufacturer<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">model</span> <span style="color: #339933;">=</span> model<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>What does <code>new</code> do?</h3>
<p>The new operator creates new objects using our constructor function. Let's start by seeing what happens when we DON'T use the <code>new</code> operator.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> dell_inspiron <span style="color: #339933;">=</span> Computer<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Dell'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Inspiron'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>dell_inspiron<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// undefined!</span></pre></div></div>

<p>So what happened. Our Computer <em>constructor</em> function ran, it applied the <code>manufacturer</code> and <code>model</code> properties to the <code>this</code> keyword, which should have then populated our <code>dell_inspiron</code> variable. So what the hell was <code>this</code> pointing to? Let's see what's happening inside our <em>constructor</em> function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Computer<span style="color: #009900;">&#40;</span>manufacturer<span style="color: #339933;">,</span> model<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">manufacturer</span> <span style="color: #339933;">=</span> manufacturer<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">model</span> <span style="color: #339933;">=</span> model<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> dell_inspiron <span style="color: #339933;">=</span> Computer<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Dell'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Inspiron'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>dell_inspiron<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// undefined</span>
<span style="color: #006600; font-style: italic;">// notice we now have two additional global objects manufacturer and model... not good</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>manufacturer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Dell</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>model<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Inspiron</span></pre></div></div>

<p>So as you can see calling a <em>constructor</em> function without using the <code>new</code> operator, causes our <code>this</code> keyword to point to the global object. Now let's try using our <em>constructor</em> function with the <code>new</code> operator.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> mac_book_pro <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Computer<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Apple'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Mac Book Pro'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>mac_book_pro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// [object OBJECT]</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>mac_book_pro.<span style="color: #660066;">manufacturer</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span> <span style="color: #339933;">+</span> mac_book_pro.<span style="color: #660066;">model</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Apple Mac Book Pro</span></pre></div></div>

<p>This works as expected, and here's how. Using the <code>new</code> operator first creates a new blank object. Then, it invokes our <em>constructor</em> function, passing the newly created blank object as the <code>this</code> keyword. Your <em>constructor</em> function then populated the object pointed to by the <code>this</code> keyword with the <code>manufacturer</code> and <code>model</code> properties. When the <em>constructor</em> function ends, it automagically returns the object referenced by the <code>this</code> keyword to the <code>mac_book_pro</code> variable.</p>
<h3>Additional Resources</h3>
<p>Here's the example code in jsfiddle you can play with.</p>
<p><a title="JSFiddle Example" href="http://jsfiddle.net/bawigga/aQb5B/10/">http://jsfiddle.net/bawigga/aQb5B/10/</a></p>
<p>If you want to read more about how the <code>new</code> operator works, I highly recommend the following books:</p>
<ul>
<li><a href="http://www.amazon.com/gp/product/047022780X?ie=UTF8&amp;tag=brianwiggi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=047022780X">Professional JavaScript for Web Developers (Wrox Programmer to Programmer)</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=brianwiggi-20&amp;l=as2&amp;o=1&amp;a=047022780X" border="0" alt="" width="1" height="1" />
<ul>
<li>Chapter 18 - Advanced Functions</li>
</ul>
</li>
<li><a href="http://www.amazon.com/gp/product/0596101996?ie=UTF8&amp;tag=brianwiggi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0596101996">JavaScript: The Definitive Guide</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=brianwiggi-20&amp;l=as2&amp;o=1&amp;a=0596101996" border="0" alt="" width="1" height="1" />
<ul>
<li>Chapter 9 - Classes, Constructors, and Prototypes</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2011/01/javascripts-new-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LAMP Stack Optimizations for Small Servers</title>
		<link>http://www.bwigg.com/2011/01/lamp-stack-optimizations-for-small-servers/</link>
		<comments>http://www.bwigg.com/2011/01/lamp-stack-optimizations-for-small-servers/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 07:07:22 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=262</guid>
		<description><![CDATA[This WordPress blog is running on a 256MB Slicehost VPS. Here are the settings I have in place to keep Apache and MySQL responsive. Without these settings, the server would often come to a grinding hault and SSH interactions would become very slow and sometimes hang. Apache - httpd.conf - mpm_prefork_module Settings &#60;IfModule mpm_prefork_module&#62; StartServers [...]]]></description>
			<content:encoded><![CDATA[<p>This WordPress blog is running on a 256MB Slicehost VPS. Here are the settings I have in place to keep Apache and MySQL responsive. Without these settings, the server would often come to a grinding hault and SSH interactions would become very slow and sometimes hang.</p>
<p><strong>Apache - httpd.conf - mpm_prefork_module Settings</strong><br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mpm_prefork_module&gt;
    <span style="color: #00007f;">StartServers</span>          <span style="color: #ff0000;">2</span>
    <span style="color: #00007f;">MinSpareServers</span>       <span style="color: #ff0000;">2</span>
    <span style="color: #00007f;">MaxSpareServers</span>       <span style="color: #ff0000;">4</span>
    <span style="color: #00007f;">MaxClients</span>            <span style="color: #ff0000;">50</span>
    <span style="color: #00007f;">MaxRequestsPerChild</span>   <span style="color: #ff0000;">500</span>
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<p></code></p>
<p>I found that I saved a bunch of memory just by using less apache processes. Instead of spawing 8 processes by default I'm only going to spawn one and limit the max spares to 4, which means after some load I should only have 4 processes lingering around waiting to serve pages.</p>
<p><strong>MySQL - my.cnf settings</strong><br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">skip<span style="color: #CC0099;">-</span><span style="color: #990099; font-weight: bold;">innodb</span>
skip<span style="color: #CC0099;">-</span><span style="color: #990099; font-weight: bold;">bdb</span>
skip<span style="color: #CC0099;">-</span>ndbcluster</pre></div></div>

<p></code></p>
<p>I dropped mysql's memory useage by about 11M (sitting right under 5M right now) just by disabling innodb support. I've also done some very heavy WordPress caching using wp-supercache. this basically caches every page and post so that I'm just serving up static html content instead of processing the entire WordPress stack for every page load.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2011/01/lamp-stack-optimizations-for-small-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2010 Development Toolbox</title>
		<link>http://www.bwigg.com/2010/11/my-development-toolbox-2010/</link>
		<comments>http://www.bwigg.com/2010/11/my-development-toolbox-2010/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 09:02:12 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=125</guid>
		<description><![CDATA[Here is a quick run down of the tools and applications I user pretty much everyday. As of this time I'm doing a lot of frontend work as well as some backend PHP development. Programming Browsers Safari - I use it for all my general development Firefox - Mostly great for tuning CSS and pixel [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick run down of the tools and applications I user pretty much everyday. As of this time I'm doing a lot of frontend work as well as some backend PHP development.</p>
<h3>Programming</h3>
<ul>
<li>Browsers
<ul>
<li>Safari - I use it for all my general development</li>
<li>Firefox - Mostly great for tuning CSS and pixel pushing</li>
<li>Google Chrome -  Great for debugging and performance testing</li>
</ul>
</li>
<li><a href="http://macromates.com/">Textmate</a> - texteditor
<ul>
<li>open in Textmate - utility to put in your Finder that lets you quickly open files in Textmate</li>
<li>project plugin - better project handling for Textmate</li>
</ul>
</li>
<li><a href="http://versionsapp.com/">Versions</a> - Very clean SVN client</li>
<li><a href="http://fluidapp.com/">Fluid</a> - great to take web pages you always access and make them their own app.
<ul>
<li>JIRA - This is just a great setup, this way JIRA is always a few keystrokes away</li>
<li>jQuery API - quick and easy access to the jQuery API</li>
</ul>
</li>
<li><a href="http://iterm.sourceforge.net/">iTerm</a> - better replacement for the built in mac terminal
<ul>
<li>vim - best TE in the world (next to Textmate?)</li>
</ul>
</li>
<li><a href="http://www.sequelpro.com/">Sequel Pro</a> - GUI for MySQL</li>
<li><a href="http://www.charlesproxy.com/">Charles Web Proxy</a> - for intercepting and viewing http data, also great for testing slow connections to a certain domain</li>
<li><a href="http://reggyapp.com/">Reggy</a> - Regular expression sandbox, great for finding out what the hell is going on with a regular expression</li>
<li><a href="http://ditchnet.org/httpclient/">HTTP Client</a> - Great app that let's you play with HTTP, great for testing out backend services</li>
<li><a href="http://www.vmware.com/products/fusion/">VMWare Fusion</a> - X-browser testing</li>
<li>Adobe Photoshop CS5</li>
</ul>
<h3>Utilities</h3>
<ul>
<li><a href="http://lightheadsw.com/caffeine/">Caffeine</a> - awesome little app to keep your computer from going to sleep or launch the screensaver. You don't know how much you love caffeine until you actually use it a few times</li>
<li><a href="http://www.mizage.com/divvy/">Divvy</a> - awesome window management app that helps you resize windows on the fly using hotkeys or your mouse.</li>
<li><a href="http://droplr.com">Droplr</a> - terrific app for taking screenshots and sharing them with others</li>
<li><a href="http://zachwaugh.com/spotcolor/">Spot Color</a> - great little color picker</li>
<li><a href="http://clickontyler.com/virtualhostx/">VirtualHostX</a> - app to manage all the virtualhosts installed on your system's apache instance</li>
<li><a href="http://bjango.com/mac/istatmenus/">iStat Menus</a> - bunch of monitors that sit in your menubar and report system status to you. Great for keeping an eye on memory and processor usage</li>
</ul>
<h3>Misc</h3>
<ul>
<li><a href="http://www.evernote.com">Evernote</a> - Great for taking notes throughout the day and also syncs back up with your iphone or mobile device</li>
<li>Mail.app</li>
<li><a href="http://www.bitcartel.com/pandorajam/">Pandorajam</a> - If you listen to pandora, do your self a favor and download this badass app right now. Simply amazing.</li>
<li><a href="http://grooveshark.com">Grooveshark</a> - think of iTunes, but has any song you can think of. Completely web based.</li>
<li><a href="http://adium.im/">Adium</a> - IM client</li>
<li><a href="http://colloquy.info">Colloquy</a> - IRC client</li>
<li><a href="http://www.echofon.com/">Echofon</a> - Twitter client</li>
<li><a href="http://skim-app.sourceforge.net/">Skim</a> - PDF Reader, much better than preview or acrobat reader</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2010/11/my-development-toolbox-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gentoo Linux &#8211; Wallpapers</title>
		<link>http://www.bwigg.com/2010/02/gentoo-linux-wallpapers/</link>
		<comments>http://www.bwigg.com/2010/02/gentoo-linux-wallpapers/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 01:19:43 +0000</pubDate>
		<dc:creator>bawigga</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.bwigg.com/?p=220</guid>
		<description><![CDATA[For those of you looking for my Gentoo Wallpapers, they can be found here.]]></description>
			<content:encoded><![CDATA[<p>For those of you looking for my Gentoo Wallpapers, they can be found <a title="Gentoo Minimalistic Wallpaper" href="http://www.bwigg.com/wallpaper/gentoo/" target="_blank">here</a>.</p>
<div class="wp-caption alignnone" style="width: 610px"><a href="http://www.bwigg.com/wallpaper/gentoo"><img class="   " title="Gentoo Minimalist Wallpaper" src="http://bwigg.com/wallpaper/gentoo/Minimal-Gentoo-1440x900.jpg" alt="Gentoo Minimalist Wallpaper" width="600" /></a><p class="wp-caption-text">1440x900 - Click for More Sizes</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bwigg.com/2010/02/gentoo-linux-wallpapers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

