<?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 Dakota Lee Martinez on Medium]]></title>
        <description><![CDATA[Stories by Dakota Lee Martinez on Medium]]></description>
        <link>https://medium.com/@dakotaleemartinez?source=rss-1d2840d405f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Aeebe73UkNyDeGfdWg2tXw.jpeg</url>
            <title>Stories by Dakota Lee Martinez on Medium</title>
            <link>https://medium.com/@dakotaleemartinez?source=rss-1d2840d405f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 18:33:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dakotaleemartinez/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[Mac OS X: Setting up a Rails Development Server to Always Run on Startup]]></title>
            <link>https://medium.com/@dakotaleemartinez/mac-os-x-setting-up-a-rails-development-server-to-always-run-on-startup-dbb710b501b6?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbb710b501b6</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[development-server]]></category>
            <category><![CDATA[rails-server-on-startup]]></category>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 18:59:28 GMT</pubDate>
            <atom:updated>2019-10-28T18:59:28.653Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aloh90rOwq1X2AnEkPwLHQ.png" /></figure><p>I was searching for a way to have projects I’m working on always run in development as I have multiple small apps that I’m using to supplement my work at Flatiron school. We have an instructor app that is deployed, but changes there are often more involved and may take longer to implement. Also, I know that there are certain things I want to see that probably aren’t worth the trouble of deploying as they’re only important to me at the moment.</p><p>I spent quite a while searching for a way to do this without finding anything. I was <a href="https://serverfault.com/questions/194832/how-to-start-stop-restart-launchd-services-from-the-command-line">messing around with launchd</a>, <a href="http://launched.zerowidth.com/">creating plist files</a>, wandering around stack overflow trying to figure out why I could use one of those plist files to start a rails server. Finally, I stumbled upon a project on github that seemed to fit the bill. It’s called <a href="https://github.com/puma/puma-dev">Puma-dev</a>, it’s not too involved to configure and I got it running in a few minutes, but there were a few things that weren’t quite obvious to me reading through the docs so I figured I’d add a quick start guide here to summarize those.</p><ol><li>The basic idea of puma-dev is to symlink different rack projects on your machine to <em>~/.puma-dev. </em>After this is done, you’ll be able to visit name_of_project_folder.test in your browser and you’ll see the dev server running there without having to manually start it up in a terminal. Puma-dev adds a command line tool that makes these symlinks super easy to create.</li><li>Your project must have <em>gem ‘puma’</em> in the Gemfile and Puma-dev must be installed.</li><li>To <a href="https://github.com/puma/puma-dev#install--setup">install puma-dev</a>, the README on GitHub provides clear instructions. It also works on Linux, but here are the two commands I used on Mac OS X (10.12.6)</li></ol><pre>brew install puma/puma/puma-dev</pre><p>Then after the brew was finished updating and installing, there are a couple of commands that we can use to finish the setup:</p><pre># Configure some DNS settings that have to be done as root<br>sudo puma-dev -setup<br># Configure puma-dev to run in the background on ports 80 and 443 with the domain `.test`.<br>puma-dev -install</pre><p>4. Finally, cd into your project directory and run</p><pre>cd ~/development/code/projects/student_progress_rails<br>puma-dev link .</pre><p>5. Visit student_progress_rails.test in the browser and you’ll see your development server running there! Also, since this is a dev server, it does respond to changes in code (running migrations or changing your view code will effect the running server)</p><p>6. If you change configuration files or gem dependencies and you do need to restart a particular app server, you can cd to that app’s directory and run</p><pre>touch tmp/restart.txt</pre><h3>Final Thoughts</h3><p>This is just an absolute beginner’s guide here, but <a href="https://github.com/puma/puma-dev">puma-dev</a> seems to be exactly what I needed for running a Rails Server in the background on startup. It’s also supposed to add https support, but at the moment Chrome doesn’t trust the certificate it generated so I’m currently just using http. I know some users mentioned having issues with all of the apps running on the same version of ruby, but <a href="https://github.com/puma/puma-dev/issues/187">puma-dev does support rvm</a> for running apps using different versions of ruby.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbb710b501b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Splitting an audio file into multiple smaller pieces]]></title>
            <link>https://medium.com/@dakotaleemartinez/splitting-an-audio-file-into-multiple-smaller-pieces-ced138de192e?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ced138de192e</guid>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Thu, 25 Jan 2018 04:17:02 GMT</pubDate>
            <atom:updated>2018-01-25T04:17:07.182Z</atom:updated>
            <content:encoded><![CDATA[<p>I was having trouble figuring out how to split up a large audio file into smaller pieces via the command line. I finally found <a href="https://www.linuxquestions.org/questions/linux-software-2/help-with-ffmpeg-make-smaller-files-from-big-ones-4175558540/">this post</a> and found that I can use the following command:</p><p>To make sure this works, you’ll need to install ffmpeg first if you don’t have it already:</p><p><em>Originally published at </em><a href="http://becomingaprogrammer.com/splitting-an-audio-file-into-multiple-smaller-pieces/"><em>Becoming a Programmer</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ced138de192e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4 Key Concepts to Understand in React-Redux]]></title>
            <link>https://medium.com/@dakotaleemartinez/4-key-concepts-to-understand-in-react-redux-d7daf53637b6?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7daf53637b6</guid>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Fri, 12 May 2017 03:51:59 GMT</pubDate>
            <atom:updated>2017-05-12T03:52:01.750Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/829/0*PpiVjb8Tz16Knvrm.jpg" /></figure><p>When building React-redux applications, there are 4 key concepts to understand. If you have a high level understanding of these 4 concepts, you’ll have a much easier time building your application.</p><h4>Container Components</h4><p>Container components are React components that are hooked in to your global Redux application state. They will behave differently and render different content depending on the state of the application. Redux has a connect function that you can use to connect a component with a piece of the global application state using a mapStateToProps function.</p><h4>Interactive Components</h4><p>Interactive components are React components that are hooked into your application’s Action Creators. This means that they present an interface to the user that allows them to trigger actions that will update the global application’s state. The Redux connect function can also be used to connect a component with your action creators, using a mapDispatchToProps function. (In this function, we also call the bindActionCreators function, imported from redux, so that calling the action creator will result in the action being dispatched to the reducers later on.)</p><h4>Action Creators</h4><p>Action Creators are simply functions that return an action object. This object has a required &#39;type&#39; key and an optional &#39;payload&#39;. Whenever an action creator is called, the returned action object will be passed to all of the reducers. If these actions result in an AJAX request, we can use a combination of axios and redux-promise middleware to make sure that the promise returned from the AJAX request resolves before the action is dispatched to the reducers.</p><h4>Reducers</h4><p>Reducers are also simply functions that take two arguments and return an object representing the state of the application. The first parameter is called state and it represents the current state of the application. The second parameter is called action and it represents the action that was returned from calling the action creator.</p><p>These reducer functions are at the heart of how redux reduces the amount of changes necessary to keep the application state up to date. Each reducer is responsible for a certain piece of the global application state.</p><p>Let’s go a little deeper here. Reducer functions typically contain a switch statement on the action’s type property. If the action’s type is one that the particular reducer cares about, then it will return a new state object representing the state of the application after incorporating changes based on the action’s payload. It’s important here not to mutate the state parameter passed to the reducer, but to return a brand new state object instead.</p><p>If the particular reducer doesn’t care about this type of action, it will simply return the same state object that it was passed as a parameter. This way, the application state can be passed to all of the reducers every time an action creator fires, allowing the entire application state to be updated in response to every user action.</p><h4>Coming Full Circle</h4><p>Putting it all together, once all of the reducers have been called and the application state has been updated, all of the redux-connected container components that are affected by the changes in state will receive new props and re-render.</p><p>If you’d like to go deeper into learning React and Redux, I highly recommend Stephen Grider’s <a href="https://www.udemy.com/react-redux/">Modern React with Redux</a> course on Udemy. It’s wonderfully paced and full of detailed diagrams and descriptions of how to use React with Redux.</p><figure><img alt="Modern React with Redux, Stephen Grider Udemy course" src="https://cdn-images-1.medium.com/max/768/0*SLOrkZ_JjSg_cY7K.jpg" /></figure><p><em>Originally published at </em><a href="http://becomingaprogrammer.com/4-key-concepts-to-understand-in-react-redux/"><em>Becoming a Programmer</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7daf53637b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4 Things to Remember When You Get Discouraged]]></title>
            <link>https://medium.com/@dakotaleemartinez/4-things-to-remember-when-you-get-discouraged-81835da84c5a?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/81835da84c5a</guid>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Mon, 27 Mar 2017 02:54:10 GMT</pubDate>
            <atom:updated>2017-03-27T02:55:52.843Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the last few months, I’ve been helping students when they get stuck working on the Learn.co online full stack web developer course. While I’ve been doing this job, I’ve encountered a few students who have expressed dismay and frustration when considering their progress. In this post, I want to talk about what I say to those students, because it’s something I wish that I had heard earlier on in my journey.</p><p>The first thing I say is that it’s okay to get discouraged. Learning is hard. It stands to reason that learning to code would be hard also! The trick is to realize that getting stuck and getting frustrated are part of the process. And, as such, those negative emotions are not a prohibitive signal that “this just isn’t for you.” Like any other skill, if you’re not feeling any discomfort or difficulty while you’re practicing, then your practice isn’t doing you much good.</p><p>I highly recommend a book called <a href="https://www.amazon.com/gp/product/0544456238/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0544456238&amp;linkCode=as2&amp;tag=becomingaprog-20&amp;linkId=5ffb7b1a18183f747042e989bd2910d1">Peak: Secrets from the New Science of Expertise</a></p><p>. The book has a lot to say about the importance of deliberate practice. Deliberate practice is a specific kind of practice, usually guided by a coach, that aims at constantly focusing your attention just outside of your comfort zone. That way, the practice integrates enough of your current skills that you don’t feel completely in the dark. But, it also introduces you to new challenges that force you to learn and grow.</p><p>So, when you’re feeling discouraged, one of the first things you can do to get unstuck is to take a step back and look at what you’re trying to do. If you find yourself in a situation where you’re trying to tackle a problem that is well outside of your comfort zone, see if you can break it down. Instead of trying to solve the entire problem all at once, see if you can imagine a way to break the problem down into pieces. Start with the pieces that are most familiar, and gradually include the parts that are more difficult. Don’t give up, just try a different approach.</p><h4>It Gets Better</h4><p>I find that I still get discouraged and frustrated, but the problems that push me to that point get bigger. Gradually, as we push the limits of our comfort zones, our comfort zones expand. After a while, it takes really complicated problems to push us to our limits. The feelings are still there, but we’re now facing problems we wouldn’t even have approached before.</p><p>I find that one of the things that really distinguishes the progress of the students I’ve worked with is how deeply they’re able to drill down into the problems they’re working on. The farther along a student is in their journey, the more details and nuances they have in their insights about what their code is doing. The ability to zoom in and zoom out on a system and examine how the parts are working together really helps when it comes time to isolate where a problem is occurring.</p><p>Working in software requires that we continually develop and improve our skills at managing complexity. It requires an ability to be confident in our ability to solve problems, all the while acknowledging that every solution has the potential to create more problems in the future. One of the most important skills to develop, then, is to write code that is easy to understand and easy to change.</p><p>This is not a world where you can just read the book and study all the right answers and coast for the rest of your career. The book is constantly being rewritten by multiple authors who may or may not agree with one another. It’s also continually published and republished. And yes, you should still be reading it as much as you can. All of that said, it’s easy to see why getting discouraged is common while learning software development.</p><h4>It’s Okay to be Wrong</h4><p>Needless to say, expecting that you’re always going to get it right the first time is not reasonable. Instead, becoming a programmer requires that we make our peace with being wrong most of the time. That said, the more mistakes we make the more likely we are to start choosing solutions that are easy to change when we discover a better approach. When you get discouraged, don’t give up, try something new!</p><p>There is an inherent disconnect between the world that we are trying to model with our software and the software itself. The map is not the territory. Thus, software developers find ourselves the guardians of that disconnect. Gods of the digital realm, we are ultimately responsible, as a group, for the assumptions we make about what is or is not valuable. What we include in our digital world can be just as important as what we leave out.</p><p>In the end, software is a tool. We build it for a particular purpose. We build it to solve a particular kind of problem. Presumably, the problem we’re trying to solve actually exists in the real world. Our task, then, is to understand that problem as thoroughly and completely as we can. Then, we must isolate the parts of the problem that are most troublesome for us unaugmented humans to consistently solve. Those parts of the problem are the ones that our software should help us to solve.</p><p>We can expect to regularly get it wrong the first time. So, instead of trying to get it right the first time, we shift our focus to making as many mistakes as we can as quickly as we can and with as little risk as we can. It is through the process of making mistakes, trying new things, and playing around with edge cases that we come to solutions that are robust and easy to change. If we get in the habit of regularly changing our code while we build it, it’s easy to develop the habit of writing code that’s easy to change. (I find that <a href="http://becomingaprogrammer.com/hidden-benefit-writing-smaller-functions/">writing smaller functions</a> can really help with this)</p><h4>Staying Focused and Maintaining Perspective</h4><p>Thus, we are best served to make sure that when we get stuck &amp; discouraged, we’re getting stuck on something that’s actually important. It is very easy to get tangled up in code that’s modeling part of a problem or situation that isn’t actually important. One of the easiest ways to get out of this trap is to follow the <a href="https://en.wikipedia.org/wiki/Rubber_duck_debugging">rubber ducky approach</a>.</p><p>The way this generally works is you take a rubber ducky, put it on your desk, and explain your problem to the ducky when you get stuck. Often, the process of taking your problem and expressing it in natural language will reveal an error in the logic, a confusion about a variable name or function return, or some other helpful place to refocus attention. The main value of the approach is that it forces you to consider your code in the context of the problem you’re trying to solve.</p><p>The reason this works is that when we communicate our problem solving process to someone else, we know that they need the context of the problem to understand our thoughts. Thus, the act of explaining our problem to someone else forces us to recontextualize our solution. I’ve found that talking out my problems has been very helpful to me in getting unstuck. Communicating problems out loud is also a great way to identify parts of your code that are unclear.</p><h4>Googling is Not Cheating</h4><p>I know this sounds ridiculous. Still, I couldn’t help but include this at the end. Believe it or not, I have had some students working through our curriculum who consciously avoiding going to Google. In the name of pedagogical responsibility, I must wholeheartedly encourage the quick and frequent use of Google. As a software gunslinger, your main focus should be working on your draw: “Be quick to the Google!”</p><p>The more often you Google, the better you’ll get at it. You’ll be forced again to frame your problem using language in the most accurate way you can. Over time, you’ll learn how to quickly distinguish the results that are appropriate for the problem you’re working on. Remember to keep iterating, if you don’t get results that look like what you want, think of another way of framing the question and try again quickly. You’ll get better at filtering out results that aren’t what you’re looking for as you get more practice.</p><p>Learn to be quick to the Google and quick to get back to your code to experiment. The goal is to shorten the feedback loop between having a question and having a testable approach to finding the answer.</p><h4>Final Thoughts</h4><p>Think about what your questions mean. If you wonder what 7/2 is in Ruby, drop into irb or repl.it/languages/ruby and check (it’s 3 by the way). Start thinking in terms of testable questions and assumptions. If I want to figure out how to get this math to work right in ruby, what could I try? What would 7/2.to_f return? What about 7.to_f/2 or (7/2).to_f?</p><p>Whenever you find yourself unsure of the way something works, find a way to get feedback and go see for yourself. For beginners, I really like recommending repl.it, because it’s easy to setup a sandbox to work in multiple languages and get feedback on the way they behave very quickly with minimal local setup. You’ll find that if you take the time to articulate your problems using the rubber ducky approach and think of example cases that will test your assumptions, you’ll learn much more quickly. Ultimately, this approach will lead you to an increasing confidence in your abilities, and a consistent and effective way to respond when you get discouraged.</p><p><em>Originally published at </em><a href="http://becomingaprogrammer.com/4-things-remember-get-discouraged/"><em>Becoming a Programmer</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81835da84c5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Hidden Benefit of Writing Smaller Functions]]></title>
            <link>https://medium.com/@dakotaleemartinez/the-hidden-benefit-of-writing-smaller-functions-cf352ae8e3d1?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf352ae8e3d1</guid>
            <category><![CDATA[small-functions]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[closure]]></category>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Wed, 15 Mar 2017 08:26:25 GMT</pubDate>
            <atom:updated>2017-03-15T08:30:56.231Z</atom:updated>
            <content:encoded><![CDATA[<p>I remember reading a passage on Quora a few years ago that really stuck with me. I’ve lost touch with the exact source, but from what I remember, the author was in the role of interviewing/hiring developers. The author’s basic idea was that experienced developer’s wrote smaller functions. Of course, it wasn’t until much later that I discovered the hidden benefit of writing smaller functions.</p><h4>Optimization vs Doing Less</h4><p>I think when I initially encountered this idea, I thought that it meant that experienced developers knew clever tricks for accomplishing tasks in fewer lines of code. While that is undoubtedly the case, there was something I was missing. I thought that being clever just to bum a few lines from a function definition might make the code more difficult to follow. That didn’t seem like a desirable outcome to me! (I’ve revisited code I wrote a couple of years ago and been shocked by how difficult it is to follow.)</p><p>There was something I still didn’t see. Actually, writing smaller functions wasn’t just about optimizing or rewriting the code to occupy fewer lines. The beauty of writing smaller functions is that you’re writing functions that do less. The missing piece for me was that writing smaller functions is mostly a practice in breaking larger functions into pieces.</p><p>Instead of one long function that contains all the logic for completing a complicated task with multiple steps and sub-tasks, we have a bunch of functions that break the problem into small pieces. Of course, one function will inevitably be used to put all of the pieces together, but that should be its one job. Ultimately, writing smaller functions makes it much easier to follow the <a href="https://code.tutsplus.com/tutorials/solid-part-1-the-single-responsibility-principle--net-36074">single responsibility principle</a>.</p><h4>Naming the Hidden Benefit</h4><p>When we start writing smaller functions, we discover the hidden benefit of more names. Since we’re writing more functions, we have to create more names. Because each function must have a name describing what it does, our code has more names in it. If we name our functions carefully, we now have a roadmap describing the path through our code. This allows us to reason much more clearly about what our code is doing and how it’s doing it. Because, adding more names forces us to be separate the what from the how.</p><p>To demonstrate the difference, I’ve started an algorithm challenge that uses the one big long function approach. First, let me introduce the problem. We’re given two arrays as inputs. One is an array of integers representing coins of a certain value. The other is an array of equal length representing the quantity of each value coin we have. Our task is to return the number of possible sums we can make given the information in both arrays.</p><p>Here are the constraints for our inputs:</p><pre>1 ≤ coins.length ≤ 20,<br>1 ≤ coins[i] ≤ 10000</pre><pre>quantity.length = coins.length,<br>1 ≤ quantity[i] ≤ 100000</pre><pre>We are also guaranteed that: (quantity[0] + 1) * (quantity[1] + 1) * … * (quantity[quantity.length — 1] + 1) &lt;= 1000000</pre><p>First, I wanted to get a sense of how my algorithm would work on one of the smaller test cases. I was originally trying to avoid having 3 nested loops, so I started with this:</p><pre>function possibleSums(coins, quantity) {<br>    var coinValues = quantity.reduce(function(values, q, index){<br>        if(q &gt; 1) {<br>            var newArr = new Array(q-1).fill(coins[index]);<br>            values = values.slice(0, index).concat(newArr).concat(values.slice(index));<br>        }<br>        return values;<br>    },coins);<br>    console.log(&#39;coinValues:&#39;, coinValues);<br>    var sums = coinValues.reduce(function(obj, coin){<br>      if (!obj.hasOwnProperty(coin)){<br>        obj[coin] = true;<br>      }<br>      return obj;<br>    },{});<br>    console.log(&#39;sums:&#39;, sums);<br>    for (var i = 0 ; i &lt; coinValues.length ; i++) {<br>      for (var j = i + 1 ; j &lt; coinValues.length; j++ ) {<br>        var sum = coinValues[i] + coinValues[j];<br>        if(!sums.hasOwnProperty(sum)) {<br>          sums[sum] = true;<br>        }<br>      }<br>    }<br>    for (var i = 0 ; i &lt; coinValues.length ; i++) {<br>      for (var j = i + 2 ; j &lt; coinValues.length; j++) {<br>        var sum = coinValues[i] + coinValues[i+1] + coinValues[j];<br>        if(!sums.hasOwnProperty(sum)) {<br>          sums[sum] = true;<br>        }<br>      }<br>    }<br>    for (var i = 0 ; i &lt; coinValues.length ; i++) {<br>      for (var j = i + 3 ; j &lt; coinValues.length; j++) {<br>        var sum = coinValues.slice(i,j+1).reduce(function(a,b){return a+b});<br>        if(!sums.hasOwnProperty(sum)) {<br>          sums[sum] = true;<br>        }<br>      }<br>    }<br>    return Object.keys(sums).length;<br>}</pre><p>The basic goal is to store each unique sum as a key on the sums object. This is basically a hard coded solution to one of the shorter test cases. It will work if the coins and quantity arrays are both only 3 items long. After that, it becomes clear that we actually need another loop.</p><p>Beyond being quite inefficient, this first stab at a solution is also difficult to understand, extend and reason about. It was hard for me to write the code this way, as I had to keep fighting the urge to pull out functions. Most notably, I wanted to extract functions to persist data on the possible sums. I also wanted a function to collect all of the possible sums that can be created by a single coin (in different quantities).</p><p>When the logic grows in length, it requires an increasing amount of mental overhead to keep focused on the problem. It was only after I split off a couple of functions that I came to a solution. I’ve rewritten that solution as one long function below.</p><pre>function possibleSums(coins, quantity) {<br>  var hasSum = {};<br>  coins.reduce(function(possibilities, coin, index){<br>    var newSums = [];<br>    var coinCombos = [];<br>    for (var i = 0 ; i &lt;= quantity[index] ; i++) {<br>      coinCombos.push(coin * i);<br>    }<br>    possibilities.forEach(function(previousSum, index){<br>      for(var i = 0 ; i &lt; coinCombos.length; i++) {<br>        var thisSum = coinCombos[i] + previousSum;<br>        if(!hasSum.hasOwnProperty(thisSum)){<br>          hasSum[thisSum] = true;<br>          newSums.push(thisSum);<br>        }<br>      }<br>    });<br>    possibilities = possibilities.concat(newSums);<br>    return possibilities;<br>  },[0]);<br>  <br>  return Object.keys(hasSum).length - 1;<br>}</pre><p>This is an improvement, to be sure. I’ve spent more time thinking about the variable names and I’ve used them to help clarify my approach. Still, this function is long and difficult to follow. There is also some repetition that can be avoided. The main thing to note at the moment is how much the code has improved given the extra time and attention paid to the naming of variables within the function.</p><h4>Extracting Smaller Functions</h4><p>First, let’s take out a function that creates an array of possible sums we can make by choosing a different quantity for a single coin. This array was built within our coins.reduce callback (lines 5-8 above) and used inside the nested possibilities.forEach callback (lines 10-11 above). Also, it&#39;s a simple pattern using a for loop to add to an array that&#39;s taking up extra space in our function. Pulling it out into a smaller function will bring the focus to a higher level where we can see how the pieces are working together.</p><pre>function possibleSums(coins, quantity) {<br>  var hasSum = {};<br>  coins.reduce(function(possibilities, coin, index){<br>    var newSums = [];<br>    var coinCombos = getPossibleSumsForCoin(coin, quantity[index]);<br>    possibilities.forEach(function(previousSum, index){<br>      for(var i = 0 ; i &lt; coinCombos.length; i++) {<br>        var thisSum = coinCombos[i] + previousSum;<br>        if(!hasSum.hasOwnProperty(thisSum)){<br>          hasSum[thisSum] = true;<br>          newSums.push(thisSum);<br>        }<br>      }<br>    });<br>    possibilities = possibilities.concat(newSums);<br>    return possibilities;<br>  },[0]);<br>  <br>  return Object.keys(hasSum).length - 1;<br>}</pre><pre>function getPossibleSumsForCoin(coin, quantity){<br>  var coinCombos = [];<br>  for (var i = 0 ; i &lt;= quantity; i++) {<br>    coinCombos.push(coin * i);<br>  }<br>  return coinCombos;<br>}</pre><p>Notice that the readability of the algorithm has improved quite a bit with the replacement of the for loop with the function getPossibleSumsForCoin. It is much clearer what the for loop was doing now that it&#39;s replaced by a reference to a descriptively named function. We&#39;ve separated the what from the how.</p><h4>Using Closure to Count Possible Sums</h4><p>Next, I was itching to separate the persistence of possible sums. To do this, I created a UniqueSumCounter function that creates a closure over a sums object that contains all of the possible sums encountered thus far. The function returns an object that responds to two functions, add(sum) and total(). This allows a neat encapsulation of adding and retrieving new possible sums. In order to be of extra use in our control flow, add(sum) will return false if the sum was already recorded.</p><pre>function possibleSums(coins, quantity) {<br>  var sums = UniqueSumCounter();<br>  coins.reduce(function(possibilities, coin, index){<br>    var newSums = [];<br>    var coinCombos = getPossibleSumsForCoin(coin, quantity[index]);<br>    possibilities.forEach(function(previousSum, index){<br>      for(var i = 0 ; i &lt; coinCombos.length; i++) {<br>        var thisSum = coinCombos[i] + previousSum;<br>        if(sums.add(thisSum)){<br>          newSums.push(thisSum);<br>        }<br>      }<br>    });<br>    possibilities = possibilities.concat(newSums);<br>    return possibilities;<br>  },[0]);<br>  <br>  return sums.total();<br>}</pre><pre>function getPossibleSumsForCoin(coin, quantity){<br>  var coinCombos = [];<br>  for (var i = 0 ; i &lt;= quantity; i++) {<br>    coinCombos.push(coin * i);<br>  }<br>  return coinCombos;<br>}</pre><pre>function UniqueSumCounter() {<br>  var sums = {};<br>  <br>  return {<br>    add: add, <br>    total: total<br>  };<br>  <br>  function add(sum) {<br>    if (!sums.hasOwnProperty(sum)) {<br>      sums[sum] = true;<br>      return true;<br>    } <br>    return false;<br>  }<br>  <br>  function total() {<br>    return Object.keys(sums).length - 1;<br>  }<br>}</pre><pre>console.log(possibleSums([10,50,100,500],[5,3,2,2])); // =&gt; 122<br>console.log(possibleSums([10,50,100],[1,2,1])) // =&gt; 9<br>console.log(possibleSums([1],[5])) // =&gt; 5</pre><p>Notice how our possibleSums function has become slightly more readable. Now, we can take a look through it and get a better sense of what it&#39;s doing before we get into how it&#39;s doing it. By extracting smaller functions and using more names, we&#39;ve made our code easier to read, follow and understand. Of course, there&#39;s a trade off with this approach, as we now have nearly twice as many lines of code. The difference is that our code is much easier to follow.</p><p>Still, there’s a big part of our possibleSums function that&#39;s still saying <strong>how</strong> instead of just <strong>what</strong>. Inside of the coins.reduce callback, we&#39;ve got a forEach loop that contains a nested for loop.</p><p>This part of the code is responsible for gathering the new possible sums we can create each time we include another one of the coins. It does this by iterating over all of the previous sum possibilities and adding each of the sums we can create with the current coin. If the sum is not already stored in memory as a possible sum, then we add it to our newSums array. Once we&#39;re finished going through all of the new possibilities, we concatenate the newSums array onto the array of possible sums (possibilities) and move on to the next coin.</p><h4>Smaller Functions Help Us to Be Explicit About Intentions</h4><p>We can dramatically improve the readability of our possibleSums function by extracting another function to handle this task. First, let&#39;s take a look at what information that code needs access to:</p><p>*possibilities: the array of possible sums created by combinations of previous coins<br> *currentCoinSums: the array of possible sums created by choosing a different amount of the current coin.<br> *sums: an instance of the UniqueSumCounter() closure that tracks the possible sums in memory .</p><p>Since we need access to sums it makes the most sense to actually add the new function to our UniqueSumCounter() object so we won&#39;t have to pass it in as a parameter:</p><p>Notice how much more explicit the possibleSums is after extracting this function:</p><pre>function possibleSums(coins, quantity) {<br>  var sums = UniqueSumCounter();<br>  coins.reduce(function(possibilities, coin, index){<br>    var currentCoinSums = getPossibleSumsForCoin(coin, quantity[index]);<br>    var newSums = sums.combinePossibleSums(possibilities, currentCoinSums);<br>    possibilities = possibilities.concat(newSums);<br>    return possibilities;<br>  },[0]);<br>  <br>  return sums.total();<br>}</pre><pre>function getPossibleSumsForCoin(coin, quantity){<br>  var coinCombos = [];<br>  for (var i = 0 ; i &lt;= quantity; i++) {<br>    coinCombos.push(coin * i);<br>  }<br>  return coinCombos;<br>}</pre><pre>function UniqueSumCounter() {<br>  var sums = {};<br>  <br>  return {<br>    add: add, <br>    total: total,<br>    combinePossibleSums: combinePossibleSums<br>  };<br>  <br>  function add(sum) {<br>    if (!sums.hasOwnProperty(sum)) {<br>      sums[sum] = true;<br>      return true;<br>    } <br>    return false;<br>  }<br>  <br>  function total() {<br>    return Object.keys(sums).length - 1;<br>  }<br>  <br>  function combinePossibleSums(previousSums, currentSums) {<br>    return previousSums.reduce(function(newSums, previousSum){<br>      currentSums.forEach(function(currentSum){<br>        var sum = previousSum + currentSum;<br>        if(add(sum)) {<br>          newSums.push(sum);<br>        }<br>      });<br>      return newSums;<br>    },[]);<br>  }<br>}</pre><pre>console.log(possibleSums([10,50,100,500],[5,3,2,2])); // =&gt; 122<br>console.log(possibleSums([10,50,100],[1,2,1])) // =&gt; 9<br>console.log(possibleSums([1],[5])) // =&gt; 5</pre><p>One of the obvious downsides here is that the code has actually become more fragmented. In the process of refactoring the solution, I realized that it would actually be easier to encapsulate all of these smaller functions inside of the possibleSums function definition. That way, the sums, coins, and quantity are all available to the child functions. This is my favorite iteration yet, because it is the easiest to follow and requires fewer variable definitions and jumping around with the eyes to follow. Also, it resolves one of the things that was bothering me about the previous solution. Namely, that I had an array of possibilities and also an object storing possibilities. This was both a waste of memory and a potential source of confusion. So, I&#39;m all the happier with the following solution:</p><pre>function possibleSums(coins,quantity) {<br>  var sums = {&#39;0&#39;: true};<br>  <br>  return calculate();<br>  <br>  function calculate() {<br>    coins.forEach(function(coin,index){<br>      var currentCoinSums = getPossibleSumsForCoin(coin, quantity[index]);<br>      combinePossibleSums(currentCoinSums);<br>    });<br>    return total();<br>  }<br>  <br>  function getPossibleSumsForCoin(coin, quantity){<br>    var coinCombos = [];<br>    for (var i = 0 ; i &lt;= quantity; i++) {<br>      coinCombos.push(coin * i);<br>    }<br>    return coinCombos;<br>  }<br>  <br>  function combinePossibleSums(currentSums) {<br>    return Object.keys(sums).forEach(function(previousSum){<br>      currentSums.forEach(function(currentSum){<br>        var sum = Number(previousSum) + currentSum;<br>        add(sum);<br>      });<br>    });<br>  }<br>  <br>  function add(sum) {<br>    if (!sums.hasOwnProperty(sum)) {<br>      sums[sum] = true;<br>    } <br>  }<br>  <br>  function total() {<br>    return Object.keys(sums).length - 1;<br>  }<br>  <br>}</pre><p>One thing that this last solution illustrates really well is the power of closure to enable object oriented programming in JavaScript. The beauty of object oriented programming in JavaScript is that instead of having to create a class and then creating instances for solutions, we can just call the function to retrieve a solution object. For instance, it would be a trivial change to adjust the return value of the function to be an object instead of a single value. Then, we could also expose the final value of sums, perhaps in array form using Object.keys(sums). That way, we could have solution objects that not only tell us how many possible sums we can make, but also what all the possibilities are!</p><h4>Final Thoughts</h4><p>Clearly, there’s a tradeoff to be considered when extracting smaller functions from a long function. We start off with a single function with 21 lines in the block and ended with one parent function with five child functions all fewer than 6 lines in length. Although the whole thing is twice as long, it seems to me to be infinitely easier to follow the logic. Extracting the functions allows a single read through of possibleSums to give a high level understanding of how the solution works. The secret is in that naming those smaller functions allows you to explain what your code is doing as you go!</p><p><em>Originally published at </em><a href="http://becomingaprogrammer.com/hidden-benefit-writing-smaller-functions/"><em>Becoming a Programmer</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf352ae8e3d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get Smallest Common Multiple with JavaScript]]></title>
            <link>https://medium.com/@dakotaleemartinez/get-smallest-common-multiple-with-javascript-77c60164c13d?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/77c60164c13d</guid>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Mon, 06 Mar 2017 01:11:05 GMT</pubDate>
            <atom:updated>2017-03-06T01:11:06.688Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Everyone! I was working on a FreeCodeCamp algorithm challenge the other day and kept running into timeout issues when I ran it in their editor. I had tried it elsewhere and it was working, but I figured that I needed to optimize the solution so that it would run on FreeCodeCamp’s servers. After spending quite a bit of time working on how to get the smallest common multiple, I think I’ve arrived at a really performant solution, so I wanted to share it with you all here.</p><p>If you’d like to try it out for yourself, the challenge is called <a href="https://www.freecodecamp.com/challenges/smallest-common-multiple">Smallest Common Multiple</a> on FreeCodeCamp’s website. The instructions say that we’re going to have a function called smallestCommons that will take a single parameter arr. Our parameter arr is an array with two elements in it ([1,5]) and we&#39;re told that they may not be in numerical order. The task we&#39;re given is to find the smallest common multiple of the provided numbers (in arr) that can be evenly divided by both, as well as by all of the sequential numbers in the range between the two numbers.</p><p>For example, for smallestCommons([1,5]) we&#39;d need to return the smallest number that is evenly divisible by 1, 2, 3, 4 &amp; 5. The test cases we&#39;re given are as follows:</p><h4>Splitting the problem into Pieces</h4><p>So my goal here was to split the problem into pieces. The main way I did that here was by defining a few functions to handle parts of the problem.</p><h4>getRange(arr)</h4><p>First, I added a getRange function that takes in the same arr we&#39;re given from our test cases and outputs the range of numbers that we&#39;re going to check for even divisibility.</p><h4>factorialFactory()</h4><p>When I was first approaching this problem I ended up running into issues with timeouts because I had a giant loop going on. So another goal I had was to reduce the amount of looping I had to do by as much as possible. One of the ways I’ve tried to do that is by adding return statements within the loops, so that we break out of them the moment we know what we need to know. I&#39;ve also implemented a closure to create a factorial function generator that keeps track of the math it has already done so it only has to do the work once. This is particularly handy for a factorial function because it means that once you call factorial(100), all of the return values for factorial(1), factorial(2)... all the way to factorial(99) are already stored in memory.</p><p>This factorialFactory function will be used to calculate the upperLimit of the values that we’ll be checking for common multiplicity.</p><h4>isCommonMultiple(range, num)</h4><p>Finally, this function will take in a range of numbers and check to see if num is a common multiple of each of the numbers in the range. Because I was having issues with performance before, this function is designed to only check all of the numbers in the range if the num we pass in is an even multiple of all of the top n-1 numbers in the range.</p><h4>Putting the pieces together in smallestCommons(arr)</h4><p>Now that we’ve got the problem split into those subtasks, we can go about implementing the solution. In my solution, I’m using the factorialFactory to calculate the upperLimit of the values I need to check for common multiplicity. The largest possible value for the Smallest Common Multiple is the product of all of the numbers in the range. This also happens to be equivalent to the factorial of the larger number divided by the factorial of one less than the smaller number. For example, if we had a range of: [5,6,7,8,9] the product 5*6*7*8*9 is equivalent to 1*2*3*4*5*6*7*8*9/(1*2*3*4) or 9!/4!.</p><p>After we’ve gotten our numbersToCheck, smallestNum, largestNum and upperLimit defined, we can use a for loop to find our smallest common multiple. Our first time through the loop, the counter i will be set equal to the largestNum value. The loop will continue until the counter is no longer less than our upperLimit. And after each iteration, the counter will be incremented by largestNum. Essentially, what we&#39;re doing here is looping through the multiples of the largest number in our range and checking each one to see if it&#39;s a common multiple of each number in the range. Once we find our first match we&#39;ll return it. If we don&#39;t find a match, we&#39;ll return the upperLimit value, which is the product of all of the numbers in the range.</p><p>Here’s the final algorithm code for your reference:</p><h4>Final Thoughts</h4><p>I’ve really enjoyed working through Algorithm challenges on FreeCodeCamp, CoderByte and HackerRank. More recently, I’ve also really enjoyed doing some challenges on codefights as well!</p><p><em>Originally published at </em><a href="http://becomingaprogrammer.com/get-smallest-common-multiple-javascript/"><em>Becoming a Programmer</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77c60164c13d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Experience with AngularJS and Rails 5]]></title>
            <link>https://medium.com/@dakotaleemartinez/my-first-experience-with-angularjs-and-rails-5-d0d882d3a85f?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0d882d3a85f</guid>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Thu, 17 Nov 2016 00:36:06 GMT</pubDate>
            <atom:updated>2016-11-17T00:36:28.737Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Everyone! My name is Dakota Lee Martinez. Over the last year or so, I’ve been working on the Flatiron School’s Full Stack Web Developer course. I’ve just completed the final project, a full stack web application built with AngularJS and Rails. I’m super excited to share my experience building the app with you all over the next series of posts.</p><h4>About My Project</h4><p>For this project, I wanted to pick something I’m passionate about and something that I would actually use. I remember when I first was exposed to code snippets. When I watched a few of Jeffrey Way’s <a href="https://laracasts.com/">laracasts</a>, I was hooked. If you’re not familiar with custom code snippets, the idea is that you can write a code template for accomplishing a certain task. You give your snippet a trigger phrase. When you type this phrase the phrase expands into your template.</p><p>If this were all it could do, it would still be really cool. But, there’s more!!! You can add variables to your template, allowing you to type in a value and have it appear in multiple places within the template. This kind of thing is very useful for variable or function names. Even better, you can cycle through these variables within the snippet by hitting the tab key. This allows you to avoid spending time and keystrokes referencing library specific syntax for a task you’ve already done a lot of times and skip right to adjusting the values that are specific to your particular application.</p><p>Working with code snippets is an absolute joy and well worth the effort of building up a library of code that you like to reuse. One of the problems with code snippets is that they’re often written in a different syntax than the code itself. They also need to be placed within a certain directory to work. These are small issues, but they definitely raise the barrier to entry. Also, snippets for one editor are unlikely to work in another. Enter <a href="https://snippetmachine.dakotaleemartinez.com/">SnippetMachine</a>!</p><h4>SnippetMachine — Taking the Pain out of Creating Custom Snippets</h4><p>By integrating with the Dropbox API, SnippetMachine allows you to sync your snippets with your Dropbox. After creating a symlink between your dropbox snippets and the appropriate directory on your computer, you can save snippets for use within your editor of choice directly from SnippetMachine. Current editor support is for Visual Studio Code and Sublime Text 2, but adding more editors to the existing system is not terribly complicated and I will do so as requests come in (I also welcome pull requests!).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FbiMqaVpJPzc%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbiMqaVpJPzc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FbiMqaVpJPzc%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ba25ca86c6d447f85956dc294b9b8df/href">https://medium.com/media/1ba25ca86c6d447f85956dc294b9b8df/href</a></iframe><p>If you are interested in contributing, I’ve added a detailed guide to the <a href="https://github.com/DakotaLMartinez/rails-angular-snippet-machine/CONTRIBUTING.md">CONTRIBUTING.md</a> file on my github repository that will give you a quick overview of the project and how it is structured.</p><p>The process of building SnippetMachine was very rewarding. But, it was also quite frustrating at times. I had quite a bit of trouble getting a good development environment set up (I ended up using a gemset for Rails 5.0 and the gulp-angular yeoman generator for the Angular side). I had quite a time putting together an automated deployment script so I can deploy the app to webfaction shared hosting using git push deployment master. I also ran into problems getting devise_token_auth and ng-token-auth working together to allow for token based authentication. I spent more time than I would have liked getting the Dropbox API integration up and running, and was frustrated when trying to get the omniauth-dropbox and dropbox-api gems to work together (I ended up choosing to forego using omniauth-dropbox and using dropbox-api exclusively).</p><h4>What I learned about AngularJS and Rails while building SnippetMachine</h4><p>I am a big believer in project based learning. I think that the most important learning moments come when solving real problems. So, I relish the opportunity to build these projects and I’m very excited to share with you some of the things that I’ve learned along the way.</p><p>In the following series of posts, we’ll be putting together a long-form tutorial of how to build a full stack web app using AngularJS and Rails. Here is a preliminary list of the topics we’ll be covering as we walk through how to build SnippetMachine. (we’ll be making use of some of my snippets to do so!)</p><ul><li>How to set up a development environment for AngularJS and Rails 5 (Angular 1.5.3 is the version we’ll be using)</li><li>How to use devise_token_auth and ng-token-auth to add authentication to your app using Angular JS and Rails</li><li>How to setup automated deployment for Ruby on Rails to Webfaction shared hosting</li><li>How to build out the domain model (Users, Snippets, UserSnippets &amp; Languages)</li><li>How to add seed data using FactoryGirl</li><li>How to interact with our Rails API using AngularJS Services and $http</li><li>How to build out a component based application architecture in AngularJS 1.5.x using UI Router</li><li>How to use Angular Filters to display snippets in different editor formats</li><li>How to add nested states using nested component routes within UI-Router</li><li>How to add components that display the same form (using the same template) for editing and creating new snippets</li><li>How to add Dropbox API integration to your app using AngularJS and Rails</li><li>How to create new files in a User’s dropbox account based on data taken from the web application.</li><li>How to create custom directives to validate input fields in AngularJS</li><li>How to cache promises returned from AngularJS services to avoid redundant calls to the database</li></ul><h4>Organizing a Project using AngularJS and Rails</h4><p>There are two main choices when it comes to organizing a site that uses both AngularJS and Rails. First, we could organize our project inside of the Rails Asset pipeline, along the lines of <a href="https://thinkster.io/angular-rails">this tutorial</a>. Second, we could organize our project in a client directory and manage our front end assets separately, the manner recommended in <a href="http://angularonrails.wpengine.com/wire-ruby-rails-angularjs-single-page-application-updated-2016/">this tutorial</a>.</p><p>For SnippetMachine, I chose to organize the project with a separate client directory as outlined in the second tutorial by Jason Swett. The reason I preferred this way is that it allows for a tighter integration with the javascript ecosystem (npm). It also allows us to structure the Angular app in a way that is much more back-end agnostic. I think this is really important because it ensures that the time we spend working in Angular can be focused on doing things the Angular way, not the Rails-Angular way.</p><p>One of the interesting challenges that comes from taking this approach is deciding where certain features should be implemented. For instance, when it came time to implement the Dropbox API integration, I had a choice between whether to hook it up in Ruby or JavaScript. In that case, it made more sense to hook it up on the server side in Ruby. The reason I chose to do it on the server side is that there really isn’t a secure way of keeping the API key and credentials private when connecting via a client side app.</p><p>Meanwhile, when it came to formatting the snippets for different editors, it actually made sense to do this differently depending on the purpose. When I was preparing the contents of files to be saved to a user’s dropbox, I did the formatting on the server side. But, when I just wanted to display the formatting to the user, I used an Angular Filter on the client side. I feel like having a separate directory and ecosystem for the Angular app helps keep the idea of separation of concerns in proper perspective.</p><figure><img alt="Snippet Machine New Snippet Form with Views for different Editor Formats" src="https://cdn-images-1.medium.com/max/976/0*TJzZXuFGQTqE09rE.jpg" /></figure><h4>What I’ll be Doing Differently When I Rebuild SnippetMachine for this Tutorial</h4><p>As I mentioned earlier, there were parts of this process that were painful to push through the first time. I’m hoping that in putting together this tutorial, I’ll be able to resolve many of those pain points as we go along. In particular, there are four things that I will be doing differently when I rebuild the application.</p><p>First, I realized after working for a bit that I actually needed another resource in my domain model. I wanted users to be able to add other user’s snippets to their account. Originally, I was thinking about some sort of a ‘forking’ where a user could create a snippet based on another user’s snippet. After some more thought, I realized that this meant that every time a user wanted to add another user’s snippet to their account, another row in the snippets table would have to be created. I only want another snippet to be created if there’s an actual modification occurring. So, what I did was to add a UserSnippet resource that is a join model for users and snippets. Quite a bit of refactoring went into making this transition, so when we go through the project together, I’m going to build the domain model that way from the start.</p><p>Second, because we’ll be building the domain model earlier on in the process, I’m going to handle authentication with devise_token_auth and ng-token-auth earlier on in the process. At least, I’ll be running rails g devise_token_auth:install earlier on in the process so that our domain model can be set up properly before we start getting deep into the client side of the app.</p><p>Third, I started out having a language column in the snippets table to hold a string representing the language the snippet was for. I discovered when I had built out the form to create new snippets in Angular that I was going to need some way of validating that snippet languages were actual supported languages for the supported editors. In order to do that, I realized that it would be better to create a Language model so that I could validate language names on the server side and also ensure that duplicate languages were not created. But, perhaps the most important reason to treat language as a resource is that doing so allows us to create a has_many &lt;-&gt; belongs_to relationship between languages and snippets. For example, this turns about to be very important later on when saving all of a user’s snippets written in JavaScript.</p><p>Fourth, in preparation for the transition to Angular 2, which was officially released during my work on this project, I’ve refactored all of my controllers into components. Controllers only exist as members of components and directives in Angular 2, so this should make the code much easier to transition when the time comes. When I go through rebuilding the application, we’ll start out building the app as a collection of components.</p><h4>What to Expect out of this Series of Tutorials on AngularJS and Rails</h4><p>If you’re not already addicted to using code snippets, I would honestly be shocked if you aren’t after working along with me as we rebuild this application. We’ll definitely be developing an appreciation for code snippets as we go through building this app. If you’re comfortable with rails and you have some experience with AngularJS, you should be able to follow along with me without too much trouble.</p><p>One of the main goals I have for this series is to come out of it with a much better understanding of what I’ve accomplished so far with <a href="https://github.com/DakotaLMartinez/rails-angular-snippet-machine">SnippetMachine</a>. I’ve found that going through the act of actually explaining and outlining the process of implementing these features and building a full-fledged application step by step is an incredible learning experience. It’s really amazing how many things we think we understand until we try to explain them to someone else!</p><p><strong>IMPORTANT NOTE</strong>: I’ll be using AngularJS v1.5.3 and Rails v5.0.0.1 for this tutorial. AngularJS v1.5.8 is currently available, but v1.5.3 is the newest version officially supported by the ng-token-auth module that we’re using for authentication.</p><p>My goal is to put together a thorough guide to getting started with AngularJS and Rails. If I’m successful, you’ll have a series of tutorials that will allow you to hook up and work with AngularJS and Rails in a way that is <strong>significantly</strong> less painful than it was for me the first time.</p><p>By the end of this tutorial, you should have a good sense of some of the issues that come up when building a web application with AngularJS and Rails. I’m particularly excited about walking you through how to set up a nice development environment for AngularJS and Rails with <a href="https://www.npmjs.com/">npm</a>, <a href="http://gulpjs.com/">gulp</a>, <a href="https://bower.io/">bower</a> and <a href="https://www.browsersync.io/">browsersync</a>. Another post I’m psyched about is the one on how to set up an automated build on deployment. The integration with the Dropbox API and all you can do with that should be a really fun part of the series as well.</p><h4>Final Thoughts</h4><p>I have had an absolutely fantastic time learning Full Stack Web Development at the <a href="https://flatironschool.com/programs/online-web-developer-career-course/">Flatiron School</a>. I cannot recommend the program highly enough. I have developed a sense of confidence in my abilities to solve problems and continuously improve my skills. It has been an exceedingly wonderful experience and I really look forward to sharing the things that I’ve learned with the community.</p><p>Yours Truly,</p><p>Dakota Lee Martinez</p><p>P.S. Stay tuned for the first tutorial next week!</p><p><em>Originally published at </em><a href="http://becomingaprogrammer.com/angularjs-rails-5-api/"><em>Becoming a Programmer</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0d882d3a85f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Wanted to Learn Software Development]]></title>
            <link>https://medium.com/@dakotaleemartinez/why-i-wanted-to-learn-software-development-bb5500f83e76?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb5500f83e76</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[learn]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Mon, 10 Oct 2016 05:29:53 GMT</pubDate>
            <atom:updated>2016-10-12T19:21:00.994Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Everyone! My name is Dakota Lee Martinez. In the following post, I want to talk to you about why I wanted to learn Software Development. In my life, I’ve been passionate about many things. But, few things are as exciting to me as the developments in the field of software.</p><p>Some of my favorite conversations have been about the role of technology in our rapidly changing world. I think that the ability to think abstractly and to create tools is one of the things that really sets humanity apart. At present, the acceleration of progress in Software Development is extremely inspiring to me. These days, there are so many amazing things that we can do on the internet.</p><p>I have always been a creative person. I would always be inventing new ways of doing math problems, imagining how different the world would be if we changed the rules, and exploring how changes in the language I use to talk to myself could transform the way I felt about my life. I’ve written many songs, recorded them, read about countless techniques for getting the best sound in a recording or a live situation. Still, as I’ve gotten older, software has become a more substantial presence in all areas of my life.</p><p>Today, I am continually amazed by all we are able to do with recording software in our bedrooms. Ultimately, I have felt the value that great software can provide within the world of music long before I decided to learn software development. There is one particular story that I have to share, because it’s a wonderful example of just how big of an emotional impact software can have. For this story, I’ll take you back to my college days studying music in Claremont.</p><h4>Understanding Bach for the First Time</h4><p>For my final project in a music history class, I wrote a paper on historical systems of tuning and temperament used in the renaissance, classical and romantic periods. Assuming that you and I are similarly nerdy, I’ll take you through a little bit of what I learned researching that paper. During my research, I read an awesome book called <a href="https://www.amazon.com/gp/product/0393334201/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0393334201&amp;linkCode=as2&amp;tag=becomingaprog-20&amp;linkId=19eb63cef7665dc55616646b107f0a49">How Equal Temperament Ruined Harmony (and Why You Should Care)</a>.</p><p>The advent of equal temperament, something that virtually all musicians take for granted today, radically transformed the experience of the sound of musical instruments and the ease with which they could be played together. Before Equal Temperament, it may surprise you to learn that there were many different methods of tuning a keyboard instrument. Before we get into the differences between them, let me give you a bit of background on why there was so much fuss.</p><p>The problem with tuning <a href="https://en.wikipedia.org/wiki/Pythagorean_tuning">goes back to Pythagoras</a>. The relationship between two notes can be looked at as a ratio of two different frequencies. In this way, we can describe a middle C and the note one perfect octave above as being related by a frequency ratio of 2:1. Similarly, the note one perfect fifth above is related by a frequency ratio of 3:2. But, there is an inconsistency. If we start at the lowest A on a Piano (referred to as A0) and go up to the A 7 octaves above (A7), we get a frequency ratio of 2⁷:1 (128:1). However, if we start at A0 and go up 12 perfect fifths to what should be the same A7 as in the previous example, we get a frequency ratio of (3/2)¹² (129.746:1). So, when it comes to tuning keyboard instruments, some compromise between the various harmonies has to be made. We can have perfectly tuned perfect fifths or perfectly tuned perfect octaves, but not both at the same time. The only way a keyboard instrument could play everything perfectly in tune would be for each octave to have many more than 12 notes in it.</p><p>Before Equal Temperament, there were literally hundreds of different methods of tuning a keyboard instrument, all making different tradeoffs, sounding different when played in different keys. Most methods of tuning sought to make the more commonly used keys sound better, while those played less often would be farther out of tune. It doesn’t take too much thought to realize how complicated this system would have been with a larger group of instruments, all of which had tuning issues of their own!</p><p>After we developed both the technology to measure the frequency of a given note and the machinery necessary to precisely calibrate string tension to adjust the frequency of that note, equal temperament allowed a standardization of tuning. Just in case you’re wondering, equal temperament uses the perfect octave at 2:1 as its basis for tuning. All of the perfect fifths on a modern piano are tuned to 2^(7/12):1, which is 1.498:1. So, all the perfect fifths on a modern piano are slightly narrower than the perfect 3:2 frequency ratio. This was truly revolutionary. Without Equal Temperament, the entire genre of Jazz might never have come to be. (Everything being equally out of tune allowed for the kind of parallel motion from chord to chord used frequently in Jazz that would have sounded horrible with older tunings.)</p><h4>Enter Software</h4><p>Yes, but what does Software have to do with any of this? Well, I want to tell you about a feature I discovered in my Digital Audio Workstation (DAW) that allowed me to actually adjust the tuning system used for playback. First, let me give you the context for my little experiment.</p><p>One of the most famous works by Johann Sebastian Bach is the Well Tempered Clavier. It was composed to demonstrate the wonder of a keyboard instrument that could be played in every key without adjusting the tuning. This was quite a big deal at the time, as there was considerable skill involved in composing pieces in the more obscure keys whose tuning was sacrificed to make the common keys sound prettier. (The temperament Bach used is thought to be out of the irregular temperaments popular at the time that were tuned to favor common keys but still be playable in less common ones.)</p><p>Hearing these works on a modern piano, I never cared much for them. It always seemed to me like there were too many modulations (key changes) and decorations and not a whole lot of substance. But, thanks to modern software, I was able to play one of these pieces on a MIDI keyboard and adjust the temperament of the electronic piano on playback to reflect a tuning system prevalent at the time it was written. All I can say is… WOW. I will never forget the feeling I got when I first heard that piece in an appropriate temperament.</p><p>I remember in the music history classes the books talked about D minor and how it was an unbelievably sad key, and F Major was a Pastoral Key and so on. This always felt strange to me as I never had any sense of the keys having any different emotional character from one another. I can tell you now, though, that I felt instantly how each tonality took on a different character in these old tuning systems. Listening to Bach’s piece in one of these old tunings, each modulation takes the listener on an emotional journey. Without Software, I may have <em>appreciated</em> the genius of Bach, but I would never have <em>experienced</em> it the way that I did. I couldn’t help wanting to learn software development to be a part of something so cool!</p><h4>Open Source Culture</h4><p>Another thing that I find extremely exciting about the world of Software Development is the prominence of open source culture. In what other industry do you hear major players announcing that they are openly collaborating on huge projects that are all open to the public to view? Google and Microsoft agreed to collaborate on building Angular 2 in TypeScript, a language developed by Microsoft and expanded for use in Angular 2. The idea that openly sharing knowledge is actually more valuable than keeping your best ideas to yourself seems self-evident to me. But, in many industries, a culture of secrecy reigns.</p><p>Okay, of course there are “tech” companies that actively cultivate a culture of secrecy (Apple comes to mind). But, I would argue that Apple is an entirely different kind of company. I would definitely check out Chris Messina’s article <a href="https://medium.com/chris-messina/silicon-valley-is-all-wrong-about-the-airpods-8204ede08f0f#.f9y26xxva">Why Silicon Valley is all wrong about Apple’s AirPods</a> for more on that idea. Many companies in the technology space have realized that the challenges we are facing deserve an open forum. In fact, the open forum encourages better software by opening the conversation to more people. More users leads to more feedback. More feedback leads to more focused work. And, in the end, more people involved leads to more contributors to the actual work itself.</p><p>There is just such a huge upside to an open discussion about the development and implementation of libraries of software as they are being developed. I am excited about the idea that the work I’m doing to solve problems that I face can be used by other people to solve problems that they face. I have benefitted so much from the generosity of strangers on the internet. Countless blog posts, podcasts, videos, and Stack Overflow posts have guided me on my quest to learn software development. I really appreciate how much sharing of information exists within this space and how much of that information is given freely, not just to an exclusive few.</p><h4>Growth in the Industry and the Prominence of Education</h4><p>Another big reason that I was excited to learn software development is the rapid pace of change in the industry. There is a tremendous amount of growth spanning many different technologies, industries and infrastructure. Software is everywhere and it’s very difficult to find any line of work where you don’t feel its influence. Because the demand for software is growing across nearly every industry, there is an intense need for more programmers. There is good money to be made in Software Development, so why aren’t there more programmers?</p><p>I think there’s an idea out there that learning to code is hard, that you have to be really good at science and math to even have a chance of being good at it. Now, there is quite a bit of debate about whether anybody can become a programmer. My full take on that is for another post, but I generally have a strong resistance to any arbitrary negative generalizations made about people. I don’t like it when people say that some people are born with abilities and others aren’t. I’ve felt like this for a long time, so I was delighted to read <a href="https://www.amazon.com/gp/product/1531864880/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1531864880&amp;linkCode=as2&amp;tag=becomingaprog-20&amp;linkId=884c616c81292748f3439edf789b7eb5">Peak: Secrets from the New Science of Expertise</a>, which offers a great discussion of how humans become experts.</p><p>I believe that anyone who has the desire and dedication to put in the deliberate practice necessary to learn a craft can do it. This country has a need for talented programmers. We can’t afford to be talking about this skill as if only certain people can do it. We want to be spending our energy making it easier for kids to develop the desire to learn software development. We also need to be focusing on how to train people from an early age to develop the skills necessary to make meaningful contributions to the world of software development. In our lifetimes, software may be running inside of our bodies. It is imperative that we give all children the opportunity at an early age to see what fun can come from learning how to talk to computers.</p><p>Fortunately, I don’t think it has ever been easier to learn software development. The amount of quality resources available on the internet for free is staggering. Check out <a href="https://www.udemy.com/">Udemy</a>, <a href="https://www.udacity.com/">Udacity</a>, <a href="http://www.w3schools.com/">W3Schools</a>, <a href="https://www.codecademy.com/">Codecademy</a>, and <a href="https://www.freecodecamp.com/">Free Code Camp</a> if you don’t believe me. And, if you’re willing to pay, the quality of those resources increases even more. I went through a 12-week part time Beta course called Codecademy Labs at the beginning of 2015 and it changed my life.</p><h4>My Experience with Coding Bootcamps</h4><p>Before attending Codecademy Labs, I hadn’t really been in an environment with other people who wanted to learn software development. When I was there interacting with the TAs and the other students, I knew that it was something I could learn how to do. In the end, it was clear to me that our instructors had faced a lot of problems and knew what resources they could use to tackle them. All I needed to do was put myself in the situation to face those problems and find the resources to solve them.</p><p>Codecademy labs was not an immersive bootcamp, but more of a part time taste of what a bootcamp could be like. We covered quite a bit of ground in just 12 weeks, and I definitely learned a lot. Still, I felt like there were things I really didn’t understand yet. I was still fuzzy on what was going on with the ORM (Object Relational Mapping) to generate database code from ruby code. I felt like I’d done a lot of coding, but not as much reading and understanding what I was doing.</p><p>After returning to Wordpress to do some freelance work to test my skills, I really had the sense that the best way for me to learn software development would be as part of a group. That way, I would feel the pressure to level up my skills to keep up, and I’d be surrounded by people who were performing at a level that I wanted to reach. So, I upped the ante again and joined the <a href="https://flatironschool.com/campuses/online/">Learn Verified Full Stack Web Developer Program</a>, recently released by the Flatiron School. After being accepted, the program is designed to put students through 800 hours of training towards becoming a full-stack web developer.</p><p>At the time I took the course (starting in November 2015) the stack was AngularJS (1.x) running on a Ruby on Rails backend. I’m in the process of completing my final project for the course and I can say that my confidence working through problems and pushing through roadblocks has increased dramatically since I began studying with Flatiron.</p><p>The main appeal to me of the Flatiron School’s new online program was its focus on people looking to make a career change. A major factor in my decision to enter the program is that they offer job placement services with a career coach upon graduation. They offer guaranteed job placement upon completion of the program. To back this up, they release an independently verified job placement report which reports how long it took graduates to get a job after graduation and what their starting salary was. I have just begun interaction with my career coach and I can tell you it’s definitely worth it.</p><h4>The Importance of Long Term Continuing Education</h4><p>Learning has always been an important part of my life. I feel most excited when I am continuing to expand my thinking and when i’m learning new skills. This is one of the main reasons I wanted to learn software development. I have gotten the sense that it’s very important to continue learning new technologies and reading about changes in the development landscape. I think that being in an environment where you are forced to continually face new concepts and challenges is exhilarating. The commitment to learn software development is a commitment to a life of constant learning.</p><p>My first full time job was at a startup in the Music Accessory business, manufacturing products that are distributed all over the world. There, I found that one of my key roles was in finding software that we could use to run the business more effectively and efficiently. Still, I found myself wanting to look under the hood and figure out how they worked. Our website was built in Wordpress, so I taught myself PHP and started reading the Wordpress Codex.</p><p>At first, a lot of it went over my head. But, I found that when I returned to Wordpress after studying Ruby on Rails and AngularJS at Codecademy labs, I had a much better sense of how the pieces were put together and the differences between the two approaches to building a web application. One of the things that is surprising when you learn software development is how much easier it is after you’ve been going at it for a while. I’m still shocked at how much progress I’ve made in the last month while working on my final projects. When I look back at code I wrote a month ago, I find myself thinking… Wow, that was really not the best way of doing that.</p><p>The experience of constantly being on the edge of my intellectual capacity is thrilling to me. I find myself growing in my capacity to solve problems every day. I feel my abilities to solve problems creatively growing every week and I am pumped to share my knowledge and start putting my skills to use in a professional capacity.</p><h4>Cool Stuff We Can Do With Software</h4><p>In the end, I am inspired by all of the amazingly cool stuff we can do with software today. By choosing to learn software development, I get to be a part of all of the wonderful things that the community is contributing to the world.</p><p>We can stay in touch with friends all over the world from virtually anywhere. When I run live sound for the 14-piece funk band that my wife, mom &amp; I sing background vocals in, I can control <a href="https://www.amazon.com/gp/product/B01JMYNDN0/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01JMYNDN0&amp;linkCode=as2&amp;tag=becomingaprog-20&amp;linkId=894a4749572c0233d501a528c9a3ec9b">my awesome digital mixer</a></p><p>with my iPad via WiFi, adjusting any of the effects, monitor feeds or volume levels from anywhere in the venue. Logic Pro X’s new Drummer App sounds amazing and it allows you to adjust the way a drummer is playing by using a super simple UI.</p><figure><img alt="User Interface for Logic Pro X&#39;s Drummer app" src="https://cdn-images-1.medium.com/max/1024/0*YOojiYB3ToH0aRtJ.jpg" /></figure><p>You can go to Disney World and use a <a href="https://disneyworld.disney.go.com/plan/my-disney-experience/bands-cards/">Magic Band</a> to customize your whole experience. You can select all the rides you want to go on and you’ll automatically be scheduled with Fast Pass+ on all of the rides. When you walk around the park, the park responds to you personally and all of the photos taken of you throughout your stay are automagically available to you via your disney account.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F__yY8M4TZoA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D__yY8M4TZoA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F__yY8M4TZoA%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4e6b9d3753646fa36ac65266b5dbad6/href">https://medium.com/media/c4e6b9d3753646fa36ac65266b5dbad6/href</a></iframe><p>Services like Uber and Lyft have made it extremely easier to get a ride in many cities all over the world. Air BnB has made it possible for people to find places to stay virtually anywhere they happen to be. This new generation of Web Applications have the potential to reshape existing markets and even create brand new ones.</p><p>Best of all, this kind of creative awesomeness is not limited to large companies. All over, there are examples of individuals who took the time to learn software development making huge contributions to the open source community. From cool project’s like Yotam Bar-On’s <a href="http://app.solarizd.com/">Solarized Music player in AngularJS</a> using the YouTube and Echonest API’s to allow users to create customized playlists from online content, to entire web application frameworks like David Heinemeier Hansson’s <a href="https://github.com/rails/rails">Ruby on Rails</a>, to the thriving javascript ecosystem emerging around <a href="https://www.npmjs.com/">NPM</a>. There are thousands and thousands of developers who share their code with the community, allowing really amazing creations to happen every day.</p><h4>Final Thoughts</h4><p>At the end of the day, there has never been a better time to learn software development. It’s a great challenge, a rapidly changing industry with lots of opportunities and an exciting new frontier. If you have any sort of interest, I definitely recommend checking out some of the free resources I mentioned (<a href="https://www.udemy.com/">Udemy</a>, <a href="https://www.udacity.com/">Udacity</a>, <a href="http://www.w3schools.com/">W3Schools</a>, <a href="https://www.codecademy.com/">Codecademy</a>, and <a href="https://www.freecodecamp.com/">Free Code Camp</a>.) If you work on those for a year or so and find yourself wanting to make the career change, check out a bootcamp like the <a href="https://flatironschool.com/">Flatiron School</a> and go for it!</p><p>Yours truly,</p><p>Dakota Lee Martinez</p><p>P.S. Insert Awesomely Inspirational Video Here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6rxWc-TNIJI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6rxWc-TNIJI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6rxWc-TNIJI%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/57ecaf50d48bdfcd22dca13a4a3bf96a/href">https://medium.com/media/57ecaf50d48bdfcd22dca13a4a3bf96a/href</a></iframe><p><em>Originally published at </em><a href="http://becomingaprogrammer.com/learn-software-development/"><em>Becoming a Programmer</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb5500f83e76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Broadcasting Events to the $rootScope in AngularJS to pass information between Directives and…]]></title>
            <link>https://medium.com/@dakotaleemartinez/broadcasting-events-to-the-rootscope-in-angularjs-to-pass-information-between-directives-and-b80594110fc9?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b80594110fc9</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularjs-event-system]]></category>
            <category><![CDATA[rootscope]]></category>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Sun, 10 Jul 2016 06:16:16 GMT</pubDate>
            <atom:updated>2016-07-10T06:16:16.184Z</atom:updated>
            <content:encoded><![CDATA[<h3>Broadcasting Events to the $rootScope in AngularJS to pass information between Directives and Controllers</h3><p>In one of the labs for the Learn Verified curriculum, we’re tasked with using the $rootScope object to publish and subscribe to events. This allows us to pass information about user behavior from one part of our application to another.</p><p>For example, in this lab we have a ContactsController that has a property called contacts. This property stores an array contains a list of many contacts.</p><pre>// app/js/controllers/ContactController.js<br>angular<br>  .module(&#39;app&#39;)<br>  .controller(&#39;ContactController&#39;, function($rootScope){<br><br>    this.contacts = [<br>        {<br>            &quot;name&quot;: {<br>                &quot;title&quot;: &quot;mr&quot;,<br>                &quot;first&quot;: &quot;liam&quot;,<br>                &quot;last&quot;: &quot;lawson&quot;<br>            },<br>            &quot;location&quot;: {<br>                &quot;street&quot;: &quot;1642 church lane&quot;,<br>                &quot;city&quot;: &quot;dundee&quot;,<br>                &quot;state&quot;: &quot;south yorkshire&quot;,<br>                &quot;zip&quot;: &quot;LN6Y 1ZG&quot;<br>            },<br>            &quot;email&quot;: &quot;liam.lawson@example.com&quot;,<br>            &quot;username&quot;: &quot;silverwolf439&quot;,<br>            &quot;dob&quot;: 924314544,<br>            &quot;phone&quot;: &quot;015242 99250&quot;,<br>            &quot;cell&quot;: &quot;0713-889-058&quot;,<br>            &quot;NINO&quot;: &quot;BX 12 80 44 W&quot;,<br>            &quot;picture&quot;: {<br>                &quot;large&quot;: &quot;https://randomuser.me/api/portraits/men/74.jpg&quot;,<br>                &quot;medium&quot;: &quot;https://randomuser.me/api/portraits/med/men/74.jpg&quot;,<br>                &quot;thumbnail&quot;: &quot;https://randomuser.me/api/portraits/thumb/men/74.jpg&quot;<br>            }<br>        },<br>        ....<br>    ];<br>  });</pre><p>Within the index.html file: We have an ng-controller scope for the ContactController, we have an ng-repeat directive that is displaying each contact using a custom directive called contact.</p><pre>&lt;!-- index.html --&gt;<br>&lt;div ng-app=&quot;app&quot; class=&quot;app&quot;&gt;<br>  &lt;div ng-controller=&quot;ContactController as ctrl&quot;&gt;<br>    &lt;ul&gt;<br>      &lt;li ng-repeat=&quot;contact in ctrl.contacts&quot;&gt;<br>        &lt;contact id=&quot;$index&quot; contact=&quot;contact&quot;&gt;&lt;/contact&gt;<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>The directive takes two attributes, id and a contact object. And displays some information about each contact:</p><pre>// app/js/directives/Contact.js<br>angular<br>  .module(&#39;app&#39;)<br>  .directive(&#39;contact&#39;, function() {<br>    return {<br>      restrict: &#39;E&#39;,<br>      template: [<br>        &#39;&lt;div class=&quot;contact&quot;&gt;&#39;,<br>          &#39;Name: {{ ctrl.contact.name.title }} {{ ctrl.contact.name.first }} {{ ctrl.contact.name.last }} - &lt;a href=&quot;&quot; ng-click=&quot;ctrl.remove(ctrl.id)&quot;&gt;Remove&lt;/a&gt;&#39;,<br>        &#39;&lt;/div&gt;&#39;<br>      ].join(&#39;&#39;),<br>      controller: function ($rootScope) {<br>        this.remove = function (id) {<br>     <br>        };<br>      },<br>      controllerAs: &#39;ctrl&#39;,<br>      bindToController: {<br>        id: &#39;=&#39;,<br>        contact: &#39;=&#39;<br>      }<br>    }<br>  });</pre><p>Looking within the template here, you can see that we have a link to remove a contact. It is calling the remove method on the Contact directive’s controller and passing in the id of this particular contact. But how does the directive know whether its contact’s data has been deleted from the ContactController? How does the ContactController know to remove the the contact from its list?</p><p>This is where Angular’s event system comes in. We can publish events on the $rootScope from the Contact directive (where we have the link to remove the contact) and then subscribe to those events from the Contact Controller (where the actual list is kept).</p><h3>Publishing an Event to the $rootScope from a Directive</h3><p>In order to publish an event to the $rootScope from the Contact Directive, we use $broadcast:</p><pre>// app/js/directives/Contact.js<br>angular<br>  .module(&#39;app&#39;)<br>  .directive(&#39;contact&#39;, function() {<br>    return {<br>      restrict: &#39;E&#39;,<br>      template: [<br>        &#39;&lt;div class=&quot;contact&quot;&gt;&#39;,<br>          &#39;Name: {{ ctrl.contact.name.title }} {{ ctrl.contact.name.first }} {{ ctrl.contact.name.last }} - &lt;a href=&quot;&quot; ng-click=&quot;ctrl.remove(ctrl.id)&quot;&gt;Remove&lt;/a&gt;&#39;,<br>        &#39;&lt;/div&gt;&#39;<br>      ].join(&#39;&#39;),<br>      controller: function ($rootScope) {<br>        this.remove = function (id) {<br>          $rootScope.$broadcast(&#39;remove&#39;, id);<br>        };<br>      },<br>      controllerAs: &#39;ctrl&#39;,<br>      bindToController: {<br>        id: &#39;=&#39;,<br>        contact: &#39;=&#39;<br>      }<br>    }<br>  });</pre><p>You’ll notice that we’re also passing through the id of the contact that we want to remove. This is how the controller will know which contact to remove when it receives a notification that the event has fired.</p><h3>Subscribing to an Event on the $rootScope from a Controller</h3><p>In order to subscribe to the event on the $rootScope that we published in the previous step, we use Angular’s $on service:</p><pre>// app/js/controllers/ContactController.js<br>angular<br>  .module(&#39;app&#39;)<br>  .controller(&#39;ContactController&#39;, function($rootScope){<br>    $rootScope.$on(&#39;remove&#39;, function(event, data){<br>      this.contacts.splice(data, 1);</pre><pre>    });    </pre><pre>    this.contacts = [<br>        {<br>            &quot;name&quot;: {<br>                &quot;title&quot;: &quot;mr&quot;,<br>                &quot;first&quot;: &quot;liam&quot;,<br>                &quot;last&quot;: &quot;lawson&quot;<br>            },<br>            &quot;location&quot;: {<br>                &quot;street&quot;: &quot;1642 church lane&quot;,<br>                &quot;city&quot;: &quot;dundee&quot;,<br>                &quot;state&quot;: &quot;south yorkshire&quot;,<br>                &quot;zip&quot;: &quot;LN6Y 1ZG&quot;<br>            },<br>            &quot;email&quot;: &quot;liam.lawson@example.com&quot;,<br>            &quot;username&quot;: &quot;silverwolf439&quot;,<br>            &quot;dob&quot;: 924314544,<br>            &quot;phone&quot;: &quot;015242 99250&quot;,<br>            &quot;cell&quot;: &quot;0713-889-058&quot;,<br>            &quot;NINO&quot;: &quot;BX 12 80 44 W&quot;,<br>            &quot;picture&quot;: {<br>                &quot;large&quot;: &quot;https://randomuser.me/api/portraits/men/74.jpg&quot;,<br>                &quot;medium&quot;: &quot;https://randomuser.me/api/portraits/med/men/74.jpg&quot;,<br>                &quot;thumbnail&quot;: &quot;https://randomuser.me/api/portraits/thumb/men/74.jpg&quot;<br>            }<br>        },<br>        ....<br>    ];<br>  });</pre><p>If we try to run this code in the browser, the remove functionality won’t work. Can you see why? The answer has to do with the way that scope works in Angular. Let’s take a look at that index.html page again:</p><pre>&lt;div ng-app=&quot;app&quot; class=&quot;app&quot;&gt;<br>  &lt;div ng-controller=&quot;ContactController as ctrl&quot;&gt;<br>    &lt;ul&gt;<br>      &lt;li ng-repeat=&quot;contact in ctrl.contacts&quot;&gt;<br>        &lt;contact id=&quot;$index&quot; contact=&quot;contact&quot;&gt;&lt;/contact&gt;<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>$rootScope is the parent scope that is created within the element that has the ng-app directive attached to it. Inside of that div, we have the scope created by the ContactController that exists within the div that has the ng-controller directive specifying the ContactController. Within that div, the ng-repeat that loops through the contacts in the ContactController creates its own scope wherein the variable ‘contact’ represents one of the items in the ‘ctrl.contacts’ array. (Note that the ctrl.contacts array exists within the ContactController scope.) Finally, within the ng-repeat, the call to the custom directive called ‘contact’ creates another nested scope.</p><p>It’s easy to see how this could get really complicated. Tracking down which scope is in charge of a particular piece of data or functionality and which scope has access to it can be difficult to grasp.</p><p>One of the ways we simplify this is by publishing events to the $rootScope and then subscribing to those events from other scopes that need to interact with that event.</p><p>But isn’t that what we did? Well, yes. The issue is that we forgot to keep track of scope within the $rootScope.$on function call.</p><h3>Fixing the Bug</h3><p>If we console.log the value of this within the $rootScope.$on function call, we can see that it actually refers to the Window object, not the Contact Controller.</p><pre>// app/js/controllers/ContactController.js<br>angular<br>  .module(&#39;app&#39;)<br>  .controller(&#39;ContactController&#39;, function($rootScope){<br>    $rootScope.$on(&#39;remove&#39;, function(event, data){<br>      // this refers to the Window object within the $rootScope<br>      console.log(this) <br>      this.contacts.splice(data, 1);</pre><pre>    });</pre><pre>  ...</pre><pre>  });</pre><p>When we open index.html in the browser and click on one of the remove links, this is what we’ll get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*itVDkY9z2spT3cBc9l0kow.png" /></figure><p>We can see that ‘this’ refers to the Window object and that when we try to call .splice() on this.contacts we get a TypeError because contacts is not defined as a property of the Window object, it’s defined as a property of the ContactController object.</p><p>So in order to access the list that is a property of the ContactController, we need to store the value of ‘this’ in another variable outside of the $rootScope.$on() function call (but still within the ContactController scope). This way, we’ll have access to the ContactController scope within the $rootScope.$on() function:</p><pre>// app/js/controllers/ContactController.js<br>angular<br>  .module(&#39;app&#39;)<br>  .controller(&#39;ContactController&#39;, function($rootScope){<br>    var ctrl = this;<br>    $rootScope.$on(&#39;remove&#39;, function(event, data){<br>       ctrl.contacts.splice(data, 1); <br>    });</pre><pre>    this.contacts = [<br>        ...<br>    ];</pre><pre>  });</pre><p>And now it’s time to break into the happy dance!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F14i8m8ddHdNJaU%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2F14i8m8ddHdNJaU&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F14i8m8ddHdNJaU%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="246" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcc9c1249c5c27d6b056eb2e8eb29074/href">https://medium.com/media/dcc9c1249c5c27d6b056eb2e8eb29074/href</a></iframe><p>The main takeaway here is to be aware of where your scope is at any given time. If you need to notify other parts of your app about events trigger by user actions, you’ll want to publish events to the $rootScope and then subscribe to them from the other parts of your app that need to know.</p><h3>Worth Checking Out</h3><ul><li><a href="https://github.com/learn-co-students/angular-using-the-events-system-lab-v-000">learn-co-students/angular-using-the-events-system-lab-v-000</a></li><li><a href="https://learn.co/">Learn - A platform for education.</a></li><li><a href="http://learncooltech.com/understanding-angulars-scope-and-rootscope-event-system-emit-broadcast-and-on/">Understanding Angular&#39;s $scope and $rootScope event system $emit, $broadcast and $on</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b80594110fc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Record Both Ends of a Skype Conversation on your Mac for Free]]></title>
            <link>https://medium.com/@dakotaleemartinez/how-to-record-both-ends-of-a-skype-conversation-on-your-mac-for-free-a67852c1a161?source=rss-1d2840d405f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a67852c1a161</guid>
            <category><![CDATA[skype]]></category>
            <category><![CDATA[quicktime]]></category>
            <category><![CDATA[podcast]]></category>
            <category><![CDATA[recording]]></category>
            <category><![CDATA[soundflower]]></category>
            <dc:creator><![CDATA[Dakota Lee Martinez]]></dc:creator>
            <pubDate>Sun, 03 Jul 2016 22:31:55 GMT</pubDate>
            <atom:updated>2016-07-03T22:31:55.423Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone, I’m hoping to start recording podcast interviews shortly, and I wanted to figure out a way to record both ends of a Skype conversation so that I could do remote interviews. A while back I had used the built in Utility application called Audio MIDI Setup to create an aggregate device so that I could combine a couple of different microphone preamps to be able to record both a keyboard and a couple of vocals at the same time. I figured there was probably a way to do something similar to be able to record both ends of a Skype conversation.</p><p>It was actually a lot more frustrating than I originally thought it would be, but I was pretty stubborn in my desire to get it done, so I eventually figured it out. I had it working so that I could hear both ends of the conversation in my headphones using what I thought were the same settings in both Quicktime Player and Skype, but I was missing a crucial step that prevented the setup from working properly. I needed to create a multi-output device within Audio MIDI Setup and then setup skype to send the conversation audio to that device. That way, Soundflower could hear the conversation and quicktime could record it through the aggregate device that included soundflower.</p><p>I ended up only needing to make minor tweaks in 4 applications/extensions, 2 of which are already installed on every mac to get it working. The 4 apps/extensions are Soundflower, Audio MIDI Setup, Skype and Quicktime Player.</p><p>I made a YouTube video with step by step instructions of how to set it up. I heard a lot of people saying that Quicktime couldn’t do something like this, but I wasn’t convinced. Feel free to give it a look if you’re curious.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXv1LMkF9-9k%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXv1LMkF9-9k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXv1LMkF9-9k%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b69a381d20b1a4e2df98862c09fb0a6/href">https://medium.com/media/4b69a381d20b1a4e2df98862c09fb0a6/href</a></iframe><h3>Worth Checking Out</h3><p><a href="http://becomingaprogrammer.com/how-to-record-both-ends-of-a-skype-call-on-your-mac-for-free-step-by-step-tutorial/">How to Record Both Ends of a Skype Call on Your Mac For Free - Step by Step Tutorial</a></p><p>If you’d like to check out the full step by step tutorial along with some resources for getting started with your own blog and podcast, you can check out the <a href="http://becomingaprogrammer.com/how-to-record-both-ends-of-a-skype-call-on-your-mac-for-free-step-by-step-tutorial/">full post</a> on my website.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a67852c1a161" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>