Chris BartholJekyll2020-07-25T19:56:39-04:00https://chrisbarthol.github.io/Chris Bartholhttps://chrisbarthol.github.io/chris.barthol@gmail.comhttps://chrisbarthol.github.io/coding/iot/msp430/msp430-setup2018-02-25T00:00:00-05:002018-02-25T00:00:00-05:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>Programming with the MSP430!</p>
<p>With the advent of arduino the Atmega328 by Microchip has been a staple of electronics hobbyists. However, there are other microcontroller (MCU) options available on the market, such as the MSP430 by Texas Instruments (TI).</p>
<p>The major advantage of the Atmega328 is the arduino ecosystem. TI has also released their own development kits called LaunchPad. One of the first was for the MSP430. You can purchase an MSP430 development LaunchPad called MSP-EXP430G2 for 10 dollars from <a href="http://www.ti.com/tool/MSP-EXP430G2#buy">TI</a>.</p>
<p>Currently TI only supports the windows platform for this particular development board in their Code Compiler Studio. However, their are other options if you want to use this board on a Mac or Linux machine. One such option is <a href="http://energia.nu/">Energia</a>. here are the steps I used to program my MSP-EXP430G2 LaunchPad on a Mac running High Sierra 10.13.2.</p>
<ol>
<li>Download and install <a href="http://energia.nu/download/">Energia</a></li>
<li>Download the LaunchPad CDC drivers. The link on the Energia website resolves into a 404 but the link on their <a href="https://github.com/energia/Energia/wiki/Getting-Started">github page works.</a></li>
<li>Since sierra Mac system will block and system extensions. You’ll need to go and update your Security & Privacy System Preferences to allow for the extension. When I loaded the drivers I did not accept or change my settings immediately. You can go into your Security & Privacy settings and towards the bottom will be a message “System software from <strong>__</strong> was blocked from loading” with an allow button next to it, do you can allow at later time.</li>
<li>Load up Energia. It is a fork of arduino so it looks identical. Under Tools, make sure you select the correct LaunchPad. For the MSP-EXP430G2 there are a variety of board options so make sure you select the correct version.</li>
<li>Connect your board through USB. Under the Tools menu make sure you are programming to the correct port.</li>
<li>Energia comes with a lot of examples! Under the File menu select Examples. A good first one to try out is the Blink program under 01. Basic menu header.</li>
<li>Compile and upload the program!</li>
</ol>
<h2 id="troubleshooting">Troubleshooting</h2>
<p>One issue I ran into occurred when trying to compile and example. Energia would always fail with an error message that included the follow:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">failed</span> <span class="no">MSpanList_Insert</span> <span class="mh">0x30d000</span> <span class="mh">0x32c44e5715c</span> <span class="mh">0x0</span>
<span class="n">fatal</span> <span class="ss">error: </span><span class="no">MSpanList_Insert</span></code></pre></figure>
<p>This failure seems to be Mac specific and comes from <a href="https://github.com/arduino/Arduino/issues/5397">arduino itself</a> .There is an <a href="https://github.com/energia/Energia/issues/983">open issue</a> on Energia github to port this fix over. However, the fix is in a beta branch currently. The next easiest solution is to swap out the arduino builder file. You can get the updated one <a href="https://github.com/energia/Energia/issues/983#issuecomment-336659482">here</a>. For me this file was in Applications/Energia/Contents/Java.</p>
<p>Your milage may vary and you might run into some issues, but that is ok! If you get completely stuck at any point there is an active community around Energia. On their <a href="https://forum.43oh.com/forum/119-energia/">forum</a> you can ask any questions you might have on your current issue.</p>
<p>Happy Programming!</p>
<p><a href="https://chrisbarthol.github.io/coding/iot/msp430/msp430-setup">MSP430 Setup on Mac</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on February 25, 2018.</p>https://chrisbarthol.github.io/coding/dynamic-fields-in-ember2016-02-06T00:00:00-05:002016-02-06T00:00:00-05:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>Our first form needs an uncertain amount of fields.</p>
<hr />
<p>With active model serializer I was able to post back to the server with data. I wanted to take this a step further and create my first form. If I’m going to make a recipe site where a user can add recipes I really need to have a new recipe form. This form will have various fields for the recipe such as Title, Description, and Ingredients.</p>
<p>But wait, ingredients are not just a simple one entry field. An ingredient has a name, an amount, and it might have a short description on its kind, minced or whole garlic for example. Ingredients really need their own model and a recipe will have many ingredients. So the form has the recipe fields and then some separate fields for the ingredients.</p>
<p>But wait, how many ingredient fields should I have? Short answer: I don’t know. I need to have a way for the user to add and remove ingredient fields from the page. As a basis I will display three ingredient fields. I like the number three plus it doesn’t overwhelm the user with too many fields. Most recipes have more than three ingredients so I need a button that adds more fields. I also need a delete button which will delete individual ingredients.</p>
<p>First pass: (Note syntax is Emblem)</p>
<figure class="highlight"><pre><code class="language-coffeescript" data-lang="coffeescript"><span class="err">/</span><span class="o">/</span><span class="nx">templates</span><span class="o">/</span><span class="nx">recipes</span><span class="o">/</span><span class="k">new</span><span class="p">.</span><span class="na">emblem</span>
<span class="nx">Recipe</span> <span class="nx">fields</span> <span class="nx">up</span> <span class="nx">here</span>
<span class="nx">div</span><span class="p">.</span><span class="na">text</span><span class="o">-</span><span class="nx">center</span>
<span class="p">.</span><span class="na">container</span><span class="o">-</span><span class="nx">fluid</span>
<span class="p">.</span><span class="na">form</span>
<span class="p">.</span><span class="na">form</span><span class="o">-</span><span class="nx">group</span>
<span class="p">.</span><span class="na">row</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">1</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">2</span>
<span class="nx">label</span> <span class="nx">Ingredient</span> <span class="nx">Amount</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">2</span>
<span class="nx">label</span> <span class="nx">Ingredient</span> <span class="nx">Name</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">4</span>
<span class="nx">label</span> <span class="nx">Ingredient</span> <span class="nx">Type</span><span class="p">(</span><span class="nx">minced</span><span class="p">,</span> <span class="nx">crushed</span><span class="p">,</span> <span class="nx">etc</span><span class="p">.)</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">2</span>
<span class="o">|</span> <span class="nx">Delete</span>
<span class="p">.</span><span class="na">form</span><span class="o">-</span><span class="nx">group</span>
<span class="p">.</span><span class="na">row</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">1</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">2</span>
<span class="o">=</span> <span class="nx">input</span> <span class="nx">value</span><span class="o">=</span><span class="nx">amount</span> <span class="k">class</span><span class="o">=</span><span class="s">"form-control"</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">2</span>
<span class="o">=</span> <span class="nx">input</span> <span class="nx">value</span><span class="o">=</span><span class="nx">name</span> <span class="k">class</span><span class="o">=</span><span class="s">"form-control"</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">4</span>
<span class="o">=</span> <span class="nx">input</span> <span class="nx">value</span><span class="o">=</span><span class="nx">type</span> <span class="k">class</span><span class="o">=</span><span class="s">"form-control"</span>
<span class="p">.</span><span class="na">col</span><span class="o">-</span><span class="nx">md</span><span class="o">-</span><span class="mi">2</span><span class="p">{</span><span class="nx">action</span> <span class="s">"remove"</span><span class="p">}</span>
<span class="nx">i</span><span class="p">.</span><span class="na">delete</span><span class="o">-</span><span class="nx">icon</span>
<span class="o">//</span> <span class="nx">more</span> <span class="nx">ingredient</span> <span class="nx">fields</span>
<span class="nx">button</span><span class="p">.</span><span class="na">btn</span><span class="p">.</span><span class="na">btn</span><span class="o">-</span><span class="nx">small</span><span class="p">{</span><span class="nx">action</span> <span class="s">"addField"</span><span class="p">}</span> <span class="nx">Add</span> <span class="nx">Another</span> <span class="nx">Ingredient</span></code></pre></figure>
<p>First those ingredient fields are going to be reproduced A LOT so lets throw it into a component. I’ll get to the actions later.</p>
<figure class="highlight"><pre><code class="language-coffeescript" data-lang="coffeescript"><span class="nx">ingredient</span><span class="o">-</span><span class="nx">field</span> <span class="nx">name</span><span class="o">=</span><span class="p">(</span><span class="nx">mut</span> <span class="p">(</span><span class="nx">get</span> <span class="nx">ingredient</span> <span class="s">'name'</span><span class="p">))</span> <span class="nx">amount</span><span class="o">=</span><span class="p">(</span><span class="nx">mut</span> <span class="p">(</span><span class="nx">get</span> <span class="nx">ingredient</span> <span class="s">'amount'</span><span class="p">))</span> <span class="nx">type</span><span class="o">=</span><span class="p">(</span><span class="nx">mut</span> <span class="p">(</span><span class="nx">get</span> <span class="nx">ingredient</span> <span class="s">'type'</span><span class="p">))</span></code></pre></figure>
<p>Woh, that is a lot of stuff! I’ve named my component ingredient-field. Components must have a - in their name to avoid conflicts with built-in controls that wrap HTML elements. This is also a requirement in web components so Ember is following the standard here. Next I am passing in data to the component through name, amount, and type. Components are usually data down, meaning that they receive data to display but do not change it. This is because components do not have the controllers scope that they are called from. They are unaware of their surroundings and can only access what is passed to them.</p>
<p>But the user will be entering data into these fields. That data has to go somewhere to get saved! It sure does and we use Ember’s mut and get to obtain a two-way binding. Taking the first property passed into the component, the name, we can run through a quick explanation. First I get an object, the ingredient, and I want the name property. I want this property to be mutable so I use mut. The same goes for the amount and type.</p>
<p>Ok, I’ve got this figured out for one set of ingredient fields now how do I make it dynamic and how do I keep the ingredients separate but still have access to them on the recipe new controller? ENTER (handlebars syntax). Each as allows iteration over a list of items. In this case I’m going to build up an array of ingredient objects which I’ll call rangeOfInputs and then iterate over each object.</p>
<figure class="highlight"><pre><code class="language-coffeescript" data-lang="coffeescript"><span class="nx">each</span> <span class="nx">rangeOfInputs</span> <span class="nx">as</span> <span class="o">|</span><span class="nx">ingredient</span> <span class="nx">index</span><span class="o">|</span>
<span class="nx">ingredient</span><span class="o">-</span><span class="nx">field</span> <span class="nx">name</span><span class="o">=</span><span class="p">(</span><span class="nx">mut</span> <span class="p">(</span><span class="nx">get</span> <span class="nx">ingredient</span> <span class="s">'name'</span><span class="p">))</span> <span class="nx">amount</span><span class="o">=</span><span class="p">(</span><span class="nx">mut</span> <span class="p">(</span><span class="nx">get</span> <span class="nx">ingredient</span> <span class="s">'amount'</span><span class="p">))</span> <span class="nx">type</span><span class="o">=</span><span class="p">(</span><span class="nx">mut</span> <span class="p">(</span><span class="nx">get</span> <span class="nx">ingredient</span> <span class="s">'type'</span><span class="p">))</span>
<span class="nx">button</span><span class="p">.</span><span class="na">btn</span><span class="p">.</span><span class="na">btn</span><span class="o">-</span><span class="nx">small</span><span class="p">{</span><span class="nx">action</span> <span class="s">"addField"</span><span class="p">}</span> <span class="nx">Add</span> <span class="nx">Another</span> <span class="nx">Ingredient</span></code></pre></figure>
<p>Each as accepts a block. I’m passing the ingredient object and the index. I can then mutate the data on each individual ingredient. In the recipe/new controller I just need to iterate over this array.</p>
<figure class="highlight"><pre><code class="language-coffeescript" data-lang="coffeescript"><span class="err">/</span><span class="o">/</span><span class="nx">controllers</span><span class="o">/</span><span class="nx">recipes</span><span class="o">/</span><span class="k">new</span><span class="p">.</span><span class="na">coffee</span>
<span class="nx">RecipesNewController</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="na">Controller</span><span class="p">.</span><span class="na">extend</span>
<span class="na">initialInputs</span><span class="o">:</span> <span class="mi">3</span><span class="p">,</span>
<span class="na">formFields</span><span class="o">:</span> <span class="p">[],</span>
<span class="na">_newIngredient</span><span class="o">:</span> <span class="o">-></span>
<span class="vi">@</span><span class="na">store</span><span class="p">.</span><span class="na">createRecord</span> <span class="s">'ingredient'</span>
<span class="na">rangeOfInputs</span><span class="o">:</span> <span class="nx">Ember</span><span class="p">.</span><span class="na">computed</span> <span class="s">'initialInputs'</span><span class="p">,</span> <span class="o">-></span>
<span class="nx">initialInputs</span> <span class="o">=</span> <span class="vi">@</span><span class="na">get</span> <span class="s">'initialInputs'</span>
<span class="nb">Array</span><span class="p">.</span><span class="na">apply</span><span class="p">(</span><span class="no">null</span><span class="p">,</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">initialInputs</span><span class="p">)).</span><span class="na">map</span><span class="p">(</span> <span class="p">(</span><span class="nx">_</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">=></span> <span class="vi">@</span><span class="na">_newIngredient</span><span class="p">())</span>
<span class="na">actions</span><span class="o">:</span>
<span class="na">addField</span><span class="o">:</span> <span class="o">-></span>
<span class="vi">@</span><span class="na">get</span><span class="p">(</span><span class="s">'rangeOfInputs'</span><span class="p">).</span><span class="na">pushObject</span><span class="p">(</span><span class="vi">@</span><span class="na">_newIngredient</span><span class="p">())</span></code></pre></figure>
<p>rangeOfInputs first grabs the initalInput number. I build an array with this number of elements. I then fill each element of array with an ingredient object. When I add another field I push a new ingredient object into the rangeOfInputs array. Removal of fields is done in the ingredient-field component.</p>
<figure class="highlight"><pre><code class="language-coffeescript" data-lang="coffeescript"><span class="err">/</span><span class="o">/</span><span class="nx">controller</span><span class="o">/</span><span class="nx">components</span><span class="o">/</span><span class="nx">ingredient</span><span class="o">-</span><span class="nx">field</span><span class="p">.</span><span class="na">coffee</span>
<span class="nx">IngredientFieldComponent</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="na">Component</span><span class="p">.</span><span class="na">extend</span>
<span class="na">actions</span><span class="o">:</span>
<span class="na">remove</span><span class="o">:</span> <span class="o">-></span>
<span class="vi">@</span><span class="na">remove</span><span class="p">()</span></code></pre></figure>
<p>This is not a complete solution yet. We still need to save the recipe fields and then save the ingredients and build the relationship to the recipe. This code also has a flaw. The remove action does not remove the element of the rangeOfInputs array. I have not figured out the solution to this but I have two basic ideas.</p>
<ol>
<li>
<p>Pass the index along so when I remove the component I also remove it from the correct position in the array.</p>
</li>
<li>
<p>Don’t worry about removing it from the array. Have the remove action also wipe all the data out of the ingredient fields. Then when I save the record I can ignore all ingredient objects that have no properties.</p>
</li>
</ol>
<p><a href="https://chrisbarthol.github.io/coding/dynamic-fields-in-ember">Dynamic Fields in Ember</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on February 06, 2016.</p>https://chrisbarthol.github.io/coding/active-model-serializer2016-01-13T00:00:00-05:002016-01-13T00:00:00-05:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>It’s better to use the Active Model Adapter</p>
<hr />
<p>When I started with this project I was trying to use the JSONAPI serializer and adapter that Ember has built in. This unfortunately was doomed to fail as I have a rails backend. Rails expects underscore between words while JSONAPI expects camelCase and so the two would never have lined up. I had set up a simple input page to try out POST calls to my rails backend. It was routing to the correct controller and action but no parameters were being sent. I checked my network tab in chrome and see that they were indeed sent, but a debugger on the rails showed no params.</p>
<p>Jumping straight to the answer I need to use the Active Model Adapater and Serializer. Their github page has some good docs to read through. Simply install it with:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">ember</span> <span class="n">install</span> <span class="n">active</span><span class="o">-</span><span class="n">model</span><span class="o">-</span><span class="n">adapter</span></code></pre></figure>
<p>To include it we need to rewrite our serializer:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="sb">`import { ActiveModelSerializer } from 'active-model-adapter';`</span>
<span class="no">ApplicationSerializer</span> <span class="o">=</span> <span class="no">ActiveModelSerializer</span><span class="p">.</span><span class="nf">extend</span><span class="p">()</span>
<span class="sb">`export default ApplicationSerializer;`</span></code></pre></figure>
<p>and adapter:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="sb">`import ActiveModelAdapter from 'active-model-adapter'`</span>
<span class="no">ApplicationAdapter</span> <span class="o">=</span> <span class="no">ActiveModelAdapter</span><span class="p">.</span><span class="nf">extend</span>
<span class="ss">namespace: </span><span class="s1">'api'</span>
<span class="sb">`export default ApplicationAdapter`</span></code></pre></figure>
<p>Sending the POST action to my backend with these change had the correct parameters and we are good to continue on our way.</p>
<p><a href="https://chrisbarthol.github.io/coding/active-model-serializer">Active Model Serializer</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on January 13, 2016.</p>https://chrisbarthol.github.io/coding/upgrading-to-the-latest2016-01-05T00:00:00-05:002016-01-05T00:00:00-05:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>It’s been awhile, so let’s upgrade!</p>
<p>–</p>
<p>Oh how the time flies. Personally projects sometimes need to take a back burner. That’s ok but once we get back at it we should make sure that all our libraries we are using are up-to-date. The biggest news is that ember-cli finally released a 2.0 version. Luckily they have an easy to follow set up steps to upgrade. Unfortunately it can take some time and you have to rebuild all your node_modules and there is no guarantee that everything will work. You can find the steps repeated from the <a href="https://github.com/ember-cli/ember-cli/releases">ember release site</a>. You might also want to upgrade bower while at it.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">npm</span> <span class="n">install</span> <span class="o">-</span><span class="n">g</span> <span class="n">bower</span></code></pre></figure>
<p>####Setup</p>
<ol>
<li>npm uninstall -g ember-cli – Remove old global ember-cli</li>
<li>npm cache clean – Clear NPM cache</li>
<li>bower cache clean – Clear Bower cache</li>
<li>npm install -g ember-cli@2.2.0-beta.3 – Install new global ember-cli</li>
</ol>
<p>####Project Update</p>
<ol>
<li>rm -rf node_modules bower_components dist tmp – Delete temporary development folders.</li>
<li>npm install –save-dev ember-cli@2.2.0-beta.3 – Update project’s package.json to use latest version.</li>
<li>npm install – Reinstall NPM dependencies.</li>
<li>bower install – Reinstall bower dependencies.</li>
<li>ember init – This runs the new project blueprint on your projects directory. Please follow the prompts, and review all changes (tip: you can see a diff by pressing d). The most common source of upgrade pain is missing changes in this step.Setup</li>
</ol>
<p>When getting to the last step I said Y to all the prompts asking to overwrite files. Your strategy may vary. I also had to reinstall ember-simple-auth as it had disappeared. The same is true for coffeescript.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">ember</span> <span class="n">install</span> <span class="n">ember</span><span class="o">-</span><span class="n">simple</span><span class="o">-</span><span class="n">auth</span>
<span class="n">ember</span> <span class="n">install</span> <span class="n">ember</span><span class="o">-</span><span class="n">cli</span><span class="o">-</span><span class="n">coffeescript</span></code></pre></figure>
<p>It also added back an app.js and router.js files. We are using coffescript so these files need to be deleted.</p>
<p>This also overwrote my ember-cli-build.js file where we import font awesome and bootstrap. This needed to change back to the following</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">var</span> <span class="no">EmberApp</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span><span class="s1">'ember-cli/lib/broccoli/ember-app'</span><span class="p">);</span>
<span class="n">module</span><span class="p">.</span><span class="nf">exports</span> <span class="o">=</span> <span class="n">function</span><span class="p">(</span><span class="n">defaults</span><span class="p">)</span> <span class="p">{</span>
<span class="n">var</span> <span class="n">app</span> <span class="o">=</span> <span class="n">new</span> <span class="no">EmberApp</span><span class="p">(</span><span class="n">defaults</span><span class="p">,</span> <span class="p">{</span>
<span class="sr">//</span> <span class="no">Add</span> <span class="n">options</span> <span class="n">here</span>
<span class="ss">emberCliFontAwesome: </span><span class="p">{</span>
<span class="ss">useScss: </span><span class="kp">true</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="n">app</span><span class="p">.</span><span class="nf">import</span><span class="p">(</span><span class="s1">'bower_components/bootstrap/dist/css/bootstrap.css'</span><span class="p">);</span>
<span class="n">app</span><span class="p">.</span><span class="nf">import</span><span class="p">(</span><span class="s1">'bower_components/bootstrap/dist/css/bootstrap-theme.css'</span><span class="p">);</span>
<span class="n">app</span><span class="p">.</span><span class="nf">import</span><span class="p">(</span><span class="s1">'bower_components/bootstrap/dist/js/bootstrap.js'</span><span class="p">);</span>
<span class="sr">//</span> <span class="no">Use</span> <span class="sb">`app.import`</span> <span class="n">to</span> <span class="n">add</span> <span class="n">additional</span> <span class="n">libraries</span> <span class="n">to</span> <span class="n">the</span> <span class="n">generated</span>
<span class="sr">//</span> <span class="n">output</span> <span class="n">files</span><span class="p">.</span>
<span class="nf">/</span><span class="o">/</span>
<span class="sr">//</span> <span class="no">If</span> <span class="n">you</span> <span class="n">need</span> <span class="n">to</span> <span class="n">use</span> <span class="n">different</span> <span class="n">assets</span> <span class="k">in</span> <span class="n">different</span>
<span class="sr">//</span> <span class="n">environments</span><span class="p">,</span> <span class="n">specify</span> <span class="n">an</span> <span class="n">object</span> <span class="n">as</span> <span class="n">the</span> <span class="n">first</span> <span class="n">parameter</span><span class="o">.</span> <span class="no">That</span>
<span class="sr">//</span> <span class="n">object</span><span class="err">'</span><span class="n">s</span> <span class="n">keys</span> <span class="n">should</span> <span class="n">be</span> <span class="n">the</span> <span class="n">environment</span> <span class="nb">name</span> <span class="n">and</span> <span class="n">the</span> <span class="n">values</span>
<span class="sr">//</span> <span class="n">should</span> <span class="n">be</span> <span class="n">the</span> <span class="n">asset</span> <span class="n">to</span> <span class="n">use</span> <span class="k">in</span> <span class="n">that</span> <span class="n">environment</span><span class="p">.</span>
<span class="nf">/</span><span class="o">/</span>
<span class="sr">//</span> <span class="no">If</span> <span class="n">the</span> <span class="n">library</span> <span class="n">that</span> <span class="n">you</span> <span class="n">are</span> <span class="n">including</span> <span class="n">contains</span> <span class="no">AMD</span> <span class="n">or</span> <span class="no">ES6</span>
<span class="sr">//</span> <span class="n">modules</span> <span class="n">that</span> <span class="n">you</span> <span class="n">would</span> <span class="n">like</span> <span class="n">to</span> <span class="n">import</span> <span class="n">into</span> <span class="n">your</span> <span class="n">application</span>
<span class="sr">//</span> <span class="n">please</span> <span class="n">specify</span> <span class="n">an</span> <span class="n">object</span> <span class="n">with</span> <span class="n">the</span> <span class="n">list</span> <span class="n">of</span> <span class="n">modules</span> <span class="n">as</span> <span class="n">keys</span>
<span class="sr">//</span> <span class="n">along</span> <span class="n">with</span> <span class="n">the</span> <span class="n">exports</span> <span class="n">of</span> <span class="n">each</span> <span class="k">module</span> <span class="nn">as</span> <span class="n">its</span> <span class="n">value</span><span class="p">.</span>
<span class="nf">return</span> <span class="n">app</span><span class="p">.</span><span class="nf">toTree</span><span class="p">();</span>
<span class="p">};</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="no">As</span> <span class="n">well</span> <span class="n">as</span> <span class="n">our</span> <span class="n">ember</span><span class="o">-</span><span class="n">simple</span><span class="o">-</span><span class="n">auth</span> <span class="n">section</span> <span class="k">for</span> <span class="n">you</span> <span class="n">environment</span><span class="p">.</span><span class="nf">js</span> <span class="n">files</span>
<span class="no">ENV</span><span class="p">[</span><span class="s1">'ember-simple-auth'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
<span class="ss">store: </span><span class="s1">'session-store:local-storage'</span>
<span class="p">}</span></code></pre></figure>
<p>Whew! Once all of the things I accidentally deleted were put back in place I have a working app again.</p>
<p><a href="https://chrisbarthol.github.io/coding/upgrading-to-the-latest">Upgrading to the latest</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on January 05, 2016.</p>https://chrisbarthol.github.io/coding/bash-background-a-day2015-10-25T00:00:00-04:002015-10-25T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>A clean desktop is indicates a clear mind.</p>
<hr />
<p>I’m a sucker for a clean desktop. Everything has a place and nothing belongs on your desktop. It may be easy to save
a file to the desktop but file that away to a correct spot immediately! Anyway, with a clean desktop you can view the
most basic personalization of a computer, the desktop picture. It’s boring to stare at the same picture over and over
so why not change the picture daily?</p>
<p>First we need a source that provides a quality photo of the day. National Geographic has a photo of the day feature on
their website at http://photography.nationalgeographic.com/photography/photo-of-the-day/. So first we can go and
download the page.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>curl <span class="s2">"http://photography.nationalgeographic.com/photography/photo-of-the-day/"</span> <span class="nt">-o</span> <span class="s2">"Pictures/photo-of-the-day"</span></code></pre></figure>
<p>We output it to a directory and file name that is easy to recognize and remember. Once we have the file we have to find
the image source. This is the tricky part so lets just throw the code out there and discuss it a bit.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">let </span><span class="nv">line</span><span class="o">=</span><span class="sb">`</span><span class="nb">cat </span>Pictures/photo-of-the-day | <span class="nb">grep</span> <span class="nt">-n</span> <span class="s1">'<div class="primary_photo">'</span> | <span class="nb">cut</span> <span class="nt">-d</span><span class="s1">':'</span> <span class="nt">-f1</span><span class="sb">`</span>+5
<span class="nv">$ url</span><span class="o">=</span><span class="sb">`</span><span class="nb">sed</span> <span class="nt">-n</span> <span class="s2">"</span><span class="nv">$line</span><span class="s2"> p"</span> Pictures/photo-of-the-day | <span class="nb">cut</span> <span class="nt">-d</span><span class="s1">' '</span> <span class="nt">-f2</span> | <span class="nb">cut</span> <span class="nt">-d</span> <span class="s1">'"'</span> <span class="nt">-f2</span><span class="sb">`</span></code></pre></figure>
<p>The first line finds the line number where the image source address exists. For the national geographic page the only
defining attribute to search for is the primary_photo class. We can not search for img src as there are many images on
the page. After we have the line number of the primary_photo class we add 5 to it. This is an annoying magic number
but from the page source we can see that the img src for the primary photo happens 5 lines after the class we just searched
for. If they change the page design this will all break, but for now it works.</p>
<p>The next line grabs the url from the img src tag. We find the line number from the file and then cut down the output
till we have the url. Next we download the actual image.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">curl <span class="s2">"</span><span class="k">${</span><span class="nv">url</span>:2<span class="k">}</span><span class="s2">"</span> <span class="nt">-o</span> <span class="s2">"Pictures/wall.jpg"</span></code></pre></figure>
<p>Notice the ${url:2}. This takes the url string we have and removes the first two characters. The url from the previous
step comes out in the form //images so we need to remove those two slashes. Now we have our image downloaded, we need
to make it the background. This is surprisingly difficult to do on macs.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">sqlite3 ~/Library/Application<span class="se">\ </span>Support/Dock/desktoppicture.db <span class="s2">"update data set value = 'Users/chrisbarthol/Pictures/wall.jpg'"</span><span class="p">;</span>
killall Dock<span class="p">;</span></code></pre></figure>
<p>Since Mavericks, background images are stored in a sqlite database. We basically have to manually insert the photo into
the database. This will destroy the other photos there, and make the background image the same for all desktops. We have
to kill the Dock for the image to reload. Now we run a script to fully fetch and update the desktop image everyday.<br />
The full script is below with an additional line on how to set it in Ubuntu.</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c">#!/bin/bash</span>
<span class="c"># clear cache</span>
<span class="nb">rm</span> <span class="nt">-f</span> Pictures/wall.jpg
<span class="nb">rm</span> <span class="nt">-f</span> Pictures/photo-of-the-day
<span class="c"># download photo-of-the-day page</span>
curl <span class="s2">"http://photography.nationalgeographic.com/photography/photo-of-the-day/"</span> <span class="nt">-o</span> <span class="s2">"Pictures/photo-of-the-day"</span>
<span class="c"># get the photo url</span>
<span class="nb">let </span><span class="nv">line</span><span class="o">=</span><span class="sb">`</span><span class="nb">cat </span>Pictures/photo-of-the-day | <span class="nb">grep</span> <span class="nt">-n</span> <span class="s1">'<div class="primary_photo">'</span> | <span class="nb">cut</span> <span class="nt">-d</span><span class="s1">':'</span> <span class="nt">-f1</span><span class="sb">`</span>+5
<span class="nv">url</span><span class="o">=</span><span class="sb">`</span><span class="nb">sed</span> <span class="nt">-n</span> <span class="s2">"</span><span class="nv">$line</span><span class="s2"> p"</span> Pictures/photo-of-the-day | <span class="nb">cut</span> <span class="nt">-d</span><span class="s1">' '</span> <span class="nt">-f2</span> | <span class="nb">cut</span> <span class="nt">-d</span> <span class="s1">'"'</span> <span class="nt">-f2</span><span class="sb">`</span>
<span class="c"># download the photo</span>
curl <span class="s2">"</span><span class="k">${</span><span class="nv">url</span>:2<span class="k">}</span><span class="s2">"</span> <span class="nt">-o</span> <span class="s2">"Pictures/wall.jpg"</span>
<span class="c">#Mac makes setting your background from bash a pain</span>
sqlite3 ~/Library/Application<span class="se">\ </span>Support/Dock/desktoppicture.db <span class="s2">"update data set value = 'Users/chrisbarthol/Pictures/wall.jpg'"</span><span class="p">;</span>
killall Dock<span class="p">;</span>
<span class="c">#For Ubuntu</span>
<span class="c">#gsettings set org.gnome.desktop.background picture-uri 'file:///home/chrisbarthol/Pictures/wall.jpg'</span></code></pre></figure>
<p><a href="https://chrisbarthol.github.io/coding/bash-background-a-day">Bash background a day</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on October 25, 2015.</p>https://chrisbarthol.github.io/coding/coffeescript-and-emblem2015-09-27T00:00:00-04:002015-09-27T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>Added Coffeescript and Emblem to An Ember Project.</p>
<hr />
<p>I personally like the syntax of coffeescript so I will be adding it do my project. ES6 has made writing ‘pure’ javascript better but the readability gains of coffeescript are just to great. I will also be adding <a href="http://emblemjs.com/">Emblem</a>. Emblem is a templating alternative to Handlebars. Think of it like Slim for Ember projects.</p>
<p>It is fairly straightforward and easy to add both of these addons to our project. First we need to install coffeescript and emblem.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">npm</span> <span class="n">install</span> <span class="o">--</span><span class="n">save</span><span class="o">-</span><span class="n">dev</span> <span class="n">ember</span><span class="o">-</span><span class="n">cli</span><span class="o">-</span><span class="n">coffeescript</span>
<span class="err">$</span> <span class="n">npm</span> <span class="n">install</span> <span class="o">--</span><span class="n">save</span><span class="o">-</span><span class="n">dev</span> <span class="n">ember</span><span class="o">-</span><span class="n">cli</span><span class="o">-</span><span class="n">emblem</span></code></pre></figure>
<p>Done! Now we just need to change our .js files to .coffee and .hbs to .emblem.</p>
<p>First change app.js to app.coffee and put everything into coffeescript.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="sb">`import Ember from 'ember';`</span>
<span class="sb">`import Resolver from 'ember/resolver';`</span>
<span class="sb">`import loadInitializers from 'ember/load-initializers';`</span>
<span class="sb">`import config from './config/environment';`</span>
<span class="no">Ember</span><span class="o">.</span><span class="no">MODEL_FACTORY_INJECTIONS</span> <span class="o">=</span> <span class="kp">true</span>
<span class="no">App</span> <span class="o">=</span> <span class="no">Ember</span><span class="o">.</span><span class="no">Application</span><span class="p">.</span><span class="nf">extend</span>
<span class="ss">modulePrefix: </span><span class="n">config</span><span class="p">.</span><span class="nf">modulePrefix</span><span class="p">,</span>
<span class="ss">podModulePrefix: </span><span class="n">config</span><span class="p">.</span><span class="nf">podModulePrefix</span><span class="p">,</span>
<span class="no">Resolver</span><span class="p">:</span> <span class="no">Resolver</span>
<span class="n">loadInitializers</span><span class="p">(</span><span class="no">App</span><span class="p">,</span> <span class="n">config</span><span class="p">.</span><span class="nf">modulePrefix</span><span class="p">)</span>
<span class="sb">`export default App;`</span></code></pre></figure>
<p>Notice that all the import and export are escaped with backticks. This is because coffeescript does not support ES6 module syntax. Next change your router.js to router.coffee and change the file to coffeescript.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="sb">`import Ember from 'ember';`</span>
<span class="sb">`import config from './config/environment';`</span>
<span class="no">Router</span> <span class="o">=</span> <span class="no">Ember</span><span class="o">.</span><span class="no">Router</span><span class="p">.</span><span class="nf">extend</span>
<span class="ss">location: </span><span class="n">config</span><span class="p">.</span><span class="nf">locationType</span>
<span class="no">Router</span><span class="p">.</span><span class="nf">map</span> <span class="o">-></span>
<span class="sb">`export default Router;`</span></code></pre></figure>
<p>Now our project is set up with coffeescript! Easy! Now to switch to emblem we can rename our application.hbs file to application.emblem and start writing the templates in emblem.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">h2</span> <span class="no">Welcome</span> <span class="n">to</span> <span class="no">Ember</span>
<span class="o">==</span> <span class="n">outlet</span></code></pre></figure>
<p>If we start are server with ember serve our page will load and we know that our switch over is complete.</p>
<p><a href="https://chrisbarthol.github.io/coding/coffeescript-and-emblem">Coffeescript and Emblem</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on September 27, 2015.</p>https://chrisbarthol.github.io/personal/half-marathon2015-08-24T00:00:00-04:002015-08-24T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>This past weekend I ran my first half marathon. I finished with a slow 13:00min per mile pace, but I finished. The first 3 miles went really well. I was averaging roughly 11:30 per mile and keeping up with the 2:30 pacer. Then the race started to go up a hill and there was a water station.</p>
<p><em>Drinking and running is a difficult task that needs to be practice</em></p>
<p>Boy was I not prepared for running and drinking. I almost chocked and had to start walking. The next 3 miles went OK. They weren’t great and my time started to slip to around 12:00 minutes per mile. At this point the sun started to come up. By the half way point I started to overheat.</p>
<p><em>How does one not overheat?</em></p>
<p>I wasn’t tired. My legs weren’t hurting, I wasn’t out of breath, but I couldn’t go on as I overheated. You know that tunnel vision feeling before you pass out? That started and I had to start walking. From this point on it was heat management. Every water station was a godsend. My time started to slip more to 13:00 minutes per mile. I would run half a mile and then need to cool down and walk a tenth of a mile. Around the 8 mile mark was a food station.</p>
<p><em>Energy gels are ridiculously gross.</em></p>
<p>I don’t remember the brand but I hear this a lot, energy gels are terrible. After running for 8 miles, starting to dehydrate, the last thing I want to eat is something overly sweet. I would rather eat something bland without flavor than what was given.</p>
<p>The last 4 miles was were my body started to hurt. It was manageable pain, but pain nonetheless. I slowed down even more to around 14:00 minutes per mile. The last couple miles were run 1-2 tenths of a mile and walk a tenth of a mile. It was mainly mental strength at this point.</p>
<p>Afterwards I felt OK. I drank a lot of water, Gatorade, and milk (love having chocolate milk at the end of a race) and felt much better after cooling down. I even walked around a lot the rest of the day and felt fine. I need to figure out how to cool down during a race. I also think running more frequent long runs would help my endurance later in the race. My next race is in April. I could run another in October but it’s super late registration and a large sum of money to run. I liked the race, but paying a ton of money to endure more pain is not high on my list of wants.</p>
<p><a href="https://chrisbarthol.github.io/personal/half-marathon">Half Marathon</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 24, 2015.</p>https://chrisbarthol.github.io/coding/starting-rust2015-08-18T00:00:00-04:002015-08-18T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>I like taking a look at other languages. I’ve recently started looking at Rust. What I like most about Rust is how it handles errors. From the starting guide:</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="nd">println!</span><span class="p">(</span><span class="s">"Please input your guess."</span><span class="p">);</span>
<span class="k">let</span> <span class="k">mut</span> <span class="n">guess</span> <span class="o">=</span> <span class="nn">String</span><span class="p">::</span><span class="nf">new</span><span class="p">();</span>
<span class="nn">io</span><span class="p">::</span><span class="nf">stdin</span><span class="p">()</span><span class="nf">.read_line</span><span class="p">(</span><span class="o">&</span><span class="k">mut</span> <span class="n">guess</span><span class="p">)</span>
<span class="nf">.ok</span><span class="p">()</span>
<span class="nf">.expect</span><span class="p">(</span><span class="s">"failed to read line"</span><span class="p">);</span>
<span class="k">let</span> <span class="n">guess</span><span class="p">:</span> <span class="nb">u32</span> <span class="o">=</span> <span class="n">guess</span><span class="nf">.trim</span><span class="p">()</span><span class="nf">.parse</span><span class="p">()</span>
<span class="nf">.ok</span><span class="p">()</span>
<span class="nf">.expect</span><span class="p">(</span><span class="s">"Please type a number!"</span><span class="p">);</span>
<span class="nd">println!</span><span class="p">(</span><span class="s">"You guessed: {}"</span><span class="p">,</span> <span class="n">guess</span><span class="p">);</span></code></pre></figure>
<p>The previous code asks the user for number. Rust reads it in through the io::stdin library. We expect the the guess to be a number. If it is ok, great, we can move on and execute others. If it doesn’t it errors out and the program stops. I like how each line automatically has to handle errors. It makes the designer think up front on how to handle errors. To often code is written and errors are handle as an afterthought.</p>
<p>So how do we move from ‘crash on error’ to actually handle the error?</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">let</span> <span class="n">guess</span><span class="p">:</span> <span class="nb">u32</span> <span class="o">=</span> <span class="k">match</span> <span class="n">guess</span><span class="nf">.trim</span><span class="p">()</span><span class="nf">.parse</span><span class="p">()</span> <span class="p">{</span>
<span class="nf">Ok</span><span class="p">(</span><span class="n">num</span><span class="p">)</span> <span class="k">=></span> <span class="n">num</span><span class="p">,</span>
<span class="nf">Err</span><span class="p">(</span><span class="mi">_</span><span class="p">)</span> <span class="k">=></span> <span class="n">continue</span><span class="p">,</span>
<span class="p">};</span></code></pre></figure>
<p>We have to switch to a match statement. If it is ok we have a number, else we just continue and again ask for a number. I find it off that we have to switch from a chaining syntax to wrapped match statement to actually handle the error. Personally the complete change from ‘fail on error’ to handle the error is a huge jump. I wish the following could be written.</p>
<figure class="highlight"><pre><code class="language-rust" data-lang="rust"><span class="k">let</span> <span class="n">guess</span><span class="p">:</span> <span class="nb">u32</span> <span class="o">=</span> <span class="n">guess</span><span class="nf">.trim</span><span class="p">()</span><span class="nf">.parse</span><span class="p">()</span>
<span class="nf">.ok</span><span class="p">()</span>
<span class="nf">.expect</span><span class="p">(</span><span class="s">"Please type a number!"</span><span class="p">)</span>
<span class="nf">.error</span><span class="p">(</span><span class="n">Handle</span> <span class="n">the</span> <span class="n">error</span><span class="p">)</span></code></pre></figure>
<p>I am by no means a language designer and understand that this could be very difficult. But if Rust is going to make you deal with errors out front the syntax shouldn’t change very much between failing and catching the error.</p>
<p><a href="https://chrisbarthol.github.io/coding/starting-rust">Starting Rust</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 18, 2015.</p>https://chrisbarthol.github.io/coding/setting-up-postgresql2015-08-16T00:00:00-04:002015-08-16T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>I’ll be using Postgresql for my database. It’s a strong open source database. For many years it has solely been a relational database management system. Recently they have added JSON support and support for NO-SQL style databases. We’ll be using it as a relational database, but the development and capabilities of Postgresql make it the best choice at this time.</p>
<p>I’ve had some old databases lying around since Postgres 9.2 and I’ve decided this is the time to clean up my machine and start fresh with the latest version (9.4.4). I installed 9.2 with homebrew so uninstall is a breeze with:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">homebrew</span> <span class="n">uninstall</span> <span class="n">postgresql</span></code></pre></figure>
<p>I’ll install the latest with homebrew as well:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">homebrew</span> <span class="n">install</span> <span class="n">postgresql</span>
<span class="no">To</span> <span class="n">have</span> <span class="n">launchd</span> <span class="n">start</span> <span class="n">postgresql</span> <span class="n">at</span> <span class="ss">login:
</span><span class="n">ln</span> <span class="o">-</span><span class="n">sfv</span> <span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">opt</span><span class="o">/</span><span class="n">postgresql</span><span class="o">/</span><span class="p">\</span><span class="o">*</span><span class="p">.</span><span class="nf">plist</span> <span class="o">~</span><span class="sr">/Library/</span><span class="no">LaunchAgents</span>
<span class="no">Then</span> <span class="n">to</span> <span class="nb">load</span> <span class="n">postgresql</span> <span class="ss">now:
</span><span class="n">launchctl</span> <span class="nb">load</span> <span class="o">~</span><span class="sr">/Library/</span><span class="no">LaunchAgents</span><span class="o">/</span><span class="n">homebrew</span><span class="p">.</span><span class="nf">mxcl</span><span class="p">.</span><span class="nf">postgresql</span><span class="p">.</span><span class="nf">plist</span>
<span class="no">Or</span><span class="p">,</span> <span class="k">if</span> <span class="n">you</span> <span class="n">don</span><span class="err">'</span><span class="n">t</span> <span class="n">want</span><span class="o">/</span><span class="n">need</span> <span class="n">launchctl</span><span class="p">,</span> <span class="n">you</span> <span class="n">can</span> <span class="n">just</span> <span class="ss">run:
</span><span class="n">postgres</span> <span class="o">-</span><span class="no">D</span> <span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">postgres</span></code></pre></figure>
<p>Sweet! I’ll wont be using launchctl right now so I’ll start postgres with the last command.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="no">LOG</span><span class="p">:</span> <span class="n">skipping</span> <span class="n">missing</span> <span class="n">configuration</span> <span class="n">file</span> <span class="s2">"/usr/local/var/postgres/postgresql.auto.conf"</span>
<span class="no">FATAL</span><span class="p">:</span> <span class="n">database</span> <span class="n">files</span> <span class="n">are</span> <span class="n">incompatible</span> <span class="n">with</span> <span class="n">server</span>
<span class="no">DETAIL</span><span class="p">:</span> <span class="no">The</span> <span class="n">data</span> <span class="n">directory</span> <span class="n">was</span> <span class="n">initialized</span> <span class="n">by</span> <span class="no">PostgreSQL</span> <span class="n">version</span> <span class="mf">9.2</span><span class="p">,</span> <span class="n">which</span> <span class="n">is</span> <span class="n">not</span> <span class="n">compatible</span> <span class="n">with</span> <span class="n">this</span> <span class="n">version</span> <span class="mf">9.4</span><span class="o">.</span><span class="mi">4</span><span class="o">.</span></code></pre></figure>
<p>Looks like I have some leftover files from 9.2. Some directory was started with 9.2 and I can’t start 9.4.4 from the 9.2 version. Let’s remove this directory and re-initialize the database.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">rm</span> <span class="o">-</span><span class="n">rf</span> <span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">postgres</span> <span class="o">&&</span> <span class="n">initdb</span> <span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">postgres</span>
<span class="o">...</span>
<span class="o">...</span>
<span class="no">Success</span><span class="o">.</span> <span class="no">You</span> <span class="n">can</span> <span class="n">now</span> <span class="n">start</span> <span class="n">the</span> <span class="n">database</span> <span class="n">server</span> <span class="ss">using:
</span><span class="n">postgres</span> <span class="o">-</span><span class="no">D</span> <span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">postgres</span>
<span class="n">or</span>
<span class="n">pg_ctl</span> <span class="o">-</span><span class="no">D</span> <span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">postgres</span> <span class="o">-</span><span class="n">l</span> <span class="n">logfile</span> <span class="n">start</span></code></pre></figure>
<p>Sweet! Let’s try this again</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="no">FATAL</span><span class="p">:</span> <span class="n">lock</span> <span class="n">file</span> <span class="s2">"postmaster.pid"</span> <span class="n">already</span> <span class="n">exists</span>
<span class="no">HINT</span><span class="p">:</span> <span class="no">Is</span> <span class="n">another</span> <span class="n">postmaster</span> <span class="p">(</span><span class="no">PID</span> <span class="mi">67098</span><span class="p">)</span> <span class="n">running</span> <span class="k">in</span> <span class="n">data</span> <span class="n">directory</span> <span class="s2">"/usr/local/var/postgres"</span><span class="p">?</span></code></pre></figure>
<p>Hrm… Looks like we killed the postgres and deleted the data directory with stopping the server. Now I have a orphan process running which is blocking my new postgres process. First I need to find which PID it is. (I know it shows up but it’s good to know where it lives.)</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">cat</span> <span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">postgres</span><span class="o">/</span><span class="n">postmaster</span><span class="p">.</span><span class="nf">pid</span>
<span class="mi">67098</span>
<span class="sr">/usr/</span><span class="n">local</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">postgres</span>
<span class="mi">1439688737</span>
<span class="mi">5432</span>
<span class="sr">/tmp
localhost
5432001 1245184</span></code></pre></figure>
<p>The first number is the PID so I’ll send the kill command to it. Do not use kill -9! When I killed the PID and started postgres I got the same message so I had a kill a few PIDs. Now I can create a db</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">createdb</span> <span class="n">recipe</span>
<span class="err">$</span> <span class="n">psql</span> <span class="n">recipe</span>
<span class="n">psql</span> <span class="p">(</span><span class="mf">9.4</span><span class="o">.</span><span class="mi">4</span><span class="p">)</span>
<span class="no">Type</span> <span class="s2">"help"</span> <span class="k">for</span> <span class="n">help</span><span class="p">.</span>
<span class="nf">recipe</span><span class="o">=</span><span class="c1">#</span></code></pre></figure>
<p>Typing psql gets my into the database where you can run SQL statements. Typing \q get you out of the database and back to the command line. That’s all for today!</p>
<p><a href="https://chrisbarthol.github.io/coding/setting-up-postgresql">Setting up Postgresql</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 16, 2015.</p>https://chrisbarthol.github.io/coding/initializing-git2015-08-15T00:00:00-04:002015-08-15T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>Now that we have our projects bare bones in place it is time to start version control. I’ll be using git for version control and github for a remote repository. I’m not going to go into a long talk about about git is and how to use it there is plenty of <a href="https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control">documentation</a> and <a href="https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control">guides</a>.</p>
<p><a href="https://github.com">Github</a> is also super simple to use. Head over and make yourself an account. Once that is complete you can add a repository. For this project I’ll have two separate repositories, one for the Ember frontside, and one for the Rails backend. When you decide on a repository name just follow the steps to initialize git in your project.</p>
<p>That’s all for today. Keeping it short and simple</p>
<p><a href="https://chrisbarthol.github.io/coding/initializing-git">Initializing Git</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 15, 2015.</p>https://chrisbarthol.github.io/coding/upgrading-ember2015-08-14T00:00:00-04:002015-08-14T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>Time to upgrade Ember to 2.0!</p>
<p>When upgrading the project I like to us the series shown on the <a href="https://github.com/ember-cli/ember-cli/releases">Ember CLI page</a>.</p>
<ol>
<li>rm -rf node_modules bower_components dist tmp – Delete temporary development folders.</li>
<li>npm install –save-dev ember-cli@1.13.8 – Update project’s package.json to use latest version.</li>
<li>npm install – Reinstall NPM dependencies.</li>
<li>bower install – Reinstall bower dependencies.</li>
<li>ember init – This runs the new project blueprint on your projects directory. Please follow the prompts, and review all changes (tip: you can see a diff by pressing d). The most common source of upgrade pain is missing changes in this step.</li>
</ol>
<p>Ember-cli should be defaulting to Ember 2.0.0. Unfortunately, when I ran this my instance was still running an older version. Have no fear as I can manually update. First open up the bower.json file. Under dependencies change the ember version as well as the ember data version.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="s2">"ember"</span><span class="p">:</span> <span class="s2">"~2.0.0"</span><span class="p">,</span>
<span class="o">...</span>
<span class="s2">"ember-data"</span><span class="p">:</span> <span class="s2">"2.0.0-beta.1"</span><span class="p">,</span></code></pre></figure>
<p>Ember Data has not release their 2.0 version as of yet. For now you’ll have to use the beta version till the official release. You can’t use an earlier version with Ember 2.0. After the dependencies section add a resolution section as follows:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="s2">"resolutions"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"ember"</span><span class="p">:</span> <span class="s2">"~2.0.0"</span>
<span class="p">}</span></code></pre></figure>
<p>Now under the package.json file also change the ember-data version to 2.0.0=beta.1. Now run:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">npm</span> <span class="n">install</span>
<span class="n">bower</span> <span class="n">install</span>
<span class="n">ember</span> <span class="n">s</span></code></pre></figure>
<p>ember s will run the ember server. It should start up easily and say</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="no">Livereload</span> <span class="n">server</span> <span class="n">on</span> <span class="n">http</span><span class="ss">:/</span><span class="o">/</span><span class="n">localhost</span><span class="p">:</span><span class="mi">49154</span>
<span class="no">Serving</span> <span class="n">on</span> <span class="n">http</span><span class="ss">:/</span><span class="o">/</span><span class="n">localhost</span><span class="p">:</span><span class="mi">4200</span><span class="o">/</span></code></pre></figure>
<p>If you go to that page you’ll see a basic ‘Welcome to Ember’ page. If you go to the app/templates directory of the project you can open up the application.hbs file. With the server running put in some new information such as</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="o"><</span><span class="nb">p</span><span class="o">></span>
<span class="no">Watch</span> <span class="n">me</span> <span class="n">live</span> <span class="n">reload!</span>
<span class="o"><</span><span class="sr">/p></span></code></pre></figure>
<p>And save the file. The page will automatically update the new information on save. This can be a blessing and a curse. Depending on your machine, the live reload might be a tad slow. It can become annoying to have the page constantly updating every time a file changes. If you don’t want the live reload feature just start the server with the following flag.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">ember</span> <span class="n">server</span> <span class="o">--</span><span class="n">live</span><span class="o">-</span><span class="n">reload</span><span class="o">=</span><span class="kp">false</span></code></pre></figure>
<p>That’s all I will do for now. Tomorrow I’ll talk a bit about git and version control. To start I wont do much on the ember side. I need to get our database prepared and start figuring out how to model the data.</p>
<p><a href="https://chrisbarthol.github.io/coding/upgrading-ember">Upgrading Ember</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 14, 2015.</p>https://chrisbarthol.github.io/coding/ember-2-is-out2015-08-13T00:00:00-04:002015-08-13T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>Boy what a time to start a new Ember project! Ember 2.0 has finally been released! You can read the notes <a href="http://emberjs.com/blog/2015/08/13/ember-2-0-released.html">here</a></p>
<p>At first Ember was an MVC (Model-View-Controller) for your frontend. With Ember 2.0 they start to remove two-thirds of the MVC. First up Ember Views are completely removed. They were not a real ‘view’ in the sense of MVC (those are templates). Ember Views encapsulated HTML content and with data rendered part of the page. These were dropped in favor of Ember Components. <a href="http://emberjs.com/api/classes/Ember.Component.html">Ember Components</a> are individual bits of code that can be reused over and over on the page. They are completely isolated from the surrounding page and there is no access to the surrounding controller.</p>
<p>Secondly controllers are starting their long move towards depreciation. Array and Object controllers have been removed in Ember 2.0 in favor of the high level controller. Eventually even these controllers will be removed and replaced by ‘routable components’. What is a routable component? At this point we don’t really know as little information is available about how this would work. Where would all the logic of the application live?</p>
<p>They was supposed to be a move to release both Ember and Ember Data at the same time with the same versioning. As of this writing Ember Data 2.0 is still in beta. This really isn’t that surprising as I feel like Ember Data was in beta much of its life cycle until it was taken over by the core team.</p>
<p>I’m glad they released Ember 2.0. As I’ve only initialized the project we can easily start over without having to much to worry about. If you have an Ember app you can easily upgrade to Ember 2.0 as long as you have no depreciation warnings and are using Ember 1.13. If you are still using Ember Views there is an compatibility addon while you rework your codebase.</p>
<p>The Ember core team as also updated the guides and the new <a href="http://guides.emberjs.com/v2.0.0/">Ember 2.0 guides</a> are available.</p>
<p><a href="https://chrisbarthol.github.io/coding/ember-2-is-out">Ember 2 is Out</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 13, 2015.</p>https://chrisbarthol.github.io/coding/day-2-initialize-the-projects2015-08-11T00:00:00-04:002015-08-11T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>Yesterday I went over the switch to rbenv to install ruby. I’ll also need to install rails which is a simple:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">gem</span> <span class="n">install</span> <span class="n">rails</span></code></pre></figure>
<p>This installs the latest rails version which is 4.2.3 as of this writing. Now I can create my backend project:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">rails</span> <span class="n">new</span> <span class="n">recipe</span><span class="o">-</span><span class="n">backend</span></code></pre></figure>
<p>For the frontend I’ll be using Ember JS. To start off I need node first. I’m going to use NVM (Node Version Manager) to install node. First you need to download nvm and then</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">curl</span> <span class="o">-</span><span class="n">o</span><span class="o">-</span> <span class="n">https</span><span class="ss">:/</span><span class="o">/</span><span class="n">raw</span><span class="p">.</span><span class="nf">githubusercontent</span><span class="p">.</span><span class="nf">com</span><span class="o">/</span><span class="n">creationix</span><span class="o">/</span><span class="n">nvm</span><span class="o">/</span><span class="n">v0</span><span class="o">.</span><span class="mf">25.4</span><span class="o">/</span><span class="n">install</span><span class="p">.</span><span class="nf">sh</span> <span class="o">|</span> <span class="n">bash</span>
<span class="err">$</span> <span class="n">nvm</span> <span class="n">install</span> <span class="n">node</span></code></pre></figure>
<p>Now you can check where node is installed:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">which</span> <span class="n">node</span>
<span class="sr">/Users/</span><span class="n">chrisbarthol</span><span class="o">/</span><span class="p">.</span><span class="nf">nvm</span><span class="o">/</span><span class="n">versions</span><span class="o">/</span><span class="n">node</span><span class="o">/</span><span class="n">v0</span><span class="o">.</span><span class="mf">12.7</span><span class="o">/</span><span class="n">bin</span><span class="o">/</span><span class="n">node</span></code></pre></figure>
<p>You can install one node globally from <a href="https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps">this post</a> if you need to. Now that we have node and npm we can install Ember</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">npm</span> <span class="n">install</span> <span class="o">-</span><span class="n">g</span> <span class="n">ember</span><span class="o">-</span><span class="n">cli</span>
<span class="err">$</span> <span class="n">npm</span> <span class="n">install</span> <span class="o">-</span><span class="n">g</span> <span class="n">phantomjs</span></code></pre></figure>
<p>Phantom JS is required to run tests. Finally we can make the frontend project:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">ember</span> <span class="n">new</span> <span class="n">recipe</span><span class="o">-</span><span class="n">frontend</span></code></pre></figure>
<p>Now we have both our projects set up! Tomorrow we’ll start talking about version control.</p>
<p><a href="https://chrisbarthol.github.io/coding/day-2-initialize-the-projects">Day 2 - Initialize the projects</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 11, 2015.</p>https://chrisbarthol.github.io/coding/day-1-removing-rvm2015-08-10T00:00:00-04:002015-08-10T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>##Switching to Rbenv</p>
<hr />
<p>I’ve noticed that I have way to many versions for ruby on my machine and it’s time to clean them up. For the last few years I’ve been using RVM to manage my ruby versions. It’s been extremely helpful but it’s become a little bit to heavy.</p>
<ol>
<li>RVM overrides cd. Dangerous!</li>
</ol>
<p>If you have two projects with different ruby versions, when you switch project directories RVM knows which ruby should be used. How does it know this? It overrides the cd function. When installing RVM you have to add the following to you bash file:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="p">[[</span> <span class="o">-</span><span class="n">s</span> <span class="vg">$HOME</span><span class="o">/</span><span class="p">.</span><span class="nf">rvm</span><span class="o">/</span><span class="n">scripts</span><span class="o">/</span><span class="n">rvm</span> <span class="p">]]</span> <span class="o">&&</span> <span class="n">source</span> <span class="vg">$HOME</span><span class="o">/</span><span class="p">.</span><span class="nf">rvm</span><span class="o">/</span><span class="n">scripts</span><span class="o">/</span><span class="n">rvm</span></code></pre></figure>
<p>That line adds a variety of scripts. <a href="https://github.com/rvm/rvm/blob/master/scripts/cd#L7-86">You can check out what RVM is doing on the github page.</a></p>
<ol>
<li>Gemsets</li>
</ol>
<p>With bundler Gemsets is unnecessary. We have bundler and there is no reason to use something else to manage gems and dependencies. There are a few other good reasons over on the <a href="https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F">rbenv github page</a></p>
<p>So how do I get rid of RVM? Simple!</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">rvm</span> <span class="n">implode</span></code></pre></figure>
<p>You’ll also want to remove the entries from your bash file. Now we can install rbenv. I’m using a Mac so homebrew is the way to go.</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="err">$</span> <span class="n">brew</span> <span class="n">update</span>
<span class="err">$</span> <span class="n">brew</span> <span class="n">install</span> <span class="n">rbenv</span> <span class="n">ruby</span><span class="o">-</span><span class="n">build</span></code></pre></figure>
<p>Now we just need to add the following to our shell:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"> <span class="n">export</span> <span class="no">PATH</span><span class="o">=</span><span class="s2">"$HOME/.rbenv/shims:$PATH"</span>
<span class="k">if</span> <span class="n">which</span> <span class="n">rbenv</span> <span class="o">></span> <span class="sr">/dev/nu</span><span class="n">ll</span><span class="p">;</span> <span class="k">then</span> <span class="nb">eval</span> <span class="s2">"$(rbenv init -)"</span><span class="p">;</span> <span class="n">fi</span></code></pre></figure>
<p>We can easily install ruby versions:</p>
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"> <span class="err">$</span> <span class="n">rbenv</span> <span class="n">install</span> <span class="mf">2.2</span><span class="o">.</span><span class="mi">2</span>
<span class="err">$</span> <span class="n">rbenv</span> <span class="n">local</span> <span class="mf">2.2</span><span class="o">.</span><span class="mi">2</span>
<span class="err">$</span> <span class="n">rbenv</span> <span class="n">rehash</span></code></pre></figure>
<p>rbenv allows you to set a global version through rbenv global version or a local directory version with local. rehash manually rebuilds the shims so everything is update and working correctly. These are just the basics and you can check out some other details on the <a href="https://github.com/sstephenson/rbenv">github project</a>.</p>
<p><a href="https://chrisbarthol.github.io/coding/day-1-removing-rvm">Day 1 - Removing rvm</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 10, 2015.</p>https://chrisbarthol.github.io/thoughts/let-s-begin2015-08-09T00:00:00-04:002015-08-09T00:00:00-04:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<p>##Let’s see how long this goes.</p>
<hr />
<p>I took a break from writing after getting a new job, graduating, having a kid, and moving into a new house. It’s always something I’ve wanted to get better at. It’s an important skill to be able to communicate your knowledge and it’s time to pick it up again. The only way to get better is to practice and develop your own voice.</p>
<p>I also didn’t have time over the last few months to work on my personal projects. Things are calming down. Well, calming down as much as possible while having a youngster on the verge of crawling around a house. There is at least a slight semblance of a routine. I have enough time to work again on my recipe site. This is a site in which I store my own recipes but there is more to it than just that. A user as the ability to save any recipe they come across or add new ones, like any good recipe website. This site also always a user to fork a recipe. Did you think that recipe used to much cinnamon? Fork it, change the ingredients, and it save it as your own. There are a lot of options that can be built off this and this will be the place where I will try to explain them.</p>
<p>This space is dedicated to this project. My goal is to work on it daily with the following day writing a bit on what I’ve accomplished, some of the problems I have come across, and anything else of interest on my mind. This space is also my log that I am actually working on the project or something else to expand my knowledge. I’ll be using Ruby/Rails on the backend and Ember JS on the frontend. The front and back will be completely separate so hopefully I can experiment with some other languages and drop them in. We’ll see.</p>
<p>Ready?</p>
<hr />
<p>##Let’s Go.</p>
<p><a href="https://chrisbarthol.github.io/thoughts/let-s-begin">Let's Begin</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on August 09, 2015.</p>https://chrisbarthol.github.io/parents/a-new-dad2015-02-14T00:00:00-05:002015-02-07 21:17:55 -0500T00:00:00-00:00Chris Bartholhttps://chrisbarthol.github.iochris.barthol@gmail.com
<h2 id="this-is-crazy-a-little-over-24-hours-ago-i-became-a-dad--it-hasnt-set-in-yet">This is crazy. A little over 24 hours ago I became a dad. It hasnt set in yet.</h2>
<p>This moment has been 9 months in the making. Forty weeks. 280 days. 6720 hours. 403,200 seconds. That’s a long time. A long time to prepare. A long time to figure out what you need, what you need to do, and how to do it. Then it happens.</p>
<h2 id="surreal">Surreal</h2>
<p>Its the only word to describe the experience. My wife had a planned C-section due to our daughter being breeched. I can’t tell if it is better or worse than a normal delivery. On one hand you know when it will happen. On the other hand you know when it will happen. The waiting is the worst part. Waiting for the pre-op procedures to take place. Waiting for the doctors to be ready and finally waiting in the OR.</p>
<h2 id="hearing-your-baby-cry-for-the-first-time-is-a-tense-and-amazing-experience">Hearing your baby cry for the first time is a tense and amazing experience.</h2>
<p>I wasn’t ready for it. It was magical. All of a sudden it hits you that you’ve brought another human being into this world. This is going to be one crazy and awesome ride. Here we go.</p>
<p><a href="https://chrisbarthol.github.io/parents/a-new-dad">A New Dad</a> was originally published by Chris Barthol at <a href="https://chrisbarthol.github.io">Chris Barthol</a> on February 14, 2015.</p>