<?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[Coding Code - Medium]]></title>
        <description><![CDATA[Just another blog about development - Medium]]></description>
        <link>https://medium.com/coding-code?source=rss----f33aff5b8f9e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Coding Code - Medium</title>
            <link>https://medium.com/coding-code?source=rss----f33aff5b8f9e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 23:14:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/coding-code" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating CircleCI with Elixir/Phoenix]]></title>
            <link>https://medium.com/coding-code/integrating-circleci-with-elixir-phoenix-e8a1733201e?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/e8a1733201e</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[phoenix]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Fri, 12 Aug 2016 17:38:02 GMT</pubDate>
            <atom:updated>2016-08-13T20:06:37.512Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrHAaZotEyQPixQfpmjF4A.png" /></figure><p>Having automated tests in a repository can be considered a <em>must-do</em> in any kind of project. In Elixir/Phoenix we can create complex and maintainable tests in a short time but, how can we integrate it with CircleCI?</p><h4>Getting in touch with CircleCI</h4><p><a href="https://circleci.com/">CircleCI</a> is just another continuous integration platform, free for both public and private repositories. The main advantage is that, as it’s based on top of containers, you can can access via SSH to the container where your tests are running and debug environment/build issues easily.</p><h4>So, what’s the matter with Elixir in CircleCI?</h4><p><strong>CircleCI doesn’t have native support for Elixir/Phoenix projects</strong>, so the only option left is trying to automatise the installation of the environment needed to run the tests.</p><p>This shouldn&#39;t be a real trouble since they allow you to define the shell commands executed at each step, so the process can be customised as much as you want.</p><p>In my case, I have decided to install the environment using <a href="https://github.com/asdf-vm"><strong><em>asdf</em></strong></a>, a new lightweight version manager that can handle multiple languages/platforms using plugins.</p><p>The idea is to install it (if it’s not previously installed) and apply the plugins needed. Then, we can use <em>.tool_versions</em> file (the default one used by <em>asdf</em>) to install required dependencies and use them to run the actual tests.</p><p>So here is the <em>circle.yml</em> that does it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2f51ad0c8b08b393363a1bf4a963a74/href">https://medium.com/media/e2f51ad0c8b08b393363a1bf4a963a74/href</a></iframe><p>Also, some adjustments are made:</p><ul><li>Various environment variables, like the <em>$PATH</em> including <em>asdf</em> paths</li><li>Copying CircleCI specific project config to use it on tests</li><li>Install required dependencies</li><li>Clean the database</li><li>Only notify the builds on <em>master</em> branch (to avoid flooding of notifications on <em>non-master</em> commits).</li></ul><p>Note that, by adding <em>asdf</em> directory to the cache list, we can avoid reinstalling and rebuilding Erlang and Elixir, which will take (<em>really</em>) long time on first execution.</p><h4>Benchmarking</h4><p>Thanks to the cache between builds, the build times of one of the projects we use at work are:</p><ul><li>~3 minutes on regular builds.</li><li>~13 minutes on the first build (download and build Erlang &amp; Elixir).</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8a1733201e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/integrating-circleci-with-elixir-phoenix-e8a1733201e">Integrating CircleCI with Elixir/Phoenix</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using CloudFlare as a Dynamic DNS service]]></title>
            <link>https://medium.com/coding-code/using-cloudflare-as-a-dynamic-dns-service-c0d797f32794?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/c0d797f32794</guid>
            <category><![CDATA[clouflare]]></category>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[ddns]]></category>
            <category><![CDATA[dynamic-dns]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Sun, 07 Feb 2016 15:19:40 GMT</pubDate>
            <atom:updated>2016-08-02T21:25:40.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*6UJel0BmjxrbkIUwG5tOQg.png" /></figure><p>I’m a big fan of <a href="https://www.cloudflare.com/"><strong>CloudFlare</strong></a>, but I always have to use a third party service to map my domains to a dynamic IP.</p><p>But thanks to the <strong>JSON API that CloudFlare uses</strong>, now we can update the IP address used in a domain by just issuing a request.</p><h4>First, get the data needed</h4><p>To use this cool feature, you will need a few things:</p><ol><li><strong>A computer</strong> (like a <em>home server</em>), in order to periodically check the external IP.</li><li><strong>A free CloudFlare account</strong> (configured in your domain) and it’s <strong>API key</strong> (which you can <a href="https://www.cloudflare.com/a/account/my-account">find here</a>)</li></ol><p>Also, you’d need to know the ID of the record that you want to update. To obtain it, you only need to issue a command to the API:</p><pre>curl <a href="https://www.cloudflare.com/api_json.html">https://www.cloudflare.com/api_json.html</a> -d ‘a=rec_load_all’ \<br> -d ‘tkn=your-api-key’ \<br> -d ‘email=your_account@email-address.com’ \<br> -d ‘z=your-domain.com’</pre><p>You only need to change the API key, your account’s e-mail address and the domain registered (the root domain, without <em>www</em> or similar).</p><p>You will obtain a JSON response with all the records. Just search the one you want to update and get it’s <strong><em>rec_id</em></strong> value.</p><p><strong>Note:</strong> the record must be an <em>A</em> record in order to update it with an IP address.</p><h4>Updating the IP assigned</h4><p>Now we are going to create a script that automatically updates the IP address in the DNS record if it has changed since the last check was performed.</p><p>The script I use is very similar to this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/191881dbaedc7183c758ee09557b94d9/href">https://medium.com/media/191881dbaedc7183c758ee09557b94d9/href</a></iframe><p>You just need to change:</p><ul><li>your API key</li><li>your account’s e-mail address</li><li>your domain’s name</li><li>the record ID</li><li>the subdomain of that record.</li></ul><p>Then, save the script and change it’s permissions:</p><pre>sudo chmod +x /path/to/script.sh</pre><p>Now, you can try the script just by running it like any other system binary:</p><pre>sudo /path/to/script.sh</pre><p>And if everything was fine, the record should be updated.</p><h4>Run the script automatically</h4><p>This kind of functionality is useful only if it’s periodically checking for changes.</p><p>In order to run the script every five minutes, you only need to add this line to your crontab:</p><pre>*/5 * * * * /path/to/script.sh</pre><p><strong>And that’s all!</strong> Hope this help anyone looking for a free dynamic DNS service, because CloudFlare is very useful and provides other services like preventing DoS or HTTPS protection.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0d797f32794" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/using-cloudflare-as-a-dynamic-dns-service-c0d797f32794">Using CloudFlare as a Dynamic DNS service</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing PipedBeats]]></title>
            <link>https://medium.com/coding-code/introducing-pipedbeats-b66260b3eb3?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/b66260b3eb3</guid>
            <category><![CDATA[pipedbeats]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Wed, 09 Dec 2015 19:01:45 GMT</pubDate>
            <atom:updated>2016-08-02T21:29:24.675Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*teLr5_YAyyfoi_v-Mzm-BQ.png" /></figure><p>A few days ago I was trying to find my perfect playlist for work, and I realised that there wasn’t only one. <strong>Some times you just want a continuous stream of songs</strong>, related to a genre or a search. That’s how <strong>PipedBeats</strong> idea came to my mind.</p><p><a href="https://pipedbeats.com/"><strong>PipedBeats</strong></a> is a <strong>radio streaming web application that let you to define a genre or some keywords to create a random stream of tracks</strong> (generously provided by <a href="https://developers.soundcloud.com/"><em>SoundCloud API</em></a>) to help you concentrate (or not, it’s up to you!) during your work (or relax) hours.</p><p>It’s built on pure <a href="https://angularjs.org/"><em>AngularJS</em></a>, so the application doesn’t need a backend. And the best part, it’s free and you can access right now on <a href="https://pipedbeats.com/">https://pipedbeats.com</a></p><h4>Main features</h4><ul><li><strong>Listen to music for free:</strong> just choose a genre or a search keywords and start listening.</li><li><strong>Responsive UI:</strong> it’s possible that it won’t fit 100% of screens, but I can assure that I have made our best effort to try. Really :)</li><li><strong>Completely browser-based:</strong> your data is yours and your computer do all the work, so no data is exposed to our server.</li><li><strong>SSL support:</strong> provided by <a href="https://www.cloudflare.com/"><em>CloudFlare</em></a>, a shiny DNS provider. Whenever you access the application, it will be over secure connections.</li></ul><h4>Known limitations</h4><p>The client hasn’t got limitations itself (except features not implemented yet), but at the moment <a href="https://soundcloud.com/"><em>SoundCloud</em></a> limits each application to a maximum of <em>15,000</em> plays per day.</p><p>Also, I have some problems with the bandwidth usage on mobile devices. As <em>SoundCloud</em> doesn’t offer different qualities, the data usage can be a problem.</p><h4>Personal experience and coding problems</h4><p>As I have mentioned in precious posts, this is my first real project on <em>AngularJS</em>. As it has to be, I have found some problems during the development:</p><p><strong>1. Sharing information between controllers</strong></p><p>This can be done using three different approaches:</p><ul><li>Storing the information in the <em>$rootScope</em>.</li><li>Creating a <a href="https://docs.angularjs.org/guide/services"><em>Service</em></a> to share variables and functions.</li><li>Passing information through events.</li></ul><p>Well, the first one is obvious: if the <em>$rootScope</em> is a shared variable between controllers, storing information on it is the first thought.</p><p>On the other hand, <a href="https://docs.angularjs.org/guide/services"><em>Services</em></a> are instantiated once, so every controller making use of it will access the same variables. It’s a kind of <em>$rootScope</em> but specialised.</p><p>Finally, the events can be emitted in a scope. If you have access to a different controller’s scope, you can emit an event to it. Otherwise, you can emit a broadcast event to all the controllers using:</p><pre><em>$rootScope.$broadcast(‘eventName’, args);</em></pre><p><strong>2. Update the User Interface when variables are changed</strong></p><p>I encounter some problems when asynchronously changing variables that are used in the UI. The just doesn’t get updated.</p><p>To solve it, you only need to do your stuff inside an `$apply` call like this:</p><pre>$scope.$apply(function(){<br> // Do your stuff here<br>});</pre><p>An the variables will be updated on the UI as soon as changed.</p><p><strong>3. Send current page to Google Tag Manager</strong></p><p>Using virtual paths is perfect for a browser-only application, but <em>Google Analytics</em> doesn’t recognise it as it should.</p><p>To avoid this, I have created a <em>Google Tag Manager</em> configuration (<strong>thanks Nico!</strong>) and pushed a dataLayer object when the state of <em>ui-router</em> is changed:</p><pre>$rootScope.$on(‘$stateChangeStart’, function(event, toState, toParams, fromState, fromParams){<br> dataLayer.push({<br> “event” : “pageView”,<br> “pageName” : event.currentScope.$state.href(toState, toParams)<br> });<br>});</pre><h4>Conclussions</h4><p>This has been an amazing (and short) project that help me to discover small and valuable things about creating a real application using <em>AngularJS</em>.</p><p>I strongly recommend anyone who want to do a new step on the <em>AngularJS</em> world to create it’s own demo application to deal with real problems on your own.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b66260b3eb3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/introducing-pipedbeats-b66260b3eb3">Introducing PipedBeats</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playing around with custom routes in AngularJS]]></title>
            <link>https://medium.com/coding-code/playing-around-with-custom-routes-in-angularjs-6d0d226615d8?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/6d0d226615d8</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ui-router]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Sat, 28 Nov 2015 12:19:22 GMT</pubDate>
            <atom:updated>2016-08-02T21:30:27.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XKaJh5P-nFAPfoBmf5oeXw.jpeg" /></figure><p>This week I have been playing a bit with custom routes using <a href="https://github.com/angular-ui/ui-router">ui-router</a>, one of the most popular routers available in the <em>AngularJS</em> ecosystem.</p><h4>An approach to the problem</h4><p>My first idea was to search some data using two optional variables (we will call them <em>var1 </em>and <em>var2</em>). This can be easy, but analysing the use cases we found that:</p><ul><li>User can give us both values.</li><li>User can give us <em>var1</em> value only.</li><li>User can give us <em>var2</em> value only.</li></ul><p>Now, we have three different scenarios that can be resolved in a few different ways:</p><ul><li>Passing variables as query parameters: <em>/search?var1=value1&amp;var2=value2</em>.</li><li>Creating routes that accept var values as part of the path: <em>/search/value1/value2</em>, <em>/search/vale1</em> or <em>/search/value2</em>.</li></ul><p>The first option works well and is easy to implement, but the second one is prettier. However, implementing the second one requires three different routes and repeating come code, which isn’t the best scenario.</p><h4>Creating routes with multiple optional variables</h4><p>The main idea is to create some piece of code that allow us to have multiple optional variables in one route.</p><p>This isn’t supported (<em>yet</em>) by <a href="https://github.com/angular-ui/ui-router">ui-router</a>, so we have to code it using the API exposed by the router.</p><p>The first thing we can do, is defining the route. But after that, I’d like to give you a general point of view of the solution:</p><ul><li>We are going to create a route with only one parameter.</li><li>That parameter will include all the parameters, which will need to be encoded and decoded.</li><li>We have to figure out how to parse the parameters and make them available at the controller.</li></ul><p>Also, I decided to identify the parameters following this schema: <em>/search/var1:value1/var2:value2</em>.</p><p>To start over, we will need to define a parameter type using <em>urlMatcherFactoryProvider</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cbf91e74926fa5aa69b4454d5b233d9/href">https://medium.com/media/6cbf91e74926fa5aa69b4454d5b233d9/href</a></iframe><p>This code define how <a href="https://github.com/angular-ui/ui-router">ui-router</a> will manage my parameter (just convert it to string if it isn’t null) and ensure that it matches the pattern defined (which is the format I told you before).</p><p>The next step is to include the route using this custom type we’ve just created:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c76436b2152ec04c3b1b1ca7f038be5/href">https://medium.com/media/2c76436b2152ec04c3b1b1ca7f038be5/href</a></iframe><p>In this code we can see a <em>resolve</em> hash, that defines the services available to the controller of this route. In this case, we use a <em>urlParams</em> service that get the search query, remove the first / and split by / character, obtaining an array of parameters following the <em>key:value</em> convention.</p><p>Then, each parameter is read and inserted into an object, that will be returned to the controller.</p><h4>Generating the search query</h4><p>To generate a valid search query, the only thing you have to do is to put the params following the schema <em>/search/var1:variable1/var2:variable2</em> (and as many variables as you want).</p><p>To do this, I use this function, but it’s specific of my own case:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4ee95a9fbda557832389bec93514ebd/href">https://medium.com/media/a4ee95a9fbda557832389bec93514ebd/href</a></iframe><p>So I can change the state using the function:</p><pre>$state.go(‘search’, {searchQuery: $scope.buildSearchQuery()});</pre><h4>Known issues</h4><p>Passing the variables using the path is far from being perfect. For example, when your variable has a value that contains ‘:’ or ‘/’, the code may malfunction.</p><p>In the code of this example, the case of having ‘:’ on your value is controlled using <em>result[query.shift()] = query.join(‘:’);</em> in the <em>urlParams</em> service.</p><p>A possible workaround is encoding the variables using, for example, <em>encodeURIComponent()</em> function.</p><p>However, the result isn’t as good as we may think, because a <em>value1</em> equal to <em>hello world</em> will end in an URL like <em>/search/var1:hello%2520world</em>. This occurs because the browser encodes the % sign to it’s <em>URL-encode</em> equivalent, which is <em>%25</em>.</p><p>Another possible solution is to limit the characters used in the variable’s values, or replacing ‘/’ and ‘:’ with another symbol that doesn’t break the schema.</p><h4>Conclussions</h4><p>At the moment, <a href="https://github.com/angular-ui/ui-router">ui-router</a> doesn’t offer support for optional variables in routes if you don’t use the query-parameter schema.</p><p>You can use a workaround similar to this by encapsulating all the query string in one validated variable, but I’m not really sure about if the effort and the amount of lines worth it.</p><p>Also, know problems with typical URL symbols and it’s encoding is far from making this solution a perfect one, so use it with care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d0d226615d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/playing-around-with-custom-routes-in-angularjs-6d0d226615d8">Playing around with custom routes in AngularJS</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Docker to run a one-time app]]></title>
            <link>https://medium.com/coding-code/using-docker-to-run-a-one-time-app-7c27a92a221d?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/7c27a92a221d</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[build]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Mon, 23 Nov 2015 20:26:43 GMT</pubDate>
            <atom:updated>2016-08-02T21:29:58.152Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qKsya9C-cI5gYt73mDiGQ.jpeg" /></figure><p>Sometimes you may want to do one specific task that requires to build/install some software and/or libraries just to run it once.</p><p>Normally it’s very painful to do it in your computer/server because it could left some files that you aren’t going to use, or just because you want to keep your system clean.</p><p>I’ve found myself with this problem this weekend, and the solution was very easy: use a specific <a href="https://www.docker.com/"><em>Docker</em></a> instance for that.</p><h4>Creating a docker instance</h4><p>We want to create a <strong>Docker container</strong> for the application we need and it’s libraries.</p><p><strong>In a normal situation we would create a <em>Dockerfile</em></strong> with instructions to build the whole container, exposing some ports (if it’s a network service) and some mount points. <strong>But due to the fact that this machine is going to be use once, it doesn’t care if we do a more <em>manual</em> work.</strong></p><p>To <strong>start a new container</strong>, you can use:</p><pre>user@host:~# docker run -i -t ubuntu:latest -name my_machine /bin/bash</pre><pre>root@73931cc4a735:/#</pre><p>With this simple command we have downloaded, created and attached a new container using the latest <em>Ubuntu</em> image available at <em>Docker Hub</em>.</p><p>We can now do whatever we want, but my personal advice is to update the repositories and upgrade the system first. You can do it with this commands:</p><pre>root@73931cc4a735:/# apt-get update<br>[…batch of information…]</pre><pre>root@73931cc4a735:/# apt-get dist-upgrade<br>[…batch of information…]</pre><p>Then we can proceed to build and install our libraries/software to do the task we want to do.</p><h4>Leaving and recovering the working container</h4><p>Right now we should be inside the container shell. But <strong>one benefit of using <em>Docker </em>is the ability to leave the container working and come back later</strong>, being able even to close the SSH connection.</p><p><strong>To de-attach from the Docker container</strong>, you can use this key combination: <em>Control+P - Control+Q</em> (in this precise order). After pressing that combination, we should be returned to the host’s shell, but the Docker container will be running on the background.</p><p><strong>To attach to the container again</strong>, we con do something like:</p><pre>user@host:~# docker attach my_machine</pre><p><em>Note:</em> if you can’t remember the name of the container, you can retrieve it with <em>docker ps</em>.</p><h4>Removing the container</h4><p>If you have finished your work with the container, you can stop it:</p><pre>user@host:~# docker stop my_machine</pre><p>or just kill it (violently):</p><pre>user@host:~# docker kill my_machine</pre><p>and the remove it:</p><pre>user@host:~# docker rm my_machine</pre><h4>More information</h4><p>If you want to know more about Docker (<em>specially the run command</em>), you can take a look at the <a href="https://docs.docker.com/">Docker reference site</a> (<em>or just leave a comment!</em>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c27a92a221d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/using-docker-to-run-a-one-time-app-7c27a92a221d">Using Docker to run a one-time app</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails-like Node.js application skeleton]]></title>
            <link>https://medium.com/coding-code/rails-like-node-js-application-skeleton-337a08b3dce5?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/337a08b3dce5</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[mean]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Tue, 17 Nov 2015 18:32:51 GMT</pubDate>
            <atom:updated>2016-08-02T21:31:23.391Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aeWo6e6FC8InJwBl3TmpDw.jpeg" /></figure><p>During the last weeks I have been working in building my first real Node.js application (in fact, I’m currently using a <a href="https://en.wikipedia.org/wiki/MEAN_(software_bundle)"><em>MEAN</em></a> stack). So the first step was to look for a good application structure.</p><p><strong>TD;LR:</strong> if you want to go directly to the code, you can go to <a href="https://github.com/odarriba/nodejs-express-skeleton">this GitHub repository</a></p><p><strong>But.. Why?</strong> The short answer is to be able to create a <em>maintainable project</em>, in which anyone can find a specific piece of the app without having to kill me first.</p><p>To achieve that, the first step was to look at well known structure for me: <strong>the project tree used in a Rails application.</strong></p><p>So I decided to create a simple skeleton (you can look and download it from my <a href="https://github.com/odarriba/nodejs-express-skeleton">GitHub repo</a>) that can be used by anyone who wants to build a <a href="https://nodejs.org/en/"><em>Node.js</em></a> application. It has been built with an <em>API-oriented</em> application in mind, but it can be easily used for traditional apps.</p><p>The app skeleton uses some actual technologies like:</p><ul><li><a href="http://expressjs.com/"><em>Express.js</em></a> as the web framework.</li><li><a href="http://mongoosejs.com/"><em>Mongoose</em></a> as the <em>ODM</em> (<em>Object Document Model</em>).</li><li><a href="https://www.mongodb.org/"><em>MongoDB</em></a> as the non-relational database.</li></ul><p>The main goals of this skeleton are:</p><ul><li><strong>Have all the initialization code in one place:</strong> this place is <em>/initializers/</em> (very original, I know). This code is loaded using the file that can be found on <a href="https://github.com/odarriba/nodejs-express-skeleton/blob/master/initializers/index.js"><em>/initializers/index.js</em></a>.</li><li><strong>Environment usage and configuration:</strong> three different environments: <em>development</em>, <em>production</em> and <em>testing</em>.</li></ul><p>Per-environment configuration is available (and automatically loaded during boot) under <em>/config/</em>. There is also the file <a href="https://github.com/odarriba/nodejs-express-skeleton/blob/master/config/index.js"><em>/config/index.js</em></a> that includes a configuration hash used as a default one.</p><ul><li><strong>Models and controllers automatic loading and registration:</strong> placed under <em>/models/</em> and <em>/controllers/</em>, they are loaded during boot time and registered in the application global variable.</li><li><strong>Routes configuration in one place:</strong> located in <a href="https://github.com/odarriba/nodejs-express-skeleton/blob/master/routes.js"><em>/routes.js</em></a>, the routes configuration file is loaded at the end of the application boot and it’s function is to load the routes of each controller and register it on the <em>Express.js</em> router.</li><li><strong>Per-environment logging:</strong> by doing use of the environments available, the logging of the application’s output console is made on different files and using different formats.</li></ul><p>I would like to mention that any improvement or comment is welcome (by doing a pull-request in the repository or just here) :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=337a08b3dce5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/rails-like-node-js-application-skeleton-337a08b3dce5">Rails-like Node.js application skeleton</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing rbenv in OSX El Capitán]]></title>
            <link>https://medium.com/coding-code/installing-rbenv-in-osx-el-capit%C3%A1n-170445e29425?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/170445e29425</guid>
            <category><![CDATA[homebrew]]></category>
            <category><![CDATA[os-x]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rbenv]]></category>
            <category><![CDATA[el-capitan]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Thu, 08 Oct 2015 19:32:13 GMT</pubDate>
            <atom:updated>2016-08-02T21:32:53.494Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anr9RqodeM9sjf3cAq1hEg.jpeg" /></figure><h3>Installing Rbenv in OSX El Capitán</h3><p>Last weekend I made a fresh installation of OSX in my personal computer. As the latest version of OSX, El Capitán (10.11), has been released the past week, it was the version I installed.</p><p>Also, I decided to look after <strong>Rbenv</strong> and compare it with <strong>RVM</strong> (<em>Ruby Version Manager</em>). After looking in some pages <a href="https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F">like this</a>, it’s clear that <strong>the best option (maybe the best structured) is <em>Rbenv</em></strong>, while <em>RVM</em> provides a more comfortable way of managing Ruby versions and <em>gemsets</em>.</p><p>In a few words, <em>Rbenv</em> provides:</p><ul><li>Easy <em>Ruby</em> version management <strong>without rewrites of shell functions, </strong>so other programs can use it’s functions without patches.</li><li>No <em>gemset</em> management (because <em>Bundle</em> can do this pretty well by it’s own).</li></ul><h4>El Capitán with Rbenv</h4><p>To install <strong>Rbenv</strong> in OSX, the easiest way is to install it through <a href="http://brew.sh/"><strong>Homebrew</strong></a>, the OSX package management tool.</p><p><em>Disclaimer:</em> Because of the SIP (<a href="https://en.wikipedia.org/wiki/System_Integrity_Protection">more info here</a>), a new security feature of OSX, there could be issues installing <em>Homebrew</em> on OSX 10.11. If this is your case, please check <a href="http://digitizor.com/2015/10/06/install-homebrew-osx-el-capitan/">this wiki page</a>.</p><h4>Prerequisites</h4><p>To install *Ruby* versions on OSX El Capitán, you will need an updated version of <strong>OpenSSL</strong> with it’s development libraries.</p><p>To install and link it:</p><pre>$&gt; brew install openssl<br>$&gt; brew link — force openssl</pre><h4>Installing Rbenv</h4><p>To install <em>Rbenv</em> using <em>Homebrew</em>:</p><pre>$&gt; brew install rbenv ruby-build rbenv-default-gems</pre><p>This command will install <em>rbenv</em>, <em>ruby-build</em> (a tool to help installing new rubies) and <em>rbenv-default-gems</em> (an extension to define default gems when installing new rubies).</p><p>Then, we have to make some symlinks:</p><pre>$&gt; export RBENV_ROOT=/usr/local/var/rbenv<br>$&gt; ln -s $RBENV_ROOT ~/.rbenv</pre><h4>Defining default gems to install</h4><p>To make use of <em>rbenv-default-gems</em> utility, you only have to edit the file placed at <em>~/.rbenv/default-gems</em> including each gem you want to install per line.</p><p>Mine looks like this:</p><pre>bundler<br>tacoma<br>powder<br>mailcatcher</pre><h4>Installing new rubies</h4><p>To install new <em>Ruby</em> versions, you just have to execute <em>install</em> <em>Rbenv</em>’s command. For example:</p><pre>$&gt; rbenv install 2.0.0-p647</pre><p>You can also install versions of other compiles, like <em>jruby</em>.</p><h4>Defining ruby version to use</h4><p>You can define the ruby version globally or just in the folder you are in. And it will live change (it’s magic!).</p><p>To define the ruby version to use globally:</p><pre>$&gt; rbenv global &lt;version&gt;</pre><p>To define a specific version inside a folder (in a project, for example):</p><pre>$&gt; rbenv local &lt;version&gt;</pre><p>You can also define the version to use inside a folder by creating a file called <em>.ruby-version</em> with just the version inside it.</p><h4>Known problems</h4><p>There are several problems I have found while doing and using all of this stuff, for example:</p><ul><li><strong>Installing old versions of <em>Ruby</em></strong>: I had to install <em>Ruby 1.8.7</em>, but I haven’t found a way of doing it because it requires old libraries and compilers that aren’t available for El Capitán.</li><li><strong>Patch versions</strong>: when specifying the version to use, <strong><em>Rbenv</em> requires to specify the patch version</strong>, which is tedious. To fix it, I have used <a href="https://github.com/tpope/rbenv-aliases"><em>rbenv-aliases</em></a> to avoid using patch versions (and it will take the higher patch version available).</li></ul><p><strong>And that’s all!</strong> If you have any trouble and want to ask something, feel free to post a comment!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=170445e29425" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/installing-rbenv-in-osx-el-capit%C3%A1n-170445e29425">Installing rbenv in OSX El Capitán</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing OpenVPN Server]]></title>
            <link>https://medium.com/coding-code/installing-openvpn-server-e59ede0e924e?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/e59ede0e924e</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[openvpn]]></category>
            <category><![CDATA[services]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Sun, 04 Oct 2015 10:36:42 GMT</pubDate>
            <atom:updated>2016-08-02T21:33:55.307Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*56CIS0PVdy_NnKAK5-Igiw.jpeg" /></figure><p>Today I’ve been installing <strong>OpenVPN server</strong> on my home server to being able to securely connect to my local network from anywhere. This can allow you to:</p><ul><li>Having access to local services on your local network , like a (in my case) a <a href="https://github.com/odarriba/docker-timemachine">Time Machine</a> docker service.</li><li>Access services only available from your country IP when travelling to other places.</li><li>Being able to use open hotspots while encrypting your whole network traffic.</li></ul><p>In order to get it, my first thought was to install the server on the bare metal machine (not on a <em>Docker</em> instance) because it may require some network privileges that can make it unable to work behind the <em>Docker</em> network layer.</p><p>But searching a bit over the Internet I’ve found <a href="https://github.com/kylemanna/docker-openvpn">this repository</a> that includes a functional Docker image. It doesn’t just works, but it includes a full documentation file with instructions to set the server up in two different containers (the one that has the daemon running and the one that stores the secure data).</p><p><strong>So, in less that 5 minutes my OpenVPN server was up and running!</strong> Also I have generated the CA file and the client certificates, so I can connect from anywhere like being at home.</p><h4>Clients</h4><p>In Mac OSX (10.11 — El Capitán) I installed <a href="https://tunnelblick.net/">Tunnelblink</a>, a free and open source alternative to OpenVPN client or Viscoso.app. It has an easy and lightweight GUI, perfect to avoid resource consumption and annoyance while using it.</p><p>In Windows 10 I used the official OpenVPN client, but it doesn’t work <em>out-of-the-box</em>. <strong>To make it works, it’s executables should be marked to be run with administrator privileges</strong>, so they can add the networking routes needed to route the traffic through the VPN.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e59ede0e924e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/installing-openvpn-server-e59ede0e924e">Installing OpenVPN Server</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to cancel a setInterval in Javascript]]></title>
            <link>https://medium.com/coding-code/how-to-cancel-a-setinterval-in-javascript-cd6dae39e693?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/cd6dae39e693</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[setinterval]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Sun, 10 May 2015 20:05:10 GMT</pubDate>
            <atom:updated>2016-08-02T21:36:13.505Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOCWWdkCBOvCJjXXepxjdA.jpeg" /></figure><p>During the development of my degree final project, I had the necessity of cancel a previously <em>setInterval</em> in Javascript. To anyone who doesn’t know what this is, a <em>setInterval</em> operation allows the programmer set a period in which the task is executed.</p><p>Searching a bit on the Internet I found a post in <a href="http://stackoverflow.com/questions/109086/stop-setinterval-call-in-javascript">StackOverflow</a> that shows various possible options to cancel (or simulate a cancellation) of a <em>setInterval</em> operation, but the most correct one could be something like this:</p><pre>var interval = setInterval(function(){ doStuff(); }, 1000);</pre><pre>// Do more stuff….</pre><pre>// Clear the interval<br>clearInterval(interval);</pre><p>This <em>clearInterval(interval)</em> function is part of the basic JavaScript standard, implemented in most browsers and avoids the execution of the interval operation again.</p><p>There are other methods using flags, but these doesn’t stop the interval forever (just returns from the operation without doing anything) so this seems a more correct way to do it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd6dae39e693" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/how-to-cancel-a-setinterval-in-javascript-cd6dae39e693">How to cancel a setInterval in Javascript</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a SOAP client in Ruby]]></title>
            <link>https://medium.com/coding-code/how-to-create-a-soap-client-in-ruby-6e6064c25b6e?source=rss----f33aff5b8f9e---4</link>
            <guid isPermaLink="false">https://medium.com/p/6e6064c25b6e</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[clients]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[soap]]></category>
            <dc:creator><![CDATA[Óscar de Arriba]]></dc:creator>
            <pubDate>Thu, 02 Apr 2015 20:56:00 GMT</pubDate>
            <atom:updated>2016-08-02T21:24:39.605Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>SOAP</strong> (<em>Simple Object Access Protocol</em>, <a href="http://en.wikipedia.org/wiki/SOAP">link</a>) is a standard protocol that defines how we can make a communication between two objects of different processes using <a href="http://en.wikipedia.org/wiki/XML">XML</a>. In other words, is a way of communicate with certain services using XML.</p><p>What I have to do is to create a client in Ruby to send petitions to a WCF (<em>Windows Communication Foundation</em>) application that uses SOAP. For this task I have researched a bit and I have found a Ruby gem called <strong>Savon</strong> (<a href="https://rubygems.org/gems/savon">link</a>).</p><p>This gem allows you to initialise an object using certain configuration parameters and allowing you to send messages to the SOAP service, and read the response.</p><h4>How do we use it?</h4><p>First of all, you have to install the gem using:</p><pre> gem install savon — version &#39;~&gt; 2.0&#39;</pre><p>After that, you can initialise a client object using code similar to this:</p><pre># Check if Savon gem is installed<br>require &quot;savon&quot;</pre><pre># Create the client<br>client = Savon.client(wsdl: ‘http://...../?wsdl&#39;)</pre><p>After this, we can access a lot of methods (described in the <a href="http://savonrb.com/version2/">gem documentation</a>), but a good approach can be doing a petition to a service called <em>example</em> using something like this:</p><pre>response = client.call(:example, message: { foo: bar })</pre><p>But if you, like me, have to call to a service using custom made objects of <em>C#</em>, your unique option is to use some WCF client (like the default included in <em>Visual Studio</em>) to examine the structure of the XML and clone it in the <em>message</em> section.</p><p>Also, the <strong>library offers many initialisation options to customize it’s behaviour</strong>, but covering them here would take a lot of time, so if you need something special, the best option is to check the <a href="http://savonrb.com/version2/">docs</a>.</p><p>To read the response, you can access to the <em>response.body</em> object to obtain your data.</p><p>And remember, if you don’t know how to do something, check the <a href="http://savonrb.com/version2/">documentation</a> or leave a comment!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e6064c25b6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-code/how-to-create-a-soap-client-in-ruby-6e6064c25b6e">How to create a SOAP client in Ruby</a> was originally published in <a href="https://medium.com/coding-code">Coding Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>