<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tyler Brewer on Medium]]></title>
        <description><![CDATA[Stories by Tyler Brewer on Medium]]></description>
        <link>https://medium.com/@tyler_brewer2?source=rss-6e4e1da4d47e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k2COBe_UzD_jLFdYHN9CNA.jpeg</url>
            <title>Stories by Tyler Brewer on Medium</title>
            <link>https://medium.com/@tyler_brewer2?source=rss-6e4e1da4d47e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 18:58:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tyler_brewer2/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Bits, Bytes, and Byte Slices in Go]]></title>
            <link>https://medium.com/@tyler_brewer2/bits-bytes-and-byte-slices-in-go-8a99012dcc8f?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a99012dcc8f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Sun, 19 Jan 2020 20:57:55 GMT</pubDate>
            <atom:updated>2022-02-07T15:35:07.789Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNlOKSdJjr-Af1R5snxIMQ.png" /></figure><p>If you come from a background other than Computer Science and learned programming through a higher level language such as Ruby (like I did), you may have never really “needed” to be concerned about what bytes, bits, and binary are. Sure, you may have done some research out of interest on the topic, but you never actually needed to create a list of bytes because the language abstracts all of this away from you.</p><p>After switching from primarily programming in Ruby to primarily programming in Go, byte slices were a source of confusion for me. I found myself not understanding when or why to use a byte slice and why integers were converted to seemingly random characters when running code like string(42) // Output: * . To truly understand what a byte slices are and when to use them, we should start by actually defining what bytes and bits are.</p><h3><strong>What are bytes and bits?</strong></h3><p>A bit references a single binary value, either a 1 or a 0. For a computer to process information the information must be written in binary. If all we could send to a computer would be a single 1 or a 0, we wouldn’t be as far as we are today with computers. Luckily, bits can be added together to reference much larger numbers than 1 and 0.</p><p>Bits can be added together and their values are equal to 2 to the power of the place of the bit (from right to left). When the bit is 1, the bit value is added to the binary value. When the bit is 0, the value is not added. The binary value consisting of 8 bits equal to00000001 would equal 1 (2 to the 0th power = 1), the value 00000010 would equal 2 (2 to the 1st power), and the value 00000100 would equal 4 (2 to the 2nd power). Once you start combining these, you start to see how they can soon represent a large number. The value of 00000011 is 3 (2 to the 0th power is 1 + 2 to the 1st power is 2 = 3), the value of 10010010 is 146 (2 to the 2nd power + 2 to the 4th power + 2 to the 7th power) and 11111111 is 256.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PaXUsW94HYWK12ycliXJbQ.png" /><figcaption>Each square in the diagram is equivalent to one bit</figcaption></figure><p>Now that you know what a bit is, bytes are easy to explain. And there’s good news, you’ve already seen a few bytes! A byte is 8 bits. All of the examples above were bytes and byte values.</p><h3>Unicode and UTF-8</h3><p>Before diving into byte slices, we need to briefly visit encoding. <a href="https://home.unicode.org/">Unicode</a> is “the universal character encoding”. Unicode supports over 137,000 characters and 150 different languages. Each character has a specific Unicode code point that represents the character. For example, the Unicode code point for the capital letter “T” is U+0054<em>, </em>the Unicode code point for the lowercase letter “t” is U+0074<em>, </em>and the Unicode point for the lower left triangle “◺” is U+25FA<em>.</em></p><p>The “problem” with Unicode is that it is most often represented in software as an int32 (32 bit integer). The vast majority of characters in widespread use could fit into a much smaller number than required for a 32 bit data type. This is where UTF-8 enters the picture.</p><p>UTF-8 is a variable length encoding of Unicode code points. For each Unicode code point, it uses between 1 and 4 bytes. All of the most common characters can be represented using 1–2 bytes (all ASCII characters can be represented in 1 byte). UTF-8 allows us to use all of the characters defined by Unicode, but allows us to save some extra space and only reach for the 3rd or 4th byte when we really need it. To again list the same examples, we could represent the Unicode code point “T” as 84, “t” as and “◺” as 226 151 186<em>.</em></p><p>This is a very brief overview of encoding, and I would highly recommend reading the article <a href="https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets</a>.</p><p>Now that you know about UTF-8, let’s talk about byte slices.</p><h3>Byte Slices</h3><p>Byte slices are a list of bytes that represent UTF-8 encodings of Unicode code points. Taking the information from above, we could create a byte slice that represents the word “Go”:</p><pre>bs := []byte{71, 111}<br>fmt.Printf(&quot;%s&quot;, bs) // Output: Go</pre><p>You may notice the %s used here. This converts the byte slice to a string. Strings are <em>literally</em> made up of arrays of bytes. This makes converting strings to byte slices and byte slices to strings very easy and convenient. %d is also often used with byte slices and prints the UTF-8 decimal value of each byte.</p><pre>s := &quot;Wow look at me&quot;<br>bs := []byte(s)<br>fmt.Printf(&quot;%s&quot;, bs) // Output: Wow look at me<br>fmt.Printf(&quot;%d&quot;, bs) // Output: [87 111 119 32 108 111 111 107 32 97 116 32 109 101]</pre><p>To view something a little more interesting, here is an example of a byte slice representing a non-ASCII value:</p><pre>bs := []byte(&quot;◺&quot;)<br>fmt.Println(bs) // Output: [226 151 186]</pre><pre>s := string(bs)<br>fmt.Println(len(s)) // Output: 3</pre><p>The length of this string may seem confusing at first, but remember a string is made up of a byte slice array. The length of this string is 3 because the UTF-8 value of “◺” is 226 151 186, which means that UTF-8 uses 3 bytes to represent the Unicode code point. To get the Unicode code point (or rune) count in a string, we can use the utf8 package in the standard library:</p><pre>import (<br>    &quot;fmt&quot;<br>    &quot;unicode/utf8<br>)</pre><pre>bs := []byte(&quot;◺&quot;) <br>s := string(bs)<br>fmt.Println(utf8.RuneCountInString(s)) // Output: 1</pre><p>This is important to remember if Unicode character count is important to your software. Luckily, we do not need to handle this within range, because Go will implicitly loop over strings by their Unicode code points. The only catch here is that the index will still be incremented by the string’s byte count. Notice how i in the below example jumps from 3 to 6 after printing the triangle:</p><pre>func main() {<br> for i, b := range &quot;Hi ◺ there&quot; {<br>  fmt.Printf(&quot;i: %d. b: %q\n&quot;, i, b)<br> }<br>}</pre><pre>// i: 0. b: &#39;H&#39;<br>// i: 1. b: &#39;i&#39;<br>// i: 2. b: &#39; &#39;<br>// i: 3. b: &#39;◺&#39;<br>// i: 6. b: &#39; &#39;<br>// i: 7. b: &#39;t&#39;<br>// i: 8. b: &#39;h&#39;<br>// i: 9. b: &#39;e&#39;<br>// i: 10. b: &#39;r&#39;<br>// i: 11. b: &#39;e&#39;</pre><p>Using %c here prints the character represented by the corresponding Unicode code point. Since each of the characters in the strings of the rune type (Unicode code point) we cannot use %s to print here.</p><p>Going back to the example I gave earlier: string(42) // Output: * . This may start to be making some sense. The UTF-8 decimal value for * is 42 . So when we pass the integer 42 into a string, it is creating a byte slice containing 42 , which is equal to *.</p><h3>Byte Slices vs Strings</h3><p>So now that we know about byte slices, when should we use them over strings? The main difference in strings and byte slices in Go is the way they are handled in memory. Strings are <em>immutable, </em>meaning they cannot be changed within memory. So every time you add or remove from a a string, Go is creating a brand new string in memory. On the contrary, byte slices are <em>mutable</em>. So whenever you are adding to a byte slice, you are not creating a new object in memory. Depending on the circumstance, this can effect application speed.</p><p>Hopefully this helps “demystify” some of these concepts. There are quite a large amount of additional resources and this post has only scratched the surface of the topic, so below are some additional resources that have helped me:</p><ul><li><a href="https://www.amazon.com/Programming-Language-Addison-Wesley-Professional-Computing/dp/0134190440/ref=sr_1_2?crid=2H8RLE0WGE9BF&amp;keywords=the+go+programming+language&amp;qid=1579457325&amp;sprefix=the+go+programming+lan%2Caps%2C287&amp;sr=8-2">The Go Programming Lanuage by Alan A. A. Donovan and Brian W. Kernighan</a> (specifically chapter 2 section 3.5)</li><li><a href="https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</a></li><li><a href="https://home.unicode.org/">Unicode Website</a></li><li><a href="http://www.fileformat.info/info/charset/UTF-8/list.htm">UTF-8 Character Set</a> (note: the decimals are listed in their hexidecimal value. You can print the hexidecimal value of a byte slice by using % x when printing)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a99012dcc8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singleton Methods in Ruby]]></title>
            <link>https://medium.com/@tyler_brewer2/singleton-methods-in-ruby-a5cc8d2e222c?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5cc8d2e222c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Tue, 30 Jan 2018 17:07:54 GMT</pubDate>
            <atom:updated>2018-01-30T19:17:02.338Z</atom:updated>
            <content:encoded><![CDATA[<p>Anytime a developer says “Maybe this situation is a good use case for a singleton,” you’ll hear either shrieks or cheers depending on the past experience of the people in the room. “Singleton” can be a trigger word because if the <a href="https://dalibornasevic.com/posts/9-ruby-singleton-pattern-again">“singleton” design pattern</a> is implemented incorrectly or used in a situation that might not be the best fit, it can be a pain to deal with. Fortunately, I’m not going to be writing about the “singleton” you’re most likely thinking of. Instead, this post is going to be about the lesser known ability in Ruby, the singleton method.</p><p>Let’s say we have a Bicycle class that takes a model, color and diameter using keyword arguments (<a href="https://medium.com/@tyler_brewer2/utilizing-ruby-keyword-arguments-462ba8366483">you are using keyword arguments, right?</a>). Each instance will also have a method called wheel_radius that will use the diameter to find the radius of the wheel. This class might look something like this:</p><pre>class Bicycle<br>  attr_accessor :make, :color, :diameter</pre><pre>  def initialize(model:, color:, diameter:)<br>    <a href="http://twitter.com/model">@model</a> = model<br>    <a href="http://twitter.com/color">@color</a> = color<br>    <a href="http://twitter.com/diameter">@diameter</a> = diameter<br>  end</pre><pre>  def wheel_radius<br>    diameter / 2<br>  end<br>end</pre><p>This works great, and we can use it to create millions of bicycles and find their radiuses:</p><pre>canyon = Bicycle.new(<br>  model: &#39;Merckx&#39;,<br>  color: &#39;black&#39;,<br>  diameter: &#39;4&#39;<br>)</pre><pre>canyon.radius # 2</pre><p>Now, maybe a few years from now we decide we want to try something new. We decide that instead of a new bike with circular wheels, we decide to create one with square wheels. We’re tired of the ease of cycling and think having square wheels will improve our quality of life and make us have larger calves. So, in our pursuit of happiness, we manufacture our bike:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*rkGM4mQvptKq7bs6oPg6iQ.jpeg" /><figcaption>The masochist’s dream bike</figcaption></figure><p>To our great surprise, we hate it. But, there are some masochists in this world who love it and refuse to ride anything else, so we have to handle this type of bike in our code. We could potentially solve this using singleton methods.</p><p>Let’s say we want to find the area of the square wheeled bike using a wheel_area method. Adding this to the Bicycle class’s interface might confuse developers using our code later since all other instances of Bicycle will not need this functionality at all. Instead, we can add a singleton method to our Bicycle instance with square wheels. By doing this, we add functionality that is specific to a particular instance.</p><p>Let’s go ahead and instantiate our bikes:</p><pre>normal_bike = Bicycle.new<br>  model: &#39;Merckx&#39;,<br>  color: &#39;black&#39;,<br>  diameter: &#39;4&#39;<br>)</pre><pre>square_bike = Bicycle.new(<br>  model: &#39;Genius&#39;,<br>  color: &#39;neon&#39;,<br>  diameter: 4<br>)</pre><p>Now that we have the bike instantiated, we can now add the functionality specific to our instance using a singleton_method:</p><pre>def square_bike.wheel_area<br>  diameter ** 2<br>end</pre><pre>square_bike.wheel_area # 16<br>normal_bike.wheel_area # this will throw undefined method wheel_area</pre><p>If you’ve never seen this before, it probably looks very weird. We just modified the functionality of our specific instance at run time. Another syntax for adding singleton methods to an instance might look something like this:</p><pre>class &lt;&lt; square_bike<br>  def wheel_area<br>    diameter ** 2<br>  end</pre><pre>  def reason_for_riding<br>   &#39;To cause pain and misfortune&#39;<br>  end<br>end</pre><p>This might be a better use case if you are adding multiple singleton methods to an instance because if your variable containing your instance ever changes names, you only need to change it in one spot (also, it’s a lot easier to type).</p><p>So how does this all work? Before we can tackle this, we need to understnad how Ruby knows where to find a method when it is called, also called method lookup. For the sake of time, <a href="https://gist.github.com/damien-roche/351bf4e7991449714533">this</a> is a great gist explaining method lookup.</p><p>When we call a method on an instance, Ruby first looks in a lesser known singleton class that’s created with each instance. This is the absolute first place Ruby ever looks to call a method, so anything in this instance will overwrite the methods in the regular class (in our case Bicycle).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*Ki12v4Fj2g6HiGUWuJtg7A.png" /><figcaption>Ruby will always first look in an instances singleton class for methods</figcaption></figure><p>We can also see this inheritance chain if we call singleton_class.ancestors on our instance:</p><pre>square_bike.singleton_class.ancestors<br># &lt;Class:#&lt;Bicycle:0x0055f3047e10b0&gt;&gt;, Bicycle, and so on</pre><p>Hopefully it’s pretty clear how powerful the use of this singleton class created for each instance can be. It’s also crucial to point out that <strong>this should be used very sparingly</strong>. If you’ve been a Ruby developer for any amount of time, you’ve probably been bitten by it’s ability to allow you to manipulate basically any object at any time. If you do use this, seriously consider how you can prevent any headaches for developers that may be using your class down the road. With that said, this can be a quick and simple way to get yourself out of a bind if the situation arises.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5cc8d2e222c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Utilizing Ruby Keyword Arguments]]></title>
            <link>https://medium.com/@tyler_brewer2/utilizing-ruby-keyword-arguments-462ba8366483?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/462ba8366483</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Thu, 09 Nov 2017 15:27:12 GMT</pubDate>
            <atom:updated>2017-11-09T15:27:12.590Z</atom:updated>
            <content:encoded><![CDATA[<p>The Ruby language is known for it’s flexibility. There aren’t many things that Ruby won’t let you do, whether that’s the ability to pass any data structure to any method or the ability to meta-program pretty much everything. If used unwisely, this flexibility can cause headaches for developers. For example, having a class that takes a generic “args” hash can be great if you need to pass in a hash with dynamic values, but can cause issues debugging since this hash can literally contain anything. Ruby 2.0 introduced a new feature that allows ruby developers to continue to take advantage of the language’s flexibility, while making sure the code is readable and maintainable. Implementing keyword arguments create cleaner and more maintainable code by simplifying future refactors, explicitly stating what arguments should be passed in and outputting more meaningful argument errors.</p><h4>Positional vs keyword arguments</h4><p>For the purposes of this post, let’s say we have a Bicycle class that initializes with a make, size, weight and color. If we were to create our class using positional arguments, our class might look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNypU5yEuDBnhd727pAByQ.png" /></figure><p>This might be a good first iteration of a class, but there are quite a few problems with this approach. One of the biggest problems is order specific arguments. If later on down the road (no pun intended) you need to set a default parameter and change the order of the arguments, you will need to find every instance of Bicycle being called and reconfigure the order of the parameters. This can be cumbersome and may cause unexpected bugs, such as a property being set incorrectly since the argument order was never changed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OnXRXOdsjiPlBEOGGatdDA.png" /></figure><p>Refactoring Bicycle to use keyword arguments can help solve this problem and make future changes much easier. Our Bicycle class will no longer be order specific and is much more flexible to change later on. If we need to add our default parameter, we no longer need to change every invocation of Bicycle since each argument is explicitly stated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LU9s612BKM187JF8jKJn6Q.png" /></figure><p>This makes future refactors much easier, since we no longer have to be worried about how Bicycle is being instantiated, as long as it’s being passed the correct arguments.</p><p>Great! So now our class is flexible and refactoring in the future should be much easier. Now, when other developers look at our class, they will know exactly which parameters are being passed. Here’s what it might have looked like if we had continued to use positional arguments:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nDOG8gFH1I1qFf1bbfZNtg.png" /></figure><p>From looking at this code, there’s no way to tell what the Bicycle class needs and what parameters it’s expecting. For example, “Canyon” could be anything and there’s no real way to tell that it is actually the Bicycle’s make without finding the Bicycle class and reading over it’s arguments. This can cause problems dealing with old code that you may not remember exactly what it’s doing. Here’s how our instantiation looks like now that we’ve refactored our class to use keyword arguments:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*krgkcFZ79ZjrRzD1M69UPw.png" /></figure><h4>Args Hash vs Keyword Arguments</h4><p>After looking at this example, you may be saying “Why don’t we just refactor Bicycle to accept an “args” hash and instantiate Bicycle with it’s properties? Future developers will be able to know exactly what’s being passed in and argument order doesn’t matter!” This is a better iteration of the class than using positional arguments, but still causes some serious problems that can be a headache to debug. Let’s go ahead and refactor Bicycle to use an “args” hash:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzqmvyPKVXhuqCQI20O-Fg.png" /></figure><p>This looks really clean right? Bicycle accepts an object and just instantiates itself based off that hash’s properties. But what happens when someone forgets to add a property, like color, to the hash being passed in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yp3dNbh6HJO89NjutnGAWQ.png" /></figure><p>Color is now instantiated as nil since there is no color property on the args hash. This can be a major pain to track down and debug, since ruby gives no indication that an argument is missing in your instantiation. Here’s how keyword arguments would handle forgetting to pass the color parameter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nIEZZBFXFNnV2FSmaZsMyA.png" /></figure><p>An argument error is thrown explicitly stating which argument is missing. A developer would immediately know they are missing an argument and know exactly which argument needs to be passed in. This, again, causes refactoring to be much easier.</p><p>Utilizing keyword arguments in ruby makes development much easier for you and for other developers looking at your code later. They simplify future refactors by eliminating the need for order dependent arguments, explicitly state which arguments need to be passed in for easier instantiation, and provide helpful errors when arguments are missing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=462ba8366483" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make sending and creating emails suck less with Ruby on Rails]]></title>
            <link>https://medium.com/@tyler_brewer2/how-to-make-sending-and-creating-emails-suck-less-with-rails-253a5e392a90?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/253a5e392a90</guid>
            <category><![CDATA[email]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Wed, 16 Dec 2015 00:21:42 GMT</pubDate>
            <atom:updated>2015-12-16T00:23:12.601Z</atom:updated>
            <content:encoded><![CDATA[<h4>And hopefully make you feel like you aren’t coding in the 90&#39;s</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UiKIBYCFSOVh6Qp20WHgFQ.png" /><figcaption>How creating HTML emails seem to make people feel</figcaption></figure><p>About 2 months ago I graduated from <a href="http://www.flatironschool.com/">Flatiron School</a> (woohoo!) and started working as a Web Developer at <a href="http://www.excella.com/">Excella Consulting</a> (double woohoo!) and more specifically on the <a href="http://my.uscis.gov/">myUSCIS</a> project. Recently, I picked up the task of styling the email that we send out to users when they receive a message. If you’ve never tried to create and style an email before I’ll let you in on a secret that isn’t much of a secret: they suck. Here are the main reasons that most front-end developers hate emails:</p><ul><li>Everything must be done with tables. This will make “divs” seem like your long lost friend that moved across the country that you’ll never see again.</li><li>All CSS styles must be inline. If you’ve never heard of inline CSS styling, there’s probably a reason for that. It sucks, and it makes making your code DRY borderline impossible.</li><li>No CSS helpers. For example, instead of using “padding: 1px, 2px, 3px, 4px” to set the sides of your padding, you have to use the specific CSS property for each side. A.k.a. pain and misfortune.</li><li>Testing what emails look like can be a nightmare. Sending your email millions of times to yourself just to make sure the padding is right will make you go insane.</li><li>Email clients. If you thought trying to get your site look decent on Internet Explorer was hard, just wait until you meet it’s annoying cousin, Outlook.</li></ul><p>Rails can make SOME of these easier. You still have to use tables, which can get really annoying but get’s a little easier over time. But everything else on the above list can either be solved, or made so much easier. So how can we use Rails to actually do this?</p><h3>1. Action Mailer</h3><p>If you have never used Action mailer with Rails before, it is very simple to set up. Creating a mailer is as simple as generating anything else in rails:</p><pre>$ rails generate mailer UserMailer</pre><p>This will create a mailer (which are very similar to controllers) , a view (what the email will actually look like) and a test. Sending emails with your newly generated mailer is incredibly simple. Below is an example:</p><pre>class UserMailer &lt; ApplicationMailer <br>  default from: ‘notifications@example.com’  </pre><pre>  def welcome_email(user) <br>    @user = user<br>    @url = ‘http://example.com/login&#39;<br>    mail(to: @user.email, subject: ‘Welcome to My Awesome Site’)<br>  end<br>end</pre><p>It is important to note that mailer views are exactly the same as normal rails views, so you must use instance variables if you want to have access to your data within the view. Now, if you wanted to call this in your application, after someone creates an account for example, you would simply do something like this:</p><pre>def send_welcome(user)<br>  UserMailer.welcome_email(user).deliver_now<br>end</pre><p>This will send the email when the method is called and boom, you’re done.</p><p>I wont go into the deeper parts of Action Mailer because the <a href="http://guides.rubyonrails.org/action_mailer_basics.html">Rails Guides</a> do a better job than I ever could. Something I do want to point out that was introduced in Rails 4.1 is Actionmailer Previews. This makes viewing a preview of your emails incredibly easy. In your “test/mailers” directory create a directory called “previews” and inside of that directory create a file called something_preview.rb (ex. user_preview.rb). Inside of that you will put something like the following:</p><pre>class UserPreview &lt; ActionMailer::Preview </pre><pre>  def welcome <br>    UserMailer.welcome(User.first) <br>  end <br>end</pre><p>This will create a route at “<a href="http://localhost:3000/rails/mailers/notifier/welcome">/rails/mailers/notifier/welcome</a>” and will be a preview of whichever email you send through the “welcome” method (or whatever you decide to call it). This makes viewing simple style changes so much quicker than actually sending an email. <strong>IMPORTANT:</strong> This doesn’t mean that it will show you what the email looks like in each email client. More on that later.</p><h3>2. Premailer-rails</h3><p>So this isn’t necessarily a “Rails” feature but it’s a gem that you can use with Rails so I’m going to say it is. Sue me. The <a href="https://github.com/fphilipe/premailer-rails">premailer-rails</a> gem is great and allows you to use external stylesheets! That means you can utilize classes just as you would for styling which will keep your code DRY-er and easier to read. Premailer-rails is incredibly easy to set up. All you have to do is add the gem to your Gemfile, bundle install and you’re all set! Whenever an email is sent premailer will be automatically run and compile all of your external stylesheets that you use for that specific mailer into inline styling that wont make email clients freak out. This is a must have.</p><h3>2.b Sass</h3><p>After you have premailer-rails installed, use <a href="http://www.sass-lang.com/">Sass</a> to create some helpful mixins. If you’ve never used Sass before, it’s amazing. It will make writing CSS easier to read and more fun to write. I used Sass to make some mixins to make writing out padding and other properties easier to write. Instead of writing:</p><pre>.some-element {<br>  padding-top: 1px;<br>  padding-right: 2px;<br>  padding-bottom: 3px;<br>  padding-left: 4px;<br>}</pre><p>You could create a mixin and simply include that throughout your stylesheet. So the same thing could look like this with a little bit of Sass magic:</p><pre>@mixin email-padding ($top, $right, $bottom, $left) {<br>  padding-top: $top;<br>  padding-right: $right;<br>  padding-bottom: $bottom;<br>  padding-left: $left;<br>}</pre><pre>.some-element {<br>  @include email-padding(1px, 2px, 3px, 4px);<br>}</pre><p>Much better. And DRY. Yay for Sass. Also, if you want to play around with Sass and get used to some of it’s syntax, <a href="http://sassmeister.com/">Sassmeister</a> is an awesome sandbox that will allow you to code in Sass and see what the compiled CSS will look like. It’s incredibly helpful if you are just learning or are a Sass master (or meister). <strong>Side-note:</strong> You should put all your mixins in a separate file to make your code look nicer. <a href="http://thesassway.com/beginner/how-to-structure-a-sass-project">Here</a> is an awesome blog post on Sass structure by John W. Long from <a href="http://thesassway.com/">The Sass Way</a> blog.</p><h3>3. Layouts</h3><p>Use layouts and partials. If you don’t know what these are, check out the <a href="http://guides.rubyonrails.org/layouts_and_rendering.html">Rails Guides</a>. Using layouts and partials means that you can reuse code that you need to put in each email that you will be styling, footers and headers for example. This will make your code easier to read and easier to change when someone says you need to add an extra word in the footer. It could potentially save you hours of time and it’s awesome that Rails lets you use them in mailers.</p><h3>4. Litmus</h3><p>Once again, this isn’t a Rails application but it is definitely worth mentioning. <a href="https://litmus.com/">Litmus</a> makes seeing what your emails will look like in multiple email clients easy. It shows you previews of what they will look like and even lets you code your emails with a live preview on the side!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*55gi2e3UrHyGA5JgoMPUMA.png" /><figcaption>Litmus in action</figcaption></figure><p>Litmus does have a free version that allows you to code with a live preview but only allows you to preview your emails in Outlook 2013, Gmail and iPhone 6s. To activate the previews for the other 40+ email clients they offer, you have to pay a hefty subscription fee starting at $79 a month, but depending on your situation could be completely worth it. You should at least try out the free trial to see how awesome it is.</p><h4>Bonus. Images</h4><p>If it’s at all possible, using images in email can allow you to make them prettier in ways that you can’t do with the limited code that you can use in them. You can make the images fully responsive so that they can be easily seen on mobile devices. If you were to look at most of promotional emails you receive, there’s a good chance they are image heavy. I figured I would mention this :)</p><p>Hopefully these tips will help you out next time you begrudgingly go to style an email. Good luck and let me know if you have any other tips!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=253a5e392a90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up and Using RSpec in a Ruby Application]]></title>
            <link>https://medium.com/@tyler_brewer2/setting-up-and-using-rspec-b170b64bb89?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b170b64bb89</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Thu, 15 Oct 2015 17:03:17 GMT</pubDate>
            <atom:updated>2015-10-15T17:04:00.812Z</atom:updated>
            <content:encoded><![CDATA[<p>I graduate Flatiron in 2 days (holy crap) and it’s been a life changing experience. I’ve learned so much about programming in such a short amount of time. We’ve covered a ton of stuff at Flatiron, but one area that I want to gain more experience in is testing applications.</p><p>While at Flatiron, we used RSpec quite a bit to test our labs, which are just different coding challenges to gain a deeper understanding of a specific topic. I became comfortable with looking at tests and understood what they were doing, but I never became comfortable actually writing them.</p><p>Recently, I was building a tic-tac-toe application and I wanted to practice writing some tests for the application. I realized I had never actually set up an environment with RSpec and knew it would be fun to set up.</p><p>First, you will need a Gemfile. A Gemfile is a place to hold all of your gems so that anyone who uses your application can use Bundler to get all the gems that are required in your application (if you don’t know what Bundler is, check it out here <a href="http://bundler.io/">bundler.io</a>).</p><p>Once you’ve made your gemfile, add ‘gem rspec’ to the file so that you can use the gem in your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*k9mOyIA-QPmzg4DeJe7Isg.png" /><figcaption>Add “gem ‘rspec’” to your gemfile</figcaption></figure><p>Once you have RSpec in your gem file, run “bundle install” in your command line to install RSpec. After that, run “rspec — — init” (two dashes) in your command line. This will create two files, .rspec and spec/spec_helper.rb. The spec/spec_helper.rb file has a pretty long comment but it explains exactly what was created when you ran “rspec — — init.” You should totally read it, but to sum up, this created a spec folder and .rspec file that contains “— require spec_helper,” which will require the spec_helper.rb and causes the file to always be loaded. The spec_helper.rb file just makes sure that all of you spec files will be able to run. It is convention that all of your test files will go in a “spec” folder, which RSpec already makes for you. Yay RSpec! You should now be set up to make all of your tests.</p><p>To create a test, first you will need to have an object to test! For this example, I will just have a Person class with a greeting method that will return “Hello there, (some name here)!” and a salutation method that will return “Goodbye, (some name here)!”</p><p>First lets create the Person class. To run your rspec test make sure you put the class you are testing in a “lib” directory. When RSpec goes to run your tests, it it will be looking for a lib directory. So create a lib directory and inside of that create a person.rb file that just like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*JiDRVjRnJHj5M1LrQlLtDQ.png" /><figcaption>Create a person.rb file in your lib directory</figcaption></figure><p>Once you have done this, you are ready to write some tests! First create a file called person_spec.rb in you spec folder. Now that you have created the file, add this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKrsm57PzgngI1kGZKU3jA.png" /><figcaption>Add this to your person_spec.rb file</figcaption></figure><p>At first look, you may think this looks a lot like english, which it does! This is one of the reasons RSpec is so great. Lets go through this file line by line.</p><pre>require &#39;person&#39;</pre><p>This line requires the person.rb file that you made in your lib directory so it can run the tests on the class.</p><pre>RSpec.describe Person do<br>  person = Person.new(&quot;Tyler&quot;)</pre><p>This line is where you state the actual class and class method that you are wanting to run your tests on. In this case we are running tests on the greeting method in the Person class. I also create a new instance of the person class since I am going to be writing a few different tests for this instance. You could also create a new person within each context, but this is much DRY-er so we are going to do that.</p><pre>context “greeting method is called with a name” do<br>  it “greets someone with ‘Hello there!’ and their name” do</pre><p>Context is where you set up what the context is for what you are going to be testing. Setting this up is extremely helpful when you go to read the tests later (you’ll see why in a bit). “it” is where you will actually describe what you want the specific method to do. Wording this well will also help when you are reading your tests.</p><pre>expect(person.greeting).to eq(“Hello there, #{person.name}!”)</pre><p>This is where your actual test will be run. It runs almost exactly the way it reads. What this is saying is that you are expecting the result of calling person.greeting to equal “Hello there, #{person.name!}”. Once again, exactly how it reads!</p><p>Now that we have a test written, we can run the test. Make sure you are in your root directory and run “rspec” in the command line. You should get something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHJCgwoX6PZaXfbqDAeBiA.png" /></figure><p>It failed! Which is expected since we haven’t created any methods in the person class. Don’t freak out though, error messages are super helpful and are vital to your programming experience (check out my <a href="https://medium.com/@tyler_brewer2/ruby-error-messages-a-k-a-sloth-fratelli-d09659e71546">blog post</a> on that). Creating your tests before you create your actual methods is a big part of Test Driven Development (TDD). You create what you want your file to be able to do, which is what we did, and then fix all of your failing tests! If you read the tests, they are very explanatory about what we need to do. It is telling us the context and is saying why it failed in a way that is easy to read. The test is telling us that there is no method called greeting for the Person class. Lets fix that :) . Add this to your person.rb file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*71qGCUU-iLEFvCkpCTvdAw.png" /></figure><p>We added attr_reader so that we could call person.name in out tests and also created the greeting method. Now run rspec to see what RSpec tells us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y4b4X4yOMtB0HYvutk7YCw.png" /></figure><p>Now rspec is saying that it expected for “Hello there, Tyler!” to be returned but instead it got “nil.” This makes sense because right now we don’t have anything in the method! Add this to your file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*XJCN2bbiDek5DaI6kETJ1w.png" /></figure><p>Now that we have something in the method, lets run the test!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yppLGb7ZmQa1_J0i-U0etQ.png" /></figure><p>Boom! Now we have one test passing! You will learn to love the green that RSpec returns. It will make you feel all good inside. Now to pass the other test, we would go through the same process. For the purpose of this blog, lets just add what we need to pass the test. Add this to your person.rb file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*tJXYmMe_0iqLmdkQnibOIA.png" /><figcaption>Create the salutation method in person.rb</figcaption></figure><p>Once you’ve added this, run RSpec to see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*-GDr8Z4pwJCjpK1HTsFLpQ.png" /><figcaption>Yay green!</figcaption></figure><p>Awesome! We are passing all our tests! This is obviously a basic test, but you can see how the principles of TDD can be extremely helpful in your coding experience. If you want to learn more about RSpec, check out <a href="http://rspec.info/">rspec.info</a>.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b170b64bb89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding &: in Ruby]]></title>
            <link>https://medium.com/@tyler_brewer2/understanding-in-ruby-1567427ffa9c?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1567427ffa9c</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Thu, 01 Oct 2015 02:43:28 GMT</pubDate>
            <atom:updated>2015-10-01T02:43:28.787Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately, I’ve been messing around with different coding challenges on <a href="http://www.codewars.com/">Codewars</a>. One of the most enjoyable things for me to do is to look at other people solutions for the problems after I solve them. Some of them are ridiculously clever and are interesting to dissect to see exactly how they are solving the solution. I’ve learned a lot of methods and tricks in Ruby just from looking at other people’s code.</p><p>One of these little tricks is using “ampersand colon” (&amp;:). Below is an example that shows when and why developers would use this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-JGX5OpJ2QKtj-Xy7R4_A.png" /></figure><p>As you can see, this is shorter than typing out the full block for an enumerable.</p><p>Contrary to what I first thought, this isn’t actually “ampersand colon.” It would be more correct to say “ampersand object.” The colon in this case is used the same way symbols are used, so you could use “map(&amp; :capitalize)” and receive the same result. The ampersand would technically be called a “unary ampersand operator” and it calls “to_proc” on the object that comes after it, which would in the example above be the capitalize method.</p><p>This was originally only available in Rails through ActiveSupport but was added to the core Ruby language in Ruby 1.8.7.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1567427ffa9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using .animate() in jQuery]]></title>
            <link>https://medium.com/@tyler_brewer2/using-animate-in-jquery-53022c041660?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/53022c041660</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[jquery]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Thu, 17 Sep 2015 00:50:39 GMT</pubDate>
            <atom:updated>2015-09-17T03:49:09.629Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m currently in week 8 at Flatiron School and it’s been amazing so far. I’ve fallen in love with Ruby and I appreciate how developer friendly it is. Last week we started to learn Javascript. Before I came to Flatiron, I had messed around with some Javascript so this has allowed me to pick up where I left off. I love Ruby, but as awesome as it is to parse data, I still love using Javascript to create something visual.</p><p>I’m currently working on building my portfolio site (it’s still a work in progress, but you can see it <a href="http://tylerbrewer2.github.io/tyler_brewer_portfolio/">here</a>) and I ran into an issue where I had a set of divs that either had the class “design” or the class “development.” I also had three buttons with the values “Show All,” “Design,” and “Development.” My goal was that when someone clicked on “Design,” all of the divs with the class “development” would be hidden, allowing the user to only see what has the class “design.” The same thing would happen when someone clicked the “Development” button except that only those with the class “development” would be shown. When the user clicks “Show All,” all of the divs would be shown. To do this, I used jQuery’s fadeIn/fadeOut effect. See the pen below for an example.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgeorgiaboy02%2Fembed%2FYyqwjy%3Fheight%3D600%26slug-hash%3DYyqwjy%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2Fgeorgiaboy02%2Fpen%2FYyqwjy&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F266971.Yyqwjy.small.c49ab8b4-8f30-4a9d-9830-9d38b704471c.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/0692dccdf604cee75dbfcca917e1b6f4/href">https://medium.com/media/0692dccdf604cee75dbfcca917e1b6f4/href</a></iframe><p>The problem with this is that it’s clunky. Once the divs disappear, the remaining divs snap into the next available position since they are floating left. I don’t consider myself a master of jQuery in the slightest bit so I decided to ask for some <a href="http://stackoverflow.com/questions/32598340/animate-floating-elements-after-removing-other-elements-from-page">advice</a> on Stack Overflow. Someone recommended that I use jQuery’s animate function so I tried that and came up with the pen below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgeorgiaboy02%2Fembed%2FqObeQB%3Fheight%3D600%26slug-hash%3DqObeQB%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2Fgeorgiaboy02%2Fpen%2FqObeQB&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F266971.qObeQB.small.131627d2-3f01-42d0-b992-dcab2033ddcc.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f217654451926784678bd305f9fa5db/href">https://medium.com/media/4f217654451926784678bd305f9fa5db/href</a></iframe><p>This uses animate to toggle the width and opacity. So if “Hide Red” is clicked, the divs with the class “red” will be animated away.</p><p>Doing this made me think of other ways that animate can be used, because who doesn’t love seeing a bunch of squares sliding across the screen? The animate function can take in four different arguments: properties, duration, easing, and complete. Properties is what the CSS will be by the time the animation is complete. In the example above, I change the width and the opacity of the divs. Duration is the length of the animation in milliseconds. Easing is the easing function that will be used for the animation. The default easing for animation is “swing.” Complete is the function that can be called once the animation is complete. In the pen below, I utilize all of these arguments to allow Stellan the Sloth to show himself (if you’ve been reading my blogs at all, you probably know that I love sloths).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgeorgiaboy02%2Fembed%2FYyqwBq%3Fheight%3D600%26slug-hash%3DYyqwBq%26default-tab%3Dresult%26host%3Dhttp%253A%252F%252Fcodepen.io&amp;url=http%3A%2F%2Fcodepen.io%2Fgeorgiaboy02%2Fpen%2FYyqwBq&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F266971.YyqwBq.small.744b732b-3d7b-412a-ab8c-b5ae21865957.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/259315374b076a798c326ff57aff11d3/href">https://medium.com/media/259315374b076a798c326ff57aff11d3/href</a></iframe><p>When you click on “See Stellan the Sloth” the first animation function is triggered. The property that is changed in the animation is the “left” property, the duration is 2 seconds (2000 milliseconds), the ease is set to “linear,” and then another animation is called which slides Stellan back off the screen (sorry, he’s shy). You can probably see from this example how cool animations can be by calling functions once the animation is complete.</p><p>To see more about the power of the animate function check out the documentation <a href="http://api.jquery.com/animate/">here</a>. The jQuery documentation is great and has some really helpful examples. Also, try to create a few pens on <a href="http://codepen.io/">Codepen</a> and play around with the animation function and see what you can come up with! Make sure that you allow jQuery to be used by clicking the gear icon next to JS and selecting “jQuery” from the “Quick-add” dropdown. This should save you a lot of time figuring out why your simple animation is doing absolutely nothing. Make sure to check out other people’s creations on there as well. There are some really amazing things that people are making using the animate function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53022c041660" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Ajax Requests with Ruby on Rails]]></title>
            <link>https://medium.com/@tyler_brewer2/making-ajax-calls-with-ruby-on-rails-d696c7bb4d?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d696c7bb4d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Wed, 02 Sep 2015 23:04:52 GMT</pubDate>
            <atom:updated>2015-09-08T02:19:02.623Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using Javascript in Rails</h4><p>When “normal” non-programming people think of Ajax, they probably think of <a href="http://www.amazon.com/Ajax-Cleaner-Bonus-Size-28/dp/B001B379BS/ref=sr_1_2?ie=UTF8&amp;qid=1441216109&amp;sr=8-2&amp;keywords=ajax">Ajax Cleaner</a>. However, in programming Ajax (“Asynchronous Javascript and XML”) is a Javascript technique used to make requests without the browser having to do a full reload. You can do a lot of cool things with Javascript and it is really “hot” right now in the programming community. To understand how Ajax works and how powerful it can be, you first need to understand how the web as a whole works.</p><p>When you type a url in your web browser a lot of things happen before the content is viewable on your screen. When you press “enter”, you send a web request to a server that asks for all of the information (HTML, CSS stylesheets, Javascript scripts, etc) it needs to show you your web page. Once it has all of your assets, it puts them all together and sends back your results, which the browser then uses to show you what you see on your screen. Every time you click a link or put a new url in your browser, you are making a completely new request that will go through the cycle again. With Javascript, you can use Ajax to make a request and update the information on your current page without you having to reload, which is awesome. This can be much more efficient than loading a complete new page with only a small amount of information.</p><p>Another important area worth mentioning is the DOM. When I first started programming, I always heard people talk about doing things to the DOM. I wasn’t really sure if the DOM was some poor guy who gets beat up for other people’s pleasure or what was going on. DOM stands for “Document Object Model”. The best way I’ve heard it defined, is that it is the virtual map of the web page that is currently loaded in your browser. If you open your development tools (“command + option + i”), you can check out all of the elements in your DOM by selecting the “elements” tag. The thing that makes Ajax requests with Javascript so cool, is that you can use the Ajax technique to actually manipulate (add, remove, change) the DOM without reloading the page.</p><p>I’ve created a Rails application that uses Ajax <a href="https://github.com/tylerbrewer2/ajax_test">here</a>. This page is an incredibly simple example of how you can use Ajax in Rails. The application only consists of a class, Sloth, with a single instance named “Stellan the Sloth.” The application’s index page shows Stellan’s avatar, and a link-button that says, “See Description.” When the user clicks the link, an Ajax request is sent to render the HTML from the “info” partial, which contains his name and description.</p><p>The first, and one of the most important things you must do, is allow your “show” action to respond to a Javascript request. you can do this by adding “respond_to” to your action.</p><pre>def show<br> <a href="http://twitter.com/sloth">@sloth</a> = Sloth.find(params[:id])<br> respond_to do |format|<br>   format.html<br>   format.js<br> end<br>end</pre><p>What this does, is allows the browser to request Javascript from the action page, which in this case is “show.” So when someone clicks the “See Description” button, the browser makes a request to the “show” page, which then runs the Javascript to render the information.</p><p>Next you need to add “remote: true” to your link in your view.</p><pre>&lt;%= link_to “See Description”, “/sloths/#{<a href="http://twitter.com/sloth">@sloth</a>.id}”, :remote =&gt; true , :id =&gt; “thelink” %&gt;</pre><p>It is important to note that the url is the path that the button will send its request to, which will be a Javascript file. “link_to” is a Rails helper that will generate a link that looks something like the link below.</p><pre>&lt;a id=“thelink” data-remote=“true” href=“/sloths...”&lt;/a&gt;</pre><p>The “data-remote” portion of the link shows the link will be sending or has already sent a request to a Javascript file.</p><p>The next part is the actual Javascript code which can look kind of tricky for someone looking at Javascript for the first time. This code can be found in the “show.js.erb” in my <a href="https://github.com/tylerbrewer2/ajax_test">github repo</a>.</p><pre>if ($(“.info”).length == 0) {<br> $(“#some_div”).append(“&lt;%= j render ‘info’ %&gt;”);<br>} else {<br> $(“.info”).remove();<br>}</pre><p>This is a very simple Ajax request, but it shows how one would go about making the request. The if/else statement is made to check whether or not the information is on the page. If it isn’t (length == 0), then the code will render the “info” partial and append it to “#somediv.” If it is, then remove it from the rendered page. Something you might notice is the random “j” in the render. This will escape Javascript carriage returns and single/double quotes to allow you to use your rendered Ruby code (which is ridiculous if you think about it).</p><p>Rails supplies different tags and helpers to make using Javascript in your application easier. To find out more, visit the <a href="http://guides.rubyonrails.org/working_with_javascript_in_rails.html"><em>Working With Javascript</em></a> section of the Rails Guides.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d696c7bb4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bridging the Gap Between Designers and Programmers]]></title>
            <link>https://medium.com/@tyler_brewer2/crossing-the-divide-between-designers-and-programmers-f3961095ffe5?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3961095ffe5</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[graphic-design]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Thu, 20 Aug 2015 00:41:24 GMT</pubDate>
            <atom:updated>2015-08-20T12:49:59.579Z</atom:updated>
            <content:encoded><![CDATA[<p>The first time I noticed a “divide” in thinking between designers and programmers was at my old job as a print (mostly) graphic designer. A designer there knew that I was learning to code and asked to see something that I had written because they were thinking about learning themselves. Their first response after I booted up a Javascript application in Atom was, “Ohhh, look at all the pretty colors!” I’ve been surrounded by programmers at Flatiron School for about a month now, and I have never heard that response from someone who is looking at a lengthy application for the first time (maybe some groans, but definitely not because of the color theme that our teachers use).</p><p>Designing and programming require different problem solving techniques. Design solves problems using visuals (colors, shapes, etc), while programming uses language (Ruby, Javascript, etc). By looking at the diagram below, you can see that design would fall under the right brain, and programming would fall under the left. Design requires creativity, imagination, and visualization to accomplish the end goal, which is ultimately to communicate and look appealing to the user. Programming requires logic, analysis, and language to ultimatly create an application to enhance the user’s life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*9i6QBaCUtnI2HWKKI8qOIg.gif" /><figcaption>Left Brain, Right Brain</figcaption></figure><p>Because of this thinking, most people say “Oh, I’m right brained so I could never do anything with logic”, or “Oh, I’m left brained so I could never be creative.” This is a <a href="http://www.attendly.com/debunking-the-myths-about-the-programmers-brain/">flawed</a> thinking process because the two sides of your brain <em>work together </em>to accomplish the task at hand. Yes, you may be a more logical thinker, but that doesn’t mean that you can’t also be creative, <em>if you practice</em>. Most people think that they are stuck with what they are “born” with. “I’m a logical person so I can’t draw”, “I’m a creative person so I can’t do math”, “I’m an analytical thinker so I can’t use my imagination”, the list goes on and on. The problem with this thinking, is that each side of the brain is dependent on the other. Communication is a great example of this. To process the language you use the left side of the brain, but to process intuition and emphasis you use the right. In technological terms, designing a website is highly mathematical, and programming an application requires creativity to decide how to create the application. Each craft is using both sides of the brain to <em>solve problems</em>. They just do it in different ways. So, whether or not you think you are right or left brained, you are still using both, which means that even though you don’t “feel” creative, you <em>do</em> have the capability to be creative.</p><p>Growing up I was an extremely analytical person. I played a lot of video games and my favorite ones were those that didn’t require me to be creative in how I accomplished the task the creators wanted me to. I hated art classes or anything that required me to make something. Then I got to college and decided I wanted to be a graphic designer, only God knows why. I don’t think I really knew what design was, I just thought Photoshop was cool (it’s now my least favorite Adobe program). I distinctly remember my first class in college, Design Fundamentals. In the class we were required to paint two objects together into a symbol. For some reason, I chose a deer and a beaver (I love animals. Sue me.) and ended up making a “Deaver.” It was horrible. And my professor thought it was too. He said something to me that changed my life, even though I didn’t realize it at the time. He said, “Tyler, this is terrible, and nothing you’ve made so far has been very good.” This didn’t register to me until my Junior year when I came to the realization that I really did suck and I was a horrible designer. I also realized I wasn’t really trying. So, I went to my professor (not the same one, he retired which I’m sure had something to do with how blunt he was) and asked what I could do better. She gave me some tips and I devoted everything I had for the next 2 years to becoming a better designer. I think I did pretty alright and I credit that to the effort that I put in. Even though I didn’t consider myself a creative person, after practicing and failing I <em>eventually</em> got better. I say all this to show you that it is possible for you to do what you think your mind won’t allow you to.</p><p>With all that being said, here are 5 universal tips for a designer who wants to code, or a programmer who wants to design:</p><h4>1. Look at other people’s work</h4><p>Looking at other people’s designs or other people’s code will make you a better designer/programmer. Period. There are tons of sites where people post their work for you to view (there’s also this crazy thing called “Google”). Figure out why they did what they did. Why they used this color. Why they used this method. Figure out not only what you like, but <em>why</em> you like it. Then use it.</p><h4>2. Steal</h4><p>One of my favorite artists, <a href="http://austinkleon.com/">Austin Kleon</a>, wrote a book called <a href="http://austinkleon.com/steal/"><em>Steal Like an Artist</em></a><em>. </em>He explains how you should<em> </em>look at other people’s work that you like and implement something from their work into something you are making and put your twist on it. Also, give credit where it is due. Not only will you be helping yourself, but you will be contributing to the community in it’s entirety.</p><h4>3. Practice and fail. A lot.</h4><p>You’re not going to be the best designer/programmer on your first project. For some reason people view these areas as something you are just “born with.” Not only is this moronic, it doesn’t give credit to those who have struggled to be in the position that they are in. When you learn a new hobby, such as playing guitar, you aren’t going to be playing like Jimi Hendrix when you first start strumming. You have to practice and struggle and learn from your mistakes. Understand that you are going to make some pretty bad stuff when you first start to learn, and there is absolutely nothing wrong with that. You’re actually making stuff, which is farther than the majority of people get when learning a new craft.</p><h4>4. Find someone honest</h4><p>I was lucky enough to have multiple people who were completely honest with me about my designs. This helped me realize areas I could improve and focus on when I was looking at other peoples work. Having a mentor to guide you through your journey is invaluable. If you consider yourself to be a little more experienced in your craft, find someone who is less experienced than you and mentor them. It’s a win-win for both parties (plus, I’m sure you’ll get some free lunches out of it).</p><h4>5. Create something. And then share it.</h4><p>Finally, just make stuff. You wont become a better designer/programmer unless you actually practice your craft. It will be a struggle, but find something that excites you and cling onto it. Also, share your stuff. Even if it sucks. People will be able to respond with criticism that will make you notice areas that you would never notice by yourself. I know it’s scary, but you can do it. <a href="http://austinkleon.com/show-your-work/"><em>Show Your Work</em></a> is another great book by Austin Kleon about this topic.</p><p>If you’ve made it this far, and have no desire to learn anything about design if you’re a programmer or vice versa, you should still understand that the world cannot function unless the two crafts work together. If you think design doesn’t matter, check <a href="http://www.lingscars.com/">this</a> site out (make sure your volume is down) and imagine living in a world like this. If you’re a designer and do any type of online shopping, you are putting your payment information into the hands of the programmer to make sure it is secure. It might be a good idea to appreciate that person.</p><p>Go forth and create.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3961095ffe5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby Error Messages a.k.a Sloth Fratelli]]></title>
            <link>https://medium.com/@tyler_brewer2/ruby-error-messages-a-k-a-sloth-fratelli-d09659e71546?source=rss-6e4e1da4d47e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d09659e71546</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Tyler Brewer]]></dc:creator>
            <pubDate>Thu, 06 Aug 2015 02:02:58 GMT</pubDate>
            <atom:updated>2015-08-07T00:59:02.633Z</atom:updated>
            <content:encoded><![CDATA[<h4>a Ruby programmer’s best friend</h4><p>Alright, I’ll be the first to admit that I don’t exactly remember everything that happened in the movie <em>The Goonies </em>and if you stop reading right here I’m incredibly sorry. One thing I do remember is there was a guy who looked nightmarishly scary and horrifying but ended up being one of the most awesome characters in the movie. His name was Lotney “Sloth” Fratelli. And he was a boss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*yKm1JTKxi3ee4Ooc_YqRlA.jpeg" /><figcaption>For those that don’t remember, this is Sloth Fratelli</figcaption></figure><p>Like I said before, Sloth is portrayed as this horrifying monster who the kids are trying to avoid. By the end of the movie (***SPOILER ALERT***) Sloth is wearing a pirate’s hat and ripping off his dull brown shirt, revealing the most 90&#39;s style Superman shirt this world has ever witnessed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*yjM9p6sk9POjBOsu-V7Jsw.jpeg" /><figcaption>Sloth Fratelli in all of his honor and glory</figcaption></figure><p>When I first started programming in Ruby, error messages were the exact same way. I would misspell a variable, forget to put an end, do something I saw as relatively small, and Ruby would send an error that made me feel like I was just struck by the Ruby gods. Then I saw the light…I actually decided to see what these seemingly long and hateful messages were actually telling me and they ended up being as “ruby-esque” as basically every other aspect of Ruby.</p><p>Ruby has a few different types of error messages for different types of errors, all of which have different meanings that basically point out exactly what your error was and where it occurred. For the purpose of this blog, we are going to talk about a basic error and show what exactly it is telling us (if you would like to see all standard Ruby Error Types, visit <a href="http://ruby-doc.org/core-2.2.0/Exception.html">here</a>).</p><p>Here is an example of a basic Ruby error message:</p><pre>lib/greeting_the_world.rb:3:in `&lt;main&gt;&#39;: undefined local variable or method `hello_world&#39; for main:Object (NameError)</pre><p>At first glance, this can seem pretty intimidating. But like almost everything else in programming, breaking up the message into parts can make your life millions of times easier.</p><pre>lib/greeting_the_world.rb:3:in `&lt;main&gt;&#39;:</pre><p>This is saying exactly what file and where in the file the error occurs. The error occurs in the file named “lib/greeting_the_world.rb” on line 3. Seriously? Did Ruby just tell us exactly what line the error is on? Thank you, Matz. “&lt;main&gt;” is the scope that the error occurs in (if this means nothing to you as a beginner, <a href="http://rubylearning.com/satishtalim/scope.html">here</a> is a good little explanation of Ruby scopes). Lets keep trekking on.</p><pre>undefined local variable or method `hello_world&#39; for main:Object</pre><p>This is Ruby’s way of telling you what it thinks went wrong. Ruby is (usually) pretty good about telling you why your code just broke. An error like this would occur if you would try to call a variable “hello_world” when that variable doesn’t exist. You will most likely see a lot of these. On to the last part.</p><pre>(NameError)</pre><p>This is a pretty informative part of the error. This shows you the type of error that it was. A NameError is called when a given name is invalid or undefined, which is pretty much what Ruby was trying to tell us earlier in the message. Like I said before, all of the standard Ruby error types can be found <a href="http://ruby-doc.org/core-2.2.0/Exception.html">here</a>. If you ever see an error and you have no idea what it is saying, go there. It’s there for your happiness.</p><p>Hopefully after reading this you can see that error messages in Ruby are not there to hinder your development process, but to make it as painless as it can possibly be. They seem ugly, but they are really there patting you on the back encouraging and guiding you on how to proceed. Understanding how to read error messages can greatly enhance your programming experience and effectiveness.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d09659e71546" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>