<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US">
  <id>tag:paydrotalks.com,2005:/feed</id>
  <link type="text/html" href="http://paydrotalks.com" rel="alternate" />
  
  <title>paydrotalks</title>
  <updated>2012-04-26T12:56:16-07:00</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/paydrotalks" /><feedburner:info uri="paydrotalks" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <id>tag:paydrotalks.com,2005:Post/135</id>
    <published>2012-04-26T12:56:16-07:00</published>
    <updated>2012-04-26T13:01:58-07:00</updated>
    <link type="text/html" href="http://feedproxy.google.com/~r/paydrotalks/~3/S42VmYwTBp4/135-unix-cat-for-file-creation" rel="alternate" />
    <title>Unix `cat` For File Creation</title>
    <content type="html">&lt;p&gt;I spend copious amounts of time on the servers at &lt;a href="http://8tracks.com"&gt;8tracks.com&lt;/a&gt;. On occasion, I upload a ruby/base/etc script to the server to test. In the past I normally fire up &lt;code&gt;vi&lt;/code&gt; on the server, paste the code in, save it, and execute it. When the script fails because of a bug, I fix the file on my local editor, copy the code, reopen the file on the server with vi, save it, and execute it. This is slow. Here&amp;#8217;s a faster way using &lt;code&gt;cat&lt;/code&gt; and the &lt;code&gt;CTRL+d&lt;/code&gt; keyboard shortcut in a terminal.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
$ cat &amp;gt; my_new_file
Hello, world!
&amp;lt;hit CTRL+d here&amp;gt;
$ cat my_new_file
Hello, world!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This removes &lt;code&gt;vi&lt;/code&gt; from the equation. This works for my &lt;a href="http://paydrotalks.com/posts/131-ruby-scripting-with-shell-here-documents"&gt;previous tip&lt;/a&gt; about executing arbitrary ruby code on the shell.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/paydrotalks/~4/S42VmYwTBp4" height="1" width="1"/&gt;</content>
    <author>
      <name>paydro</name>
    </author>
  <feedburner:origLink>http://paydrotalks.com/posts/135-unix-cat-for-file-creation</feedburner:origLink></entry>
  <entry>
    <id>tag:paydrotalks.com,2005:Post/133</id>
    <published>2012-04-19T09:41:28-07:00</published>
    <updated>2012-04-19T09:53:45-07:00</updated>
    <link type="text/html" href="http://feedproxy.google.com/~r/paydrotalks/~3/Pbg7GR8xFWY/133-punctuation-in-quotes" rel="alternate" />
    <title>Punctuation In Quotes</title>
    <content type="html">&lt;p&gt;I&amp;#8217;m always confused by punctuations marks with quotations. For instance, where do you place the period when the sentence ends with quotes? Does the period go inside the quotes or outside? I know the rules (inside), but it still bothers me and I couldn&amp;#8217;t figure out why &amp;#8230; until I found &lt;a href="http://grammartips.homestead.com/inside.html"&gt;this&lt;/a&gt; (emphasis mine)!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When it comes to commas and periods, though, &lt;b&gt;logic doesn&amp;#8217;t enter into the equation&lt;/b&gt;, at least not in the United States.  Universal American usage places commas and periods inside the quotation marks, regardless of logic.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I was doing it all wrong with logic! It&amp;#8217;s like measuring distance in America. Obviously, one mile is 5,280 feet. And one foot is 12 inches! DUH.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/paydrotalks/~4/Pbg7GR8xFWY" height="1" width="1"/&gt;</content>
    <author>
      <name>paydro</name>
    </author>
  <feedburner:origLink>http://paydrotalks.com/posts/133-punctuation-in-quotes</feedburner:origLink></entry>
  <entry>
    <id>tag:paydrotalks.com,2005:Post/132</id>
    <published>2012-04-11T14:55:16-07:00</published>
    <updated>2012-04-11T15:23:34-07:00</updated>
    <link type="text/html" href="http://feedproxy.google.com/~r/paydrotalks/~3/diIKZjm-NJs/132-load-mysqldump-csvs-into-ruby-fastercsv" rel="alternate" />
    <title>Load mysqldump CSVs into Ruby FasterCSV</title>
    <content type="html">&lt;p&gt;Working with &lt;a href="http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html"&gt;&lt;code&gt;mysqldump&lt;/code&gt;&lt;/a&gt; CSV files using the &lt;a href="http://fastercsv.rubyforge.org/"&gt;FasterCSV&lt;/a&gt; is a pain. &lt;code&gt;mysqldump&lt;/code&gt; converts NULL fields into &lt;code&gt;\N&lt;/code&gt; and it uses backslashes (&amp;#8216;\&amp;#8217;) to escape characters. The only character in a well formed CSV that you need to escape is the double quote (&amp;#8216;&amp;quot;&amp;#8217;). You can change the &lt;code&gt;mysqldump&lt;/code&gt; escape characters and force double quotes around the fields, but  &lt;code&gt;FasterCSV::MalformedCsvError&lt;/code&gt; errors still occur.&lt;/p&gt;
&lt;p&gt;After multiple tries I looked to shell scripting to get this working. Modifying large files this way wont be fast, but I do this with scripts that run in the background so I don&amp;#8217;t mind the time it takes.&lt;/p&gt;
&lt;p&gt;First thing is to dump your table(s) into CSV formats. The following &lt;code&gt;mysqldump&lt;/code&gt; command outputs tab separated fields with no surrounding quotes.&lt;/p&gt;
&lt;pre class="active4d"&gt;  &lt;span class="LineComment"&gt;&lt;span class="LineComment"&gt;#&lt;/span&gt; Creates a &amp;quot;/path/to/store/csvs/your_table_here.txt&amp;quot; file&lt;/span&gt;
  $ mysqldump -u&lt;span class="Operator"&gt;&amp;lt;&lt;/span&gt;user&lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; -p&lt;span class="Operator"&gt;&amp;lt;&lt;/span&gt;password&lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; -t --tab=/path/to/store/csvs/ your_db_here your_table_here
&lt;/pre&gt;
&lt;p&gt;Since the only double quote in the file belongs to the content, I can escape them with &lt;code&gt;sed&lt;/code&gt;. At the same time, I like to change &lt;code&gt;\N&lt;/code&gt; to &lt;code&gt;NULL&lt;/code&gt;. This &lt;code&gt;sed&lt;/code&gt; command does the trick.&lt;/p&gt;
&lt;pre class="active4d"&gt;  &lt;span class="LineComment"&gt;&lt;span class="LineComment"&gt;#&lt;/span&gt; Edit in place&lt;/span&gt;
  $ sed -i \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; -e &lt;span class="String"&gt;&lt;span class="String"&gt;'&lt;/span&gt;s/&amp;quot;/&amp;quot;&amp;quot;/g&lt;span class="String"&gt;'&lt;/span&gt;&lt;/span&gt; \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; -e &lt;span class="String"&gt;&lt;span class="String"&gt;'&lt;/span&gt;s/\t[[:space:]]*\\N/\tNULL/g&lt;span class="String"&gt;'&lt;/span&gt;&lt;/span&gt; \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; /path/to/store/csvs/your_table_here.txt
&lt;/pre&gt;
&lt;p&gt;Now that everything is properly escaped I double quote the fields and replace the tabs with commas.&lt;/p&gt;
&lt;pre class="active4d"&gt;  &lt;span class="LineComment"&gt;&lt;span class="LineComment"&gt;#&lt;/span&gt; Edit in place&lt;/span&gt;
  $ sed -i \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; -e &lt;span class="String"&gt;&lt;span class="String"&gt;'&lt;/span&gt;s/\t/&amp;quot;,&amp;quot;/g&lt;span class="String"&gt;'&lt;/span&gt;&lt;/span&gt; \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; -e &lt;span class="String"&gt;&lt;span class="String"&gt;'&lt;/span&gt;s/^\(.*\)$/&amp;quot;\1&amp;quot;/g&lt;span class="String"&gt;'&lt;/span&gt;&lt;/span&gt; \
  &lt;span class="Operator"&gt;&amp;gt;&lt;/span&gt; /path/to/store/csvs/your_table_here.txt
&lt;/pre&gt;
&lt;p&gt;You can combine both of those steps into one &lt;code&gt;sed&lt;/code&gt; command, but I like having them separate in my scripts. It&amp;#8217;s easier to digest.&lt;/p&gt;
&lt;p&gt;Now you&amp;#8217;re ready to use that file with FasterCSV (or CSV if you&amp;#8217;re on ruby 1.9) with the default settings!&lt;/p&gt;
&lt;pre class="active4d"&gt;  &lt;span class="LibraryClassType"&gt;FasterCSV&lt;/span&gt;.&lt;span class="FunctionName"&gt;open&lt;/span&gt;(&lt;span class="String"&gt;&lt;span class="String"&gt;'&lt;/span&gt;/path/to/store/csvs/your_table_here.txt&lt;span class="String"&gt;'&lt;/span&gt;&lt;/span&gt;) &lt;span class="Keyword"&gt;do &lt;/span&gt;|&lt;span class="Variable"&gt;row&lt;/span&gt;|
    puts row[&lt;span class="Number"&gt;0&lt;/span&gt;], row[&lt;span class="Number"&gt;1&lt;/span&gt;] &lt;span class="LineComment"&gt;&lt;span class="LineComment"&gt;#&lt;/span&gt; ...&lt;/span&gt;
  &lt;span class="Keyword"&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;I like to use a converter to convert those NULL fields to &lt;code&gt;nil&lt;/code&gt;s.&lt;/p&gt;
&lt;pre class="active4d"&gt;  &lt;span class="LibraryClassType"&gt;FasterCSV&lt;/span&gt;.&lt;span class="FunctionName"&gt;open&lt;/span&gt;(
    &lt;span class="String"&gt;&lt;span class="String"&gt;'&lt;/span&gt;/path/to/store/csvs/your_table_here.txt&lt;span class="String"&gt;'&lt;/span&gt;&lt;/span&gt;, 
    &lt;span class="UserDefinedConstant"&gt;&lt;span class="UserDefinedConstant"&gt;:&lt;/span&gt;converters&lt;/span&gt; =&amp;gt; lambda{|&lt;span class="Variable"&gt;f&lt;/span&gt;| f &lt;span class="Operator"&gt;==&lt;/span&gt; &lt;span class="String"&gt;&lt;span class="String"&gt;&amp;quot;&lt;/span&gt;NULL&lt;span class="String"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class="Operator"&gt;?&lt;/span&gt; &lt;span class="BuiltInConstant"&gt;nil&lt;/span&gt; : f}
  ) &lt;span class="Keyword"&gt;do &lt;/span&gt;|&lt;span class="Variable"&gt;row&lt;/span&gt;|
    puts row[&lt;span class="Number"&gt;0&lt;/span&gt;], row[&lt;span class="Number"&gt;1&lt;/span&gt;] &lt;span class="LineComment"&gt;&lt;span class="LineComment"&gt;#&lt;/span&gt; ...&lt;/span&gt;
  &lt;span class="Keyword"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/paydrotalks/~4/diIKZjm-NJs" height="1" width="1"/&gt;</content>
    <author>
      <name>paydro</name>
    </author>
  <feedburner:origLink>http://paydrotalks.com/posts/132-load-mysqldump-csvs-into-ruby-fastercsv</feedburner:origLink></entry>
  <entry>
    <id>tag:paydrotalks.com,2005:Post/131</id>
    <published>2012-04-11T12:49:32-07:00</published>
    <updated>2012-04-11T13:05:33-07:00</updated>
    <link type="text/html" href="http://feedproxy.google.com/~r/paydrotalks/~3/T-QSTFg3DYY/131-ruby-scripting-with-shell-here-documents" rel="alternate" />
    <title>Ruby Scripting with Shell Here Documents</title>
    <content type="html">&lt;p&gt;Ever need to run a command you know how to do very well in Ruby but don&amp;#8217;t know off hand with bash? It&amp;#8217;s pretty easy if you have a single line handy for ruby like:&lt;/p&gt;
&lt;pre&gt;
$ ruby -e 'puts "hello!"'
&lt;/pre&gt;
&lt;p&gt;But, what happens if the ruby code is more complex and has multiple lines? You can obviously use semi-colons, but that&amp;#8217;s less elegant. Let me introduce you to &lt;a href="http://tldp.org/LDP/abs/html/here-docs.html"&gt;bash heredocs&lt;/a&gt;. Here&amp;#8217;s an example of uploading a file to S3 with the &lt;a href="https://rubygems.org/gems/right_aws"&gt;right_aws gem&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;
$ cat &amp;lt;&amp;lt;RUBIES | ruby
&amp;gt; # Write my rubyies here!
&amp;gt; require 'right_aws'
&amp;gt; s3 = RightAws::S3.new('key', 'secret_key')
&amp;gt; bucket = s3.bucket("my_awesome_bucket")
&amp;gt; bucket.put("path/in/s3/my_large_file.csv", open('/path/to/local/file.csv', 'r'))
&amp;gt; RUBIES
&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/paydrotalks/~4/T-QSTFg3DYY" height="1" width="1"/&gt;</content>
    <author>
      <name>paydro</name>
    </author>
  <feedburner:origLink>http://paydrotalks.com/posts/131-ruby-scripting-with-shell-here-documents</feedburner:origLink></entry>
  <entry>
    <id>tag:paydrotalks.com,2005:Post/130</id>
    <published>2012-04-05T09:34:48-07:00</published>
    <updated>2012-04-05T09:35:20-07:00</updated>
    <link type="text/html" href="http://feedproxy.google.com/~r/paydrotalks/~3/pAe9n9ZKVeg/130-lets-rock-out" rel="alternate" />
    <title>Let's rock out</title>
    <content type="html">&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="250"&gt;&lt;param name="movie" value="http://8tracks.com/mixes/683238/player_v3"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed src="http://8tracks.com/mixes/683238/player_v3" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="300" height="250" allowscriptaccess="always" &gt;&lt;/embed&gt;&lt;/object&gt;&lt;p class="_8t_embed_p" style="font-size: 11px; line-height: 12px;"&gt;&lt;a href="http://8tracks.com/paydro/i-love-rock-n-roll"&gt;I Love Rock &amp;#8216;n&amp;#8217; Roll&lt;/a&gt; from &lt;a href="http://8tracks.com/paydro"&gt;paydro&lt;/a&gt; on &lt;a href="http://8tracks.com"&gt;8tracks&lt;/a&gt;.&lt;/p&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/paydrotalks/~4/pAe9n9ZKVeg" height="1" width="1"/&gt;</content>
    <author>
      <name>paydro</name>
    </author>
  <feedburner:origLink>http://paydrotalks.com/posts/130-lets-rock-out</feedburner:origLink></entry>
  <entry>
    <id>tag:paydrotalks.com,2005:Post/129</id>
    <published>2011-08-17T14:38:52-07:00</published>
    <updated>2011-08-17T19:49:23-07:00</updated>
    <link type="text/html" href="http://feedproxy.google.com/~r/paydrotalks/~3/yQ63v-EJbSs/129-chrome-browser-just-made-my-day" rel="alternate" />
    <title>Chrome Browser Just Made My Day</title>
    <content type="html">&lt;p&gt;Chrome added the ability to view &lt;code&gt;:hover&lt;/code&gt; or &lt;code&gt;:focus&lt;/code&gt; styles in the web inspector.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://paydrotalks.s3.amazonaws.com/images/chrome-awesome.jpg" width="351" height="370"&gt;&lt;/p&gt;
&lt;p&gt;This is amazing.&lt;/p&gt;
&lt;p&gt;If only they added &lt;code&gt;:before&lt;/code&gt; and &lt;code&gt;:after&lt;/code&gt; as well.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/paydrotalks/~4/yQ63v-EJbSs" height="1" width="1"/&gt;</content>
    <author>
      <name>paydro</name>
    </author>
  <feedburner:origLink>http://paydrotalks.com/posts/129-chrome-browser-just-made-my-day</feedburner:origLink></entry>
  <entry>
    <id>tag:paydrotalks.com,2005:Post/128</id>
    <published>2011-04-01T12:54:23-07:00</published>
    <updated>2011-04-01T12:55:26-07:00</updated>
    <link type="text/html" href="http://feedproxy.google.com/~r/paydrotalks/~3/G9HnDro-rxY/128-racc" rel="alternate" />
    <title>Racc</title>
    <content type="html">&lt;p&gt;I just came across &lt;a href="http://i.loveruby.net/en/projects/racc/"&gt;Racc&lt;/a&gt; &amp;#8211; a ruby implementation of &lt;a href="http://dinosaur.compilertools.net/"&gt;Yacc&lt;/a&gt;. This is bringing back memories of my compiler course in college. I&amp;#8217;m geeking out!&lt;/p&gt;
&lt;p&gt;In college, I built a compiler for Pascal with Lex and Yacc. The project converted Pascal code to Lisp code and ran on Sun machines. It was pretty awesome. Sadly, I don&amp;#8217;t have the code anymore, but I loved building it!&lt;/p&gt;
&lt;p&gt;I started building a Mysql client in the web (think phpmyadmin but without the suck) and I have a need to parse SQL. Racc + SQL Parsing? Can there be anymore joy? Also, Racc&amp;#8217;s runtime modules come with the Ruby standard library. How did I miss this?&lt;/p&gt;
&lt;p&gt;Time to build a simple SQL parser in Ruby.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/paydrotalks/~4/G9HnDro-rxY" height="1" width="1"/&gt;</content>
    <author>
      <name>paydro</name>
    </author>
  <feedburner:origLink>http://paydrotalks.com/posts/128-racc</feedburner:origLink></entry>
</feed>
