<?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>PMA Media Group</title>
	<atom:link href="http://www.pmamediagroup.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pmamediagroup.com</link>
	<description>Unique Marketing Techniques and Strategies with Guaranteed Results!</description>
	<lastBuildDate>Fri, 17 May 2013 17:26:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>MongoDB, What it is?</title>
		<link>http://www.pmamediagroup.com/2010/08/mongodb-what-it-is/</link>
		<comments>http://www.pmamediagroup.com/2010/08/mongodb-what-it-is/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 17:25:01 +0000</pubDate>
		<dc:creator>Narshlob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=1053</guid>
		<description><![CDATA[Puts simply, MongoDB is a document store database. Things are written to the database in BSON (Binary jSON) and displayed to the user in JSON. The power of MongoDB is that it can handle tons of data. We ran a benchmark between MySQL and MongoDB. The dataset was huge, 50 million records. We did a [...]]]></description>
			<content:encoded><![CDATA[<p>
Puts simply, MongoDB is a document store database. Things are written to the database in BSON (Binary jSON) and displayed to the user in JSON. The power of MongoDB is that it can handle tons of data. We ran a benchmark between MySQL and MongoDB. The dataset was huge, 50 million records. We did a search by email address to find everyone that had an email domain of yahoo.com.
</p>
<p>
The query in MySQL looked like this,<br />
<code>SELECT * FROM user_table WHERE email_address LIKE '%yahoo.com';<br />
</code><br />
The results looked like this:</p>
<pre>+--------------+
 | count(*)    |
+--------------+
 | 8354         |
+--------------+
1 row in set (11 min 41.79 sec)
</pre>
<p>The same query run in Mongo looked like this:</p>
<pre>&gt; db.user_collection.find({email_address : /neo\.rr\.com$/}).explain();
      ....
          "n" : 123904,
          "millis" : 126008,
      ....
</pre>
</p>
<p>
As you can see, the query in MySQL took just under 12 minutes while the one in Mongo took barely over 2 minutes. That&#8217;s a ton of time saved.<br />
Note that the MySQL table is MyISAM and indexed on email_address. The MongoDB collection is also indexed on email_address.
</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>
MongoDB is written in C++. From the MongoDB website (http://www.mongodb.org/) we receive this synopsis;</p>
<blockquote><p>&#8220;MongoDB bridges the gap between key-value stores (which are fast and highly scalable) and traditional RDBMS systems (which provide rich queries and deep functionality).<br />
MongoDB (from &#8220;humongous&#8221;) is a scalable, high-performance, open source, document-oriented database.&#8221;</p></blockquote>
<p>
MongoDB is a document store database featuring full index support, replication and high availability, auto sharding, querying, fast in-place updates, map/reduce functionality, GridFS, and commercial support.
</p>
<p>
When searching for something in a relational database with a foreign key to a separate table, two queries must be performed to pull all the data pertaining to the two tables for the specific data. In MongoDB, there are no server-side joins. You will generally want one database collection for each top level object so when pulling related data, you don&#8217;t want to store the data in two separate tables, just embed it into the collection.
</p>
<p>
Let&#8217;s see this with an example:<br />
Say you have a Peeps table and a Favs table. Favs is a collection of different things such as &#8220;Pepsi&#8221;, &#8220;Mt. Dew&#8221;, &#8220;Dr Pepper&#8221; and Peeps is a collection of different people we&#8217;ve interviewed.<br />
In MySQL, Peeps might be built like so,</p>
<pre>
Peeps
  :id
  :name,
  :email_address,
  :phone
  ........
  :favs_id
</pre>
<p>
And Favs would look like this</p>
<pre>
Favs
  :id
  :what
</pre>
</p>
<p>
In MongoDB, we wouldn&#8217;t worry about trying to link two collections together using ids. We would simply embed the favs into the Peeps collection. It would look something like this:</p>
<pre>
{
  peeps: [
    {name: "yourmom", email_address: "blah@arhar.com", favs: [
      {what: "Pepsi"}]
    }
  ]
}
</pre>
</p>
<p>
Thus when we query looking for &#8220;yourmom&#8221; we can easily find yourmom&#8217;s favs as well, without an additional query. You might be saying to yourself, &#8220;But that adds a lot of unnecessary data! Using a foreign key takes up a lot less space! Thou Fool!!&#8221;. I&#8217;d say, &#8220;space is cheap&#8221;. 100 million records might take up roughly 100 gigs of data in MongoDB, which is nothing. How many people out there really have that much data anyway?
</p>
<p>
We&#8217;re contemplating using MongoDB as our server log. The advantage to this would be that we can query on the log much easier than by using grep, or something like that. All we&#8217;d have to do is </p>
<pre>db.logs.find({error: "RuntimeError"}).limit(20)</pre>
<p> to find the first twenty instances of RuntimeError in our logs.
</p>
<p>
As you can see, there&#8217;s a lot of benefit to using MongoDB, and a lot of different ways it can be used. My advice is to check it out for yourself (http://www.mongodb.org/). Set up a server and start messing around with it. It even supports JavaScript in the client console. Simply.. Amazing..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2010/08/mongodb-what-it-is/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making SUPERFAST THINGS in Ruby (Using C Extensions)</title>
		<link>http://www.pmamediagroup.com/2010/07/making-superfast-things-in-ruby-using-c-extensions/</link>
		<comments>http://www.pmamediagroup.com/2010/07/making-superfast-things-in-ruby-using-c-extensions/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 15:34:44 +0000</pubDate>
		<dc:creator>fugufish</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=1030</guid>
		<description><![CDATA[I will address one of the primary uses for a C extension in Ruby, speed. Due to it&#8217;s very nature, Ruby is slow (as compared to compiled languages like C). It gets the job done, but sometimes it takes it&#8217;s sweet time doing it. Sometimes it is necessary to speed things up a bit, and [...]]]></description>
			<content:encoded><![CDATA[<p>I will address one of the primary uses for a C extension in Ruby, speed. Due to it&#8217;s very nature, Ruby is slow (as compared to compiled languages like C). It gets the job done, but sometimes it takes it&#8217;s sweet time doing it. Sometimes it is necessary to speed things up a bit, and here enter C extensions. There are several methods of implementing extensions, from the generic C extension, to ruby-inline. In this particular article I will focus on the generic C extension.</p>
<p>In this example, I am going to use a fairly inefficient piece of Ruby code I created a while ago for Project Euler (Problem 10) for finding the sum of all primes under 2000000:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">Integer</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> prime?
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span> == <span style="color:#006666;">2</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span> <span style="color:#006600; font-weight:bold;">&amp;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#006666;">0</span>
    square = <span style="color:#CC00FF; font-weight:bold;">Math</span>.<span style="color:#9900CC;">sqrt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">round</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span>
    i = <span style="color:#006666;">1</span>
    <span style="color:#9966CC; font-weight:bold;">while</span> i <span style="color:#006600; font-weight:bold;">&lt;</span>= square
      i<span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">2</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span> <span style="color:#006600; font-weight:bold;">%</span> i<span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#006666;">0</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
numbers = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2</span>..<span style="color:#006666;">2000000</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>
&nbsp;
numbers = numbers.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>n<span style="color:#006600; font-weight:bold;">|</span> n.<span style="color:#9900CC;">prime</span>? <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> numbers.<span style="color:#9900CC;">inject</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>result, element<span style="color:#006600; font-weight:bold;">|</span> result = element <span style="color:#006600; font-weight:bold;">+</span> result <span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<p>At the time that I wrote this, I was relatively unaware of more efficient ways of resolving prime numbers (such as a euler sieve), however the code still ran under the allotted 2 minute window (52 seconds) so I went with it. Now to speed it up. To write a C extension you need, at a bare minimum two things:</p>
<ol>
<li>an extconf.rb file &#8211; this file is used by ruby to generate the Makefile that is used to compile the extension</li>
<li>the source file for the extension (in this case primed.c)</li>
</ol>
<p>Here is a look at these two files for my new version of problem 10:<br />
<code>primed.c</code></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;ruby.h&quot;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;math.h&gt;</span>
&nbsp;
VALUE Primed<span style="color: #339933;">;</span>
&nbsp;
VALUE method_prime<span style="color: #009900;">&#40;</span>VALUE obj<span style="color: #339933;">,</span> VALUE args<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">register</span> <span style="color: #993333;">uint64_t</span> n<span style="color: #339933;">;</span>
	n <span style="color: #339933;">=</span> NUM2INT<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>n <span style="color: #339933;">==</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> Qtrue<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>n <span style="color: #339933;">&amp;</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> Qfalse<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">register</span> <span style="color: #993333;">uint64_t</span> sqrt_n <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint64_t</span><span style="color: #009900;">&#41;</span><span style="color: #000066;">sqrt</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">register</span> <span style="color: #993333;">uint64_t</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span> sqrt_n<span style="color: #339933;">;</span> i<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>n <span style="color: #339933;">%</span> i <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> Qfalse<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> Qtrue<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> Init_primed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	Primed <span style="color: #339933;">=</span> rb_define_module<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Primed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	rb_define_method<span style="color: #009900;">&#40;</span>Primed<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;prime?&quot;</span><span style="color: #339933;">,</span> method_prime<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><code>extconf.rb</code></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Loads mkmf which is used to make makefiles for Ruby extensions</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mkmf'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Give it a name</span>
extension_name = <span style="color:#996600;">'primed'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># The destination</span>
dir_config<span style="color:#006600; font-weight:bold;">&#40;</span>extension_name<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Do the work</span>
create_makefile<span style="color:#006600; font-weight:bold;">&#40;</span>extension_name<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>First let me explain primed.c. The objective of this extension is to determine whether or not a number is prime, so that an integer can call <code>x.prime?</code> and return true or false. It is essentially identical to the method used in the pure ruby script above. One of the first thing you may notice is this line:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;">VALUE Primed</pre></td></tr></table></div>

<p>VALUE is a data type defined by Ruby that represents the Ruby object in memory. It is basically a struct that contains the data related to the object. In this case, the object will represent the &#8220;Primed&#8221; module in ruby, so it will contain data about the instance methods, variables, etc. for that module. All Ruby objects are represented in C by VALUE, regardless of their type within the Ruby VM, anything else will likely result in a segfault.</p>
<p>Next we define the actual method to calculate whether the value is prime. Note that because we need to return a Ruby object, we set the return type as VALUE as well. QTrue and QFalse are directly representative of true and false in ruby, and also return correctly within C (QTrue will evaluate as true, QFalse will evaluate as false). </p>
<p>Finally we see the Init_primed method. Every time a class or module is instantiated within the Ruby VM it calles Init_<em>name</em>. It is here we actually instantiate the Primed module and bind the <code>method_prime</code> function to the Ruby method <code>prime?</code>. Both functions used are pretty self explanatory as to what they do, except for the last argument used in <code>ruby_define_method</code> which is essentially the arity or number of arguments to expect in the Ruby method. In this case, <code>-2</code> actually make ruby send back <code>self</code> as the first argument to the <code>method_prime</code> function, and an array of any other arguments as the second.</p>
<p>Now we have all of our code. The last thing to put in place is <code>extconf.rb</code>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Loads mkmf which is used to make makefiles for Ruby extensions</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mkmf'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Give it a name</span>
extension_name = <span style="color:#996600;">'primed'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># The destination</span>
dir_config<span style="color:#006600; font-weight:bold;">&#40;</span>extension_name<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Do the work</span>
create_makefile<span style="color:#006600; font-weight:bold;">&#40;</span>extension_name<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Pretty simple right? Now when you call <code>ruby extconf.rb</code> it will generate a Makefile that you can use to build the extension. And the final result? Using the C extension the code runs in just under 3 seconds. Still not really efficient, but it demonstrates the point. When Ruby&#8217;s speed is the bottle neck, using C is a viable and easy option.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2010/07/making-superfast-things-in-ruby-using-c-extensions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lambdas</title>
		<link>http://www.pmamediagroup.com/2010/07/procs-and-lambdas/</link>
		<comments>http://www.pmamediagroup.com/2010/07/procs-and-lambdas/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 22:52:42 +0000</pubDate>
		<dc:creator>Narshlob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=1014</guid>
		<description><![CDATA[What are these Lambdas you speak of? This article is focused on Lambdas as used in the Ruby language. What are Lambdas? They&#8217;re given several names in other languages. Lambda Anonymous Function Closure In Ruby, we just call it a Lambda function. It&#8217;s defined as such: x = lambda &#123; return &#34;ar har har har&#34; [...]]]></description>
			<content:encoded><![CDATA[<h2>What are these Lambdas you speak of?</h2>
<p>This article is focused on Lambdas as used in the Ruby language.<br />
What are Lambdas? They&#8217;re given several names in other languages.</p>
<ul>
<li>Lambda</li>
<li>Anonymous Function</li>
<li>Closure</li>
</ul>
<p>In Ruby, we just call it a Lambda function. It&#8217;s defined as such:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">x = <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">&quot;ar har har har&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<p>Calling this method will return &#8220;ar har har har&#8221; as a return value. If that were put into a function, like so,</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> foo
  x = <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">&quot;ar har har har&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  x.<span style="color:#9900CC;">call</span>
  <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">&quot;yo ho ho ho&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>This will actually return &#8220;yo ho ho ho&#8221;. If you were to puts x.call, however, you would see &#8220;ar har har har&#8221;. Very interesting. So returning from lambda acts just as a function would, hence it&#8217;s an anonymous function.</p>
<p>Lambdas have an interesting quirk in that if you declare one as such:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">x = <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>x, y<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> x <span style="color:#006600; font-weight:bold;">+</span> y <span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<p>And then call it like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">x.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>It will throw an argument error</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2010/07/procs-and-lambdas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database syncronization woes</title>
		<link>http://www.pmamediagroup.com/2009/11/database-syncronization-woes/</link>
		<comments>http://www.pmamediagroup.com/2009/11/database-syncronization-woes/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 00:00:50 +0000</pubDate>
		<dc:creator>Narshlob</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database replication]]></category>
		<category><![CDATA[database syncronization]]></category>
		<category><![CDATA[mysql replication]]></category>
		<category><![CDATA[mysql sync]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=978</guid>
		<description><![CDATA[Database resyncronization depends on what went wrong but the steps below will most likely solve most issues. Run these commands on the slave database STOP SLAVE; # stop the Slave I/O threads RESET SLAVE; # forget about all the relay log files Then go to the master database and run these RESET MASTER; # reset [...]]]></description>
			<content:encoded><![CDATA[<p>Database resyncronization depends on what went wrong but the steps below will most likely solve most issues.<br />
Run these commands on the slave database</p>
<ol>
<li>STOP SLAVE; # stop the Slave I/O threads</li>
<li>RESET SLAVE; # forget about all the relay log files</li>
</ol>
<p>Then go to the master database and run these</p>
<ol>
<li>RESET MASTER; # reset the bin log counter and wipe out bin log files
<li>FLUSH TABLES WITH READ LOCK; # flush buffers and LOCK tables
<li>show master status\G
</ol>
<p>Note what the show master status command returns. You&#8217;ll need to know the file name and the position.<br />
You can do one of two things here, make a dump of the entire master database (in which case I suggest you follow <a href="http://blog.gurudelleccelsopicco.org/2009/09/howto-mysql-master-slave-resync/">this</a>)<br />
or you can just update the tables.<br />
Usually we just need to update the tables so release the lock on the master database tables (UNLOCK TABLES;) and then run this command on the slave database (download maatkit tools <a href="http://code.google.com/p/maatkit/downloads/list">here</a>),</p>
<ul>
<li>cd ~/maatkit-5014/bin &#038;&#038; sudo ./mk-table-sync &#8211;[print][execute] u=[user],p=[pass],h=[master_host_name] &#8211;databases [database_name(s)] localhost</li>
</ul>
<p>I suggest you run &#8211;print before you run &#8211;execute. If you run &#8211;execute first, you have no idea what just happened. &#8211;print will let you know what it&#8217;ll do without actually doing anything.<br />
Back to the slave database mysql client, issue these commands,</p>
<ol>
<li>CHANGE MASTER TO MASTER_LOG_FILE=&#8217;[file name from show master status command]&#8216;, MASTER_LOG_POS=[pos];</p>
<li>SLAVE START;</ol>
<p>Run this command,</p>
<ul>
<li>show slave status\G</li>
</ul>
<p>And check that these aren&#8217;t NO or NULL,</p>
<p>Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes<br />
&#8230;.<br />
Seconds_Behind_Master: 1634</p>
<p>If things aren&#8217;t back to normal, follow the instructions on <a href="http://blog.gurudelleccelsopicco.org/2009/09/howto-mysql-master-slave-resync/">this website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/11/database-syncronization-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Call it &#8220;Case Equality&#8221;</title>
		<link>http://www.pmamediagroup.com/2009/07/dont-call-it-case-equality/</link>
		<comments>http://www.pmamediagroup.com/2009/07/dont-call-it-case-equality/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 17:47:23 +0000</pubDate>
		<dc:creator>Brett Rasmussen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=956</guid>
		<description><![CDATA[I&#8217;ve recently learned to love Ruby&#8217;s &#8220;triple equals&#8221; operator, sometimes referred to as the &#8220;case equality operator&#8221;. But I stand with Hal Fulton, author of The Ruby Way, in disliking the latter term, since there&#8217;s no real equality going on with its usage. It&#8217;s also not really an operator&#8211;it&#8217;s a method&#8211;but I&#8217;m not going to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently learned to love Ruby&#8217;s &#8220;triple equals&#8221; operator, sometimes referred to as the &#8220;case equality operator&#8221;.  But I stand with Hal Fulton, author of <em>The Ruby Way</em>, in disliking the latter term, since there&#8217;s no real equality going on with its usage.  It&#8217;s also not really an operator&#8211;it&#8217;s a method&#8211;but I&#8217;m not going to complain too loudly about that one, considering that I prefer the term &#8220;relationship operator&#8221;.  I&#8217;m also not opposed to &#8220;trequals&#8221;, which has a certain <em>jeunesse doree</em> about it.  You could say &#8220;trequals&#8221; at a trendy restaurant with post-modern decor and everyone wearing black.</p>
<p>With one equals sign you assign a value to a variable:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">composer = <span style="color:#996600;">&quot;Beethoven&quot;</span></pre></td></tr></table></div>

<p>With <em>two</em> equals signs you see if two things are the same thing:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;9th Symphony&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> melody == <span style="color:#996600;">&quot;Ode to Joy&quot;</span></pre></td></tr></table></div>

<p>With <em>three</em> equal signs you get, well, essentially you get a placeholder that you can use to define arbitrary relationships between objects which you will mostly never call by hand yourself but which Ruby will call for you when you run case statements:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Composer
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:works</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>works<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@works</span> = works
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> ===<span style="color:#006600; font-weight:bold;">&#40;</span>work<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@works</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>work<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>The trequals operator (ok, method) returns true or false depending on a condition I&#8217;ve defined.  Now I can test a given work against a bunch of composer objects using a case statement:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">beethoven = Composer.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Fur Elise&quot;</span>, <span style="color:#996600;">&quot;Missa Solemnis&quot;</span>, <span style="color:#996600;">&quot;9th Symphony&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
mozart = Composer.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;The Magic Flute&quot;</span>, <span style="color:#996600;">&quot;C Minor Mass&quot;</span>, <span style="color:#996600;">&quot;Requiem&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
bach = Composer.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;St. Matthew Passion&quot;</span>, <span style="color:#996600;">&quot;Jesu, Joy of Man's Desiring&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">case</span> <span style="color:#996600;">&quot;Requiem&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> beethoven
    process_beethoven_work
  <span style="color:#9966CC; font-weight:bold;">when</span> mozart
    process_mozart_work
  <span style="color:#9966CC; font-weight:bold;">when</span> bach
    process_bach_work
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>The trequals is called behind the scenes by Ruby.  Since I&#8217;ve defined it on the Composer class to look for a matching entry in that composer&#8217;s list of works, the case statement becomes a way of running different code based on which composer wrote the work in question.</p>
<p>This example is contrived, of course, because if it was this simple a need you&#8217;d probably just check &#8220;some_composer.works.include?(&#8216;Requiem&#8217;)&#8221; by hand.  But the example demonstrates the crucial point, that there&#8217;s no <em>equality</em> being checked for.  A work in no way <em>is</em> the composer.  It&#8217;s a <em>relationship</em> that the case statement is checking for&#8211;the given work <em>was written by</em> the given composer&#8211;and it&#8217;s a relationship that I&#8217;ve defined explicitly for my own music-categorizing purposes.</p>
<p>That case statements work this way is yet another example of the magical and powerful stuff that characterizes Ruby.  Instead of simply a strict equality match, we can now switch against multiple types, all with different definitions of what qualifies as a relationship:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">String</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> ===<span style="color:#006600; font-weight:bold;">&#40;</span>other_str<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">strip</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span>, other_str.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">downcase</span> == other_str.<span style="color:#9900CC;">downcase</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">Array</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> ===<span style="color:#006600; font-weight:bold;">&#40;</span>str<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">any</span>? <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>elem<span style="color:#006600; font-weight:bold;">|</span> elem.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>str<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Fixnum</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> ===<span style="color:#006600; font-weight:bold;">&#40;</span>str<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span> == str.<span style="color:#9900CC;">to_i</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
string_to_test = <span style="color:#996600;">&quot;99 Monkeys&quot;</span>
<span style="color:#9966CC; font-weight:bold;">case</span> string_to_test
  <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;99 monkeys jumping on the bed&quot;</span>
    do_monkey_stuff
  <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;77 Rhinos Jumped&quot;</span>, <span style="color:#996600;">&quot;88 Giraffes Danced&quot;</span>, <span style="color:#996600;">&quot;99 Monkeys Sang&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    do_animal_behavior_stuff
  <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">99</span>
    do_quantity_stuff
  <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">/</span>^\d<span style="color:#006600; font-weight:bold;">+</span>\s<span style="color:#006600; font-weight:bold;">+</span>\w<span style="color:#006600; font-weight:bold;">+/</span>
     do_regex_stuff
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Here, if the string to be tested is the first portion of the larger string (case-insensitively speaking), if it is part of any of the elements in the specified array, if it starts out with 99 (string.to_i returns only <em>leading</em> integers), or if it matches the given regular expression, the respective code will be run.  In this case, it matches all of them, so only the code for the first case&#8211;the string match&#8211;will be run (in Ruby, switches automatically stop at the first match, so you don&#8217;t need to give each case its own &#8220;end&#8221; line).</p>
<p>Note that I didn&#8217;t need to define (actually, override) the trequals on the regular expression.  The relationship operator is a method on Object, so all Ruby objects inherit it.  If not overridden, it defaults to a simple double-equals equality check (thus contributing to the momentum of the misnomer &#8220;case equality&#8221;).  But some standard Ruby classes already come with their own definition for trequals.  Regexp and Range are the notable examples: Regexp defines it to mean a match on that regular expression, and Range defines it to mean a number that falls somewhere within that range, as such:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">num = <span style="color:#006666;">77</span>
<span style="color:#9966CC; font-weight:bold;">case</span> num
  <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">1</span>..<span style="color:#006666;">50</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;found a lower number&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">51</span>..<span style="color:#006666;">100</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;found a higher number&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Note that since === is really a method, it is not <em>commutative</em>, meaning you can&#8217;t swap sides on the call;  &#8220;a === b&#8221; is <strong>not</strong> the same as &#8220;b === a&#8221;.  If you think through it, it makes sense.  You&#8217;re really calling &#8220;a.===(b)&#8221;. If a is an array, you&#8217;re calling a method on Array, which will be defined for Array&#8217;s own purposes.  If b is a string, and you swapped the order, you&#8217;d be calling a String method, which would have a different purpose for its trequals operator, so &#8220;b.===(a)&#8221; would most likely be something quite different.  This concept also means that the variable you&#8217;re testing in a case statement is being passed as a parameter to the trequals methods of the various case objects, not the other way around.  These two snippets are equivalent:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">case</span> <span style="color:#996600;">&quot;St. Matthew Passion&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> mozart
    process_mozart_work
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
process_mozart_work <span style="color:#9966CC; font-weight:bold;">if</span> mozart === <span style="color:#996600;">&quot;St. Matthew Passion&quot;</span></pre></td></tr></table></div>

<p>Note that the second snippet was <strong>not</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">process_mozart_work <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#996600;">&quot;St. Matthew Passion&quot;</span> === mozart</pre></td></tr></table></div>

<p>It&#8217;s also good (although I&#8217;m not sure how <em>useful</em>) to know that the relationship operator is used implicitly by Ruby when rescuing errors in a begin-rescue block.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">begin</span>
  do_some_stuff
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>, <span style="color:#CC00FF; font-weight:bold;">SyntaxError</span>
  handle_arg_or_syn_error
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">IOError</span>
  handle_io_error
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">NoMemoryError</span>
  handle_mem_error
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>In this example, Ruby runs ArgumentError.===, passing it the global variable $!, which holds the most recent error.  If that returns false, it moves along, doing the same with SyntaxError, IOError, and NoMemoryError, each in turn.  With errors, the trequals is defined to just compare the class of the error that occurred with that of each candidate class (in this case, ArgumentError, etc.) and its ancestors.</p>
<p>It took me a long time before I cared about this little Ruby feature, which I think is sad.  I think I just saw the phrase &#8220;case equality&#8221; and thought something like &#8220;Hmm, another subtle variation on what it means for two objects to be equal.  I&#8217;m sure I&#8217;ll have occasion to use this someday.  I&#8217;ll figure it out then.&#8221;  But it&#8217;s more useful than that, and I think it would get better traction without the specious nomenclature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/07/dont-call-it-case-equality/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby file trimming app</title>
		<link>http://www.pmamediagroup.com/2009/07/ruby-file-trimming-app/</link>
		<comments>http://www.pmamediagroup.com/2009/07/ruby-file-trimming-app/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 22:26:33 +0000</pubDate>
		<dc:creator>hals</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=950</guid>
		<description><![CDATA[We recently had an interesting experience with very large files. These were comma delimited files (.csv) containing hundreds of thousands of records, each with a dozen or so fields. e.g. rec1,field2,,,,,,xxx,fieldn,,,1,2,3,,,fieldx rec2,field22,,,a,s,d,fieldmore,,,,etc . . . recn,field2n,,,,ring,,,,ring,1,2,,,hello?,,etc While testing the setup, we had smaller files to work with. The goal was to create a new file [...]]]></description>
			<content:encoded><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">We recently had an interesting experience with very large files. These were comma delimited files (.csv) containing hundreds of thousands of records, each with a dozen or so fields.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">e.g.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">rec1,field2,,,,,,xxx,fieldn,,,1,2,3,,,fieldx</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">rec2,field22,,,a,s,d,fieldmore,,,,etc</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">recn,field2n,,,,ring,,,,ring,1,2,,,hello?,,etc</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">While testing the setup, we had smaller files to work with. The goal was to create a new file containing only the first field from each record.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">e.g.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">rec1</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">rec2</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">recn</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">During testing this was easily done by opening the file in a spreadsheet program (such as OpenOffice), which would split the records on the comma delimiter and place each field in a different column. Then, it was easy to select the first column and write it out to the new file.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">On switching to production files, we discovered that OpenOffice has a limit of 65k rows &#8211; a fraction of what we needed. We then tried some other spreadsheet programs, which produced the same results. We knew there was at least one spreadsheet program that would work, but it was not open source.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">At this point the comment was made: &#8220;well, we ARE ruby developers &#8230;&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">And that lead to the following simple solution to the problem at hand.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">With a few lines of ruby code, the source files could be read in, line by line, split on the comma delimiter, and the first entry written out to the destination file.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">So, when the usual tools just don&#8217;t work &#8211; remember that a new ruby tool might be just around the corner.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400;">#!/usr/bin/ruby</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400;">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400;">#  trimfile.rb</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400;">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16;"><span style="color: #aa0d91;">require</span><span style="color: #000000;"> </span>&#8220;rubygems&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16;"><span style="color: #aa0d91;">require</span><span style="color: #000000;"> </span>&#8220;ruby-debug&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;"><span style="color: #aa0d91;">class</span> Trimfile</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;"><span style="white-space: pre;"> </span>attr_accessor :fileName, :newFile</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;"><span style="white-space: pre;"> </span><span style="color: #aa0d91;">def</span> initialize(fileName, newFile)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16;"><span style="color: #000000;"> puts </span>&#8220;\nSplit off first comma delimited item of each line.&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;"><span style="white-space: pre;"> </span>@fnam = fileName</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;"><span style="color: #aa0d91;">if</span> @fnam == <span style="color: #aa0d91;">nil</span> <span style="color: #aa0d91;">then</span> @fnam = <span style="color: #c41a16;">&#8220;trimin.txt&#8221;</span> <span style="color: #aa0d91;">end</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">@newfnam = newFile</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;"><span style="color: #aa0d91;">if</span> @newfnam == <span style="color: #aa0d91;">nil</span> <span style="color: #aa0d91;">then</span> @newfnam = <span style="color: #c41a16;">&#8220;trimout.txt&#8221;</span> <span style="color: #aa0d91;">end</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">linecount = <span style="color: #1c00cf;">0</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16;"><span style="color: #000000;"> puts </span>&#8220;\nFilenames &#8211; input: #{@fnam}, output: #{@newfnam}&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">aFile = File.new(@newfnam, <span style="color: #c41a16;">&#8220;w&#8221;</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">IO.foreach(@fnam) <span style="color: #aa0d91;">do</span> |line|</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">aFile.puts line.split(<span style="color: #1c00cf;">&#8216;,&#8217;</span>)[0]</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">linecount += <span style="color: #1c00cf;">1</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;"><span style="color: #aa0d91;">end</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">aFile.close</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #c41a16;"><span style="color: #000000;"> puts </span>&#8220;\nTotal lines: #{linecount}&#8221;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91;"><span style="color: #000000;"> </span>end</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91;">end</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco;">test = Trimfile.new(ARGV[0], ARGV[1])</p>
<div><span style="font-family: Monaco, 'Times New Roman', 'Bitstream Charter', Times, fantasy; font-size: x-small;"><span style="line-height: normal;"><br />
</span></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/07/ruby-file-trimming-app/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Working with Git</title>
		<link>http://www.pmamediagroup.com/2009/06/working-with-git/</link>
		<comments>http://www.pmamediagroup.com/2009/06/working-with-git/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 23:34:48 +0000</pubDate>
		<dc:creator>Narshlob</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[git branch]]></category>
		<category><![CDATA[git rebase]]></category>
		<category><![CDATA[git tutorial]]></category>
		<category><![CDATA[manage repo]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=904</guid>
		<description><![CDATA[Use Git to keep track of your project and to share it between all members of your team/company.]]></description>
			<content:encoded><![CDATA[<p>This tutorial covers all the commands (hopefully) we&#8217;ll need for the projects we build here at PMA. If there&#8217;s anything that needs to be added to it, feel free to comment.</p>
<p>Starting with the basics, we&#8217;ll first cover retrieving a project:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>repository<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>This will get the currently active branch from the repository</p>
<p>Obviously you&#8217;ll want to do something with this newly retrieved working copy of the project. Let&#8217;s first create a branch for the new features/bug fixes we&#8217;ll be coding.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git checkout</span> <span style="color: #660033;">-b</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>newbranchname<span style="color: #7a0874; font-weight: bold;">&#93;</span> origin</pre></td></tr></table></div>

<p>Ok, so we got a new branch. While we&#8217;re coding, it&#8217;s a good idea to commit tons of times to preserve the changes we&#8217;ve just made. Don&#8217;t worry about the log, we&#8217;ll make it pretty later. Just commit often.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>filename<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #c20cb9; font-weight: bold;">git commit</span></pre></td></tr></table></div>

<p>If it&#8217;s a small change that doesn&#8217;t require much explanation, you can use these commands</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #c20cb9; font-weight: bold;">git commit</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;The commit message&quot;</span></pre></td></tr></table></div>

<p>Or, even shorter</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git commit</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;The commit message&quot;</span></pre></td></tr></table></div>

<p>You finished that feature so now it&#8217;s time to merge that branch with the master branch (or some other branch depending on what VCS (Version Control System) paradigm you/your team chose). First, you should make those hard-to-read commits less hard-to-read. Let&#8217;s rebase!<br />
Please note that if you rebase after pushing to the repository, you will create problems for those pulling from that repository. Rebase changes the history of the project. Your teammates merges will not be fast-forward[able]. It won&#8217;t be pretty, trust me.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git rebase</span> <span style="color: #660033;">-i</span> HEAD~<span style="color: #7a0874; font-weight: bold;">&#91;</span>number of commits back<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>You&#8217;ll now be looking at something similar to this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">pick ce86448 A random commit
pick a8564a9 Another random commit</pre></td></tr></table></div>

<p>How you order things in this editor will affect the order of the commits. Note that merge commits are not shown here. They aren&#8217;t editable.<br />
Replacing &#8220;pick&#8221; with &#8220;edit&#8221; will allow you to edit the changes you made as well as the commit message.<br />
After you&#8217;ve edited the files you wanted to edit, you can now</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #000000; font-weight: bold;">*</span></pre></td></tr></table></div>

<p>then</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git commit</span> <span style="color: #660033;">--amend</span></pre></td></tr></table></div>

<p>and move on.</p>
<p>As I mentioned before, you have the opportunity to clean up the mess you made with all those many commits using the rebase option. Here&#8217;s how:</p>
<ol>
<li>Run the

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git rebase</span> <span style="color: #660033;">-i</span> HEAD~<span style="color: #7a0874; font-weight: bold;">&#91;</span>x<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p> command from earlier</li>
<li>Replace &#8220;pick&#8221; with &#8220;squash&#8221; on the commit you want to be combined with one exactly previous to it.
<pre>pick ace72dd I squashed these commits. I'm cool.
squash e99fd59 This commit will be sqaushed with the one above it
pick d0770e8 commited again
pick af845d0 I'm really committed
</pre>
</li>
</ol>
<p>Pretty straight forward and easy. Everyone loves rebasing<br />
If you want to know more about git-rebase, I recommend checking it out <a href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html">here</a>.</p>
<p>Now, you&#8217;ve made all these changes and everything looks great. What are you gonna call this pretty new feature? Are you gonna tag it? I would..</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git tag</span> <span style="color: #660033;">-a</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>fancy_feature<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;A fancy message for a fancy feature&quot;</span></pre></td></tr></table></div>

<p>If you happen to leave out the -m, git will open an editor and you&#8217;ll be able to add your fancy message there, just like with commit!<br />
Read more about tags <a href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html">here</a>.<br />
One scenario for using tags could be that, within a project, one wants to keep track of versions. Each commit could be tagged with a version number like with bug fixes in some VCSs. If something goes wrong, it&#8217;s really simple to go back to a previous version using git rebase, as we&#8217;ve already shown.</p>
<p>You&#8217;ve squashed those ugly commits, changed the commit message(s), and tagged everything. Time to merge. Switch to the master branch (or whatever branch you&#8217;re wanting to merge with) and type this command which will merge [branchname] with the current branch:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git merge</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>branchname<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>You&#8217;ll probably want to fix any conflicts and continue with the merge.<br />
It&#8217;s now safe to delete [branchname] because all the changes from that branch are now on the current one.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git branch</span> <span style="color: #660033;">-d</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>branchname<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>This next feature is pretty neat. Say you&#8217;ve done a bunch of changes that haven&#8217;t been committed yet and you realize you aren&#8217;t on a feature branch. Here&#8217;s what you do:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span>
<span style="color: #c20cb9; font-weight: bold;">git stash</span> branch <span style="color: #7a0874; font-weight: bold;">&#91;</span>newbranchname<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>This will stash away all uncommitted changes, create a new branch and check it out, then unstash all your stashed changes into that new branch. Awesome</p>
<p>Stash is also useful in scenarios where you don&#8217;t want to commit yet but you need to switch to a different branch and do something. You could stash the current changes using the above git stash command, do the needed changes, then switch back to the branch you were working on and use this command to unstash the changes:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> apply</pre></td></tr></table></div>

<p>It&#8217;s a good idea to check out the other things offered by git stash (<a href="http://www.kernel.org/pub/software/scm/git/docs/git-stash.html">git-stash</a>)</p>
<p>To get this new branch into the origin repository, do:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git push</span> origin <span style="color: #7a0874; font-weight: bold;">&#91;</span>branchname<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>To delete a branch from the origin repository, do:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git push</span> origin :<span style="color: #7a0874; font-weight: bold;">&#91;</span>branchname<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>Don&#8217;t forget the colon!</p>
<p>Another scenario; your co-worker does some work on a feature and gets stuck. You don&#8217;t want to type on their computer cause yours is set up just the way you want it. Is there a solution to this quandary? Yeah. There is&#8230;<br />
Tell them to push their changes then do this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git fetch</span> origin <span style="color: #7a0874; font-weight: bold;">&#91;</span>remotebranchname<span style="color: #7a0874; font-weight: bold;">&#93;</span>:<span style="color: #7a0874; font-weight: bold;">&#91;</span>localbranchname<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

<p>You now have the branch they were working on locally and can modify to your hearts content.</p>
<hr width="75%" />
<h2>Noteworthy Notes</h2>
<p>There&#8217;s a difference between</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git pull</span></pre></td></tr></table></div>

<p>and</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git fetch</span></pre></td></tr></table></div>

<p>The difference is that &#8220;git pull&#8221; will run a &#8220;git fetch&#8221; then a &#8220;git merge&#8221; to merge the retrieved head into the current branch.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git log</span> <span style="color: #660033;">-p</span> path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>file.rb</pre></td></tr></table></div>

<p>This command will show the history of a specific file;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git blame</span> path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>file.rb</pre></td></tr></table></div>

<p>will go line by line in a file and give a short description + the name of the person that changed the line last (brilliant, actually)</p>
<hr width="75%" />
<h2>From the Git manual</h2>
<p><a href="http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#fast-forwards">check it out</a><br />
A few configuration variables (see git-config(1)) can make it easy to push both branches to your public tree. (See the section called “Setting up a public repository”.)</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; .git<span style="color: #000000; font-weight: bold;">/</span>config <span style="color: #000000; font-weight: bold;">&amp;</span>lt;
      <span style="color: #7a0874; font-weight: bold;">&#91;</span>remote <span style="color: #ff0000;">&quot;mytree&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
           url =  master.kernel.org:<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>scm<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>kernel<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>aegl<span style="color: #000000; font-weight: bold;">/</span>linux-<span style="color: #000000;">2.6</span>.git
           push = release
           push = <span style="color: #7a0874; font-weight: bold;">test</span>
EOF</pre></td></tr></table></div>

<p>Then you can push both the test and release trees using git-push(1):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git push</span> mytree</pre></td></tr></table></div>

<p>or push just one of the test and release branches using:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git push</span> mytree <span style="color: #7a0874; font-weight: bold;">test</span></pre></td></tr></table></div>

<p>or</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git push</span> mytree release</pre></td></tr></table></div>

<p>To rebase your current working tree to obtain the changes from the master tree,<br />
Suppose that you create a branch &#8220;mywork&#8221; on a remote-tracking branch &#8220;origin&#8221;, and create some commits on top of it:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git checkout</span> <span style="color: #660033;">-b</span> mywork origin
<span style="color: #007800;">$vi</span> file.txt
$ <span style="color: #c20cb9; font-weight: bold;">git commit</span>
$ <span style="color: #c20cb9; font-weight: bold;">vi</span> otherfile.txt
$ <span style="color: #c20cb9; font-weight: bold;">git commit</span></pre></td></tr></table></div>

<p>&#8230;<br />
You have performed no merges into mywork, so it is just a simple linear sequence of patches on top of &#8220;origin&#8221;:<br />
o&#8211;o&#8211;o <-- origin<br />
\<br />
o--o--o <-- mywork<br />
Some more interesting work has been done in the upstream project, and "origin" has advanced:<br />
o--o--O--o--o--o <-- origin<br />
\<br />
a--b--c <-- mywork<br />
At this point, you could use "pull" to merge your changes back in; the result would create a new merge commit, like this:<br />
o--o--O--o--o--o <-- origin<br />
\        \<br />
a--b--c--m <-- mywork<br />
However, if you prefer to keep the history in mywork a simple series of commits without any merges, you may instead choose to use git-rebase(1):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">git checkout</span> mywork
$ <span style="color: #c20cb9; font-weight: bold;">git rebase</span> origin</pre></td></tr></table></div>

<p>This will remove each of your commits from mywork, temporarily saving them as patches (in a directory named &#8220;.git/rebase-apply&#8221;), update mywork to point at the latest version of origin, then apply each of the saved patches to the new mywork. The result will look like:<br />
o&#8211;o&#8211;O&#8211;o&#8211;o&#8211;o <-- origin<br />
\<br />
a'--b'--c' <-- mywork<br />
In the process, it may discover conflicts. In that case it will stop and allow you to fix the conflicts; after fixing conflicts, use git add to update the index with those contents, and then, instead of running git commit, just run</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">git rebase</span> <span style="color: #660033;">--continue</span></pre></td></tr></table></div>

<p>and git will continue applying the rest of the patches.<br />
At any point you may use the —abort option to abort this process and return mywork to the state it had before you started the rebase:</p>
<pre lang="bash>
$ git rebase --abort
</pre>
<hr width="75%" />
<h2>The commands</h2>
<p>Here&#8217;s a list of all commands covered in this tutorial:<br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html">git-clone</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html">git-checkout</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html">git-add</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html">git-commit</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html">git-rebase</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html">git-tag</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html">git-merge</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-branch.html">git-branch</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-stash.html">git-stash</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html">git-push</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-pull.html">git-pull</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html">git-fetch</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/06/working-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asynchronous Processing with Workling and Starling</title>
		<link>http://www.pmamediagroup.com/2009/06/asynchronous-processing-with-workling-and-starling/</link>
		<comments>http://www.pmamediagroup.com/2009/06/asynchronous-processing-with-workling-and-starling/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 14:40:10 +0000</pubDate>
		<dc:creator>fugufish</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[starling]]></category>
		<category><![CDATA[workling]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=897</guid>
		<description><![CDATA[When working with applications whose actions may take some time to complete, it may be better to  handle the request asynchronously. A quick and easy way to do this is using Starling and Workling. Starling is a light weight message queue based on the Memcache protocol, and Workling is a simple, lightweight consumer. Setup is [...]]]></description>
			<content:encoded><![CDATA[<p>When working with applications whose actions may take some time to complete, it may be better to  handle the request asynchronously. A quick and easy way to do this is using <a title="Starling" href="http://github.com/starling/starling/tree/master" target="_blank">Starling</a> and <a title="Workling" href="http://github.com/purzelrakete/workling/tree/master" target="_blank">Workling</a>. Starling is a light weight message queue based on the Memcache protocol, and Workling is a simple, lightweight consumer. Setup is dead simple:</p>
<p>First, install Starling:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> starling</pre></td></tr></table></div>

<p>This will install Starling and it&#8217;s dependencies (memcache-client and eventmachine) if you don&#8217;t already have them.</p>
<p>Now install Workling. This doesn&#8217;t have a gemspec so we will install it as a plugin:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">cd ~<span style="color:#006600; font-weight:bold;">/</span>path_to_your_project
script<span style="color:#006600; font-weight:bold;">/</span>plugin install git:<span style="color:#006600; font-weight:bold;">//</span>github.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>purzelrakete<span style="color:#006600; font-weight:bold;">/</span>workling.<span style="color:#9900CC;">git</span></pre></td></tr></table></div>

<p>Finally, tell Workling, which will want to use Spawn by default if it is installed on your machine, to use Starling by placing this in your environment.rb:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Workling::Remote</span>.<span style="color:#9900CC;">dispatcher</span> = <span style="color:#6666ff; font-weight:bold;">Workling::Remote::Runners::StarlingRunner</span>.<span style="color:#9900CC;">new</span></pre></td></tr></table></div>

<p>That is it for the installation process! Easy. Now for actually handling requests. Believe it or  not, it is just as simple as the installation. Say you have a controller that has to do several long running tasks:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> SkinnyController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> fat_action
    .. <span style="color:#9966CC; font-weight:bold;">do</span> some crazy stuff that takes a few minutes ..
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now typically, you should avoid doing things that take longer than a few seconds to complete. And this is okay for most application requirements, however in some cases, it is inevitable that a few tasks will take much longer, such as above. That is where Workling comes in. Simply refactor the code into a worker (conveniently located in app/workers):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># app/workers/fat_worker.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> FatWorker <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Workling::Base</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># this method can be named anything you want</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> do_work<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    .. <span style="color:#9900CC;">you</span> get the picture ..
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now, in your controller, call the worker:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> SkinnyController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> fat_action
    FatWorker.<span style="color:#9900CC;">asynch_do_work</span><span style="color:#006600; font-weight:bold;">&#40;</span>some_args<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Just start up starling and workling (starling start, and script/workling_client start respectively) And that is all. You can now handle large tasks asynchronously, and because the tasks are queued with starling, the action can be called multiple times, and it will queue up the worker and process it as soon as the previous tasks are complete. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/06/asynchronous-processing-with-workling-and-starling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Scan() Method for Regular Expressions</title>
		<link>http://www.pmamediagroup.com/2009/06/the-scan-method-for-regular-expressions/</link>
		<comments>http://www.pmamediagroup.com/2009/06/the-scan-method-for-regular-expressions/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 19:59:36 +0000</pubDate>
		<dc:creator>Chris Gunnels</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[occurrences]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scan method]]></category>
		<category><![CDATA[white space]]></category>

		<guid isPermaLink="false">http://www.pmamediagroup.com/?p=891</guid>
		<description><![CDATA[As I was writing a simple script to display the education I received from reading The Ruby Way 2nd Edition chapters 2 and 3, I found a really neat method that helped me complete my task. If you didn&#8217;t read the title of this blog post then your out of luck, but if you read [...]]]></description>
			<content:encoded><![CDATA[<p>As I was writing a simple script to display the education I received from reading The Ruby Way 2nd Edition chapters 2 and 3, I found a really neat method that helped me complete my task. If you didn&#8217;t read the title of this blog post then your out of luck, but if you read the title then you will know that I am talking about the <a href="http://www.ruby-doc.org/core/classes/String.html#M000827">scan()</a> method.</p>
<p>Back to my script, since I wanted to find the number of occurrences white space showed up in a given string I had to come up with a way to count white space. My first thought was to do some regular expression matching. Well after a little thought and a lot of reading, I found a this:<br />
<span id="more-891"></span><br />
<code><br />
answer = params[:string].scan(/(\s)/)<br />
puts answer.size<br />
</code><br />
Here&#8217;s a little breakdown of whats happening for those that don&#8217;t know. </p>
<p>GIVEN: params is a hash with the values that were posted via a form.<br />
Line 1: we are running the scan method on params[:string] which the value is a string. Then we pass scan method a regular expression that looks for any white space. Then the value of that is assigned to the local answer variable.<br />
Line 2: we print the answer&#8217;s size.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/06/the-scan-method-for-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced Routing Wireless To Your LAN With Cisco WRT400N</title>
		<link>http://www.pmamediagroup.com/2009/06/advanced-routing-wireless-to-your-lan-with-cisco-wrt400n/</link>
		<comments>http://www.pmamediagroup.com/2009/06/advanced-routing-wireless-to-your-lan-with-cisco-wrt400n/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 23:16:28 +0000</pubDate>
		<dc:creator>Aaron Murphy</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Cisco]]></category>
		<category><![CDATA[Linksys]]></category>
		<category><![CDATA[router]]></category>
		<category><![CDATA[wireless]]></category>

		<guid isPermaLink="false">http://www2.pmamediagroup.com/?p=20</guid>
		<description><![CDATA[Advanced routing wireless to LAN with the Cisco WRT400N router is simple, once you know how. Just do the basic setup on the router as usual, only disable the DHCP server. Then go to the Advaned Routing page and disable NAT and enable Dynamic Routing. Now you can connect a local network to one of [...]]]></description>
			<content:encoded><![CDATA[<p>Advanced routing wireless to LAN with the <a href="http://www.linksysbycisco.com/US/en/products/WRT400N">Cisco WRT400N</a> router is simple, once you know how. Just do the basic setup on the router as usual, only disable the DHCP server. Then go to the Advaned Routing page and disable NAT and enable Dynamic Routing. Now you can connect a local network to one of the four LAN ports. Don&#8217;t use the WAN port as the Internet connection will go through your main LAN.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmamediagroup.com/2009/06/advanced-routing-wireless-to-your-lan-with-cisco-wrt400n/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
