<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>paydrotalks</title>
  <link type="text/html" rel="alternate" href="http://paydrotalks.com"/>
  <link type="application/atom+xml" rel="self" href="http://paydrotalks.com/feed.atom"/>
  <updated>2016-01-03T17:01:29-08:00</updated>
  <author>
    <name>Peter Bui</name>
    <email>peter@paydrotalks.com</email>
  </author>

  
  <entry>
    <published>2016-01-03T00:00:00-08:00</published>
    <updated>2016-01-03T00:00:00-08:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/2016/01/03/hacking-redis-to-save-money.html"/>
    <id>http://paydrotalks.com/2016/01/03/hacking-redis-to-save-money</id>
    <title>Hacking Redis To Save Money</title>
    <content type="html">&lt;p&gt;Check out my &lt;a href=&quot;https://medium.com/@paydro/hacking-redis-to-save-money-6472332697e4#.i5xg6jdh0&quot;&gt;latest post on redis&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Site note – I’m kind of diggin’ medium for writing.&lt;/p&gt;
</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2015-12-24T00:00:00-08:00</published>
    <updated>2015-12-24T00:00:00-08:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/2015/12/24/scaling-the-8tracks-music-player.html"/>
    <id>http://paydrotalks.com/2015/12/24/scaling-the-8tracks-music-player</id>
    <title>Scaling the 8tracks Music Player</title>
    <content type="html">&lt;p&gt;I started using medium to see if I would write more. First post is &lt;a href=&quot;https://medium.com/@paydro/scaling-the-8tracks-music-api-c467418f8d5f#.2ds07dion&quot;&gt;Scaling the
8tracks Music
Player&lt;/a&gt;.
check it out!&lt;/p&gt;
</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2013-11-20T00:00:00-08:00</published>
    <updated>2013-11-20T00:00:00-08:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/2013/11/20/macvim-tip-tabs-per-project.html"/>
    <id>http://paydrotalks.com/2013/11/20/macvim-tip-tabs-per-project</id>
    <title>MacVim Tip: Tabs Per Project</title>
    <content type="html">&lt;p&gt;I dislike having too many windows open on my desktop. If I can consolidate them
then I will. Here’s a tip to do this with MacVim.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;:lcd path/to/proj&lt;/code&gt; instead of &lt;code&gt;:cd path/to/proj&lt;/code&gt; in the new tab.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:cd&lt;/code&gt; will change the working directory for the whole window, while &lt;code&gt;:lcd&lt;/code&gt; does
it for the current window.&lt;/p&gt;

&lt;p&gt;My &lt;a href=&quot;http://github.com/paydro/vim-config&quot;&gt;vim&lt;/a&gt; setup uses &lt;a href=&quot;http://www.vim.org/scripts/script.php?script_id=2572&quot;&gt;&lt;code&gt;ack.vim&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;http://www.vim.org/scripts/script.php?script_id=1658&quot;&gt;&lt;code&gt;NERDTree&lt;/code&gt;&lt;/a&gt;,
and &lt;a href=&quot;http://www.vim.org/scripts/script.php?script_id=3025&quot;&gt;&lt;code&gt;command-t&lt;/code&gt;&lt;/a&gt; plugins. These depend on the current working
directory. If you’ve ever decided to open another project in another tab
instead of another window, you know that running these plugins will not search
within the new project directory. Well, now when you open a new tab use &lt;code&gt;:lcd&lt;/code&gt;
to move to that directory first.&lt;/p&gt;

&lt;p&gt;For more info on &lt;code&gt;:cd&lt;/code&gt; and &lt;code&gt;:lcd&lt;/code&gt; you can run &lt;code&gt;:help current-directory&lt;/code&gt; to find
out more.&lt;/p&gt;

</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2013-07-23T00:00:00-07:00</published>
    <updated>2013-07-23T00:00:00-07:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/2013/07/23/to-orm-or-not-to-orm.html"/>
    <id>http://paydrotalks.com/2013/07/23/to-orm-or-not-to-orm</id>
    <title>To ORM Or Not To ORM</title>
    <content type="html">&lt;p&gt;I spend most of my time building/fixing/maintaining the infrastructure at
&lt;a href=&quot;http://8tracks.com&quot;&gt;8tracks&lt;/a&gt;, but every now and then I have the opportunity to
do some good old fashion ruby web application programming. This week happens to
  be one of those times. Everything was glorious … until I needed to make a
  decision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I use a gem or roll my own library to handle feature X?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I hate making this decision. It’s amazing when it’s easy. For instance,
choosing to use the &lt;code&gt;aws-sdk&lt;/code&gt; gem over rolling my own AWS library (it sucks
just generating the stupid signature much less making an normal API call). I face
so many facets dealing with choosing a gem vs. rolling my own. I always tell
myself to suck it up and choose one so I can move on, but I never fail to
change my mind shortly afterwards. And then change it again. And again. And again.&lt;/p&gt;

&lt;p&gt;I was in this horrible state yesterday. Working on an internal
sinatra/backbone.js/mongo application I had to choose whether or not to add a
mongo object relational mapping (ORM) gem or roll my own. For the past several
months I didn’t need to have any ORM as simple procedural code was more than
sufficient. The application logic mostly existed in the browser with
Backbone.js. Sinatra was a simple pipe to load mongo data to the browser. It
was extremely efficient and simple.&lt;/p&gt;

&lt;p&gt;But I needed more logic in ruby land. I thought I could add more helper methods
to manage hashes, but that soon became unmanageable (for me anyways - I have a
hard enough time remembering two variables much less 10 different helper methods).
The features I wanted to add begged for more behavior that suits a model class.
I attempted to add one of the mongo ORMs, but some of the conventions I used in
the application conflicted with the way the ORMs behaved and would require that
I write code to massage the gem into place. I decided to attempt rolling my own
ORM that behaved like ActiveRecord. This was fun until my Superman ego deflated
and I realized the scope of what I was trying to do. As usual, the scope was
huge. I was sad. I spent many hours yesterday trying out each approach but to
no avail. It’s hard replicating these huge libraries!&lt;/p&gt;

&lt;p&gt;Then something clicked last night. What I really needed was a class around the
hash that would allow me to CRUD it. All other access to the hash would behave
like a normal hash. This concept basically made normal ruby hashes in to super
hashes. Hashes with logic. Hashes with awesome. And if you’ve ever worked with
mongo, that’s basically what is stored in that database. Hashes!&lt;/p&gt;

&lt;p&gt;I had been asking myself the wrong question the whole time.  It’s not to ORM or
not to ORM, but rather CRUD this hash and add a few domain specific logic to
the hash. That’s not a question, I know. It punted me out of the horrible
decision making though.&lt;/p&gt;

&lt;p&gt;So, I spent my time today crafting a small library that would make it easier to
manage mongo documents. It was glorious. It even has tests! And I hate writing
tests.&lt;/p&gt;

</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2012-04-26T00:00:00-07:00</published>
    <updated>2012-04-26T00:00:00-07:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/posts/135-unix-cat-for-file-creation/index.html"/>
    <id>http://paydrotalks.com/posts/135-unix-cat-for-file-creation/unix-cat-for-file-creation</id>
    <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=&quot;http://8tracks.com&quot;&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;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;cat &amp;lt; my_new_file
Hello, world!
&amp;lt;hit CTRL+d here&amp;gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;cat my_new_file
Hello, world!&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This removes &lt;code&gt;vi&lt;/code&gt; from the equation. This works for my &lt;a href=&quot;/posts/131-ruby-scripting-with-shell-here-documents&quot;&gt;previous tip&lt;/a&gt; about executing arbitrary ruby code on the shell.&lt;/p&gt;
</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2012-04-19T00:00:00-07:00</published>
    <updated>2012-04-19T00:00:00-07:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/posts/133-punctuation-in-quotes/index.html"/>
    <id>http://paydrotalks.com/posts/133-punctuation-in-quotes/punctuation-in-quotes</id>
    <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=&quot;http://grammartips.homestead.com/inside.html&quot;&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;
</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2012-04-11T00:00:00-07:00</published>
    <updated>2012-04-11T00:00:00-07:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/posts/131-ruby-scripting-with-shell-here-documents/index.html"/>
    <id>http://paydrotalks.com/posts/131-ruby-scripting-with-shell-here-documents/ruby-scripting-with-shell-here-documents</id>
    <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 &#39;puts &quot;hello!&quot;&#39;
&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=&quot;http://tldp.org/LDP/abs/html/here-docs.html&quot;&gt;bash heredocs&lt;/a&gt;. Here&amp;#8217;s an example of uploading a file to S3 with the &lt;a href=&quot;https://rubygems.org/gems/right_aws&quot;&gt;right_aws gem&lt;/a&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cat &lt;&lt;RUBIES | ruby
&gt; # Write my rubyies here!
&gt; require &#39;right_aws&#39;
&gt; s3 = RightAws::S3.new(&#39;key&#39;, &#39;secret_key&#39;)
&gt; bucket = s3.bucket(&quot;my_awesome_bucket&quot;)
&gt; bucket.put(&quot;path/in/s3/my_large_file.csv&quot;, open(&#39;/path/to/local/file.csv&#39;, &#39;r&#39;))
&gt; RUBIES
&lt;/code&gt;&lt;/pre&gt;


</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2012-04-11T00:00:00-07:00</published>
    <updated>2012-04-11T00:00:00-07:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/posts/132-load-mysqldump-csvs-into-ruby-fastercsv/index.html"/>
    <id>http://paydrotalks.com/posts/132-load-mysqldump-csvs-into-ruby-fastercsv/load-mysqldump-csvs-into-ruby-fastercsv</id>
    <title>Load mysqldump CSVs into Ruby FasterCSV</title>
    <content type="html">&lt;p&gt;Working with &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html&quot;&gt;&lt;code&gt;mysqldump&lt;/code&gt;&lt;/a&gt; CSV files using the &lt;a href=&quot;http://fastercsv.rubyforge.org/&quot;&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=&quot;shell-unix-generic&quot;&gt;
  # Creates a &quot;/path/to/store/csvs/your_table_here.txt&quot; file
  $ mysqldump -u&amp;lt;user&amp;gt; \
  &amp;gt; -p&amp;lt;password&amp;gt; \
  &amp;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=&quot;shell-unix-generic&quot;&gt;
  # Edit in place
  $ sed -i \
  &amp;gt; -e &#39;s/&quot;/&quot;&quot;/g&#39; \
  &amp;gt; -e &#39;s/\t[[:space:]]*\\N/\tNULL/g&#39; \
  &amp;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=&quot;shell-unix-generic&quot;&gt;
  # Edit in place
  $ sed -i \
  &amp;gt; -e &#39;s/\t/&quot;,&quot;/g&#39; \
  &amp;gt; -e &#39;s/^\(.*\)$/&quot;\1&quot;/g&#39; \
  &amp;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=&quot;ruby&quot;&gt;
  FasterCSV.open(&#39;/path/to/store/csvs/your_table_here.txt&#39;) do |row|
    puts row[0], row[1] # ...
  end
&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=&quot;ruby&quot;&gt;
  FasterCSV.open(
    &#39;/path/to/store/csvs/your_table_here.txt&#39;, 
    :converters =&amp;gt; lambda{|f| f == &quot;NULL&quot; ? nil : f}
  ) do |row|
    puts row[0], row[1] # ...
  end
&lt;/pre&gt;
</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2012-04-05T00:00:00-07:00</published>
    <updated>2012-04-05T00:00:00-07:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/posts/130-lets-rock-out/index.html"/>
    <id>http://paydrotalks.com/posts/130-lets-rock-out/lets-rock-out</id>
    <title>Let's rock out</title>
    <content type="html">&lt;p&gt;&lt;object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0&quot; width=&quot;300&quot; height=&quot;250&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://8tracks.com/mixes/683238/player_v3&quot;&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;embed src=&quot;http://8tracks.com/mixes/683238/player_v3&quot; pluginspage=&quot;http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;300&quot; height=&quot;250&quot; allowscriptaccess=&quot;always&quot; &gt;&lt;/embed&gt;&lt;/object&gt;&lt;p class=&quot;_8t_embed_p&quot; style=&quot;font-size: 11px; line-height: 12px;&quot;&gt;&lt;a href=&quot;http://8tracks.com/paydro/i-love-rock-n-roll&quot;&gt;I Love Rock &amp;#8216;n&amp;#8217; Roll&lt;/a&gt; from &lt;a href=&quot;http://8tracks.com/paydro&quot;&gt;paydro&lt;/a&gt; on &lt;a href=&quot;http://8tracks.com&quot;&gt;8tracks&lt;/a&gt;.&lt;/p&gt;&lt;/p&gt;
</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
  <entry>
    <published>2011-08-17T00:00:00-07:00</published>
    <updated>2011-08-17T00:00:00-07:00</updated>
    <link type="text/html" rel="alternate" href="http://paydrotalks.com/posts/129-chrome-browser-just-made-my-day/index.html"/>
    <id>http://paydrotalks.com/posts/129-chrome-browser-just-made-my-day/chrome-browser-just-made-my-day</id>
    <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=&quot;https://paydrotalks.s3.amazonaws.com/images/chrome-awesome.jpg&quot; width=&quot;351&quot; height=&quot;370&quot;&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;
</content>
    <author>
      <name>paydro</name>
    </author>
  </entry>
  
</feed>


