<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!-- generator="wordpress/2.2.1" --><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>good coders code, great reuse</title>
	<link>http://www.catonmat.net</link>
	<description>Peteris Krumins' blog about programming, hacking, software reuse, software ideas, computer security, google and technology.</description>
	<pubDate>Thu, 04 Feb 2010 13:46:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/catonmat" /><feedburner:info uri="catonmat" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><feedburner:emailServiceId>catonmat</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Famous Perl One-Liners Explained, Part V: Text conversion and substitution</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/ZepRCtiIfC8/</link>
		<comments>http://www.catonmat.net/blog/perl-one-liners-explained-part-five/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 09:10:56 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Programming]]></category>
<category>base64</category><category>camelcase</category><category>cr</category><category>crlf</category><category>find</category><category>html decode</category><category>html encode</category><category>lc</category><category>lf</category><category>lowercase</category><category>newline</category><category>one liner</category><category>one liners</category><category>perl</category><category>perl1line.txt</category><category>replace</category><category>rot13</category><category>strip</category><category>substitute</category><category>text</category><category>uc</category><category>uppercase</category><category>url escape</category><category>url unescape</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/perl-one-liners-explained-part-five/</guid>
		<description><![CDATA[This is the fifth part of a nine-part article on famous Perl one-liners. In this part I will create various one-liners for text conversion and substitution. See part one for introduction of the series.
Famous Perl one-liners is my attempt to create &#8220;perl1line.txt&#8221; that is similar to &#8220;awk1line.txt&#8221; and &#8220;sed1line.txt&#8221; that have been so popular among [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/dxsQzc-tI1BwfGVg3Wu2IgH2WAo/0/da"><img src="http://feedads.g.doubleclick.net/~a/dxsQzc-tI1BwfGVg3Wu2IgH2WAo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/dxsQzc-tI1BwfGVg3Wu2IgH2WAo/1/da"><img src="http://feedads.g.doubleclick.net/~a/dxsQzc-tI1BwfGVg3Wu2IgH2WAo/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/02/perl-one-liners.jpg' alt='Perl One Liners' class='post-icon' align='left' />This is the fifth part of a nine-part article on <strong>famous Perl one-liners</strong>. In this part I will create various one-liners for <strong>text conversion and substitution</strong>. See <a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-one/">part one</a> for introduction of the series.</p>
<p>Famous Perl one-liners is my attempt to create &#8220;<strong>perl1line.txt</strong>&#8221; that is similar to &#8220;<a href="http://www.catonmat.net/blog/awk-one-liners-explained-part-one/">awk1line.txt</a>&#8221; and &#8220;<a href="http://www.catonmat.net/blog/sed-one-liners-explained-part-one/">sed1line.txt</a>&#8221; that have been so popular among Awk and Sed programmers.</p>
<p>The article on famous Perl one-liners will consist of nine parts:</p>
<ul>
<li><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-one/">Part I: File spacing.</a></li>
<li><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-two/">Part II: Line numbering.</a></li>
<li><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-three/">Part III: Calculations.</a></li>
<li><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-four/">Part IV: String creation and array creation.</a></li>
<li><strong>Part V: Text conversion and substitution (this part).</strong></li>
<li>Part VI: Selective printing and deleting of certain lines.</li>
<li>Part VII: Handy regular expressions.</li>
<li>Part VIII: Release of perl1line.txt.</li>
<li>Part IX: Release of Perl One-Liners e-book.</li>
</ul>
<p>Everyone who&#8217;s <a href="http://www.catonmat.net/feed/">subscribed to my blog</a> will get a <strong>free copy of Perl One-Liners e-book</strong> when I release it as part 9 of this article series!</p>
<p>Alright then, here are today&#8217;s one-liners:</p>
<h2 style="margin-bottom: 10px">Text conversion and substitution</h2>
<p><strong>62. ROT13 a string.</strong></p>
<pre>'y/A-Za-z/N-ZA-Mn-za-m/'</pre>
<p>This one-liner uses the <code>y</code> operator (also known as <code>tr</code> operator) to do ROT13. Operators <code>y</code> and <code>tr</code> do string transliteration. Given <code>y/SEARCH/REPLACE/</code>, the operator transliterates all occurrences of the characters found in <code>SEARCH</code> list with the corresponding (position-wise) characters in <code>REPLACE</code> list.</p>
<p>In this one-liner <code>A-Za-z</code> creates the following list of characters:</p>
<pre>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</pre>
<p>And <code>N-ZA-Mn-za-m</code> creates this list:</p>
<pre>NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm</pre>
<p>If you look closely you&#8217;ll notice that the second list is actually the first list offset by 13 characters. Now the <code>y</code> operator translates each character in the first list to a character in the second list, thus performing the ROT13 operation.</p>
<p>If you wish to ROT13 the whole file then do this:</p>
<pre>perl -lpe 'y/A-Za-z/N-ZA-Mn-za-m/' file</pre>
<p>The <code>-p</code> argument puts each of <code>file</code>&#8217;s line in the <code>$_</code> variable, the <code>y</code> does ROT13, and <code>-p</code> prints the <code>$_</code> out. The <code>-l</code> appends a newline to the output.</p>
<p>Note: remember that applying ROT13 twice produces the same string, i.e., <code>ROT13(ROT13(string)) == string</code>.</p>
<p><strong>63. Base64 encode a string.</strong></p>
<pre>perl -MMIME::Base64 -e 'print encode_base64("string")'</pre>
<p>This one-liner uses the <a href="http://search.cpan.org/~gaas/MIME-Base64-3.09/Base64.pm">MIME::Base64</a> module that is in the core (no need to install it, it comes with Perl). This module exports the <code>encode_base64</code> function that takes a string and returns base64 encoded version of it.</p>
<p>To base64 encode the whole file do the following:</p>
<pre>perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' file</pre>
<p>Here the <code>-0777</code> argument together with <code>-n</code> causes Perl to slurp the whole file into the <code>$_</code> variable. Then the file gets base64 encoded and printed out, just like the string example above.</p>
<p>If we didn&#8217;t slurp the file and encoded it line-by-line we&#8217;d get a mess.</p>
<p><strong>64. Base64 decode a string.</strong></p>
<pre>perl -MMIME::Base64 -le 'print decode_base64("base64string")'</pre>
<p>The <code>MIME::Base64</code> module also exports <code>decode_base64</code> function that takes a base64-encoded string and decodes it.</p>
<p>The whole file can be similarly decoded by:</p>
<pre>perl -MMIME::Base64 -ne 'print decode_base64($_)' file</pre>
<p>There is no need to slurp the whole file into <code>$_</code> because each line of a base64 encoded file is exactly 76 characters and decodes nicely.</p>
<p><strong>65. URL-escape a string.</strong></p>
<pre>perl -MURI::Escape -le 'print uri_escape($string)'</pre>
<p>You&#8217;ll need to install the <a href="http://search.cpan.org/~gaas/URI-1.52/URI/Escape.pm">URI::Escape</a> module as it doesn&#8217;t come with Perl. The module exports two functions - <code>uri_escape</code> and <code>uri_unescape</code>. The first one does URL-escaping (sometimes also referred to as URL encoding), and the other does URL-unescaping (URL decoding).</p>
<p><strong>66. URL-unescape a string.</strong></p>
<pre>perl -MURI::Escape -le 'print uri_unescape($string)'</pre>
<p>This one-liner uses the <code>uri_unescape</code> function from <code>URI::Escape</code> module to do URL-unescaping.</p>
<p><strong>67. HTML-encode a string.</strong></p>
<pre>perl -MHTML::Entities -le 'print encode_entities($string)'</pre>
<p>This one-liner uses the <code>encode_entities</code> function from <a href="http://search.cpan.org/~gaas/HTML-Parser-3.64/lib/HTML/Entities.pm">HTML::Entities</a> module. This function encodes HTML entities. For example, <code>&lt;</code> and <code>&gt;</code> get turned into <code>&amp;lt;</code> and <code>&amp;gt;</code>.</p>
<p><strong>68. HTML-decode a string.</strong></p>
<pre>perl -MHTML::Entities -le 'print decode_entities($string)'</pre>
<p>This one-liner uses the <code>decode_entities</code> function from <code>HTML::Entities</code> module.</p>
<p><strong>69. Convert all text to uppercase.</strong></p>
<pre>perl -nle 'print uc'</pre>
<p>This one-liner uses the <code>uc</code> function, which by default operates on the <code>$_</code> variable and returns an uppercase version of it.</p>
<p>Another way to do the same is to use <code>-p</code> command line option that enables automatic printing of <code>$_</code> variable and modify it in-place:</p>
<pre>perl -ple '$_=uc'</pre>
<p>The same can also be also achieved by applying the <code>\U</code> escape sequence to string interpolation:</p>
<pre>perl -nle 'print "\U$_"'</pre>
<p>It causes anything after it (or until the first occurrence of <code>\E</code>) to be upper-cased.</p>
<p><strong>70. Convert all text to lowercase.</strong></p>
<pre>perl -nle 'print lc'</pre>
<p>This one-liner is very similar to the previous. Here the <code>lc</code> function is used that converts the contents of <code>$_</code> to lowercase.</p>
<p>Or, using escape sequence <code>\L</code> and string interpolation:</p>
<pre>perl -nle 'print "\L$_"'</pre>
<p>Here <code>\L</code> causes everything after it (until the first occurrence of <code>\E</code>) to be lower-cased.</p>
<p><strong>71. Uppercase only the first word of each line.</strong></p>
<pre>perl -nle 'print ucfirst lc'</pre>
<p>The one-liner first applies the <code>lc</code> function to the input that makes it lower case and then uses the <code>ucfirst</code> function that upper-cases only the first character.</p>
<p>It can also be done via escape codes and string interpolation:</p>
<pre>perl -nle 'print "\u\L$_"'</pre>
<p>First the <code>\L</code> lower-cases the whole line, then <code>\u</code> upper-cases the first character.</p>
<p><strong>72. Invert the letter case.</strong></p>
<pre>perl -ple 'y/A-Za-z/a-zA-Z/'</pre>
<p>This one-liner does transliterates capital letters <code>A-Z</code> to lowercase letters <code>a-z</code>, and lowercase letters to uppercase letters, thus switching the case.</p>
<p><strong>73. Camel case each line.</strong></p>
<pre>perl -ple 's/(\w+)/\u$1/g'</pre>
<p>This is a lousy Camel Casing one-liner. It takes each word and upper-cases the first letter of it. It fails on possessive forms like &#8220;friend&#8217;s car&#8221;. It turns them into &#8220;Friend&#8217;S Car&#8221;.</p>
<p>An improvement is:</p>
<pre>s/(?&lt;!['])(\w+)/\u\1/g</pre>
<p>Which checks if the character before the word is not single quote <code>'</code>. But I am sure it still fails on some more exotic examples.</p>
<p><strong>74. Strip leading whitespace (spaces, tabs) from the beginning of each line.</strong></p>
<pre>perl -ple 's/^[ \t]+//'</pre>
<p>This one-liner deletes all whitespace from the beginning of each line. It uses the substitution operator <code>s</code>. Given <code>s/REGEX/REPLACE/</code> it replaces the matched <code>REGEX</code> by the <code>REPLACE</code> string. In this case the <code>REGEX</code> is <code>^[ \t]+</code>, which means &#8220;match one or more space or tab at the beginning of the string&#8221; and <code>REPLACE</code> is nothing, meaning, replace the matched part with empty string.</p>
<p>The regex class <code>[ \t]</code> can actually be replaced by <code>\s+</code> that matches any whitespace (including tabs and spaces):</p>
<pre>perl -ple 's/^\s+//'</pre>
<p><strong>75. Strip trailing whitespace (space, tabs) from the end of each line.</strong></p>
<pre>perl -ple 's/[ \t]+$//'</pre>
<p>This one-liner deletes all whitespace from the end of each line.</p>
<p>Here the <code>REGEX</code> of the <code>s</code> operator says &#8220;match one or more space or tab at the end of the string.&#8221; The <code>REPLACE</code> part is empty again, which means to erase the matched whitespace.</p>
<p><strong>76. Strip whitespace from the beginning and end of each line.</strong></p>
<pre>perl -ple 's/^[ \t]+|[ \t]+$//g'</pre>
<p>This one-liner combines the previous two. Notice that it specifies the global <code>/g</code> flag to the <code>s</code> operator. It&#8217;s necessary because we want it to delete whitespace at the beginning AND end of the string. If we didn&#8217;t specify it, it would only delete whitespace at the beginning (assuming it exists) and not at the end.</p>
<p><strong>77. Convert UNIX newlines to DOS/Windows newlines.</strong></p>
<pre>perl -pe 's|\n|\r\n|'</pre>
<p>This one-liner substitutes the Unix newline <code>\n</code> LF with Windows newline <code>\r\n</code> CRLF on each line. Remember that the <code>s</code> operator can use anything for delimiters. In this one-liner it uses vertical pipes to delimit <code>REGEX</code> from <code>REPLACE</code> to improve readibility. </p>
<p><strong>78. Convert DOS/Windows newlines to UNIX newlines.</strong></p>
<pre>perl -pe 's|\r\n|\n|'</pre>
<p>This one-liner does the opposite of the previous one. It takes Windows newlines CRLF and converts them to Unix newlines LF.</p>
<p><strong>79. Convert UNIX newlines to Mac newlines.</strong></p>
<pre>perl -pe 's|\n|\r|'</pre>
<p>Apple Macintoshes used to use <code>\r</code> CR as newlines. This one-liner converts UNIX&#8217;s <code>\n</code> to Mac&#8217;s <code>\r</code>.</p>
<p><strong>80. Substitute (find and replace) &#8220;foo&#8221; with &#8220;bar&#8221; on each line.</strong></p>
<pre>perl -pe 's/foo/bar/'</pre>
<p>This one-liner uses the <code>s/REGEX/REPLACE/</code> command to substitute &#8220;foo&#8221; with &#8220;bar&#8221; on each line.</p>
<p>To replace all &#8220;foos&#8221; with &#8220;bars&#8221;, add the global <code>/g</code> flag:</p>
<pre>perl -pe 's/foo/bar/g'</pre>
<p><strong>81. Substitute (find and replace) &#8220;foo&#8221; with &#8220;bar&#8221; on lines that match &#8220;baz&#8221;. </strong></p>
<pre>perl -pe '/baz/ &#038;&#038; s/foo/bar/'</pre>
<p>This one-liner is equivalent to:</p>
<pre>
while (defined($line = &lt;&gt;)) {
  if ($line =~ /baz/) {
    $line =~ s/foo/bar/
  }
}
</pre>
<p>It puts each line in variable <code>$line</code>, then checks if line matches &#8220;baz&#8221;, and if it does, it replaces &#8220;foo&#8221; with &#8220;bar&#8221; in it.</p>
<h2 style="margin-bottom: 10px">Got tired.</h2>
<p>I got tired of writing one-liners at this moment. I&#8217;ll update this article the same way I did the <a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-three/">3rd part</a> - I&#8217;ll add a few new one-liners each week until the article is finished.</p>
<h2 style="margin-bottom: 10px">Have Fun!</h2>
<p>Have fun with these one-liners for now. The next part is going to be about selective printing and deleting of certain lines.</p>
<p><strong>Can you think of other text conversion and substitution procedures that I did not include here?</strong></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=ZepRCtiIfC8:OjQz3FLoYxQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=ZepRCtiIfC8:OjQz3FLoYxQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=ZepRCtiIfC8:OjQz3FLoYxQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=ZepRCtiIfC8:OjQz3FLoYxQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=ZepRCtiIfC8:OjQz3FLoYxQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=ZepRCtiIfC8:OjQz3FLoYxQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=ZepRCtiIfC8:OjQz3FLoYxQ:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/ZepRCtiIfC8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/perl-one-liners-explained-part-five/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/perl-one-liners-explained-part-five/</feedburner:origLink></item>
		<item>
		<title>How to keep track of who’s talking about you</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/pxOJfVPY2rE/</link>
		<comments>http://www.catonmat.net/blog/how-to-keep-track-of-whos-talking-about-you/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 06:20:08 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Howto]]></category>
<category>backtweets</category><category>backtype</category><category>feedblitz</category><category>google alerts</category><category>rss</category><category>twitter</category><category>twitter search</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/how-to-keep-track-of-whos-talking-about-you/</guid>
		<description><![CDATA[Hey everyone, just wanted to do a quick post on how to keep track of who&#8217;s talking about you on the net. Nothing really unique, just a list of tools that I use often. Why is it important? Well, it&#8217;s always interesting to know what people are saying about you and sometimes you want to [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/FnHKM3fBSSPpqMIKbwqkG6l_doM/0/da"><img src="http://feedads.g.doubleclick.net/~a/FnHKM3fBSSPpqMIKbwqkG6l_doM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/FnHKM3fBSSPpqMIKbwqkG6l_doM/1/da"><img src="http://feedads.g.doubleclick.net/~a/FnHKM3fBSSPpqMIKbwqkG6l_doM/1/di" border="0" ismap="true"></img></a></p><p>Hey everyone, just wanted to do a quick post on how to keep track of who&#8217;s talking about you on the net. Nothing really unique, just a list of tools that I use often. Why is it important? Well, it&#8217;s always interesting to know what people are saying about you and sometimes you want to engage in a conversation or just thank them for linking to your article.</p>
<p>Alright, here are the tools that I use:</p>
<h2 style="margin-bottom: 10px">Twitter Search</h2>
<p><a href="http://search.twitter.com/">Twitter search</a> is definitely the #1 source for keeping track of who&#8217;s talking about you right now. But you already knew that.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/twitter-search.jpg' alt='Twitter Search' /><br />
<small>Twitter search example for the term &#8220;catonmat.&#8221;</small>
</div>
<p>Perhaps what you didn&#8217;t know is that they have an RSS feed for search queries.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/twitter-search-rss-feed.jpg' alt='Twitter search RSS feed' /><br />
<small>Location of RSS feed link for Twitter search results.</small>
</div>
<p>Now combined with a service like <a href="http://www.feedblitz.com">feedblitz.com</a> you can email the RSS updates to yourself or just read them from your favorite RSS reader.</p>
<p>I am monitoring terms &#8220;Peteris Krumins&#8221;, &#8220;pkrumins&#8221; and &#8220;catonmat&#8221;.</p>
<h2 style="margin-bottom: 10px">Google Alerts</h2>
<p><a href="http://www.google.com/alerts/">Google Alerts</a> automatically notifies you when the Google search engine locates new results for your search terms. You can choose to have your alerts delivered via email or RSS feed.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/google-alerts.gif' alt='Google Alerts' /><br />
<small>Google Alerts email for the term &#8220;catonmat.&#8221;</small>
</div>
<p>You can even customize the type of alerts you wish to receive. Google Alerts lets you choose to get notified when a new result appears on web pages, usenet (google groups), blogs, news or videos.</p>
<h2 style="margin-bottom: 10px">Backtype Comment Alerts</h2>
<p><a href="http://www.backtype.com/">Backtype</a> is Google for comments. Want to find out when someone&#8217;s mentioned you on Reddit, FriendFeed, Digg or Hacker News? Backtype will alert you.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/backtype-alerts.gif' alt='Backtype Comment Alerts' /><br />
<small>Backtype Alerts email for the term &#8220;peteris.&#8221;</small>
</div>
<p>Backtype also recently launched a service called <a href="http://www.backtweets.com">BackTweets</a> that allows you to find who&#8217;s linking back to you via shortened URLs.</p>
<h2 style="margin-bottom: 10px">Have Fun!</h2>
<p>Have fun keeping track of yourself!</p>
<p><strong>Btw, let me know in the comments if I missed any other cool tools.</strong></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=pxOJfVPY2rE:veKZMpKZew8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=pxOJfVPY2rE:veKZMpKZew8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=pxOJfVPY2rE:veKZMpKZew8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=pxOJfVPY2rE:veKZMpKZew8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=pxOJfVPY2rE:veKZMpKZew8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=pxOJfVPY2rE:veKZMpKZew8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=pxOJfVPY2rE:veKZMpKZew8:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/pxOJfVPY2rE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/how-to-keep-track-of-whos-talking-about-you/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/how-to-keep-track-of-whos-talking-about-you/</feedburner:origLink></item>
		<item>
		<title>How to Steal a Botnet (Video Lecture Summary)</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/doqlg9CH-oQ/</link>
		<comments>http://www.catonmat.net/blog/how-to-steal-a-botnet-video-lecture-review/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 08:05:49 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Security]]></category>
<category>bot</category><category>botmaster</category><category>botnet</category><category>bots</category><category>control channel</category><category>control server</category><category>credit card</category><category>cybercriminal</category><category>domain flux</category><category>domain fluxing</category><category>dos</category><category>financial theft</category><category>hacker</category><category>ip</category><category>john the ripper</category><category>malware</category><category>mebroot</category><category>password</category><category>password manager</category><category>richard kemmerer</category><category>theft</category><category>torpig</category><category>twitter</category><category>ucsb</category><category>video lecture</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/how-to-steal-a-botnet-video-lecture-review/</guid>
		<description><![CDATA[I recently watched an interesting video lecture on stealing botnets. A group of researchers at UCSB recently managed to take control over a part of Torpig botnet for 10 days. During this time, they observed 180 thousand infections and recorded almost 70GB of data that bots collected. This data included submitted form information from all [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/uCpBO5tX9MxJHjYYQ7gDT2h0Ci4/0/da"><img src="http://feedads.g.doubleclick.net/~a/uCpBO5tX9MxJHjYYQ7gDT2h0Ci4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/uCpBO5tX9MxJHjYYQ7gDT2h0Ci4/1/da"><img src="http://feedads.g.doubleclick.net/~a/uCpBO5tX9MxJHjYYQ7gDT2h0Ci4/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2008/07/hackers-steal-money.jpg' alt='hackers steal money' class="post-icon" align="left" />I recently watched an interesting video lecture on stealing botnets. A group of researchers at <a href="http://www.cs.ucsb.edu/~seclab/projects/torpig/">UCSB</a> recently managed to take control over a part of Torpig botnet for 10 days. During this time, they observed 180 thousand infections and recorded almost 70GB of data that bots collected. This data included submitted form information from all the websites the infected person had visited, smtp, ftp, pop3, windows, passwords, credit card numbers and passwords from various password managers.</p>
<p>Here are the most interesting facts from the lecture:</p>
<p>Torpig uses a technique called &#8220;<strong>domain fluxing</strong>&#8221; to avoid being shut down by simply blocking the IP or the domain name of control center servers. The idea is simple - depending on date and time the algorithm generates a domain name to connect to. If the domain gets shut down, the bots will simply use a different domain after some time. </p>
<p>The researchers were able to take control over a part of the botnet by cracking the domain name generating algorithm and registering some of the domain names to be used for communication in the future.</p>
<p>The bad guys noticed that a part of botnet has been taken over and issued a software update to all bots to use a new domain flux algorithm, which used Twitter&#8217;s popular topics for the day to generate domain names. It was no longer possible to predict the domain that would be used tomorrow.</p>
<p>When communicating with command &#038; control server, the bots included a unique id field that was generated from machine&#8217;s hardware. This allowed researchers to estimate the real number of unique computers infected. Researchers saw 1.2 million unique IP addresses but only 180k unique machines.</p>
<p>The bots would steal financial data from 410 financial institutions (top 5: PayPal, Poste Italiane, Capital One, E*Trade, Chase), they would log credit card information (top 5 cards: Visa, Mastercard, American Express, Maestro, Discover), and they would also steal all the passwords from browser&#8217;s password manager.</p>
<p>In a 2008 study Symantec estimated that credit card information is valued at $.10 to $25 per card in the underground market. The bank account information is valued at $10.00 to $1,000 per account. Using this study, researchers estimated that during 10 day period the amount of financial data bots collected were worth $83k to $8.3 million.</p>
<p>Using various estimations researchers calculated that if the bots are used for denial of service the total bandwidth would be 17Gbps.</p>
<p>Researchers observed that there was a fraction of people who&#8217;d fill out the phishing page and then immediately email the company&#8217;s security group telling that they may have been victims of identity theft.</p>
<p>Since Torpig was sending all the HTTP POST data and emails to command &#038; control servers, researchers did statistics on emails and found out that 14% of all captured emails were about jobs and resumes, 10% discussed computer security/malware, 7% discussed money, 6% were sports fans, 5% were worried about exams and their grades, 4% were seeking partners online.</p>
<p>Researchers collected 300,000 unique credentials on 370,000 websites. 28% of people reused their password on multiple domains. There were 173,686 unique passwords.</p>
<p>Researchers converted the passwords in Unix format and tried to crack them with John the Ripper. 56,000 were cracked in less than 65 minutes using brute-force. Using a wordlist 14,000 passwords were cracked in the next 10 minutes. And another 30,000 passwords were cracked in the next 24 hours. That&#8217;s 58% of all passwords cracked in 24 hours.</p>
<p>You&#8217;re welcome to watch the video lecture. It&#8217;s 1h 15m long. It&#8217;s presented by Richard A. Kemmerer.</p>
<div class="center-aligner">
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/2GdqoQJa6r4&#038;hl=en&#038;fs=1&#038;"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/2GdqoQJa6r4&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
Direct URL: <a href="http://www.youtube.com/watch?v=2GdqoQJa6r4">http://www.youtube.com/watch?v=2GdqoQJa6r4</a>
</div>
<p>Here are all the topics in the lecture:</p>
<ul>
<li>[02:00] Botnet terminology - bot, botnet, command &#038; control server, control channel, botmaster.</li>
<li>[03:00] Introduction to the Torpig trojan and Mebroot malware platform.</li>
<li>[05:00] How Torpig works.</li>
<li>[11:30] Torpig HTML injection.</li>
<li>[15:00] Domain fluxing.</li>
<li>[19:15] Taking over Torpig&#8217;s c&#038;c server.</li>
<li>[24:10] Data collection principles.</li>
<li>[26:00] C&#038;c server protocol.</li>
<li>[31:10] Botnet&#8217;s size estimation.</li>
<li>[37:00] Botnet&#8217;s threats: theft of financial information, denial of service, proxy servers, privacy thefts.</li>
<li>[37:30] Threat: Theft of financial information.</li>
<li>[42:00] Threat: Denial of service.</li>
<li>[43:30] Threat: Proxy servers.</li>
<li>[44:20] Threat: Privacy theft.</li>
<li>[47:00] Password analysis.</li>
<li>[50:40] Criminal retribution.</li>
<li>[53:00] Law enforcement.</li>
<li>[58:00] Repatriating the data.</li>
<li>[01:00:00] Ethics.</li>
<li>[01:02:00] Conclusions.</li>
<li>[01:06:00] Questions and answers.</li>
</ul>
<p>For more information see the publication &#8220;<a href='http://www.catonmat.net/blog/wp-content/uploads/2010/01/torpig.pdf' title='Torpig, Your Botnet is My Botnet: Analaysis of a Botnet Takeover'>Your Botnet is My Botnet: Analaysis of a Botnet Takeover</a>.&#8221;</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=doqlg9CH-oQ:5xyngc72rMo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=doqlg9CH-oQ:5xyngc72rMo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=doqlg9CH-oQ:5xyngc72rMo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=doqlg9CH-oQ:5xyngc72rMo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=doqlg9CH-oQ:5xyngc72rMo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=doqlg9CH-oQ:5xyngc72rMo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=doqlg9CH-oQ:5xyngc72rMo:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/doqlg9CH-oQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/how-to-steal-a-botnet-video-lecture-review/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/how-to-steal-a-botnet-video-lecture-review/</feedburner:origLink></item>
		<item>
		<title>MIT Linear Algebra, Lecture 5: Vector Spaces and Subspaces</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/zbwCUNJwsc8/</link>
		<comments>http://www.catonmat.net/blog/mit-linear-algebra-part-five/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 05:40:43 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Linear Algebra]]></category>
<category>a lu</category><category>column space</category><category>column spaces</category><category>identity matrices</category><category>line</category><category>linear algebra</category><category>matlab</category><category>matrix transposition</category><category>mit</category><category>pa lu</category><category>permutation matrices</category><category>permutations</category><category>plane</category><category>r2</category><category>r3</category><category>rn</category><category>subspace</category><category>subspaces</category><category>symmetric matrices</category><category>transpose</category><category>transpose matrices</category><category>transposes</category><category>vector</category><category>vector space</category><category>vector spaces</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/mit-linear-algebra-part-five/</guid>
		<description><![CDATA[This is the fifth post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture five that finally introduces real linear algebra topics such as vector spaces their subspaces and spaces from matrices. But before it does that it closes the topics that were started in the previous lecture [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/YRZPzGU6pwqeOFVqejBnaa1GMwU/0/da"><img src="http://feedads.g.doubleclick.net/~a/YRZPzGU6pwqeOFVqejBnaa1GMwU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YRZPzGU6pwqeOFVqejBnaa1GMwU/1/da"><img src="http://feedads.g.doubleclick.net/~a/YRZPzGU6pwqeOFVqejBnaa1GMwU/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/11/mit-introduction-to-linear-algebra.jpg' alt='MIT Introduction to Linear Algebra' class="post-icon" align="left" />This is the fifth post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture five that finally introduces real linear algebra topics such as <strong>vector spaces</strong> their <strong>subspaces</strong> and <strong>spaces from matrices</strong>. But before it does that it closes the topics that were started in <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-four/">the previous lecture</a> on <strong>permutations</strong>, <strong>transposes</strong> and <strong>symmetric matrices</strong>.</p>
<p>Here is a list of the previous posts in this article series:</p>
<ul>
<li><a href="http://www.catonmat.net/blog/mit-linear-algebra-part-one/">Lecture 1: Geometry of Linear Equations</a></li>
<li><a href="http://www.catonmat.net/blog/mit-linear-algebra-part-two/">Lecture 2: Elimination with Matrices</a></li>
<li><a href="http://www.catonmat.net/blog/mit-linear-algebra-part-three/">Lecture 3: Matrix Multiplication and Inverse Matrices</a></li>
<li><a href="http://www.catonmat.net/blog/mit-linear-algebra-part-four/">Lecture 4: A=LU Factorization</a></li>
</ul>
<h2 style="margin-bottom:10px">Lecture 5: Vector Spaces and Subspaces</h2>
<p>Lecture starts with reminding some facts about permutation matrices. Remember from <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-four/">the previous lecture</a> that permutation matrices P execute row exchanges and they are identity matrices with reordered rows.</p>
<p>Let&#8217;s count how many permutation matrices are there for an n<small>x</small>n matrix.</p>
<p>For a matrix of size 1<small>x</small>1, there is just one permutation matrix - the identity matrix.</p>
<p>For a matrix of size 2<small>x</small>2 there are two permutation matrices - the identity matrix and the identity matrix with rows exchanged.</p>
<p>For a matrix of size 3<small>x</small>3 we may have the rows of the identity matrix rearranged in 6 ways - {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1}.</p>
<p>For a matrix of size 4<small>x</small>4 the number of ways to reorder the rows is the same as the number of ways to rearrange numbers {1,2,3,4}. This is the simplest possible combinatorics problem. The answer is 4! = 24 ways.</p>
<p>In general, for an n<small>x</small>n matrix, there are n! permutation matrices.</p>
<p>Another key fact to remember about permutation matrices is that their inverse P<sup>-1</sup> is their transpose P<sup>T</sup>. Or algebraically P<sup>T</sup>·P = I.</p>
<p>The lecture proceeds to <strong>transpose matrices</strong>. The transpose of a matrix exchanges its columns with rows. Another way to think about it that it flips the matrix over its main diagonal. Transpose of matrix A is denoted by A<sup>T</sup>.</p>
<p>Here is an example of transpose of a 3-by-3 matrix. I color coded the columns to better see how they get exchanged:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/matrix-transpose-3-by-3.gif' alt='Transpose A^T of a 3x3 matrix A' />
</div>
<p>A matrix does not have to be square for its transpose to exist. Here is another example of transpose of a 3-by-2 matrix:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/matrix-transpose-3-by-2.gif' alt='Transpose A^T of a 3x2 matrix A' />
</div>
<p>In algebraic notation transpose is expressed as (A<sup>T</sup>)<sub>ij</sub> = A<sub>ji</sub>, which says that an element a<sub>ij</sub> at position ij get transposed into the position ji.</p>
<p>Here are the rules for matrix transposition:</p>
<ul>
<li>The transpose of A + B is (A + B)<sup>T</sup> = A<sup>T</sup> + B<sup>T</sup>.</li>
<li>The transpose of A·B is (A·B)<sup>T</sup> = B<sup>T</sup>·A<sup>T</sup>.</li>
<li>The transpose of A·B·C is (A·B·C)<sup>T</sup> = C<sup>T</sup>·B<sup>T</sup>·A<sup>T</sup>.</li>
<li>The transpose of A<sup>-1</sup> is (A<sup>-1</sup>)<sup>T</sup> = (A<sup>T</sup>)<sup>-1</sup>.</li>
</ul>
<p>Next the lecture continues with <strong>symmetric matrices</strong>. A symmetric matrix has its transpose equal to itself, i.e., A<sup>T</sup> = A. It means that we can flip the matrix along the diagonal (transpose it) but it won&#8217;t change.</p>
<p>Here is an example of a symmetric matrix. Notice that the elements on opposite sides of the diagonal are equal:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/symmetric-matrix.gif' alt='Symmetric matrix' />
</div>
<p>Now check this out. If you have a matrix R that is not symmetric and you multiply it with its transpose R<sup>T</sup> as R·R<sup>T</sup>, you get a symmetric matrix! Here is an example:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/matrix-multiplication-produces-symmetric-matrix.gif' alt='Matrix times its transpose is symmetric matrix' />
</div>
<p>Are you wondering why it&#8217;s true? The proof is really simple. Remember that matrix is symmetric if its transpose is equal to itself. Now what&#8217;s the transpose of the product R·R<sup>T</sup>? It&#8217;s (R·R<sup>T</sup>)<sup>T</sup> = (R<sup>T</sup>)<sup>T</sup>·R<sup>T</sup> = R·R<sup>T</sup> - it&#8217;s the same product, which means that R·R<sup>T</sup> is always symmetric.</p>
<p>Here is another cool fact - the inverse of a symmetric matrix (if it exists) is also symmetric. Here is the proof. Suppose A is symmetric, then the transpose of A<sup>-1</sup> is (A<sup>-1</sup>)<sup>T</sup> = (A<sup>T</sup>)<sup>-1</sup>. But A<sup>T</sup> = A, therefore (A<sup>T</sup>)<sup>-1</sup> = A<sup>-1</sup>.</p>
<p>At this point lecture finally reaches the fundamental topic of linear algebra - <strong>vector spaces</strong>. As usual, it introduces the topic by examples.</p>
<p>Example 1: Vector space <strong>R</strong><sup>2</sup> - all 2-dimensional vectors. Some of the vectors in this space are (3, 2), (0, 0), (π, e) and infinitely many others. These are all the vectors with two components and they represent the xy plane. </p>
<p>Example 2: Vector space <strong>R</strong><sup>3</sup> - all vectors with 3 components (all 3-dimensional vectors).</p>
<p>Example 3: Vector space <strong>R</strong><sup>n</sup> - all vectors with n components (all n-dimensional vectors).</p>
<p>What makes these vectors vector spaces is that they are closed under multiplication by a scalar and addition, i.e., vector space must be closed under linear combination of vectors. What I mean by that is if you take two vectors and add them together or multiply them by a scalar they are still in the same space.</p>
<p>For example, take a vector (1,2,3) in <strong>R</strong><sup>3</sup>. If we multiply it by any number α, it&#8217;s still in <strong>R</strong><sup>3</sup> because α·(1,2,3) = (α, 2α, 3α). Similarly, if we take any two vectors (a, b, c) and (d, e, f) and add them together, the result is (a+d, b+e, f+c) and it&#8217;s still in <strong>R</strong><sup>3</sup>.</p>
<p>There are actually <a href="http://mathworld.wolfram.com/VectorSpace.html">8 axioms</a> that the vectors must satisfy for them to make a space, but they are not listed in this lecture.</p>
<p>Here is an example of not-a-vector-space. It&#8217;s 1/4 of <strong>R</strong><sup>2</sup> (the 1st quadrant). The <span style="color: green">green vectors</span> are in the 1st quadrant but the <span style="color: red">red one</span> is not:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/not-a-vector-space.gif' alt='Not a vector space' /><br />
<small>An example of not-a-vector-space.</small>
</div>
<p>This is not a vector space because the <span style="color: green">green vectors</span> in the space are not closed under multiplication by a scalar. If we take the vector (3,1) and multiply it by -1 we get the <span style="color: red">red vector</span> (-3, -1) but it&#8217;s not in the 1st quadrant, therefore it&#8217;s not a vector space.</p>
<p>Next, Gilbert Strang introduces <strong>subspaces</strong> of vector spaces.</p>
<p>For example, any line in <strong>R</strong><sup>2</sup> that goes through the origin (0, 0) is a subspace of <strong>R</strong><sup>2</sup>. Why? Because if we take any vector on the line and multiply it by a scalar, it&#8217;s still on the line. And if we take any two vectors on the line and add them together, they are also still on the line. The requirement for a subspace is that the vectors in it do not go outside when added together or multiplied by a number.</p>
<p>Here is a visualization. The blue line is a subspace of <strong>R</strong><sup>2</sup> because the red vectors on it can&#8217;t go outside of line:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/subspace-of-r2.gif' alt='Subspace of R2' /><br />
<small>An example of subspace of <strong>R</strong><sup>2</sup>.</small>
</div>
<p>And example of not-a-subspace of <strong>R</strong><sup>2</sup> is any line that does not go through the origin. If we take any vector on the line and multiply it by 0, we get the zero vector, but it&#8217;s not on the line. Also if we take two vectors and add them together, they are not on the line. Here is a visualization:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/not-a-vector-subspace.gif' alt='Not a vector subspace' /><br />
<small>An example of not-a-subspace of <strong>R</strong><sup>2</sup>.</small>
</div>
<p>Why not list all the subspaces of <strong>R</strong><sup>2</sup>. They are:</p>
<ul>
<li>the <strong>R</strong><sup>2</sup> itself,</li>
<li>any line through the origin (0, 0),</li>
<li>the zero vector (0, 0).</li>
</ul>
<p>And all the subspaces of <strong>R</strong><sup>3</sup> are:</p>
<ul>
<li>the <strong>R</strong><sup>3</sup> itself,</li>
<li>any line through the origin (0, 0, 0),</li>
<li>any plane through the origin (0, 0, 0),</li>
<li>the zero vector.</li>
</ul>
<p>The last 10 minutes of the lecture are spent on <strong>column spaces of matrices</strong>.</p>
<p>The column space of a matrix is made out of all the linear combinations of its columns. For example, given this matrix:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/matrix-a.gif' alt='Matrix a' />
</div>
<p>The column space C(A) is the set of all vectors {α·(1,2,4) + β·(3,3,1)}. In fact, this column space is a subspace of <strong>R</strong><sup>3</sup> and it forms a plane through the origin.</p>
<p>More about column spaces in the next lecture.</p>
<p>You&#8217;re welcome to watch the video lecture five:</p>
<div class="center-aligner">
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/JibVXBElKL0&#038;hl=en_US&#038;fs=1&#038;"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/JibVXBElKL0&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
Direct link: <a href="http://www.youtube.com/watch?v=JibVXBElKL0">http://www.youtube.com/watch?v=JibVXBElKL0</a>
</div>
<p>Topics covered in lecture five:</p>
<ul>
<li>[01:30] Permutations.</li>
<li>[03:00] A=LU elimination without row exchanges.</li>
<li>[03:50] How Matlab does A=LU elimination.</li>
<li>[04:50] PA=LU elimination with row exchanges</li>
<li>[06:40] Permutation matrices.</li>
<li>[07:25] How many permutation matrices are there?</li>
<li>[08:30] Permutation matrix properties.</li>
<li>[10:30] Transpose matrices.</li>
<li>[11:50] General formula for transposes: (A<sup>T</sup>)<sub>ij</sub> = A<sub>ji</sub>.</li>
<li>[13:06] Symmetric matrices.</li>
<li>[13:30] Example of a symmetric matrix.</li>
<li>[15:15] R·R<sup>T</sup> is always symmetric.</li>
<li>[18:23] Why is R·R<sup>T</sup> symmetric?</li>
<li>[20:50] Vector spaces.</li>
<li>[22:05] Examples of vector spaces.</li>
<li>[22:55] Real vector space <strong>R</strong><sup>2</sup>.</li>
<li>[23:20] Picture of <strong>R</strong><sup>2</sup> - xy plane.</li>
<li>[26:50] Vector space <strong>R</strong><sup>3</sup>.</li>
<li>[28:00] Vector space <strong>R</strong><sup>n</sup>.</li>
<li>[30:00] Example of not a vector space.</li>
<li>[32:00] Subspaces of vector spaces.</li>
<li>[33:00] A vector space inside <strong>R</strong><sup>2</sup>.</li>
<li>[34:35] A line in <strong>R</strong><sup>2</sup> that is subspace.</li>
<li>[34:50] A line in <strong>R</strong><sup>2</sup> that is not a subspace.</li>
<li>[36:30] All subspaces of <strong>R</strong><sup>2</sup>.</li>
<li>[39:30] All subspaces of <strong>R</strong><sup>3</sup>.</li>
<li>[40:20] Subspaces of matrices.</li>
<li>[41:00] Column spaces of matrices C(A).</li>
<li>[44:10] Example of column space of matrix with columns in <strong>R</strong><sup>3</sup>.</li>
</ul>
<p>Here are my notes of lecture five:</p>
<div class="center-aligner">
<a href='http://www.catonmat.net/blog/wp-content/uploads/2010/01/mit-linear-algebra-lecture-05.jpg' title='MIT Linear Algebra, Lecture 5: Vector Spaces and Subspaces'><img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/mit-linear-algebra-lecture-05-thumb.jpg' alt='MIT Linear Algebra, Lecture 5: Vector Spaces and Subspaces' /></a><br />
<small>My notes of linear algebra lecture 5 on vector spaces and subspaces.</small>
</div>
<p>Have fun with this lecture! The next post is going to be more about column spaces and null spaces of matrices.</p>
<p>PS. This course is taught from <a href="http://www.amazon.com/gp/product/0980232716?tag=catonmat-20">Introduction to Linear Algebra</a> textbook. Get it here:</p>
<div class="center-aligner">
<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=freesciencand-20&#038;o=1&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=10FE9736YVPPT7A0FBG2&#038;asins=0980232716" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=zbwCUNJwsc8:7WWTmyJnpao:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=zbwCUNJwsc8:7WWTmyJnpao:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=zbwCUNJwsc8:7WWTmyJnpao:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=zbwCUNJwsc8:7WWTmyJnpao:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=zbwCUNJwsc8:7WWTmyJnpao:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=zbwCUNJwsc8:7WWTmyJnpao:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=zbwCUNJwsc8:7WWTmyJnpao:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/zbwCUNJwsc8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/mit-linear-algebra-part-five/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/mit-linear-algebra-part-five/</feedburner:origLink></item>
		<item>
		<title>Vim Plugins You Should Know About, Part VI: nerd_tree.vim</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/x9rff1I_bKg/</link>
		<comments>http://www.catonmat.net/blog/vim-plugins-nerdtree-vim/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 07:15:27 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Programming]]></category>
<category>directories</category><category>file system</category><category>files</category><category>marty grenfell</category><category>nerd tree</category><category>nerdtree</category><category>plugins</category><category>scrooloose</category><category>tree</category><category>vim</category><category>vim plugin</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/vim-plugins-nerdtree-vim/</guid>
		<description><![CDATA[This is the sixth post in the article series &#8220;Vim Plugins You Should Know About&#8220;. This time I am going to introduce you to a vim plugin called &#8220;nerd_tree.vim&#8220;. It&#8217;s so useful that I can&#8217;t imagine working without it in vim.
Nerd Tree is a nifty plugin that allows you to explore the file system and [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/Ijcj4wh3hgXoTqUHD5MIbKDsVek/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ijcj4wh3hgXoTqUHD5MIbKDsVek/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ijcj4wh3hgXoTqUHD5MIbKDsVek/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ijcj4wh3hgXoTqUHD5MIbKDsVek/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2008/12/vim-plugins-surround-vim.gif' alt='Vim Plugins, surround.vim' class="post-icon" align="left" />This is the sixth post in the article series &#8220;<strong>Vim Plugins You Should Know About</strong>&#8220;. This time I am going to introduce you to a vim plugin called &#8220;<strong>nerd_tree.vim</strong>&#8220;. It&#8217;s so useful that I can&#8217;t imagine working without it in vim.</p>
<p><strong>Nerd Tree</strong> is a nifty plugin that allows you to explore the file system and open files and directories directly from vim. It opens the file system tree in a new vim window and you may use keyboard shortcuts and mouse to open files in new tabs, in new horizontal and vertical splits, quickly navigate between directories and create bookmarks for your most important projects.</p>
<p>This plugin was written by <strong>Marty Grenfell</strong> (also known as <strong>scrooloose</strong>).</p>
<p>Previous articles in the series:</p>
<ul>
<li><a href="http://www.catonmat.net/blog/vim-plugins-surround-vim/">Part I: surround.vim</a> - find and edit surrounding parens, quotes, html tags, etc.</li>
<li><a href="http://www.catonmat.net/blog/vim-plugins-repeat-vim/">Part II: repeat.vim</a> - repeat the previous surrounding command.</li>
<li><a href="http://www.catonmat.net/blog/vim-plugins-matchit-vim/">Part III: matchit.vim</a> - extends the functionality of % key.</li>
<li><a href="http://www.catonmat.net/blog/vim-plugins-snipmate-vim/">Part IV: snipmate.vim</a> - the best snippet plugin for vim</li>
<li><a href="http://www.catonmat.net/blog/vim-plugins-a-vim/">Part V: a.vim</a> - quickly change between source and header files (.c/.h).</li>
</ul>
<p>Ps. Please help me reach 10,000 RSS subscribers. I am almost there. If you enjoy my posts and have not yet subscribed, subscribe <a href="http://www.catonmat.net/feed/">here!</a></p>
<h2 style="margin-bottom:10px">How to use nerd_tree.vim?</h2>
<p>Nerd Tree plugin can be activated by the <code>:NERDTree</code> vim command. It will open in vim as a new vertical split on the left:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/nerd-tree-vim.png' alt='Vim Nerd Tree' /><br />
<small>A screenshot of Nerd Tree plugin in action.</small>
</div>
<p>Here are the basics of how to use the plugin:</p>
<ul>
<li>Use the natural vim navigation keys <code>hjkl</code> to navigate the files.</li>
<li>Press <code>o</code> to open the file in a new buffer or open/close directory.</li>
<li>Press <code>t</code> to open the file in a new tab.</li>
<li>Press <code>i</code> to open the file in a new horizontal split.</li>
<li>Press <code>s</code> to open the file in a new vertical split.</li>
<li>Press <code>p</code> to go to parent directory.</li>
<li>Press <code>r</code> to refresh the current directory.</li>
</ul>
<p>All other keyboard shortcuts can be found by pressing <code>?</code>. It will open a special help screen with the shortcut listings. Press <code>?</code> again to get back to file tree.</p>
<p>To close the plugin execute the <code>:NERDTreeClose</code> command.</p>
<p>Typing <code>:NERDTree</code> and <code>:NERDTreeClose</code> all the time is really inconvenient. Therefore I have mapped the toggle command <strong>:NERDTreeToggle</strong> to the F2 key. This way I can quickly open and close Nerd Tree whenever I wish. You can also map it to F2 by putting <code>map &lt;F2&gt; :NERDTreeToggle&lt;CR&gt;</code> in your .vimrc file.</p>
<h2 style="margin-bottom:10px">How to install nerd_tree.vim?</h2>
<p>To get the latest version:</p>
<ul>
<li>1. Download <a href="http://www.vim.org/scripts/script.php?script_id=1658">NERD_tree.zip</a>.</li>
<li>2. Extract NERD_tree.zip to ~/.vim (on Unix/Linux) or ~\vimfiles (on Windows).</li>
<li>3. Run :helptags ~/.vim/doc (on Unix/Linux) or :helptags ~/vimfiles/doc (on Windows) to rebuild the tags file (so that you can read :help NERD_tree.)</li>
<li>4. Restart Vim.</li>
</ul>
<h2 style="margin-bottom:10px">Have Fun!</h2>
<p>Have fun exploring your files with this awesome plugin and until next time!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=x9rff1I_bKg:pjlVRpxADhY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=x9rff1I_bKg:pjlVRpxADhY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=x9rff1I_bKg:pjlVRpxADhY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=x9rff1I_bKg:pjlVRpxADhY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=x9rff1I_bKg:pjlVRpxADhY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=x9rff1I_bKg:pjlVRpxADhY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=x9rff1I_bKg:pjlVRpxADhY:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/x9rff1I_bKg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/vim-plugins-nerdtree-vim/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/vim-plugins-nerdtree-vim/</feedburner:origLink></item>
		<item>
		<title>Using Fibonacci Numbers to Convert from Miles to Kilometers and Vice Versa</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/BVZ_07TeOas/</link>
		<comments>http://www.catonmat.net/blog/using-fibonacci-numbers-to-convert-from-miles-to-kilometers/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 06:20:52 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Mathematics]]></category>
<category>conversion</category><category>convert</category><category>fibonacci</category><category>golden ratio</category><category>kilometers</category><category>km</category><category>miles</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/using-fibonacci-numbers-to-convert-from-miles-to-kilometers/</guid>
		<description><![CDATA[I learned an interesting fact about Fibonacci numbers recently while watching a lecture on number theory. Fibonacci numbers can be used to approximately convert from miles to kilometers and back.
Here is how.
Take two consecutive Fibonacci numbers, for example 5 and 8. And you&#8217;re done converting. No kidding – there are 8 kilometers in 5 miles. [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/LyB8B7RVlGlgRXy5dOpWG3lKqms/0/da"><img src="http://feedads.g.doubleclick.net/~a/LyB8B7RVlGlgRXy5dOpWG3lKqms/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/LyB8B7RVlGlgRXy5dOpWG3lKqms/1/da"><img src="http://feedads.g.doubleclick.net/~a/LyB8B7RVlGlgRXy5dOpWG3lKqms/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/fibonacci-sunflower.jpg' alt='Fibonacci Sunflower' class='post-icon' align='left' />I learned an interesting fact about Fibonacci numbers recently while watching a lecture on number theory. Fibonacci numbers can be used to approximately convert from miles to kilometers and back.</p>
<p>Here is how.</p>
<p>Take two consecutive Fibonacci numbers, for example 5 and 8. And you&#8217;re done converting. No kidding – there are 8 kilometers in 5 miles. To convert back just read the result from the other end - there are 5 miles in 8 km!</p>
<p>Another example. Let&#8217;s take the consecutive Fibonacci numbers 21 and 34. What this tells us is that there are approximately 34 km in 21 miles and vice versa. (The exact answer is 33.79 km.)</p>
<p>If you need to convert a number that is not a Fibonacci number, just express the original number as a sum of Fibonacci numbers and do the conversion for each Fibonacci number separately. </p>
<p>For example, how many kilometers are there in 100 miles? Number 100 can be expressed as a sum of Fibonacci numbers 89 + 8 + 3. Now, the Fibonacci number following 89 is 144, the Fibonacci number following 8 is 13 and the Fibonacci number following 3 is 5. Therefore the answer is 144 + 13 + 5 = 162 kilometers in 100 miles. This is less than 1% off from the precise answer, which is 160.93 km.</p>
<p>Another example, how many miles are there in 400 km? Well, 400 is 377 + 21 + 2. Since we are going the opposite way now from miles to km, we need the preceding Fibonacci numbers. They are 233, 13 and 1. Therefore there are 233 + 13 + 1 = 247 miles in 400 km. (The correct answer is 248.55 miles.)</p>
<p>Just remember that if you need to convert from km to miles, you need to find the preceding Fibonacci number. But if you need to convert from miles to km, you need the subsequent Fibonacci number.</p>
<p>If the distance you&#8217;re converting can be expressed as a single Fibonacci number, then for numbers greater than 21 the error is always around 0.5%. However, if the distance needs to be composed as a sum of <code>n</code> Fibonacci numbers, then the error will be around sqrt(n)·0.5%.</p>
<p><strong>Here&#8217;s why it works.</strong></p>
<p>Fibonacci numbers have a property that the ratio of two consecutive numbers tends to the <a href="http://mathworld.wolfram.com/GoldenRatio.html">Golden ratio</a> as numbers get bigger and bigger. The Golden ratio is a number and it happens to be approximately 1.618.</p>
<p>Coincidentally, there are 1.609 kilometers in a mile, which is within 0.5% of the Golden ratio.</p>
<p>Now that we know these two key facts, we can figure out how to do the conversion. If we take two consecutive Fibonacci numbers, F<sub>n+1</sub> and F<sub>n</sub>, we know that their ratio F<sub>n+1</sub>/F<sub>n</sub> is 1.618. Since the ratio is approximately the same as kilometers per mile, we can write F<sub>n+1</sub>/F<sub>n</sub> = [mile]/[km]. It follows that F<sub>n</sub>·[mile] = F<sub>n+1</sub>·[km], which translates to English as &#8220;n-th Fibonacci number in miles is the same as (n+1)-th Fibonacci number in kilometers&#8221;.</p>
<p>That&#8217;s all there is to it. A pure coincidence that the Golden ratio is almost the same as kilometers in a mile.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=BVZ_07TeOas:A_2nU1yWu3I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=BVZ_07TeOas:A_2nU1yWu3I:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=BVZ_07TeOas:A_2nU1yWu3I:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=BVZ_07TeOas:A_2nU1yWu3I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=BVZ_07TeOas:A_2nU1yWu3I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=BVZ_07TeOas:A_2nU1yWu3I:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=BVZ_07TeOas:A_2nU1yWu3I:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/BVZ_07TeOas" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/using-fibonacci-numbers-to-convert-from-miles-to-kilometers/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/using-fibonacci-numbers-to-convert-from-miles-to-kilometers/</feedburner:origLink></item>
		<item>
		<title>Famous Perl One-Liners Explained, Part IV: String and Array Creation</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/Yb-bhDJHsVI/</link>
		<comments>http://www.catonmat.net/blog/perl-one-liners-explained-part-four/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 05:00:02 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Programming]]></category>
<category>alphabet</category><category>array</category><category>ascii</category><category>dec</category><category>dec to hex</category><category>even</category><category>hex</category><category>length</category><category>list</category><category>list context</category><category>odd</category><category>one liner</category><category>one liners</category><category>password</category><category>password generator</category><category>perl</category><category>perl1line.txt</category><category>qw</category><category>random</category><category>scalar context</category><category>sprintf</category><category>string</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/perl-one-liners-explained-part-four/</guid>
		<description><![CDATA[This is the fourth part of a nine-part article on famous Perl one-liners. In this part I will create various one-liners for string and array creation. See part one for introduction of the series.
Famous Perl one-liners is my attempt to create &#8220;perl1line.txt&#8221; that is similar to &#8220;awk1line.txt&#8221; and &#8220;sed1line.txt&#8221; that have been so popular among [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/4S1vda3Ha-4hoYmBHdqozwyr8y0/0/da"><img src="http://feedads.g.doubleclick.net/~a/4S1vda3Ha-4hoYmBHdqozwyr8y0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/4S1vda3Ha-4hoYmBHdqozwyr8y0/1/da"><img src="http://feedads.g.doubleclick.net/~a/4S1vda3Ha-4hoYmBHdqozwyr8y0/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/02/perl-one-liners.jpg' alt='Perl One Liners' class='post-icon' align='left' />This is the fourth part of a nine-part article on <strong>famous Perl one-liners</strong>. In this part I will create various one-liners for <strong>string and array creation</strong>. See <a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-one/">part one</a> for introduction of the series.</p>
<p>Famous Perl one-liners is my attempt to create &#8220;<strong>perl1line.txt</strong>&#8221; that is similar to &#8220;<a href="http://www.catonmat.net/blog/awk-one-liners-explained-part-one/">awk1line.txt</a>&#8221; and &#8220;<a href="http://www.catonmat.net/blog/sed-one-liners-explained-part-one/">sed1line.txt</a>&#8221; that have been so popular among Awk and Sed programmers.</p>
<p>The article on famous Perl one-liners will consist of nine parts:</p>
<ul>
<li><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-one/">Part I: File spacing</a>.</li>
<li><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-two/">Part II: Line numbering</a>.</li>
<li><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-three/">Part III: Calculations</a>.</li>
<li><strong>Part IV: String creation and array creation (this part).</strong></li>
<li>Part V: Text conversion and substitution.</li>
<li>Part VI: Selective printing and deleting of certain lines.</li>
<li>Part VII: Handy regular expressions.</li>
<li>Part VIII: Release of perl1line.txt.</li>
<li>Part IX: Release of Perl One-Liners e-book.</li>
</ul>
<p>I decided that there will be two new parts in this series. The most powerful feature in Perl is its regular expressions, therefore I will write a part on &#8220;<strong>Handy Perl regular expressions</strong>.&#8221; I also decided to <strong>publish an e-book</strong> after I am done with the series, so that will be the last part of this series. Everyone who&#8217;s subscribed to my blog will get a free copy! <a href="http://www.catonmat.net/feed/">Subscribe to my blog now!</a></p>
<p>I also updated the <a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-three/">previous part on calculations</a> with 14 new one-liners on finding values of constants pi and e, doing date calculations, finding factorial, greatest common divisor, least common multiple, generating random numbers, generating permutations, finding power sets and doing some IP address conversions.</p>
<p>Here are today&#8217;s one-liners:</p>
<h2 style="margin-bottom: 10px">String Creation and Array Creation</h2>
<p><strong>49. Generate and print the alphabet.</strong></p>
<pre>perl -le 'print a..z'</pre>
<p>This one-liner prints all the letters from a to z as <code>abcdefghijklmnopqrstuvwxyz</code>. The letters are generated by the range operator <code>..</code>. The range operator, when used in the list context (which is forced here by <code>print</code>) on strings, uses the magical auto-increment algorithm that advances the string to the next character. So in this one-liner the auto-increment algorithm on the range <code>a..z</code> produces all the letters from a to z.</p>
<p>I really golfed this one-liner. If you used <code>strict</code> it would not work because of barewords <code>a</code> and </code>z</code>. Semantically more correct version is this:</p>
<pre>perl -le 'print ("a".."z")'</pre>
<p>Remember that the range operator <code>..</code> produced a list of values. If you wish, you may print them comma separated by setting the <code>$,</code> special variable:</p>
<pre>perl -le '$, = ","; print ("a".."z")'</pre>
<p>There are many more special variables. Take a look at my <a href="http://www.catonmat.net/blog/perls-special-variable-cheat-sheet/">special variable cheat sheet</a> for a complete listing.</p>
<p>Syntactically more appealing is to use join to separate the list with a comma:</p>
<pre>perl -le 'print join ",", ("a".."z")'</pre>
<p>Here the list <code>a..z</code> gets joined by a comma before printing.</p>
<p><strong>50. Generate and print all the strings from &#8220;a&#8221; to &#8220;zz&#8221;.</strong></p>
<pre>perl -le 'print ("a".."zz")'</pre>
<p>Here the range operator <code>..</code> is used again. This time it does not stop at &#8220;z&#8221; as in the previous one-liner, but advances z by one-character producing &#8220;aa&#8221;, then it keeps going, producing &#8220;ab&#8221;, &#8220;ac&#8221;, &#8230;, until it hits &#8220;az&#8221;. At this point it advances the string to &#8220;ba&#8221;, continues with &#8220;bb&#8221;, &#8220;bc&#8221;, &#8230;, until it reaches &#8220;zz&#8221;. </p>
<p>Similarly, you may generate all strings from &#8220;aa&#8221; to &#8220;zz&#8221; by:</p>
<pre>perl -le 'print "aa".."zz"'</pre>
<p>Here it goes like &#8220;aa&#8221;, &#8220;ab&#8221;, &#8230;, &#8220;az&#8221;, &#8220;ba&#8221;, &#8220;bb&#8221;, &#8230;, &#8220;bz&#8221;, &#8220;ca&#8221;, &#8230; &#8220;zz&#8221;.</p>
<p><strong>51. Create a hex lookup table.</strong></p>
<pre>@hex = (0..9, "a".."f")</pre>
<p>Here the array <code>@hex</code> gets filled with values <code>0, 1, 2, 3, 4, 5, 6, 7, 8, 9</code> and letters <code>a, b, c, d, e, f</code>.</p>
<p>You may use this array to convert a number (in variable <code>$num</code>) from decimal to hex using base conversion formula:</p>
<pre>perl -le '$num = 255; @hex = (0..9, "a".."f"); while ($num) { $s = $hex[($num%16)&#038;15].$s; $num = int $num/16 } print $s'</pre>
<p>Surely, much easier way to convert a number to hex is just using the <code>printf</code> function (or <code>sprintf</code> function) with <code>%x</code> format specifier. (The example above just illustrates a use of a hex lookup table that we created by using the range operator.)</p>
<pre>perl -le '$hex = sprintf("%x", 255); print $hex'</pre>
<p>(See my Perl <a href="http://www.catonmat.net/blog/perl-pack-unpack-printf-cheat-sheet/">printf and sprintf format cheat</a> sheet for all the format specifiers.)</p>
<p>To convert the number back from hex to dec use the </code>hex</code> function:</p>
<pre>perl -le '$num = "ff"; print hex $num'</pre>
<p>The <code>hex</code> function takes a hex string (beginning with or without &#8220;0x&#8221;) and converts it to decimal.</p>
<p><strong>52. Generate a random 8 character password.</strong></p>
<pre>perl -le 'print map { ("a".."z")[rand 26] } 1..8'</pre>
<p>Here the map function executes <code>("a".."z")[rand 26]</code> code 8 times (because it iterates over the dummy range <code>1..8</code>). In each iteration the code chooses a random letter from the alphabet. When <code>map</code> is done iterating, it returns the generated list of characters and <code>print</code> function prints it out by concatenating all the characters together.</p>
<p>If you also wish to include numbers in the password, add <code>0..9</code> to the list of characters to choose from and change <code>26</code> to <code>36</code> as there are 36 different characters to choose from:</p>
<pre>perl -le 'print map { ("a".."z", 0..9)[rand 36] } 1..8'</pre>
<p>If you need a longer password, change <code>1..8</code> to <code>1..20</code> to generate a 20 character long password.</p>
<p><strong>53. Create a string of specific length.</strong></p>
<pre>perl -le 'print "a"x50'</pre>
<p>Operator <code>x</code> is the repetition operator. This one-liner creates a string of 50 letters &#8220;a&#8221; and prints it.</p>
<p>If the repetition operator is used in list context, it creates a list (instead of scalar) with the given elements repeated:</p>
<pre>perl -le '@list = (1,2)x20; print "@list"'</pre>
<p>This one liner creates a list of twenty repetitions of (1, 2) (it looks like (1, 2, 1, 2, 1, 2, &#8230;)).</p>
<p><strong>54. Create an array from a string.</strong></p>
<pre>@months = split ' ', "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"</pre>
<p>Here the <code>@months</code> gets filled with values from the string containing month names. As each month name is separated by a space, the <code>split</code> function splits them and puts them in <code>@months</code>. This way <code>$months[0]</code> contains &#8220;Jan&#8221;, <code>$months[1]</code> contains &#8220;Feb&#8221;, &#8230;, and <code>$months[11]</code> contains &#8220;Dec&#8221;.</p>
<p>Another way to do the same is by using <code>qw//</code> operator:</p>
<pre>@months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/</pre>
<p>The <code>qw//</code> operator takes a space separated string and creates an array with each word being an array element.</p>
<p><strong>55. Create a string from an array.</strong></p>
<pre>@stuff = ("hello", 0..9, "world"); $string = join '-', @stuff</pre>
<p>Here the values in array <code>@stuff</code> get turned in a string <code>$string</code> that has them separated by a hyphen. Turning an array in a string was done by the <code>join</code> function that takes a separator and a list, and concatenates the items in the list in a single string, separated by the separator.</p>
<p><strong>56. Find the numeric values for characters in the string.</strong></p>
<pre>perl -le 'print join ", ", map { ord } split //, "hello world"'</pre>
<p>This one-liner takes the string &#8220;hello world&#8221;, splits it into a list of characters by <code>split //, "hello world"</code>, then it <code>map</code>s the <code>ord</code> function onto each of the characters, which returns the numeric, native 8-bit encoding (like ASCII or EBCDIC) of the character. Finally all the numeric values get joined together by a comma and get printed out.</p>
<p>Another way to do the same is use the <code>unpack</code> function and specify <code>C*</code> as the unpacking template (C means unsigned character and * means as many characters there are):</p>
<pre>perl -le 'print join ", ", unpack("C*", "hello world")'</pre>
<p><strong>57. Convert a list of numeric ASCII values into a string.</strong></p>
<pre>perl -le '@ascii = (99, 111, 100, 105, 110, 103); print pack("C*", @ascii)'</pre>
<p>Just as we unpacked a string into a list of values with the <code>C*</code> template in the one-liner above, we can pack them back into a string.</p>
<p>Another way to do the same is use the <code>chr</code> function that takes the code point value and returns the corresponding character:</p>
<pre>perl -le '@ascii = (99, 111, 100, 105, 110, 103); print map { chr } @ascii'</pre>
<p>Similar to one-liner #55 above, function <code>chr</code> gets mapped onto each value in the <code>@ascii</code> producing the characters.</p>
<p><strong>58. Generate an array with odd numbers from 1 to 100.</strong></p>
<pre>perl -le '@odd = grep {$_ % 2 == 1} 1..100; print "@odd"'</pre>
<p>This one-liner generates an array of odd numbers from 1 to 99 (as 1, 3, 5, 7, 9, 11, &#8230;, 99). It uses the <code>grep</code> function that evaluates the given code <code>$_ % 2 == 1</code> for each element in the given list <code>1..100</code> and returns only the elements that had the code evaluate to true. In this case the code tests if the reminder of the number is 1. If it is, the number is odd and it has to be put in the <code>@odd</code> array.</p>
<p>Another way to write is by remembering that odd numbers have the low-bit set and testing this fact:</p>
<pre>perl -le '@odd = grep { $_ &#038; 1 } 1..100; print "@odd"'</pre>
<p>Expression <code>$_ &#038; 1</code> isolates the low-bit, and grep selects only the numbers with low-bit set (odd numbers).</p>
<p>See my <a href="http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/">explanation of bit-hacks</a> for full explanation and other related bit-hacks.</p>
<p><strong>59. Generate an array with even numbers from 1 to 100.</strong></p>
<pre>perl -le '@even = grep {$_ % 2 == 0} 1..100; print "@even"'</pre>
<p>This is almost the same as the previous one-liner, except the condition <code>grep</code> tests for is &#8220;is the number even (reminder dividing by 2 is zero)?&#8221;</p>
<p><strong>60. Find the length of the string.</strong></p>
<pre>perl -le 'print length "one-liners are great"'</pre>
<p>Just for completeness, the <code>length</code> subroutine finds the length of the string.</p>
<p><strong>61. Find the number of elements in an array.</strong></p>
<pre>perl -le '@array = ("a".."z"); print scalar @array'</pre>
<p>Evaluating an array in a scalar context returns the number of elements in it.</p>
<p>Another way to do the same is by adding one to the last index of the array:</p>
<pre>
perl -le '@array = ("a".."z"); print $#array + 1'
</pre>
<p>Here <code>$#array</code> returns the last index in array <code>@array</code>. Since it&#8217;s a number one less than the number of elements, we add 1 to the result to find the total number of elements in the array.</p>
<h2 style="margin-bottom: 10px">Have Fun!</h2>
<p>Have fun with these one-liners for now. The next part is going to be about text conversion and substitution.</p>
<p><strong>Can you think of other string creating and array creation one-liners that I didn&#8217;t include here?</strong></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=Yb-bhDJHsVI:UBrD_cX4n-M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=Yb-bhDJHsVI:UBrD_cX4n-M:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=Yb-bhDJHsVI:UBrD_cX4n-M:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=Yb-bhDJHsVI:UBrD_cX4n-M:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=Yb-bhDJHsVI:UBrD_cX4n-M:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=Yb-bhDJHsVI:UBrD_cX4n-M:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=Yb-bhDJHsVI:UBrD_cX4n-M:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/Yb-bhDJHsVI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/perl-one-liners-explained-part-four/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/perl-one-liners-explained-part-four/</feedburner:origLink></item>
		<item>
		<title>MIT Linear Algebra, Lecture 4: A=LU Factorization</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/UHfx79QKNUU/</link>
		<comments>http://www.catonmat.net/blog/mit-linear-algebra-part-four/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 12:20:56 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Linear Algebra]]></category>
<category>a ldu decomposition</category><category>a ldu factorization</category><category>a lu decomposition</category><category>a lu factorization</category><category>elementary matrix</category><category>elimination matrix</category><category>inverse matrices</category><category>linear algebra</category><category>mit</category><category>transpose matrices</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/mit-linear-algebra-part-four/</guid>
		<description><![CDATA[This is the fourth post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture four on factorizing a matrix A into a product of a lower-triangular matrix L and an upper-triangular matrix U, or in other words A=LU. The lecture also shows how to find the inverse of [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/c9H85CZ3Dq0fTTfgKFprQgZHync/0/da"><img src="http://feedads.g.doubleclick.net/~a/c9H85CZ3Dq0fTTfgKFprQgZHync/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/c9H85CZ3Dq0fTTfgKFprQgZHync/1/da"><img src="http://feedads.g.doubleclick.net/~a/c9H85CZ3Dq0fTTfgKFprQgZHync/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/11/mit-introduction-to-linear-algebra.jpg' alt='MIT Introduction to Linear Algebra' class="post-icon" align="left" />This is the fourth post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture four on <strong>factorizing</strong> a matrix A into a product of a <strong>lower-triangular</strong> matrix L and an <strong>upper-triangular</strong> matrix U, or in other words A=LU. The lecture also shows how to find the <strong>inverse of matrix product</strong> A·B, how to find the <strong>inverse of transposed matrix</strong> A<sup>T</sup>, and introduces <strong>permutation matrices</strong>.</p>
<p>Here are the previous lectures:</p>
<ul>
<li><a href="http://www.catonmat.net/blog/mit-linear-algebra-part-one/">Lecture 1: Geometry of Linear Equations</a></li>
<li><a href="http://www.catonmat.net/blog/mit-linear-algebra-part-two/">Lecture 2: Elimination with Matrices</a></li>
<li><a href="http://www.catonmat.net/blog/mit-linear-algebra-part-three/">Lecture 3: Matrix Multiplication and Inverse Matrices</a></li>
</ul>
<h2 style="margin-bottom:10px">Lecture 4: A=LU Factorization</h2>
<p>Lecture four starts with a small review of <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-three/">inverse matrices</a>. Remember from <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-three/">previous lecture</a> that the inverse of matrix A is matrix A<sup>-1</sup> such that multiplying them together A·A<sup>-1</sup> produces the identity matrix I.</p>
<p>Another key fact to remember is that matrix multiplication is associative (can change parenthesis) and that for square matrices the right-inverse is also the left-inverse A·A<sup>-1</sup> = A<sup>-1</sup>·A = I.</p>
<p>Lecture then continues with finding the inverse of matrix product A·B. The answer is found by reasoning what should we multiply A·B to get the identity matrix. Let&#8217;s try B<sup>-1</sup>·A<sup>-1</sup>. If this is the inverse of A·B, then multiplying it with A·B from the left and right sides should produce the identity matrix I. Let&#8217;s test this.</p>
<p>From the right side: (A·B)·(B<sup>-1</sup>·A<sup>-1</sup>). Since we can rearrange parenthesis, this is the same as A·(B·B<sup>-1</sup>)·A<sup>-1</sup>. But B·B<sup>-1</sup> is identity, therefore A·(B·B<sup>-1</sup>)·A<sup>-1</sup> = A·I·A<sup>-1</sup> = A·A<sup>-1</sup> = I. Seems good so far.</p>
<p>Now the left side: (B<sup>-1</sup>·A<sup>-1</sup>)·(A·B). We rearrange parenthesis again, B<sup>-1</sup>·(A<sup>-1</sup>·A)·B and just like in the previous example, A<sup>-1</sup>·A is identity and B<sup>-1</sup>·I·B is B<sup>-1</sup>·B = I.</p>
<p>We have found the inverse of (A·B). It&#8217;s (B<sup>-1</sup>·A<sup>-1</sup>).</p>
<p>Next, while we&#8217;re at it, the lecture continues with finding the inverse of transposed matrix A<sup>T</sup>. It&#8217;s found by reasoning again. Let&#8217;s first look at the equation A·A<sup>-1</sup> = I. We can transpose both sides of this equation and it will still hold. If we transpose the right side, we get the same identity matrix I, because I<sup>T</sup>=I. But what about the left-hand side? Transposing the left-hand side we get (A·A<sup>-1</sup>)<sup>T</sup> = (A<sup>-1</sup>)<sup>T</sup>·A<sup>T</sup>. Now left-hand side is still equal to right-hand side, therefore (A<sup>-1</sup>)<sup>T</sup>·A<sup>T</sup> = I. But from this equation it&#8217;s instantly obvious that the inverse of A<sup>T</sup> is (A<sup>-1</sup>)<sup>T</sup>.</p>
<p>We can therefore note and remember that (A<sup>T</sup>)<sup>-1</sup> = (A<sup>-1</sup>)<sup>T</sup>.</p>
<p>Finally the lecture moves on to today&#8217;s key topic of <strong>A=LU decomposition</strong>. As usual, the topic is introduced by an example.</p>
<p>Let&#8217;s take a look at this 2<small>x</small>2 matrix A:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/2x2-matrix.jpg' alt='2×2 matrix' />
</div>
<p>And let&#8217;s try to find the elementary matrix E<sub>21</sub> that will eliminate the element at row 2, column 1. Multiplying the first row by 4 and subtracting it from the second row will produce a zero at 2, 1.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/one-step-elimination.jpg' alt='one step elimination' />
</div>
<p>But look at the right-hand side. It&#8217;s the <strong>upper-triangular matrix</strong> U (all elements below the diagonal are 0) that we were looking for!</p>
<p>Now if we multiply both sides by the inverse of E<sub>21</sub>, we get (E<sub>21</sub>)<sup>-1</sup>·E<sub>21</sub>·A = (E<sub>21</sub>)<sup>-1</sup>·U. But (E<sub>21</sub>)<sup>-1</sup>·E<sub>21</sub> is identity, therefore A = (E<sub>21</sub>)<sup>-1</sup>·U. From this equation it&#8217;s instantly obvious that the <strong>lower-triangular matrix</strong> L is nothing else but (E<sub>21</sub>)<sup>-1</sup>!</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/alu.jpg' alt='A=LU' />
</div>
<p>Another form of factorization is A = LDU, where D is the diagonal matrix that contains the pivots. For this example it would be:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/aldu.jpg' alt='A=LU' />
</div>
<p>Now imagine that we have some arbitrary 3<small>x</small>3 matrix A. To reduce matrix A into upper-triangular matrix U, we first eliminate the element at position 2,1, that is, we multiply A (from the left side) with elimination matrix E<sub>21</sub>. Then we eliminate the element at 3,1 by multiplying (from the left side) with elimination matrix E<sub>31</sub>. Finally we eliminate the element at 3,2 by multiplying with elimination matrix E<sub>32</sub>:</p>
<div class="center-aligner">
E<sub>32</sub>·E<sub>31</sub>·E<sub>21</sub>·A = U
</div>
<p>It follows from this equation that the lower-triangular matrix is the inverse of E<sub>32</sub>·E<sub>31</sub>·E<sub>21</sub>, that is, </p>
<div class="center-aligner">
L = (E<sub>32</sub>·E<sub>31</sub>·E<sub>21</sub>)<sup>-1</sup> = E<sub>21</sub><sup>-1</sup>·E<sub>31</sub><sup>-1</sup>·E<sub>32</sub><sup>-1</sup>
</div>
<p>We have found the factorization of a 3<small>x</small>3 matrix:</p>
<div class="center-aligner">
A = E<sub>21</sub><sup>-1</sup>·E<sub>31</sub><sup>-1</sup>·E<sub>32</sub><sup>-1</sup>·U = L·U
</div>
<p>The algorithm for finding matrices L and U should now be clear. First do the elimination to find matrix U, then invert the product of elimination matrices used for finding U to find L. Actually it&#8217;s even easier, you don&#8217;t even need to keep elimination matrices E, or find their inverse. You can just keep the multipliers used in each elimination step. Please see the video to find out how it works.</p>
<p>Next, the cost of elimination algorithm is discussed. How many steps does it take to go from matrix A to U? Turns out the elimination is O(n<sup>3</sup>) process (more carefully, it takes around n<sup>3</sup>/3 steps). (See my notes on <a href="http://www.catonmat.net/blog/mit-introduction-to-algorithms-part-one/">MIT&#8217;s Introduction to Algorithms</a> for more info about O-notation.)</p>
<p>Since we sometimes need to do row exchanged to do elimination, the last ten minutes of lecture are spent on permutation matrices. Remember from <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-two/">lecture two</a> that multiplying a matrix from the left side with a permutation matrix exchanges its rows.</p>
<p>The key facts about permutation matrices P are:</p>
<ul>
<li>The inverse of P is its transpose: P<sup>-1</sup> = P<sup>T</sup>.</li>
<li>There are n! permutation matrices for n<sub>x</sub>n matrices.</li>
</ul>
<p>Here is the video of the fourth lecture:</p>
<div class="center-aligner">
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/5hO3MrzPa0A&#038;hl=en_US&#038;fs=1&#038;"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/5hO3MrzPa0A&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
Direct link: <a href="http://www.youtube.com/watch?v=5hO3MrzPa0A">http://www.youtube.com/watch?v=5hO3MrzPa0A</a>
</div>
<p>Topics covered in lecture four:</p>
<ul>
<li>[01:20] What is the inverse of A·B?</li>
<li>[05:20] What is the inverse of A<sup>T</sup>?</li>
<li>[09:20] A=LU factorization for 2&#215;2 matrices.</li>
<li>[13:20] A=LDU factorization.</li>
<li>[14:50] A=LU decomposition for 3&#215;3 matrices.</li>
<li>[18:30] Why is finding matrix L trivial?</li>
<li>[27:25] How many operations does elimination take?</li>
<li>[42:20] Permutation matrices.</li>
<li>[47:20] What is the inverse of a permutation matrix?</li>
<li>[48:20] How many P matrices for 3&#215;3 and 4&#215;4 matrices?</li>
</ul>
<p>Here are my notes of lecture four:</p>
<div class="center-aligner">
<a href='http://www.catonmat.net/blog/wp-content/uploads/2010/01/mit-linear-algebra-lecture-04.jpg' title='MIT Linear Algebra, Lecture 4: A=LU Factorization'><img src='http://www.catonmat.net/blog/wp-content/uploads/2010/01/mit-linear-algebra-lecture-04-thumb.jpg' alt='MIT Linear Algebra, Lecture 4: A=LU Factorization' /></a><br />
<small>My notes of linear algebra lecture 4 on the A=LU factorization.</small>
</div>
<p>Have fun with this lecture! The next post is going to be about transpose matrices, symmetric matrices, vector spaces, their subspaces and column spaces of matrices.</p>
<p>PS. This course is taught from <a href="http://www.amazon.com/gp/product/0980232716?tag=catonmat-20">Introduction to Linear Algebra</a> textbook. Get it here:</p>
<div class="center-aligner">
<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=freesciencand-20&#038;o=1&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=10FE9736YVPPT7A0FBG2&#038;asins=0980232716" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=UHfx79QKNUU:fLomLd3IWiE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=UHfx79QKNUU:fLomLd3IWiE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=UHfx79QKNUU:fLomLd3IWiE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=UHfx79QKNUU:fLomLd3IWiE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=UHfx79QKNUU:fLomLd3IWiE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=UHfx79QKNUU:fLomLd3IWiE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=UHfx79QKNUU:fLomLd3IWiE:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/UHfx79QKNUU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/mit-linear-algebra-part-four/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/mit-linear-algebra-part-four/</feedburner:origLink></item>
		<item>
		<title>A Unix Utility You Should Know About: lsof</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/v0J4xWeVunI/</link>
		<comments>http://www.catonmat.net/blog/unix-utilities-lsof/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 05:55:13 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Tools]]></category>
<category>fd</category><category>fds</category><category>files</category><category>linux</category><category>lsof</category><category>mem</category><category>open files</category><category>pgid</category><category>pid</category><category>tcp</category><category>txt</category><category>udp</category><category>unix</category><category>utility</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/unix-utilities-lsof/</guid>
		<description><![CDATA[This is the third post in the article series about Unix and Linux utilities that you should know about. In this post I will take you through the useful lsof tool. If netcat was called the Swiss Army Knife of Network Connections, then I&#8217;d call lsof the Swiss Army Knife of Unix debugging.
Lsof follows Unix [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/rvUtM-A5twxwxpk1VooQh1W_RrY/0/da"><img src="http://feedads.g.doubleclick.net/~a/rvUtM-A5twxwxpk1VooQh1W_RrY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/rvUtM-A5twxwxpk1VooQh1W_RrY/1/da"><img src="http://feedads.g.doubleclick.net/~a/rvUtM-A5twxwxpk1VooQh1W_RrY/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/02/unix-utilities.jpg' alt='Unix Utilities' class="post-icon" align="left" />This is the third post in the article series about Unix and Linux utilities that you should know about. In this post I will take you through the useful <strong>lsof</strong> tool. If <a href="http://www.catonmat.net/blog/unix-utilities-netcat/">netcat</a> was called the Swiss Army Knife of Network Connections, then I&#8217;d call lsof the <strong>Swiss Army Knife of Unix debugging</strong>.</p>
<p>Lsof follows Unix philosophy closely. It does just one task and it does it perfectly &#8212; it lists information about files opened by processes. An open file may be a regular file, a directory, a NFS file, a block special file, a character special file, a shared library, a regular pipe, a named pipe, a symbolic link, a socket stream, an Internet socket, a UNIX domain socket, and many others. Since almost everything in Unix is a file, you can imagine how incredibly useful lsof is!</p>
<p>See the first post on <a href="http://www.catonmat.net/blog/unix-utilities-pipe-viewer/">pipe viewer</a> for the introduction to this article series. If you are interested in articles like this one, I suggest that you subscribe to <a href="http://feeds.feedburner.com/catonmat">my rss feed</a> to receive my future posts automatically!</p>
<h2 style="margin-bottom: 10px">How to use lsof?</h2>
<p>In this article I will try to present lsof based on as many use cases as I can think of. Let&#8217;s start with the simplest (that you probably already know) and proceed to more complicated ones.</p>
<h2 style="margin-bottom: 10px">List all open files.</h2>
<pre>
# lsof
</pre>
<p>Running <code>lsof</code> without any arguments lists all open files by all processes. </p>
<h2 style="margin-bottom: 10px">Find who&#8217;s using a file.</h2>
<pre>
# lsof /path/to/file
</pre>
<p>With an argument of a path to a file, lsof lists all the processes, which are using the file in some way.</p>
<p>You may also specify several files, which lists all the processes, which are using all the files:</p>
<pre>
# lsof /path/to/file1 /path/to/file2
</pre>
<h2 style="margin-bottom: 10px">Find all open files in a directory recursively.</h2>
<pre>
# lsof +D /usr/lib
</pre>
<p>With the <code>+D</code> argument lsof finds all files in the specified directory and all the subdirectories.</p>
<p>Note that it&#8217;s slower than the usual version with <code>grep</code>:</p>
<pre>
# lsof | grep '/usr/lib'
</pre>
<p>It&#8217;s slower because <code>+D</code> first finds all the files and only then does the output.</p>
<h2 style="margin-bottom: 10px">List all open files by a user.</h2>
<pre>
# lsof -u pkrumins
</pre>
<p>The <code>-u</code> option (think <strong>u</strong>ser) limits output of files opened only by user <strong>pkrumins</strong>.</p>
<p>You can use comma separated list of values to list files open by several users:</p>
<pre>
# lsof -u rms,root
</pre>
<p>This will list all the files that are open by users <strong>rms</strong> and <strong>root</strong>.</p>
<p>Another way to do the same is by using the <code>-u</code> option twice:</p>
<pre>
# lsof -u rms -u root
</pre>
<h2 style="margin-bottom: 10px">Find all open files by program&#8217;s name.</h2>
<pre>
# lsof -c apache
</pre>
<p>The <code>-c</code> option selects the listing of files for processes whose name begins with <strong>apache</strong>.</p>
<p>So instead of writing:</p>
<pre>
# lsof | grep foo
</pre>
<p>You can now write the shorter version:</p>
<pre>
# lsof -c foo
</pre>
<p>In fact, you can specify just the beginning part of the process name you&#8217;re looking for:</p>
<pre>
# lsof -c apa
</pre>
<p>This will list all the open files by a processes whose starts with <strong>apa</strong>.</p>
<p>You can also specify several <code>-c</code> options to output open files by several processes:</p>
<pre>
# lsof -c apache -c python
</pre>
<p>This will list all open files by <strong>apache</strong> and <strong>python</strong>.</p>
<h2 style="margin-bottom: 10px">List all open files by a user OR process.</h2>
<pre>
# lsof -u pkrumins -c apache
</pre>
<p>Lsof options can be combined. The default is to OR between options. It means it will combine outputs of <code>-u pkrumins</code> and <code>-c apache</code> producing a listing of all open files by <strong>pkrumins</strong> and all open files by <strong>apache</strong>.</p>
<h2 style="margin-bottom: 10px">List all open files by a user AND process.</h2>
<pre>
# lsof -a -u pkrumins -c bash
</pre>
<p>Notice the <code>-a</code> option. It combines the options with AND. The output listing is files opened by <strong>bash</strong>, which is run under <strong>pkrumins</strong> user.</p>
<h2 style="margin-bottom: 10px">List all open files by all users EXCEPT root.</h2>
<pre>
# lsof -u ^root
</pre>
<p>Notice the <code>^</code> character before <strong>root</strong> username. It negates the match and causes lsof print all open files by all users who are not root.</p>
<h2 style="margin-bottom: 10px">List all open files by the process with PID.</h2>
<pre>
# lsof -p 1
</pre>
<p>The <code>-p</code> option (think <b>P</b>ID) filters out open files by program&#8217;s id.</p>
<p>Remember that you can select multiple PIDs by either comma separating the list or using multiple <code>-p</code> arguments:</p>
<pre>
# lsof -p 450,980,333
</pre>
<p>This selects processes with PIDs 450, 980 and 333.</p>
<h2 style="margin-bottom: 10px">List all open files by all the processes EXCEPT process with PID.</h2>
<pre>
# lsof -p ^1
</pre>
<p>Here the negation operator <code>^</code> is used again. It inverts the list and does not include process with PID 1.</p>
<h2 style="margin-bottom: 10px">List all network connections.</h2>
<pre>
# lsof -i
</pre>
<p>Lsof with <code>-i</code> option lists all processes with open Internet sockets (TCP and UDP).</p>
<h2 style="margin-bottom: 10px">List all TCP network connections.</h2>
<pre>
# lsof -i tcp
</pre>
<p>The <code>-i</code> argument can take several options, one of them is <code>tcp</code>. The <code>tcp</code> option forces lsof to list only processes with TCP sockets.</p>
<h2 style="margin-bottom: 10px">List all UDP network connections.</h2>
<pre>
# lsof -i udp
</pre>
<p>The <code>udp</code> option causes lsof to list processes with UDP sockets.</p>
<h2 style="margin-bottom: 10px">Find who&#8217;s using a port.</h2>
<pre>
# lsof -i :25
</pre>
<p>The <code>:25</code> option to <code>-i</code> makes lsof find processes using TCP or UDP port 25.</p>
<p>You may also use service port name (found in <code>/etc/services</code>) rather than port number:</p>
<pre>
# lsof -i :smtp
</pre>
<h2 style="margin-bottom: 10px">Find who&#8217;s using a specific UDP port.</h2>
<pre>
# lsof -i udp:53
</pre>
<p>Similarly, to find who&#8217;s using a TCP port, use:</p>
<pre>
# lsof -i tcp:80
</pre>
<h2 style="margin-bottom: 10px">Find all network activity by user.</h2>
<pre>
# lsof -a -u hacker -i
</pre>
<p>Here the <code>-a</code> option combines <code>-u</code> and <code>-i</code> to produce listing of network file usage by user <strong>hacker</strong>.</p>
<h2 style="margin-bottom: 10px">List all NFS (Network File System) files.</h2>
<pre>
# lsof -N
</pre>
<p>This option is easy to remember because <code>-N</code> is <strong>N</strong>FS.</p>
<h2 style="margin-bottom: 10px">List all Unix domain socket files.</h2>
<pre>
# lsof -U
</pre>
<p>This option is also easy to remember because <code>-U</code> is <strong>U</strong>nix.</p>
<h2 style="margin-bottom: 10px">List all files for processes with a specific group id.</h2>
<pre>
# lsof -g 1234
</pre>
<p>Process groups are used to logically group processes. This example finds all files opened by processes with PGID <code>1234</code>.</p>
<h2 style="margin-bottom: 10px">List all files associated with specific file descriptors.</h2>
<pre>
# lsof -d 2
</pre>
<p>This lists all files that have been opened as file descriptor <code>2</code>.</p>
<p>You may also specify ranges of file descriptors:</p>
<pre>
# lsof -d 0-2
</pre>
<p>This would list all files with file descriptors 0, 1 and 2.</p>
<p>There are also many special values, such as <code>mem</code>, that lists memory-mapped files:</p>
<pre>
# lsof -d mem
</pre>
<p>Or <code>txt</code> for programs loaded in memory and executing:</p>
<pre>
# lsof -d txt
</pre>
<h2 style="margin-bottom: 10px">Output PIDs of processes using some resource.</h2>
<pre>
# lsof -t -i
</pre>
<p>The <code>-t</code> option outputs only PIDs of processes. Used together with <code>-i</code> it outputs PIDs of all processes with network connections. It&#8217;s easy to kill all processes that use network:</p>
<pre>
# kill -9 `lsof -t -i`
</pre>
<h2 style="margin-bottom: 10px">Repeat listing files.</h2>
<pre>
# lsof -r 1
</pre>
<p>The <code>-r</code> option makes lsof repeatedly list files until interrupted. Argument <code>1</code> means repeat the listing every 1 second. This option is best combined with a narrower query such as monitoring user network file activity:</p>
<pre>
# lsof -r 1 -u john -i -a
</pre>
<h2 style="margin-bottom: 10px">How to install lsof?</h2>
<p>Lsof comes preinstalled on many Unix systems. If your system doesn&#8217;t have it, try to install it from the <a href="http://people.freebsd.org/~abe/">source</a>.</p>
<p>BSD supplies its own utility that does similar things, it&#8217;s called <strong>fstat</strong>.</p>
<p>For the full documentation of lsof see the <a href="http://www.opensource.apple.com/source/lsof/lsof-33/lsof/lsof.man">man lsof</a> page or type <code>lsof -h</code> for a small cheat sheet.</p>
<p>Have fun with lsof!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=v0J4xWeVunI:yjb5WZu5cA0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=v0J4xWeVunI:yjb5WZu5cA0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=v0J4xWeVunI:yjb5WZu5cA0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=v0J4xWeVunI:yjb5WZu5cA0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=v0J4xWeVunI:yjb5WZu5cA0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=v0J4xWeVunI:yjb5WZu5cA0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=v0J4xWeVunI:yjb5WZu5cA0:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/v0J4xWeVunI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/unix-utilities-lsof/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/unix-utilities-lsof/</feedburner:origLink></item>
		<item>
		<title>MIT Linear Algebra, Lecture 3: Matrix Multiplication and Inverse Matrices</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/AaaVktte_Gg/</link>
		<comments>http://www.catonmat.net/blog/mit-linear-algebra-part-three/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 08:35:25 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Linear Algebra]]></category>
<category>gauss jordan</category><category>gauss jordan elimination</category><category>inverse matrices</category><category>inverse matrix</category><category>inverses</category><category>invertible matrix</category><category>matrices</category><category>matrix multiplication</category><category>mit</category><category>nonsingular matrix</category><category>singular matrix</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/mit-linear-algebra-part-three/</guid>
		<description><![CDATA[This is the third post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture three on five ways to multiply matrices, inverse matrices and an algorithm for finding inverse matrices called Gauss-Jordan elimination.
The first lecture covered the geometry of linear equations and the second lecture covered the matrix [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/RGIyHbx0aWllz2Dckg6bGYiXMJI/0/da"><img src="http://feedads.g.doubleclick.net/~a/RGIyHbx0aWllz2Dckg6bGYiXMJI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/RGIyHbx0aWllz2Dckg6bGYiXMJI/1/da"><img src="http://feedads.g.doubleclick.net/~a/RGIyHbx0aWllz2Dckg6bGYiXMJI/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/11/mit-introduction-to-linear-algebra.jpg' alt='MIT Introduction to Linear Algebra' class="post-icon" align="left" />This is the third post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture three on five ways to <strong>multiply matrices</strong>, <strong>inverse matrices</strong> and an algorithm for finding inverse matrices called <strong>Gauss-Jordan elimination</strong>.</p>
<p>The first lecture covered <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-one/">the geometry of linear equations</a> and the second lecture covered <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-two/">the matrix elimination</a>.</p>
<p>Here is lecture three.</p>
<h2 style="margin-bottom:10px">Lecture 3: Matrix Multiplication and Inverse Matrices</h2>
<p>Lecture three starts with <strong>five ways to multiply matrices</strong>.</p>
<p>The first way is the classical way. Suppose we are given a matrix <strong>A</strong> of size m<small>x</small>n with elements a<sub>ij</sub> and a matrix <strong>B</strong> of size n<small>x</small>p with elements b<sub>jk</sub>, and we want to find the product <strong>A</strong>·<strong>B</strong>. Multiplying matrices <strong>A</strong> and <strong>B</strong> will produce matrix <strong>C</strong> of size m<small>x</small>p with elements <img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-multiplication-cij-sum-aik-bkj.gif' style="position:relative; top: 4px" alt='Matrix multiplication cij = sum from k=1 to n of aik times bjk' />.</p>
<p>Here is how this sum works. To find the first element c<sub>11</sub> of matrix <strong>C</strong>, we sum over the 1st row of <strong>A</strong> and the 1st column of <strong>B</strong>. The sum expands to c<sub>11</sub> = a<sub>11</sub>·b<sub>11</sub> + a<sub>12</sub>·b<sub>21</sub> + a<sub>13</sub>·b<sub>31</sub> + &#8230; + a<sub>1n</sub>·b<sub>n1</sub>. Here is a visualization of the summation:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-multiplication-a-times-b-equals-c.gif' alt='Matrix multiplication A·B = C' />
</div>
<p>We continue this way until we find all the elements of matrix <strong>C</strong>. Here is another visualization of finding c<sub>23</sub>:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-multiplication-a-times-b-equals-c23.gif' alt='Matrix multiplication a2j*bj3 = c23' />
</div>
<p>The second way is to take each column in <strong>B</strong>, multiply it by the whole matrix <strong>A</strong> and put the resulting column in the matrix <strong>C</strong>. The columns of <strong>C</strong> are combinations of columns of <strong>A</strong>. (Remember from <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-two/">previous lecture</a> that a matrix times a column is a column.)</p>
<p>For example, to get column 1 of matrix <strong>C</strong>, we multiply <strong>A</strong>·(column 1 of matrix <strong>B</strong>):</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-multiplication-a-times-column-b.gif' alt='Matrix multiplication A times column 1 of B' />
</div>
<p>The third way is to take each row in <strong>A</strong>, multiply it by the whole matrix <strong>B</strong> and put the resulting row in the matrix <strong>C</strong>. The rows of <strong>C</strong> are combinations of rows of <strong>B</strong>. (Again, remember from <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-two/">previous lecture</a> that a row times a matrix is a row.)</p>
<p>For example, to get row 1 of matrix <strong>C</strong>, we multiply row 1 of matrix <strong>A</strong> with the whole matrix <strong>B</strong>:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-multiplication-row-a-times-matrix-b.gif' alt='Matrix multiplication row of A times matrix B' />
</div>
<p>The fourth way is to look at the product of <strong>A</strong>·<strong>B</strong> as a sum of (columns of <strong>A</strong>) times (rows of <strong>B</strong>).</p>
<p>Here is an example:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-multiplication-sum-columns-a-rows-b.gif' alt='Matrix multiplication columns A times rows B' />
</div>
<p>The fifth way is to chop matrices in blocks and multiply blocks by any of the previous methods.</p>
<p>Here is an example. Matrix <strong>A</strong> gets subdivided in four submatrices A<sub>1</sub> A<sub>2</sub> A<sub>3</sub> A<sub>4</sub>, matrix <strong>B</strong> gets divided in four submatrices B<sub>1</sub> B<sub>2</sub> B<sub>3</sub> B<sub>4</sub> and the blocks get treated like simple matrix elements.</p>
<p>Here is the visualization:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-multiplication-blocks.gif' alt='Matrix multiplication by blocks' />
</div>
<p>Element <strong>C</strong><sub>1</sub>, for example, is obtained by multiplying <strong>A</strong><sub>1</sub>·<strong>B</strong><sub>1</sub> + <strong>A</strong><sub>2</sub>·<strong>B</strong><sub>3</sub>.</p>
<p>Next the lecture proceeds to finding the <strong>inverse matrices</strong>. An inverse of a matrix <strong>A</strong> is another matrix, such that <strong>A<sup>-1</sup></strong>·<strong>A</strong> = <strong>I</strong>, where I is the identity matrix. In fact if <strong>A<sup>-1</sup></strong> is the inverse matrix of a square matrix <strong>A</strong>, then it&#8217;s both the left-inverse and the right inverse, i.e., <strong>A<sup>-1</sup></strong>·<strong>A</strong> = <strong>A</strong>·<strong>A<sup>-1</sup></strong> = <strong>I</strong>.</p>
<p>If a matrix <strong>A</strong> has an inverse then it is said to be <strong>invertible</strong> or <strong>non-singular</strong>.</p>
<p>Matrix A is singular if we can find a non-zero vector <strong>x</strong> such that A·<strong>x</strong> = <strong>0</strong>. The proof is easy. Suppose A is not singular, i.e., there exists matrix A<sup>-1</sup>. Then A<sup>-1</sup>·A·<strong>x</strong> = <strong>0</strong>·A<sup>-1</sup>, which leads to a false statement that <strong>x</strong> = <strong>0</strong>. Therefore A must be singular.</p>
<p>Another way of saying that matrix <strong>A</strong> is singular is to say that columns of matrix <strong>A</strong> are linearly dependent (one ore more columns can be expressed as a linear combination of others).</p>
<p>Finally, the lecture shows a deterministic method for finding the inverse matrix. This method is called the <strong>Gauss-Jordan elimination</strong>. In short, Gauss-Jordan elimination transforms augmented matrix (<strong>A</strong>|<strong>I</strong>) into (<strong>I</strong>|<strong>A</strong><sup>-1</sup>) by using only row eliminations.</p>
<p>Please watch the lecture to find out how it works in all the details:</p>
<div class="center-aligner">
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/FX4C-JpTFgY&#038;hl=en_US&#038;fs=1&#038;"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/FX4C-JpTFgY&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
Direct link: <a href="http://www.youtube.com/watch?v=FX4C-JpTFgY">http://www.youtube.com/watch?v=FX4C-JpTFgY</a>
</div>
<p>Topics covered in lecture three:</p>
<ul>
<li>[00:51] The first way to multiply matrices.</li>
<li>[04:50] When are we allowed to multiply matrices?</li>
<li>[06:45] The second way to multiply matrices.</li>
<li>[10:10] The third way to multiply matrices.</li>
<li>[12:30] What is the result of multiplying a column of A and a row of B?</li>
<li>[15:30] The fourth way to multiply matrices.</li>
<li>[18:35] The fifth way to multiply matrices by blocks.</li>
<li>[21:30] Inverses for square matrices.</li>
<li>[24:55] Singular matrices (no inverse matrix exists).</li>
<li>[30:00] Why singular matrices can&#8217;t have inverse?</li>
<li>[36:20] Gauss-Jordan elimination.</li>
<li>[41:20] Gauss-Jordan idea A·I -> I·A<sup>-1</sup>.</li>
</ul>
<p>Here are my notes of lecture three:</p>
<div class="center-aligner">
<a href='http://www.catonmat.net/blog/wp-content/uploads/2009/12/mit-linear-algebra-lecture-03.jpg' title='MIT Linear Algebra, Lecture 3: Matrix Multiplication and Inverse Matrices'><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/mit-linear-algebra-lecture-03-thumb.jpg' alt='MIT Linear Algebra, Lecture 3: Matrix Multiplication and Inverse Matrices' /></a><br />
<small>My notes of linear algebra lecture 3 on the matrix multiplication and inverses.</small>
</div>
<p>Have fun with this lecture! The next post is going to be about the A=LU matrix decomposition (also known as factorization).</p>
<p>PS. This course is taught from <a href="http://www.amazon.com/gp/product/0980232716?tag=catonmat-20">Introduction to Linear Algebra</a> textbook. Get it here:</p>
<div class="center-aligner">
<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=freesciencand-20&#038;o=1&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=10FE9736YVPPT7A0FBG2&#038;asins=0980232716" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=AaaVktte_Gg:VgpFZDtSJjg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=AaaVktte_Gg:VgpFZDtSJjg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=AaaVktte_Gg:VgpFZDtSJjg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=AaaVktte_Gg:VgpFZDtSJjg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=AaaVktte_Gg:VgpFZDtSJjg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=AaaVktte_Gg:VgpFZDtSJjg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=AaaVktte_Gg:VgpFZDtSJjg:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/AaaVktte_Gg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/mit-linear-algebra-part-three/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/mit-linear-algebra-part-three/</feedburner:origLink></item>
		<item>
		<title>Recursive Regular Expressions</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/eTX_ascV6Qg/</link>
		<comments>http://www.catonmat.net/blog/recursive-regular-expressions/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 05:05:27 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Programming]]></category>
<category>0n1n</category><category>balanced parentheses</category><category>fully parenthesized expression</category><category>perl</category><category>recursive regular expressions</category><category>regex</category><category>regular expression</category><category>regular expressions</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/recursive-regular-expressions/</guid>
		<description><![CDATA[


The regular expressions we use in our daily lives are actually not that &#8220;regular.&#8221; Most of the languages support some kind of extended regular expressions that are computationally more powerful than the &#8220;regular&#8221; regular expressions as defined by the formal language theory.
For instance, the so often used capture buffers add auxiliary storage to the regular [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/88RloN21aueKwouEsuQPx71ihnQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/88RloN21aueKwouEsuQPx71ihnQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/88RloN21aueKwouEsuQPx71ihnQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/88RloN21aueKwouEsuQPx71ihnQ/1/di" border="0" ismap="true"></img></a></p><div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/yo-dawg-regex.jpg' alt='Yo dawg, I heard you liked regular expressions, so I put a regex in your regex so you can match while you match!' />
</div>
<p>The regular expressions we use in our daily lives are actually not that &#8220;regular.&#8221; Most of the languages support some kind of extended regular expressions that are computationally more powerful than the &#8220;<a href="http://en.wikipedia.org/wiki/Regular_expression">regular</a>&#8221; regular expressions as defined by the <a href="http://en.wikipedia.org/wiki/Formal_language">formal language theory</a>.</p>
<p>For instance, the so often used <a href="http://perldoc.perl.org/perlre.html#Capture-buffers">capture buffers</a> add auxiliary storage to the regular expressions that allow them to match an arbitrary pattern repeatedly. Or <a href="http://perldoc.perl.org/perlre.html#Look-Around-Assertions">look-ahead assertions</a> that allow the regular expression engine to peek ahead before it making a decision. These extensions make regular expressions powerful enough to describe some <a href="http://en.wikipedia.org/wiki/Context-free_grammar">context-free grammars</a>.</p>
<p>The Perl programming language has an especially rich with regex engine. One of the engine&#8217;s features is the <strong>lazy regular subexpressions</strong>. The lazy regular subexpressions are expressed as <code>(??{ code })</code>, where the &#8220;<code>code</code>&#8221; is arbitrary Perl code that gets executed when the moment this subexpression may match.</p>
<p>This allows us to construct something really interesting - we can define a regular expression that has itself in the &#8220;<code>code</code>&#8221; part. The result is <strong>a recursive regular expression</strong>!</p>
<p>One of the classical problems that a regular expression can&#8217;t match is the language <code>0<sup>n</sup>1<sup>n</sup></code>, i.e., a string with a number of zeroes followed by an equal number of ones. Surprisingly, using the lazy regular subexpressions this problem becomes tractable!</p>
<p>Here is a Perl regular expression that matches <code>0<sup>n</sup>1<sup>n</sup></code>:</p>
<pre>
$regex = qr/0(??{$regex})?1/;
</pre>
<p>This regular expression matches a <code>0</code> followed by itself zero or one time, followed by a one. If the itself part doesn&#8217;t match, then the string this regular expression matches is <code>01</code>. If the itself part matches, the string this regular expression matches is <code>00($regex)?11</code>, which is <code>0011</code> if <code>$regex</code> doesn&#8217;t match or it&#8217;s <code>000($regex)?111</code> if it matches, &#8230;, etc.</p>
<p>Here is a Perl program that matches <code>0<sup>50000</sup>1<sup>50000</sup></code>:</p>
<pre>
#!/usr/bin/perl

$str = "0"x50000 . "1"x50000;
$regex = qr/0(??{$regex})*1/;

if ($str =~ /^$regex$/) {
  print "yes, it matches"
}
else {
  print "no, it doesn't match"
}
</pre>
<p>Now let&#8217;s look at the Yo Dawg regular expression in the picture above. Can you guess what it does? It matches a fully parenthesized expression such as <code>(foo(bar())baz)</code> or balanced parentheses <code>((()()())())</code>.</p>
<pre>
$regex = qr/
  \(                 # (1) match an open paren (
    (                # followed by
      [^()]+         #   (3) one or more non-paren character
    |                # OR
      (??{$regex})   #   (5) the regex itself
    )*               # (6) repeated zero or more times
  \)                 # (7) followed by a close paren )
/x;
</pre>
<p>Here is how to think about this regular expression. For an expression to be fully parenthesized, it has to start with an open paren, so we match it (point <code>(1)</code> in the regex). It also has to end with close paren, so we match a close paren at the end (point <code>(7)</code>). Now we have to think what can be in-between the parens? Well, we can either have some text that is neither an open paren or closed paren (point <code>(3)</code>) <strong>OR</strong> we can have another fully parenthesized expression! (point <code>(5)</code>). And all this may be repeated either zero times (point <code>(6)</code>) to match the smallest fully parenthesized expression <code>()</code> or more times to match a more complex expression.</p>
<p>Without the <code>/x</code> flag (that allows multiline regexes), it can be written more compactly:</p>
<pre>
$regex = qr/\(([^()]+|(??{$regex}))*\)/;
</pre>
<p>But please don&#8217;t use these regular expressions in production as they are too cryptic. Use <a href="http://search.cpan.org/dist/Text-Balanced/">Text::Balanced</a> or <a href="http://search.cpan.org/dist/Regexp-Common/">Regexp::Common</a> Perl modules.</p>
<p>And finally, in Perl 5.10 you can use <a href="http://perldoc.perl.org/perlre.html#%28?PARNO%29-%28?-PARNO%29-%28?+PARNO%29-%28?R%29-%28?0%29">recursive capture buffers</a> instead of lazy code subexpressions to achieve the same result.</p>
<p>Here is a regular expression that matches <code>0<sup>n</sup>1<sup>n</sup></code> and uses the recursive capture buffer syntax <code>(?N)</code>:</p>
<pre>
my $rx = qr/(0(?1)*1)/
</pre>
<p>The <code>(?1)*</code> says &#8220;match the first group zero or more times,&#8221; where the first group is the whole regular expression.</p>
<p>You can try to rewrite the regular expression that matches balanced parens as an exercise.</p>
<p>Have fun!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=eTX_ascV6Qg:I-FPSKJkc0Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=eTX_ascV6Qg:I-FPSKJkc0Y:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=eTX_ascV6Qg:I-FPSKJkc0Y:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=eTX_ascV6Qg:I-FPSKJkc0Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=eTX_ascV6Qg:I-FPSKJkc0Y:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=eTX_ascV6Qg:I-FPSKJkc0Y:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=eTX_ascV6Qg:I-FPSKJkc0Y:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/eTX_ascV6Qg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/recursive-regular-expressions/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/recursive-regular-expressions/</feedburner:origLink></item>
		<item>
		<title>50 ideas for the new catonmat.net website</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/gTczt-4E1-Y/</link>
		<comments>http://www.catonmat.net/blog/50-ideas-for-the-new-catonmat-website/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 05:15:50 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[The New Catonmat]]></category>
<category>301</category><category>404</category><category>categories</category><category>catonmat</category><category>comments</category><category>crazyegg</category><category>github</category><category>google analytics</category><category>gravatar</category><category>ideas</category><category>knowledge database</category><category>latex</category><category>linkback</category><category>meta description</category><category>miniblog</category><category>pingback</category><category>programming</category><category>psychology</category><category>quotes</category><category>refback</category><category>revision control</category><category>seo</category><category>snippets</category><category>social media</category><category>statcounter</category><category>statistics</category><category>tags</category><category>tiny url</category><category>tips</category><category>trackback</category><category>traffic</category><category>web design</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/50-ideas-for-the-new-catonmat-website/</guid>
		<description><![CDATA[I have been working on the new catonmat.net website for quite some time now and I have gathered a very long list ideas of what a modern website should have. They include ideas from psychology, search engine optimization, social media, programming, and the best web design practices.
Since I started to use github last week, all [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/IpFJZ-kbJlTztJjiabcnqUETVk0/0/da"><img src="http://feedads.g.doubleclick.net/~a/IpFJZ-kbJlTztJjiabcnqUETVk0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/IpFJZ-kbJlTztJjiabcnqUETVk0/1/da"><img src="http://feedads.g.doubleclick.net/~a/IpFJZ-kbJlTztJjiabcnqUETVk0/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/catonmat-logo-paw-150x150.gif' alt='catonmat paw' class="post-icon" align="left" />I have been working on the new catonmat.net website for quite some time now and I have gathered a very long list ideas of what a modern website should have. They include ideas from psychology, search engine optimization, social media, programming, and the best web design practices.</p>
<p>Since I started to use <a href="http://www.catonmat.net/blog/i-pushed-30-of-my-projects-to-github/">github</a> last week, all the new catonmat code will be there. I already created a <a href="http://github.com/pkrumins/catonmat.net">catonmat repository</a> and I am going to be pushing code there daily.</p>
<p>I love to share my ideas, so here are the first 50 of them. I am going to share more later in the upcoming article series &#8220;<strong>Designing the new catonmat.net together with me.</strong>&#8221; You should subscribe to my blog <a href="http://www.catonmat.net/feed/">here</a>, if you are interested in this topic and haven&#8217;t subscribed yet.</p>
<p>The ideas are in no particular order. If some of them seem fuzzy or unclear, please ask me to clarify in the comments.</p>
<h2 style="margin-bottom:10px">1. 301 Redirect Table.</h2>
<p>The idea is to maintain a table that will be checked against the request URLs. If the request URL is in the table, it gets redirected to a new destination URL with the 301 HTTP header, which forwards the link juice from one URL to another. This is necessary because some forums break URLs in multiple lines and the resulting clickable URL is 404. If I didn&#8217;t do a 301 to the new location, this link would be lost. Anyone who clicked it, would end up on the 404 error page. Another example is if someone links to a mistyped URL. Anyone who clicks it ends up being unsatisfied, at 404 page. With a 301 table I can quickly fix these problems. Here is a concrete example: Someone links to www.catonmat.net/artikle when they wanted to link to www.catonmat/article. I&#8217;d simply insert an entry to 301 redirect /artikle to /article and everyone&#8217;s happy.</p>
<h2 style="margin-bottom:10px">2. 404 Error Log.</h2>
<p>I absolutely have to know what pages trigger 404 errors so that I can fix them ASAP with the 301 redirect table. There may be many false alarms, therefore I have to add filters to the 404 error log to ignore some spammy patterns.</p>
<h2 style="margin-bottom:10px">3. A Great 404 Page.</h2>
<p>If someone ends up on a non-existing page, log it as described in #2 and then explain to the visitor why the page he visited was not found. Suggest him or her or it to view 5 latest post titles, or 5 most popular posts, or most popular downloads, or something else (still have to think about it when I implement it).</p>
<h2 style="margin-bottom:10px">4. A Separate Trackback/Pingback/Linkback/Refback Page With Moderation.</h2>
<p>Tracebacks are usually displayed among comments. This is very messy. There is no place for them among comments. The idea is to have them on a separate page like www.catonmat.net/post-title/trackbacks. Also add bulk moderation as spammers love to exploit trackback. (Perhaps drop trackbacks altogether as they are of very little value.)</p>
<h2 style="margin-bottom:10px">5. A Page With Last Comments.</h2>
<p>Currently I am displaying only the 10 last comments on the right sidebar. This is insufficient. I want to see all the comments (like <a href="http://www.reddit.com/comments">www.reddit.com/comments</a>) on a single page, so that even if I am away from computer for several days, I can easily navigate through them and reply/hide/edit/delete in-place. Perhaps add a RSS feed for comments page.</p>
<h2 style="margin-bottom:10px">6. Comment Statistics.</h2>
<p>I need to tell my blog readers who are the most active people on my website. This will stimulate people to be more active. Therefore I should add a comment statistics with most popular commentators, link to their pages without nofollow to give them link juice. Also add statistics of the most commented articles.</p>
<h2 style="margin-bottom:10px">7. Add Incoming Search Term Statistics On All Pages.</h2>
<p>When people come from Google or Yahoo, save the query they used and display it on the page. This way I will always know what terms were searched for on each of the pages, without having to write complex queries.</p>
<h2 style="margin-bottom:10px">8. Add Download Statistics.</h2>
<p>Currently I have sloppy download statistics. I want nice graphs and want to see the most popular downloads by day, month, etc. This should be written as a statistics framework as traffic statistics, article statistics, delicious statistics and download statistics will all have more or less same graphs.</p>
<h2 style="margin-bottom:10px">9. Public Statistics Section For del.icious.com Bookmarks.</h2>
<p>I want to see how often my posts get bookmarked on del.icious.com. I also want nice graphs for them by day, week, month, etc. I also want a list of people who bookmarked my posts the most often, and tags they used. Make this public and also very modular so other people can reuse the code and put it on their sites. Reward the most frequent bookmarkers with links to their sites.</p>
<h2 style="margin-bottom:10px">10. Insert Beautiful Images To Give Rest To Eyes.</h2>
<p>Insert some beautiful landscape images after serveral paragraphs of text to give rest to eyes and give the reader positive emotions.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/flower-blur-510x130.jpg' alt='Flowers' /><br />
<small>An image from <a href="http://www.flickr.com/photos/ginnerobot">ginnerobot&#8217;s photostream</a> on Flickr.</small>
</div>
<h2 style="margin-bottom:10px">11. Public Traffic Statistics.</h2>
<p>I want the super statistics for my website. And make them public. I want to see which is the most popular article today, which was yesterday. I want nice traffic graphs and trends.</p>
<h2 style="margin-bottom:10px">12. Public Twitter Statistics.</h2>
<p>Find who&#8217;s tweeting about catonmat and put all these tweets on a separate page. Find who&#8217;s the most active catonmat tweeter and make this person stand out. Link to twitter profiles.</p>
<h2 style="margin-bottom:10px">13. Integrate GitHub Directly In Catonmat</h2>
<p>Integrate GitHub with status updates, friend count, directly in catonmat. Would have to write some kind of a scraper or use their API, if it&#8217;s usable for this purpose.</p>
<h2 style="margin-bottom:10px">14. Implement Threaded Comments.</h2>
<p>Currently I have linear comments, which are no good. To find whom someone replied to I have to scroll through the comments. This doesn&#8217;t make any sense. I have to add threaded comments. This will also engage users is more conversations.</p>
<h2 style="margin-bottom:10px">15. Have Individual Links To Comments Like On Reddit.</h2>
<p>I don&#8217;t like links to comments in a form www.catonmat.net/article/#comment-55. I want them to be in form www.catonmat.net/article/comment-55 so that each comment (or thread of comments) is on its own page. This way, if linked to a comment, person will precisely have that comment loaded. Browsers can misbehave in case of anchor links like #comment-55 and I don&#8217;t like that.</p>
<h2 style="margin-bottom:10px">16. Lightweight Syntax For Comments.</h2>
<p>There are just a few things comments need:</p>
<ul>
<li>Quote someone.</li>
<li>Emphesize part of a comment in bold or italic.</li>
<li>Link to some page.</li>
<li>Share code fragment (auto syntax highlight it).</li>
</ul>
<p>That&#8217;s it. Nothing else is necessary, no stupid HTML comments.</p>
<h2 style="margin-bottom:10px">17. Filter Comments By Language.</h2>
<p>My website is getting a lot of spam from Russia with comments in Russian. I am sure no one would write comments in Russian on my site. Add a filter to leave just the English comments. All other are spam.</p>
<h2 style="margin-bottom:10px">18. Add Gravatar Icons To Comments.</h2>
<p>Gravatar is at <a href="http://www.gravatar.com">www.gravatar.com</a>. It&#8217;s a map from emails to jpegs of user icons. This will make people stand out. Also display the gravatar user icons on comment statistics (point above). Having gravatars will emotionally associates you with commentators and the next time you see a gravatar you can predict the nature of the comment (depending if you had positive emotions or negative before).</p>
<h2 style="margin-bottom:10px">19. Add More &#8220;Contact Me&#8221; Options Near &#8220;About me&#8221; on The Right Sidebar.</h2>
<p>You want to get yourself out. If you don&#8217;t do it, no one will come after you. Add links to <a href="http://www.facebook.com/pkrumins">Facebook</a>, <a href="http://www.linkedin.com/in/pkrumins">Linked In</a>, <a href="http://twitter.com/pkrumins">Twitter</a>, <a href="http://plurk.com/pkrumins">Plurk</a>, <a href="http://github.com/pkrumins">GitHub</a>, <a href="http://friendfeed.com/pkrumins">FriendFeed</a>, perhaps some other sites. Show the email as an image and add a link to my IRC channel #catonmat on irc.freenode.net. Initially show only Twitter, Facebook and GitHub. Add an arrow down clickable image. After clicked displays all other contact options.</p>
<h2 style="margin-bottom:10px">20. Snippets Page.</h2>
<p>I have been writing and collecting various programming snippets. I want to have them in a central database on my site. Instead of putting them on some foreign service like GitHub&#8217;s <a href="http://gist.github.com/">Gist</a> or Pastebin of some kind, I want to keep them on my website in my database so that I can easily modify them in a single place and integrate within posts.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/flower-field-510x130.jpg' alt='Flower Field' /><br />
<small>An image from <a href="http://www.flickr.com/photos/14646075@N03/">digital cat&#8217;s photostream</a> on Flickr.</small>
</div>
<h2 style="margin-bottom:10px">21. Add Revision Control For All The Pages.</h2>
<p>Currently if I edit a page, the previous page is lost and I can&#8217;t see the changes. It&#8217;s crucial to keep the changes as sometimes I need to get something from a year ago. I have to add revision control like wikipedia does. The URL scheme could be www.catonmat.net/article/revisions - displays all available revisions, and www.catonmat.net/article/revisions/r1/r2 displays changes between r1 and r2, but I have to think about it a bit more.</p>
<h2 style="margin-bottom:10px">22. Create Tiny URLs For Articles On My Own Site</h2>
<p>I don&#8217;t want to depend on some service that may go down. Make short urls like http://catonmat.net/abc, where abc is [a-zA-Z0-9] this will give me 238328 URLs, more than enough. I could even go for something shorter.</p>
<h2 style="margin-bottom:10px">23. Optimize Catonmat Load Speed To Maximum.</h2>
<p>Use the page-speed FireBug plugin to optimize site loading speed. Page-speed is at <a href="http://code.google.com/speed/page-speed/">http://code.google.com/speed/page-speed/</a>. Things to be optimized include minified javascript, minified html, gzip compressed content, maximizing caching, use asynchronous js loading of google analytics and others.</p>
<h2 style="margin-bottom:10px">24. Make The Posts More Available</h2>
<p>Currently the posts are only available as HTML documents. I should try to convert them to PDF and put them to Scribd. I have to think about consequences as Scribd may show up on search engines at a higher ranking position than catonmat iself, which would have drastic impact on the traffic. Saving to PDF has a benefit that it&#8217;s a single file. If saved as HTML, the browser creates a folder with tons of images. Can&#8217;t be shared easily and is clutter. Perhaps offer a PDF download for all articles.</p>
<h2 style="margin-bottom:10px">25. Make Posts Printer Friendly.</h2>
<p>Create a nice CSS template for printing articles. At the end of the article include URLs to all the mentioned resources. Add an option to choose whether to print comments or not. URL structure could be www.catonmat.net/article/print</p>
<h2 style="margin-bottom:10px">26. Add A &#8220;Share this&#8221; Widget.</h2>
<p>Add &#8220;Share this&#8221; widget and perhaps &#8220;Reddit this&#8221;, &#8220;Digg this&#8221;, &#8220;Stumble this&#8221;, etc., buttons. This should be based on referrer as I don&#8217;t want to show &#8220;Reddit this&#8221; to a Digg visitor as there is a holy war between Reddit and Digg. Also add &#8220;Tweet this&#8221; button somewhere.</p>
<h2 style="margin-bottom:10px">27. Utilize The New Google Feature Of Displaying Named Anchors In Search Results.</h2>
<p>See this post: <a href="http://googleblog.blogspot.com/2009/09/jump-to-information-you-want-right-from.html">http://googleblog.blogspot.com/2009/09/jump-to-information-you-want-right-from.html</a> Some of my posts utilize this (10 Awk Tips, Tricks and Pitfalls), but I need to utilize it more.</p>
<h2 style="margin-bottom:10px">28. Highlight The Python Code As In SQLalchemy Documentation.</h2>
<p>I like how the code is highlighted in SQLalchemy documentation. I am not sure if they are using Pygments or not, but I&#8217;ll try to make mine exactly the same. Example: http://www.sqlalchemy.org/docs/05/ormtutorial.html</p>
<h2 style="margin-bottom:10px">29. Create Pagination For Posts/Categories/Tags As In Flickr.com</h2>
<p>I like the style of Flickr&#8217;s pagination. Got to implement the same on catonmat. Example: http://www.flickr.com/photos/frijole/</p>
<h2 style="margin-bottom:10px"><strike>30. Have Pages Open In A New Window By Default.</strike></h2>
<p>I feel that opening links in a new window would keep visitors on the website longer. I haven&#8217;t tested but I will A/B this. Update: This is not a good idea, won&#8217;t implement it.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/butterfly-510x130.jpg' alt='Butterfly' /><br />
<small>An image from <a href="http://www.flickr.com/photos/paraflyer/">paraflyer&#8217;s photostream</a> on Flickr.</small>
</div>
<h2 style="margin-bottom:10px">31. Investigate What Do Various &lt;a rel=&#8221;&#8230;&#8221;> Do.</h2>
<p>There are a bunch of different relations like rel=&#8221;bookmark&#8221;, rel=&#8221;prev&#8221;, rel=&#8221;next&#8221;. This could improve the website navigation greatly. More info here: <a href="http://www.w3schools.com/TAGS/att_a_rel.asp">http://www.w3schools.com/TAGS/att_a_rel.asp</a></p>
<h2 style="margin-bottom:10px">32. Perhaps Remove The Article Date Altogether.</h2>
<p>I have noticed myself that if I search for something and I find an article from 2004, I want to look for something fresher. Got to A/B test this and see how long do people stay on the site.</p>
<h2 style="margin-bottom:10px">33. Add An IP Ban List.</h2>
<p>Sometimes spammers use the same IPs. Rather than `iptables -I INPUT &#8211;src IP -j REJECT` them, just block them at application level, 404 all pages, or redirect them elsewhere.</p>
<h2 style="margin-bottom:10px">34. Automatically Translate All Pages To All Languages Via Google Translate</h2>
<p>Sometimes people search for something in their own language and can&#8217;t find it. Perhaps they don&#8217;t know English term and therefore can&#8217;t find what they wanted. If I automatically translate all pages to all languages, people would end up on my website and find what they were looking for.  The URL scheme for this could be: www.catonmat.net/xx/&#8230;, where xx is two letter international language code.</p>
<h2 style="margin-bottom:10px">35. Try Out Dustin Curtis&#8217; Advice On Best Performing Link Texts.</h2>
<p>Dustin Curtis did <a href="http://dustincurtis.com/you_should_follow_me_on_twitter.html">an experiment</a> where he tried various link texts to invite readers to follow him on Twitter. The first version was &#8220;I&#8217;m on Twitter&#8221;, this got 4.70% click through rate. The last version was &#8220;You Should follow me on Twitter &lt;here>&#8221;. This had 12.81% CTR, which is a massive improvement.</p>
<h2 style="margin-bottom:10px">36. Add &#8220;Ask Peteris Krumins&#8221; Section Where People Can Ask Me Various Questions.</h2>
<p>People ask me a lot of questions over email. I could answer all the questions on my website instead of email. This way everyone could always find all my answers.</p>
<h2 style="margin-bottom:10px">37. Add A &#8220;FAQ&#8221; section.</h2>
<p>I get asked the same questions over and over again over email. For example,</p>
<ul>
<li>What do I have to know for Google interview?</li>
<li>What books do I read?</li>
<li>How to learn C++/C/Python/Algorithms?</li>
<li>etc.</li>
</ul>
<p>Instead of sending the answer over email, I could send these people to FAQ page where they could find my latest answers (as they change over time).</p>
<h2 style="margin-bottom:10px">38. Add Knowledge Database.</h2>
<p>This idea has the highest priority. A knowledge database is a section on my website where I can write everything that I learned each day.  This should be accompanied with a desktop application that has a hotkey that instantly brings up input dialog and I can type what I just learned. I had a database like this in 2002-2004 and my knowledge literally went exponential. I wrote out key facts that I learned each day and could easily locate as necessary.</p>
<h2 style="margin-bottom:10px">39. Add A Miniblog For Quick Articles.</h2>
<p>Sometimes I have some cool idea or quick hack that I want to share, but as I am used to writing large and well thought out articles, I can&#8217;t post the quick hacks and my thoughts don&#8217;t get shared. A miniblog would allow me to share even the smallest thoughts that I have.</p>
<h2 style="margin-bottom:10px">40. Add More Programming Quotes.</h2>
<p>I love various smart programming quotes. I should make them more accessible, make them searchable by author/text.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/bird-510x130.jpg' alt='Butterfly' /><br />
<small>An image from <a href="http://www.flickr.com/photos/paraflyer/">paraflyer&#8217;s photostream</a> on Flickr.</small>
</div>
<h2 style="margin-bottom:10px">41. Integrate LaTeX In My Posts.</h2>
<p>As I am sometimes writing about maths, I need to integrate LaTeX directly in my posts. I should not forget to do SEO on images it generates - instead of having some ridiculous &lt;img src=&#8221;latex-generator?q=$\begin{bmatrix}1&#038;2\\3&#038;4\end{bmatrix}$>&#8221; I should have it generate an image &#8220;&lt;img src=&#8221;matrix.jpg&#8221; title=&#8221;Matrix&#8221;>&#8221;. This way people will be able to find my posts via image search if they search for some mathematical terms like &#8220;Matrix&#8221;.</p>
<h2 style="margin-bottom:10px">42. Try Out How The Articles Look With Text-Align: Justify.</h2>
<p>I currently have the default left-aligned text. Books and journals have it justified. Not sure how it would look on my website. Have to try it out. A/B. I read somewhere that this may feel confusing to dyslexic users.</p>
<h2 style="margin-bottom:10px">43. Have In-Line Code Snippets And Variables Stand Out From Rest Of The Text.</h2>
<p>A nice example of this is Github&#8217;s blog. They have gray background for constant-width things. See this: <a href="http://github.com/blog/530-how-we-made-github-fast">http://github.com/blog/530-how-we-made-github-fast</a></p>
<h2 style="margin-bottom:10px">44. Have &lt;a> Links Change Background Color On Hover.</h2>
<p>I love how mattt.me has done it: <a href="http://mattt.me/articles/">http://mattt.me/articles/</a> I want this.</p>
<h2 style="margin-bottom:10px">45. Have Only One Category Per Post But Multiple Tags.</h2>
<p>A post should have only one single category. The category must strictly define the main theme of the article. A post can have multiple tags. Tags define topics discussed in the post.</p>
<h2 style="margin-bottom:10px">46. Add Crazyegg Tracking For The First Month.</h2>
<p>Must add crazyegg to track how the users navigate the site, where they click and what they visit. Optimize based on the results. <a href="http://crazyegg.com/">http://crazyegg.com/</a></p>
<h2 style="margin-bottom:10px">47. Add A Job Board.</h2>
<p>As my site is getting more popular and popular among programmers, it may be a good idea to add a job board. Joel Spolsky made a million $ in a year with job boards. As the popularity of my site increases, I might make a few dollars out of it as well.</p>
<h2 style="margin-bottom:10px">48. Use Statcounter and Google Analytics</h2>
<p>This is obvious. Statcounter is for real-time data. The free version is limited to statistics of last 500 visits. Google Analytics is for keeping long term statistics with a day of delay in updates.  Load them asynchronously: <a href="http://googlecode.blogspot.com/2009/12/google-analytics-launches-asynchronous.html">http://googlecode.blogspot.com/2009/12/google-analytics-launches-asynchronous.html</a></p>
<h2 style="margin-bottom:10px">49. Form Input Fields And Text Fields Should Change Border Color On Focus.</h2>
<p>Users should know what field they are focused to without trying to find the cursor. </p>
<h2 style="margin-bottom:10px">50. Mandatory Alt Attributes For Images, Title Attributes For Links.</h2>
<p>The rationale of this feature is that if images don&#8217;t get loaded or if blind people are listening to the content of my posts via text-to-speech engine, they should know what the image displays. Alt tags also help the search engines to classify images. The same goes for title attributes for links.</p>
<h2 style="margin-bottom:10px">51. Optimize Meta Description For Categories And Tags</h2>
<p>Category and tag pages usually have meta description as &#8220;Posts in &lt;category>&#8221;. This is unsatisfactory. I want a description of category and if it&#8217;s missing or is too short, I want it to have some post titles in it, to make it unique. The same for tags, make meta tags &#8220;Posts in &lt;tag>: post title1, post title2, &#8230;&#8221; not exceeding 20 words or so.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/bee-510x130.jpg' alt='Bee' /><br />
<small>An image from <a href="http://www.flickr.com/photos/paraflyer/">dsevilla&#8217;s photostream</a> on Flickr.</small>
</div>
<p>The next post in this series will be about Python libraries that I use for the new catonmat and the structure of the site. You can also follow the development on <a href="http://github.com/pkrumins/catonmat.net">GitHub</a> (I started importing code only yesterday so there is not much yet).</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=gTczt-4E1-Y:6J9qlHStPN4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=gTczt-4E1-Y:6J9qlHStPN4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=gTczt-4E1-Y:6J9qlHStPN4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=gTczt-4E1-Y:6J9qlHStPN4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=gTczt-4E1-Y:6J9qlHStPN4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=gTczt-4E1-Y:6J9qlHStPN4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=gTczt-4E1-Y:6J9qlHStPN4:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/gTczt-4E1-Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/50-ideas-for-the-new-catonmat-website/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/50-ideas-for-the-new-catonmat-website/</feedburner:origLink></item>
		<item>
		<title>I pushed 30 of my projects to GitHub</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/ybN1O7iewyE/</link>
		<comments>http://www.catonmat.net/blog/i-pushed-30-of-my-projects-to-github/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 04:35:14 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Misc]]></category>
<category>adns</category><category>api</category><category>awk</category><category>bash</category><category>bit hacks</category><category>busy beaver</category><category>codinghorror</category><category>cpp</category><category>digg</category><category>dns</category><category>dpf</category><category>ed</category><category>emacs</category><category>feedburner</category><category>git</category><category>github</category><category>hacker news</category><category>perl</category><category>php</category><category>picurls</category><category>plurk</category><category>programming</category><category>projects</category><category>python</category><category>reddit</category><category>screen</category><category>sed</category><category>statcounter</category><category>unix</category><category>vbscript</category><category>vi</category><category>winamp</category><category>xgoogle</category><category>youtube</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/i-pushed-30-of-my-projects-to-github/</guid>
		<description><![CDATA[Hey everyone, I just pushed 30 of my projects to GitHub. I realized that all the projects were scattered across my blog and there was no central repository. So I took time to organize them, write documentation, and uploaded them to GitHub.
I did all of these projects for fun and to learn better programming. You [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/es4xs3GjfF2lCgL56dkZLj8Mp1I/0/da"><img src="http://feedads.g.doubleclick.net/~a/es4xs3GjfF2lCgL56dkZLj8Mp1I/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/es4xs3GjfF2lCgL56dkZLj8Mp1I/1/da"><img src="http://feedads.g.doubleclick.net/~a/es4xs3GjfF2lCgL56dkZLj8Mp1I/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/github-social-coding.gif' alt='GitHub Social Coding' class="post-icon" align="left" />Hey everyone, I just pushed 30 of my projects to GitHub. I realized that all the projects were scattered across my blog and there was no central repository. So I took time to organize them, write documentation, and uploaded them to GitHub.</p>
<p>I did all of these projects for fun and to learn better programming. You can&#8217;t become a great programmer if you don&#8217;t program a lot. The more you program, the more language idioms and constructs you&#8217;ll learn. You&#8217;ll learn common patterns that occur frequently in programming and it will greatly improve your problem solving skills.</p>
<p>These were all relatively small projects and I think I am ready to move to the next level. I have several larger ideas in mind that need to be turned into code. I will post the updates to catonmat.</p>
<p>If you find any of my projects interesting, clone and start hacking. You can also follow <a href="http://github.com/pkrumins">my profile at github</a>. :-)</p>
<p>Here they all are. Enjoy!</p>
<h2 style="margin-bottom:10px">1. Busy Beaver</h2>
<p>Busy beaver is a computer science problem to finding the smallest Turing Machine that outputs the most data and eventually halts. This project is an implementation of a Turing Machine in Python and C++ that runs the busy beavers. It also comes with Turing Machine&#8217;s tape visualization tool written in Perl.</p>
<ul>
<li><a href="http://github.com/pkrumins/busy-beaver">Busy Beaver on Github</a>.</li>
<li><a href="http://www.catonmat.net/blog/busy-beaver/">Article about Busy Beaver on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">2. Feedburner Graph Generator</h2>
<p>Current <a href="http://www.feedburner.com">Feedburner</a> statistics graphs do not look nice. I wrote this Perl program to generate the nice graphs they had in 2008.</p>
<ul>
<li><a href="http://github.com/pkrumins/feedburner-graph-generator">Feedburner graph generator on Github</a>.</li>
<li><a href="http://www.catonmat.net/blog/generating-feedburner-graphs/">Article about feedburner graph generator on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">3. CodingHorror Keyword Analyzer</h2>
<p>This is a Perl program that parses public statcounter data for codinghorror.com blog and stores the search keywords in an SQLite database.</p>
<ul>
<li><a href="http://github.com/pkrumins/codinghorror-keyword-analyzer">CodingHorror keyword analyzer on Github</a>.</li>
<li><a href="http://www.catonmat.net/blog/analyzing-keyword-activity-on-coding-horror/">Article about analyzing Coding Horror keywords on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">4. Adns</h2>
<p>This is a tiny Python module that does asynchronous DNS resolution with adns library. My benchmarks were 20,000 resolutions per minute on a 512kbit/s connection.</p>
<ul>
<li><a href="http://github.com/pkrumins/adns">Adns on Github</a>.</li>
<li><a href="http://www.catonmat.net/blog/asynchronous-dns-resolution/">Article about ands on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">5. Winamp Music Reporter Plugin</h2>
<p>This is a Winamp plugin that reports to digitalpoint forums the tracks you are listening to. Written in C and uses Winamp SDK. The code can be modified to make it report to Facebook or Twitter, or anywhere you wish.</p>
<ul>
<li><a href="http://github.com/pkrumins/winamp-plugin-digitalpoint-music-reporter">Winamp music reporter on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/projects/dpf-winamp-music-reporter/">An article about Winamp music reporter on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">6. Bithacks.h</h2>
<p>Bithacks.h is a C header file that implements various bit operations.</p>
<ul>
<li><a href="http://github.com/pkrumins/bithacks.h">Bithacks.h on Github</a>.</li>
<li><a href="http://www.catonmat.net/blog/bit-hacks-header-file/">Article about bithacks.h on catonmat</a>.</li>
<li><a href="http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/">Explanation of all the bithacks</a>.</li>
</ul>
<h2 style="margin-bottom:10px">7. Set Operations in Unix Shell</h2>
<p>This is an implementation of 14 set operations by using only Unix utilities such as sort, uniq, diff, comm, cat, head, tail, awk, and others.</p>
<ul>
<li><a href="http://github.com/pkrumins/set-operations-in-unix-shell">Set operations in Unix shell on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/set-operations-in-unix-shell/">Article about set operations in Unix shell on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">8. Hacker Top</h2>
<p>Hacker top is a Unix top-like program written in Python for monitoring <a href="http://news.ycombinator.com">Hacker News</a> from the console.</p>
<ul>
<li><a href="http://github.com/pkrumins/hacker-top">Hacker top on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/follow-hacker-news-from-the-console/">Article about the Hacker top program on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">9. Reddit Top</h2>
<p>Reddit top is a Unix top-like program written in Python for monitoring <a href="http://www.reddit.com">Reddit</a> from the console.</p>
<ul>
<li><a href="http://github.com/pkrumins/reddit-top">Reddit top on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/follow-reddit-from-the-console/">Article about the Reddit top program on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">10. GNU Awk YouTube Downloader</h2>
<p>This is a program written in GNU Awk that downloads YouTube videos. It works well but please don&#8217;t take it too seriously. It&#8217;s a proof of concept code, written to see what can be done with GNU Awk&#8217;s networking interface.</p>
<ul>
<li><a href="http://github.com/pkrumins/gnu-awk-youtube-downloader">GNU Awk YouTube downloader on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/downloading-youtube-videos-with-gawk/">Article about GNU Awk YouTube downloader on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">11. VBScript YouTube Downloader</h2>
<p>This is a program written in VBScript that downloads YouTube videos. I wrote it because when I was a child, I did a lot of programming in Visual Basic and I wanted to remember what it was like.</p>
<ul>
<li><a href="http://github.com/pkrumins/vbscript-youtube-downloader">YouTube downloader in VBScript on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/writing-a-youtube-video-downloader-in-vbscript/">An article about VBScript YouTube downloader on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">12. Perl One-Liner YouTube Downloader</h2>
<p>This is a Perl one-liner that downloads YouTube videos. I wrote it because I love Perl golf.</p>
<ul>
<li><a href="http://github.com/pkrumins/perl-youtube-downloader-one-liner">YouTube downloader one-liner in Perl on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/downloading-youtube-videos-with-a-perl-one-liner/">An article about creating the Perl one-liner that downloads YouTube videos on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">13. YouTube Video Uploader</h2>
<p>This is a YouTube video uploader that works without any APIs. It just simulates what a browser would do and takes all the steps to post the video and set the video info. Written in Perl.</p>
<ul>
<li><a href="http://github.com/pkrumins/youtube-uploader">YouTube video uploader on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/how-to-upload-youtube-videos-programmatically/">An article about creating the video uploader on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">14. Plurk Translation Tool</h2>
<p>This is a GreaseMonkey script that translates Plurks to English.</p>
<p><a href="http://www.plurk.com">Plurk</a> is like Twitter but more fun and organized. Come be my friend on Plurk, my profile name is <a href="http://www.plurk.com/pkrumins">pkrumins</a>. Written in JavaScript.</p>
<ul>
<li><a href="http://github.com/pkrumins/plurk-translation-tool">Plurk translation tool on Github</a>.</li>
<li><a href="http://opensource.plurk.com/Translation_Tool/">Plurk translation tool description on Plurk&#8217;s Open Source website</a>.</li>
</ul>
<h2 style="margin-bottom:10px">15. Command Line Plurker</h2>
<p>Plurk from your command line. Written in Perl.</p>
<ul>
<li><a href="http://github.com/pkrumins/plurk-command-line-plurker">Command line plurker on GitHub</a>.</li>
</ul>
<h2 style="margin-bottom:10px">16. Find Plurks on Google</h2>
<p>This program searches for plurks that were indexed by Google. It outputs URLs to indexed pages. It&#8217;s written in Python and uses my <a href="http://www.catonmat.net/blog/python-library-for-google-search/">xgoogle library</a>.</p>
<ul>
<li><a href="http://github.com/pkrumins/plurk-find-plurks-on-google">Plurk finder on GitHub</a>.</li>
</ul>
<h2 style="margin-bottom:10px">17. Delete Plurks</h2>
<p>This is a GreaseMonkey script that adds a &#8220;delete&#8221; button on individual plurk pages. This way you can delete your or other people plurks (if it&#8217;s your thread) directly from the plurk page. Written in JavaScript.</p>
<ul>
<li><a href="http://github.com/pkrumins/plurk-delete-plurks">Delete plurks on GitHub</a>.</li>
</ul>
<h2 style="margin-bottom:10px">18. Xgoogle</h2>
<p>A Python library to Google services - Google Search, Google Sets, Google Translate and Sponsored Links.</p>
<ul>
<li><a href="http://github.com/pkrumins/xgoogle">Xgoogle on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/python-library-for-google-search/">An article about Google search module on catonmat</a>.</li>
<li><a href="http://www.catonmat.net/blog/python-library-for-google-sets/">An article about Google sets module on catonmat</a>.</li>
<li><a href="http://www.catonmat.net/blog/python-library-for-google-translate/">An article about Google translate module on catonmat</a>.</li>
<li><a href="http://www.catonmat.net/blog/python-library-for-google-sponsored-links-search/">An article about Google sponsored links module on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">19. Reddit Media</h2>
<p>The old Reddit Media website that I created in 2007. No longer maintained. It was written in Perl.</p>
<ul>
<li><a href="http://github.com/pkrumins/reddit-media">Reddit media on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/designing-reddit-media-website/">An article about creating Reddit media website on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">20. Reddit River</h2>
<p>The old Reddit River website for mobile devices. No longer maintained. It was written in Python.</p>
<ul>
<li><a href="http://github.com/pkrumins/reddit-river">Reddit river on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/designing-redditriver-dot-com-website/">An article about creating Reddit river website on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">21. Digpicz</h2>
<p>This is the digpicz.com website that I created back in 2007. It got massive attention back then because Digg didn&#8217;t have picture section then. It was written in Perl.</p>
<ul>
<li><a href="http://github.com/pkrumins/digpicz">Digpicz on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/designing-digg-picture-website/">An article about creating Digpicz website on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">22. Picurls</h2>
<p>Picurls.com is a picture aggregator much like popurls.com but for pics. Currently down for maintenance, will be soon up again. Written in PHP.</p>
<ul>
<li><a href="http://github.com/pkrumins/picurls.com">Picurls on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/making-of-picurls-popurls-for-pictures-part-one/">An article about creating Picurls.com website part I</a>.</li>
<li><a href="http://www.catonmat.net/blog/making-of-picurls-popurls-for-pictures-part-two/">An article about creating Picurls.com website part II</a>.</li>
</ul>
<h2 style="margin-bottom:10px">23. Bash Vi Editing Mode Cheat Sheet</h2>
<p>Bash has two input modes - emacs and vi. This is vi input/editing mode keyboard shortcut cheat sheet.</p>
<ul>
<li><a href="http://github.com/pkrumins/bash-vi-editing-mode-cheat-sheet">Bash vi cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/">Article about bash vi mode on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">24. Bash Emacs Editing Mode Cheat Sheet</h2>
<p>Bash has two input modes - emacs and vi. This is emacs input/editing mode keyboard shortcut cheat sheet.</p>
<ul>
<li><a href="http://github.com/pkrumins/bash-emacs-editing-mode-cheat-sheet">Bash emacs cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-sheet/">Article about bash emacs mode on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">25. Bash History Cheat Sheet</h2>
<p>This is the bash history cheat sheet. It summarizes everything there is to know about working efficiently with command line history in bash.</p>
<ul>
<li><a href="http://github.com/pkrumins/bash-history-cheat-sheet">Bash history cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/">The definitive guide to bash history on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">26. Screen Cheat Sheet</h2>
<p>This is the screen terminal emulator cheat sheet. It lists the default keyboard shortcuts for working with screen.</p>
<ul>
<li><a href="http://github.com/pkrumins/screen-cheat-sheet">Screen cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/screen-terminal-emulator-cheat-sheet/">Article about screen cheat sheet on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">27. Perl Special Variable Cheat Sheet</h2>
<p>This is Perl predefined variable cheat sheet. It lists all the variables from `<a href="http://perldoc.perl.org/perlvar.html">perldoc perlvar</a>` with a concise description and some example usages. I created it when I was mastering Perl. I enjoy Perl golf and I wanted to know all of the variables.</p>
<ul>
<li><a href="http://github.com/pkrumins/perl-predefined-variable-cheat-sheet">Perl special variable cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/perls-special-variable-cheat-sheet/">An article about Perl predefined variable cheat sheet on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">28. Perl pack/unpack and printf/sprintf Cheat Sheet</h2>
<p>This is Perl pack/unpack/printf/sprintf cheat sheet. The pack/unpack cheat sheet is on page one, and it lists the pack/unpack template parameters and what they do. The printf/sprintf cheat sheet is on page two, and it lists the printf/sprintf format specifiers and format attributes.</p>
<p>I created this when I was mastering what could be done with pack/unpack. I added printf/sprintf as I could never remember all the format specifiers.</p>
<ul>
<li><a href="http://github.com/pkrumins/perl-pack-unpack-printf-sprintf-cheat-sheet">Perl pack, unpack, printf, sprintf cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/perl-pack-unpack-printf-cheat-sheet/">An article about Perl pack, unpack, printf, sprintf cheat sheet on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">29. Awk Cheat Sheet</h2>
<p>AWK programming language cheat sheet.</p>
<ul>
<li><a href="http://github.com/pkrumins/awk-cheat-sheet">Awk cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/awk-nawk-and-gawk-cheat-sheet/">An article about Awk cheat sheet on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">30. Sed Cheat Sheet</h2>
<p>This is sed cheat sheet. Sed is the Unix stream editor. If you don&#8217;t know it, you don&#8217;t know Unix.</p>
<ul>
<li><a href="http://github.com/pkrumins/sed-cheat-sheet">Sed cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/sed-stream-editor-cheat-sheet/">An article about sed cheat sheet on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">31. Ed Cheat Sheet</h2>
<p>This is ed cheat sheet. Ed is The Unix Text Editor.</p>
<p>One day when I was learning sed, I got interested if it originated from ed, which got me interested in ed itself. I find that cheat sheets are a great way to learn new topics and therefore I created this cheat sheet.</p>
<ul>
<li><a href="http://github.com/pkrumins/ed-cheat-sheet">Ed cheat sheet on GitHub</a>.</li>
<li><a href="http://www.catonmat.net/blog/ed-unix-text-editor-cheat-sheet/">An article about ed cheat sheet on catonmat</a>.</li>
</ul>
<h2 style="margin-bottom:10px">32. The New catonmat.net Website</h2>
<p>I just started pushing code to the new catonmat.net repository. It&#8217;s going to be a state of the art personal website from now on.</p>
<p>I have around 100 ideas for it, and the next big article series on catonmat is going to be &#8220;<strong>Designing the new catonmat.net together with me.</strong>&#8221; You should subscribe to my blog <a href="http://www.catonmat.net/feed/">here</a> if you are interested!</p>
<ul>
<li><a href="http://github.com/pkrumins/catonmat.net">The New catonmat.net on GitHub</a>.</li>
<li>Articles about designing the new catonmat coming soon.</a>
</ul>
<p>If you have any questions, don&#8217;t hesitate to ask in the comments!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=ybN1O7iewyE:Szjme1_hB7g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=ybN1O7iewyE:Szjme1_hB7g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=ybN1O7iewyE:Szjme1_hB7g:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=ybN1O7iewyE:Szjme1_hB7g:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=ybN1O7iewyE:Szjme1_hB7g:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=ybN1O7iewyE:Szjme1_hB7g:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=ybN1O7iewyE:Szjme1_hB7g:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/ybN1O7iewyE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/i-pushed-30-of-my-projects-to-github/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/i-pushed-30-of-my-projects-to-github/</feedburner:origLink></item>
		<item>
		<title>MIT Linear Algebra, Lecture 2: Elimination with Matrices</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/Zf5TfLx7qsI/</link>
		<comments>http://www.catonmat.net/blog/mit-linear-algebra-part-two/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 03:32:30 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Linear Algebra]]></category>
<category>associativity</category><category>augmented matrix</category><category>ax=b</category><category>back substitution</category><category>column</category><category>column vector</category><category>commutativity</category><category>determinant</category><category>ea=u</category><category>elimination</category><category>elimination matrix</category><category>gilbert strang</category><category>inverse matrices</category><category>inverse matrix</category><category>linear algebra</category><category>matrices</category><category>matrix</category><category>mit</category><category>ocw</category><category>permutation matrix</category><category>pivot</category><category>row</category><category>row vector</category><category>solution</category><category>upper triangular matrix</category><category>video lectures</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/mit-linear-algebra-part-two/</guid>
		<description><![CDATA[This is the second post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture two on solving systems of linear equations by elimination and back-substitution. The other topics in the lecture are elimination matrices (also known as elementary matrices) and permutation matrices.
The first post covered the geometry of [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/fXyE__lzySjK9SGjwpxnqgYG-9Q/0/da"><img src="http://feedads.g.doubleclick.net/~a/fXyE__lzySjK9SGjwpxnqgYG-9Q/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/fXyE__lzySjK9SGjwpxnqgYG-9Q/1/da"><img src="http://feedads.g.doubleclick.net/~a/fXyE__lzySjK9SGjwpxnqgYG-9Q/1/di" border="0" ismap="true"></img></a></p><p><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/11/mit-introduction-to-linear-algebra.jpg' alt='MIT Introduction to Linear Algebra' class="post-icon" align="left" />This is the second post in an article series about MIT&#8217;s course &#8220;Linear Algebra&#8221;. In this post I will review lecture two on solving systems of linear equations by <strong>elimination</strong> and <strong>back-substitution</strong>. The other topics in the lecture are <strong>elimination matrices</strong> (also known as <strong>elementary matrices</strong>) and <strong>permutation matrices</strong>.</p>
<p>The <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-one/">first post</a> covered the geometry of linear equations. </p>
<p>One of my blog readers, Seyed M. Mottaghinejad, had also watched this course and sent me his lecture notes. They are awesome. Grab them here: <a href='http://www.catonmat.net/blog/wp-content/uploads/2009/12/lecture-notes-by-seyed-m-mottaghinejad.zip' title='Linear Algebra lecture notes by Seyed M. Mottaghinejad'>lecture notes by Seyed M. Mottaghinejad</a> (includes .pdf, .tex and his document class).</p>
<p>Okay, here is the second lecture.</p>
<h2 style="margin-bottom:10px">Lecture 2: Elimination with Matrices</h2>
<p><strong>Elimination</strong> is the way every software package solves equations. If the elimination succeeds it gets the answer. If the matrix A in A<strong>x</strong>=<strong>b</strong> is a &#8220;good&#8221; matrix (we&#8217;ll see what a good matrix is later) then the elimination will work and we&#8217;ll get the answer in an efficient way. It&#8217;s also always good to ask how can it fail. We&#8217;ll see in this lecture how elimination decides if the matrix A is good or bad. After the elimination there is a step called <strong>back-substitution</strong> to complete the answer.</p>
<p>Okay, here is a system of equations. Three equations in three unknowns.</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/3-equations-3-unknowns.jpg' alt='three equations, three unknowns' />
</div>
<p>Remember from <a href="http://www.catonmat.net/blog/mit-linear-algebra-part-one/">lecture one</a>, that every such system can be written in the matrix form A<strong>x</strong>=<strong>b</strong>, where A is the matrix of coefficients, <strong>x</strong> is a column vector of unknowns and <strong>b</strong> is the column vector of solutions (the right hand side). Therefore the matrix form of this example is the following:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/ax-equals-b.jpg' alt='Ax=b' />
</div>
<p>For the elimination process we need the matrix A and the column vector b. The idea is very simple, first we write them down in the augmented matrix form A|b:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/augmented-matrix-ab.jpg' alt='augmented matrix form a|b' />
</div>
<p>Next we subtract rows from one another in such a way that the final result is an upper triangular matrix (a matrix with all the elements below the diagonal being zero).</p>
<p>So the first step is to subtract the first row multiplied by 3 from the second row. This gives us the following matrix:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/elimination-step-one.jpg' alt='elimination step one' />
</div>
<p>The next step is to subtract the second row multiplied by 2 from the third row. This is the final step and produces an upper triangular matrix that we needed:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/elimination-step-two.jpg' alt='elimination step one' />
</div>
<p>Now let&#8217;s write down the equations that resulted from the elimination:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/ax-equals-b-after-elimination.jpg' alt='Ax=b after elimination' />
</div>
<p>Working from the bottom up we can immediately find the solutions z, y, and x. From the last equation, z = -10/5 = -2. Now we put z in the middle equation and solve for y. 2y = 6 + 2z = 6 + 2(-2) = 6 - 4 = 2 => y = 1. And finally, we can substitute y and z in the first equation and solve for x. x = 2 - 2y - z = 2 - 2(1) - (-2) = 2.</p>
<p>We have found the solution, it&#8217;s (x=2, y=1, z=-2). The process we used to find it is called the <strong>back-substitution</strong>.</p>
<p>The elimination would fail if taking a multiple of one row and adding to the next would produce a zero on the diagonal (and there would be no other row to try to exchange the failing row with).</p>
<p>The lecture continues with figuring out how to do the elimination by using matrices. In the first lecture we learned that <strong>a matrix times a column vector gave us a combination of the columns of the matrix</strong>. Similarly, <strong>a row times a matrix gives us a combination of the rows of the matrix</strong>.</p>
<p>Let&#8217;s look at our first step of elimination again. It was to subtract 3 times the first row from the second row. This can be expressed as matrix multiplication (forget the column b for a while):</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-elimination-step-one.jpg' alt='matrix elimination' />
</div>
<p>Let&#8217;s call the matrix on the right E as elimination matrix (or elementary matrix), and give it subscript E<sub>21</sub> for making a zero in the resulting matrix at row 2, column 1.</p>
<p>The next step was twice the second row minus the third row:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-elimination-step-two.jpg' alt='matrix elimination' />
</div>
<p>The matrix on the right is again an elimination matrix. Let&#8217;s call it E<sub>32</sub> for giving a zero at row 3, column 2.</p>
<p>But notice that these two operations can be combined:</p>
<div class="center-aligner">
<img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/matrix-elimination-step-three.jpg' alt='matrix elimination' />
</div>
<p>And we can write E<sub>32</sub>(E<sub>21</sub>A) = U. Now remember that matrix operations are associative, therefore we can change the parenthesis (E<sub>32</sub>E<sub>21</sub>)A = U. If we multiply (E<sub>32</sub>E<sub>21</sub>) we get a single matrix E that we will call the <strong>elimination matrix</strong>. What we have done is expressed the whole elimination process in matrix language!</p>
<p>Next, the lecture continues takes a step back and looks at <strong>permutation matrices</strong>. The question asked is &#8220;what matrix would exchange two rows of a matrix?&#8221; and &#8220;what matrix would exchange two columns of a matrix?&#8221;</p>
<p>Watch the lecture to find the answer to these questions!</p>
<div class="center-aligner">
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/QVKj3LADCnA&#038;hl=en_US&#038;fs=1&#038;"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/QVKj3LADCnA&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
Direct link: <a href="http://www.youtube.com/watch?v=QVKj3LADCnA">http://www.youtube.com/watch?v=QVKj3LADCnA</a>
</div>
<p>Topics covered in lecture two:</p>
<ul>
<li>[00:25] Main topic for today: elimination.</li>
<li>[02:35] A system with three equations and three unknowns: <img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/3-equations-3-unknowns.jpg' alt='two linear equations, two unknowns' style="vertical-align: middle" /></li>
<li>[03:30] Elimination process. Taking matrix A to U.</li>
<li>[08:35] Three pivots of matrix U.</li>
<li>[10:15] Relation of pivots to determinant of a matrix.</li>
<li>[10:40] How can elimination fail?</li>
<li>[14:40] Back substitution. Solution (x=2, y=1, z=-2).</li>
<li>[19:45] Elimination with matrices.</li>
<li>[21:10] Matrix times a column vector is a linear combination of columns the matrix.</li>
<li>[22:15] A row vector times a matrix is a linear combination of rows of the matrix.</li>
<li>[23:40] Matrix x column = column.</li>
<li>[24:10] Row x matrix = row.</li>
<li>[24:20] Elimination matrix for subtracting three times row one from row two.</li>
<li>[26:55] The identity matrix.</li>
<li>[30:00] Elimination matrix for subtracting two times row two from row three.</li>
<li>[32:40] E<sub>32</sub>E<sub>21</sub>A = U.</li>
<li>[37:20] Permutation matrices.</li>
<li>[37:30] How to exchange rows of a 2&#215;2 matrix?</li>
<li>[37:55] Permutation matrix P to exchange rows of a 2&#215;2 matrix.</li>
<li>[38:40] How to exchange columns of a 2&#215;2 matrix?</li>
<li>[39:40] Permutation matrix P to exchange columns of a 2&#215;2 matrix.</li>
<li>[42:00] Commutative law does not hold for matrices.</li>
<li>[44:25] Introduction to inverse matrices.</li>
<li>[47:10] E<sup>-1</sup>E = I.</li>
</ul>
<p>Here are my notes of lecture two:</p>
<div class="center-aligner">
<a href='http://www.catonmat.net/blog/wp-content/uploads/2009/12/mit-linear-algebra-lecture-02.jpg' title='MIT Linear Algebra, Lecture 2: Elimination with Matrices'><img src='http://www.catonmat.net/blog/wp-content/uploads/2009/12/mit-linear-algebra-lecture-02-thumb.jpg' alt='MIT Linear Algebra, Lecture 2: Elimination with Matrices' /></a><br />
<small>My notes of linear algebra lecture 2 on elimination with matrices.</small>
</div>
<p>Have fun with this lecture! The next post is going to be either on lectures three and four together or just lecture three. Lecture three will touch a bit more on matrix multiplication and then dive into the inverse matrices. Lecture four will cover A=LU matrix decomposition (also called factorization).</p>
<p>PS. This course is taught from <a href="http://www.amazon.com/gp/product/0980232716?tag=catonmat-20">Introduction to Linear Algebra</a> textbook. Get it here:</p>
<div class="center-aligner">
<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=freesciencand-20&#038;o=1&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=10FE9736YVPPT7A0FBG2&#038;asins=0980232716" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=Zf5TfLx7qsI:4GIDQ8SmMBc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=Zf5TfLx7qsI:4GIDQ8SmMBc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=Zf5TfLx7qsI:4GIDQ8SmMBc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=Zf5TfLx7qsI:4GIDQ8SmMBc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=Zf5TfLx7qsI:4GIDQ8SmMBc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=Zf5TfLx7qsI:4GIDQ8SmMBc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=Zf5TfLx7qsI:4GIDQ8SmMBc:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/Zf5TfLx7qsI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/mit-linear-algebra-part-two/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/mit-linear-algebra-part-two/</feedburner:origLink></item>
		<item>
		<title>Secret Perl Operators</title>
		<link>http://feedproxy.google.com/~r/catonmat/~3/uIE_s5KQQik/</link>
		<comments>http://www.catonmat.net/blog/secret-perl-operators/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 05:10:32 +0000</pubDate>
		<dc:creator>Peteris Krumins</dc:creator>
		
		<category><![CDATA[Programming]]></category>
<category>eskimo greeting</category><category>goatse</category><category>inchworm</category><category>inchworm on a stick</category><category>operators</category><category>perl</category><category>spaceship</category><category>spacestation</category><category>turtle</category><category>venus</category>
		<guid isPermaLink="false">http://www.catonmat.net/blog/secret-perl-operators/</guid>
		<description><![CDATA[There is a mysterious underground Perl organization that hardly anyone has heard of. Their primary mission is to discover new secret Perl operators but they are not allowed to talk about them. I managed to infiltrate this organization and steal some of their secrets. Here are 8 secret Perl operators that I retrieved from their [...]]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/IRcli-dhBP5C-MkvAYImYTZOmbg/0/da"><img src="http://feedads.g.doubleclick.net/~a/IRcli-dhBP5C-MkvAYImYTZOmbg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/IRcli-dhBP5C-MkvAYImYTZOmbg/1/da"><img src="http://feedads.g.doubleclick.net/~a/IRcli-dhBP5C-MkvAYImYTZOmbg/1/di" border="0" ismap="true"></img></a></p><p>There is a mysterious underground Perl organization that hardly anyone has heard of. Their primary mission is to discover new secret Perl operators but they are not allowed to talk about them. I managed to infiltrate this organization and steal some of their secrets. Here are 8 secret Perl operators that I retrieved from their mysterious hoard:</p>
<ul>
<li><a name="toc-spaceship" style="background:none;padding-right:0"><a href="#spaceship">The Spaceship Operator</a></li>
<li><a name="toc-eskimo" style="background:none;padding-right:0"><a href="#eskimo">The Eskimo Greeting Operator</a></li>
<li><a name="toc-goatse" style="background:none;padding-right:0"><a href="#goatse">The Goatse Operator</a></li>
<li><a name="toc-turtle" style="background:none;padding-right:0"><a href="#turtle">The Turtle Operator</a></li>
<li><a name="toc-inchworm" style="background:none;padding-right:0"><a href="#inchworm">The Inchworm Operator</a></li>
<li><a name="toc-inchwormstick" style="background:none;padding-right:0"><a href="#inchwormstick">The Inchworm-On-A-Stick Operator</a></li>
<li><a name="toc-spacestation" style="background:none;padding-right:0"><a href="#spacestation">The Spacestation Operator</a></li>
<li><a name="toc-venus" style="background:none;padding-right:0"><a href="#venus">The Venus Operator</a></li>
</ul>
<p>(to be honest, only the first is a real Perl operator, all others are syntactic tricks.)</p>
<h2 style="margin-bottom:10px"><a name="spaceship" style="background:none;padding-right:0"></a><a href="#toc-spaceship">The Spaceship Operator &lt;=&gt;</a></h2>
<p>&lt;=&gt; is the spaceship operator. Most commonly it&#8217;s used to sort a list of numbers. Here is an example:</p>
<pre>
my @numbers = (-59, 99, 87, 1900, 42, 1, -999, 30000, 0);
my @sorted = sort { $a &lt;=&gt; $b } @numbers;
print "@sorted\n";

# output: -999 -59 0 1 42 87 99 1900 30000
</pre>
<p>If you don&#8217;t specify a block with the spaceship operator to sort() function, it will treat the numbers as strings and sort them asciibetically:</p>
<pre>
my @numbers = (-59, 99, 87, 1900, 42, 1, -999, 30000, 0);
my @sorted = sort @numbers;
print "@sorted\n";

# output: -59 -999 0 1 1900 30000 42 87 99
</pre>
<p>In general the spaceship operator is defined as following:</p>
<ul>
<li>$a &lt;=&gt; $b is -1 if $a &lt; $b.</li>
<li>$a &lt;=&gt; $b is 0 if $a == $b.</li>
<li>$a &lt;=&gt; $b is 1 if $a &gt; $b.</li>
<li>$a &lt;=&gt; $b is undef if $a and $b are NaN.</li>
</ul>
<h2 style="margin-bottom:10px"><a name="eskimo" style="background:none;padding-right:0"></a><a href="#toc-eskimo">The Eskimo Greeting Operator }{</a></h2>
<p>The Eskimo greeting operator can be most frequently met in Perl one-liners. </p>
<p>For example, this one-liner uses the Eskimo greeting to emulate `wc -l` command and prints the number of lines in a file:</p>
<pre>
perl -lne '}{ print $.' file
</pre>
<p>Here the Eskimo greets the print function. To understand what happens here, you have to know what the -n command line option does. It causes Perl to assume the following loop around your program:</p>
<pre>
while (<>) {
  &#46;&#46;&#46;
}
</pre>
<p>Where `&#46;&#46;&#46;` contains the code specified by the -e command line option. If the code specified is `}{ &#46;&#46;&#46;` then it causes the while loop to be closed with no actions to be done and only the `&#46;&#46;&#46;` part gets executed.</p>
<p>Therefore the one-liner above is equivalent to:</p>
<pre>
while (<>) {
}
{
print $.
}
</pre>
<p>This just prints the <a href="http://www.catonmat.net/blog/perls-special-variable-cheat-sheet/">special variable</a> $. which is the number of input lines processed.</p>
<p>This can be extended further and we can have Eskimo greet code on both sides:</p>
<pre>
perl -lne 'code1 }{ code2'
</pre>
<p>Code1 gets executed within the loop and code2 after the loop is done:</p>
<pre>
while (<>) {
  code1
}
{
  code2
}
</pre>
<p>If you are interested in the topic of Perl one-liners, see the first part of my article &#8220;<a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-one/">Perl One-Liners Explained</a>&#8220;.</p>
<h2 style="margin-bottom:10px"><a name="goatse" style="background:none;padding-right:0"></a><a href="#toc-goatse">The Goatse Operator =()=</a></h2>
<p>The Goatse operator, as nasty as it may sound, doesn&#8217;t do any nasty things. Instead it does a wonderful thing and causes an expression on the right to be evaluated in array context.</p>
<p>Here is an example, </p>
<pre>
my $str = "5 foo 6 bar 7 baz";
my $count =()= $str =~ /\d/g;
print $count;
</pre>
<p>This program prints 3 - the number of digits in $str. How does it do it? Let&#8217;s deparse the 2nd line:</p>
<pre>
(my $count = (() = ($str =~ /\d/g)));
</pre>
<p>What happens here is that the expression ($str =~ /\d/g) gets assigned to the empty list (). Assigning to a list forces the list context. The whole (() = ($str =~ /\d/g)) thing gets evaluated in list context, but then it gets assigned to a scalar which causes it to get evaluated again in scalar context. So what we have is a list assignment in scalar context. The key thing to remember is that a list assignment in scalar context returns the number of elements on the right-hand side of the list assignment. In this example the right-hand side of the list assignment is ($str =~ /\d/g). This matches globally (/g flag) and finds 3 digits in $str. Therefore the result is 3.</p>
<h2 style="margin-bottom:10px"><a name="turtle" style="background:none;padding-right:0"></a><a href="#toc-turtle">The Turtle Operator &#8220;@{[]}&#8221;</a></h2>
<p>I couldn&#8217;t find the name of this operator therefore I decided to name it the turtle operator, because it looks a bit like a turtle, @ being the head, and {[]} being the shell.</p>
<p>This operator is useful for interpolating an array inside a string.</p>
<p>Compare these two examples:</p>
<pre>
print "these people @{[get_names()]} get promoted"
</pre>
<p>and</p>
<pre>
print "these people ", join " ",get_names(), " get promoted"
</pre>
<p>Clearly, the first example wins for code clarity.</p>
<p>More precisely, writing</p>
<pre>
print "@{[something]}"
</pre>
<p>is exactly the same as writing</p>
<pre>
print join $", something
</pre>
<h2 style="margin-bottom:10px"><a name="inchworm" style="background:none;padding-right:0"></a><a href="#toc-inchworm">The Inchworm Operator ~~</a></h2>
<p>The inchworm operator can be used to force scalar context.</p>
<p>Here is an example with localtime() function. In scalar context localtime() returns human readable time, but in list context it returns a 9-tuple with various date elements.</p>
<pre>
$ perl -le 'print ~~localtime'
Mon Nov 30 09:06:13 2009
</pre>
<p>Here localtime was evaluated in scalar context, even though it was called within print that forces list context. It returned human readable date and time.</p>
<pre>
$ perl -le 'print localtime'
579301010913330
</pre>
<p>Here localtime returned a list of 9 elements and print function just printed them one after another. To really see that it&#8217;s a list of 9 elements, let&#8217;s use the turtle operator:</p>
<pre>
$ perl -le 'print "@{[localtime]}"'
5 13 9 30 10 109 1 333 0
</pre>
<h2 style="margin-bottom:10px"><a name="inchwormstick" style="background:none;padding-right:0"></a><a href="#toc-inchwormstick">The Inchworm-On-A-Stick Operator ~-</a></h2>
<p>For numbers greater than 0, this operator decrements them by one. Example:</p>
<pre>
my $x = 5;
print ~-$x;

# prints 4
</pre>
<p>It works because ~-$x parses to (~(-$x)), which on a two-complement machine is effectively the same as $x-1.</p>
<h2 style="margin-bottom:10px"><a name="spacestation" style="background:none;padding-right:0"></a><a href="#toc-spacestation">The Spacestation Operator -+-</a></h2>
<p>The spacestation operator turns a string starting with positive number into a number. Here are some examples:</p>
<pre>
print -+-"4zy"   # prints 4
print -+-'3.99'  # prints 3.99
print -+-'2e5'   # prints 200000
</pre>
<h2 style="margin-bottom:10px"><a name="venus" style="background:none;padding-right:0"></a><a href="#toc-venus">The Venus Operator 0+</a></h2>
<p>It&#8217;s named the Venus operator because the astronomical symbol for the planet Venus looks similar.</p>
<p>It does the same as the spacestation operator, it numifies a string, but it binds less tightly than spacestation. An example:</p>
<pre>
print 0+"4zy"  # prints 4
</pre>
<p>Share the secrets!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/catonmat?a=uIE_s5KQQik:QY0mqTepmZA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/catonmat?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=uIE_s5KQQik:QY0mqTepmZA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/catonmat?i=uIE_s5KQQik:QY0mqTepmZA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=uIE_s5KQQik:QY0mqTepmZA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/catonmat?i=uIE_s5KQQik:QY0mqTepmZA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/catonmat?a=uIE_s5KQQik:QY0mqTepmZA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/catonmat?i=uIE_s5KQQik:QY0mqTepmZA:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/catonmat/~4/uIE_s5KQQik" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catonmat.net/blog/secret-perl-operators/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.catonmat.net/blog/secret-perl-operators/</feedburner:origLink></item>
	</channel>
</rss>
