{"id":195,"date":"2014-09-10T22:47:34","date_gmt":"2014-09-11T05:47:34","guid":{"rendered":"http:\/\/icanthascheezburger.com\/wordpress\/?p=195"},"modified":"2014-09-10T22:47:34","modified_gmt":"2014-09-11T05:47:34","slug":"til","status":"publish","type":"post","link":"https:\/\/icanthascheezburger.com\/wordpress\/2014\/09\/til\/","title":{"rendered":"TIL"},"content":{"rendered":"<p>After being inspired by a bunch of Ruby Rogues episodes and in part by my colleague Brett&#8217;s <a href=\"http:\/\/brettu.com\/rails-ruby-tips-365-omfg-a-year-of-ruby-tips\/\">year of Ruby tips<\/a> I decided to try a simple experiment in which I get into the habit of starting to document every time I encounter some new piece of information. Sometimes days pass by when I feel like I haven&#8217;t grown in any appreciable way, and this is a really great and deliberate reminder that you learn something new every day, and you learn something new and remember to make a note of it almost every day.<\/p>\n<p>Being the hardcore Evernote user that I am, I started dumping these notes into a new tag called <code>things I learned today<\/code>. <\/p>\n<p>It&#8217;s a great habit. I find I remember these things a little better, and even when I don&#8217;t, it doesn&#8217;t matter! I have it saved safely in Evernote! I don&#8217;t just use this for programming topics, either. I make a note any time I figure out something and think &#8220;hey, that&#8217;s neat!&#8221; or if I was trying to figure out something and it was hard to google because I had such a tenuous grasp on how to describe it (like songs where the tune is stuck in my head but I can&#8217;t remember anything about the lyrics).<\/p>\n<p>Here are a few things that I learned over the past several weeks:<\/p>\n<h4 id=\"refinements_in_irb\">Refinements in irb<\/h4>\n<p>It turns out that due to a change after refinements were introduced in Ruby 2.0.0, they&#8217;re not nearly as easy to use and play with in an <code>irb<\/code> console. You&#8217;re better off writing them in a file and including the file in IRB if you want to play. <a href=\"https:\/\/bugs.ruby-lang.org\/issues\/9580\">Learn more<\/a><\/p>\n<h4 id=\"markdown_to_evernote\">Markdown to Evernote<\/h4>\n<p>There exists a handy OS X service for taking some Markdown and sending it into an Evernote note. I love this because I love to type bulleted lists using Markdown&#8217;s bulleted list syntax, but just having plain old Markdown in my Evernote note doesn&#8217;t feel nearly as fancy. The maintainer admits he has been neglecting it a bit, but you can check it out <a href=\"http:\/\/nsuserview.kopischke.net\/post\/6223792409\/i-can-has-some-markdown\">on his blog<\/a>.<\/p>\n<h4 id=\"regex_postgres_queries_with_activerecord\">Regex Postgres queries with ActiveRecord<\/h4>\n<p>Here&#8217;s how to construct an ActiveRecord query to find records where a field matches a regex pattern:<\/p>\n<p><code>things_with_a_pathetic_90s_description = Thing.where(\"description ~ '^.*NOT!$'\")<\/code><\/p>\n<h4 id=\"chocolate_chip_cookie_science\">Chocolate Chip Cookie Science<\/h4>\n<p>A photographic diagram of how various ingredients affect the resulting cookie. <a href=\"http:\/\/note.io\/ZgovNg\">Delicious&#8230;<\/a><\/p>\n<h4 id=\"rendering_collections_without_loops\">Rendering collections without loops<\/h4>\n<p>Using ERB templates in Rails, there&#8217;s a concise way you can render a partial of every item in a collection:<\/p>\n<p><code>&lt;%= render partial:\"line_item\", collection:@line_items, as: :line_item  %&gt;<\/code><\/p>\n<h4 id=\"enumerablegroup_by\">Enumerable#group_by<\/h4>\n<p>I love SQL&#8217;s <code>GROUP BY<\/code>. I wanted to do something similar with a plain old Ruby array, and in the process I learned why ActiveRecord calls it <code>group<\/code> and not <code>group_by<\/code>; the method name was taken. Also, that was the best I could do at coming up with a good mnemonic device for remembering which is for which.<\/p>\n<p><code>(1..6).group_by { |i| i%3 } #=&gt; {0=&gt;[3, 6], 1=&gt;[1, 4], 2=&gt;[2, 5]}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After being inspired by a bunch of Ruby Rogues episodes and in part by my colleague Brett&#8217;s year of Ruby tips I decided to try a simple experiment in which I get into the habit of starting to document every time I encounter some new piece of information. Sometimes days pass by when I feel [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":0,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"wp:attachment":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}