<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fernando Damian Lopez on Medium]]></title>
        <description><![CDATA[Stories by Fernando Damian Lopez on Medium]]></description>
        <link>https://medium.com/@lopez.fernando.damian?source=rss-e7ad20e4d2d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*upvlRtVwxj3myM81.jpg</url>
            <title>Stories by Fernando Damian Lopez on Medium</title>
            <link>https://medium.com/@lopez.fernando.damian?source=rss-e7ad20e4d2d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:16:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lopez.fernando.damian/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Yes! You can test you coroutine code. And should!]]></title>
            <link>https://medium.com/@lopez.fernando.damian/yes-you-can-test-you-coroutine-code-and-should-c2a122756662?source=rss-e7ad20e4d2d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2a122756662</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[coroutines-in-kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Fernando Damian Lopez]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 00:28:50 GMT</pubDate>
            <atom:updated>2024-11-28T00:31:30.113Z</atom:updated>
            <content:encoded><![CDATA[<h3>Streamlining Coroutines Testing on Android</h3><p>Coroutines have become a prevalent approach for handling asynchronous tasks in Android development. While powerful, testing coroutines can introduce complexities due to their asynchronous nature. This blog post dives into effective strategies for testing coroutines within the Android framework, leveraging insights from the official Android developer documentation (<a href="https://developer.android.com/kotlin/coroutines/test">Testing Kotlin coroutines on Android</a>).</p><h3>Understanding the Challenges</h3><p>Traditional JUnit test functions assume synchronous execution, posing a hurdle when testing suspending coroutines. To address this, we can employ a coroutine builder specifically designed for testing purposes: runTest.</p><h3>Introducing the runTest Coroutine Builder</h3><p>The runTest coroutine builder simplifies testing coroutines by establishing a new coroutine specifically for the test. This empowers you to call suspending functions within your tests.</p><h4>Illustrative Example: Testing Coroutine-based Data Fetching</h4><p>Consider a scenario where you want to test a ViewModel that retrieves data from the network using coroutines. Here’s a breakdown of how runTest facilitates this process:</p><pre>@Test<br>fun testDataFetch() = runTest {<br>  val expectedData = &quot;Some data&quot;<br>  val viewModel = MainViewModel()<br>  viewModel.fetchData()<br>  // Use withContext to switch back to the main dispatcher for testing purposes<br>  withContext(Dispatchers.Main) {<br>    assertEquals(expectedData, viewModel.data.value)<br>  }<br>}</pre><p>In this example:</p><ul><li>The runTest coroutine builder initiates a new coroutine for the test.</li><li>Inside the coroutine, we invoke the suspending function fetchData on the ViewModel.</li><li>We leverage withContext to transition back to the main dispatcher for testing purposes.</li><li>Finally, we assert that the anticipated data has been successfully fetched.</li></ul><h4>Key Takeaways</h4><p>By incorporating runTest into your testing arsenal, you can streamline the testing of coroutines without getting entangled in the intricacies of suspending functions. This empowers you to write more robust and maintainable coroutine-based code for your Android applications.</p><p>Remember, this blog post merely scratches the surface of coroutines testing on Android. The provided documentation offers a comprehensive exploration of the subject, including utilizing TestDispatchers to manage coroutine execution within tests. I highly recommend delving deeper into the resource for a more in-depth understanding.</p><p>I hope this blog post provides valuable insights into testing coroutines on Android. Feel free to reach out if you have any questions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2a122756662" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quiero aprender a usar Angular JS (parte 2)]]></title>
            <link>https://medium.com/angular-argentina/quiero-aprender-a-usar-angular-js-parte-2-2f7d8f219177?source=rss-e7ad20e4d2d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f7d8f219177</guid>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Fernando Damian Lopez]]></dc:creator>
            <pubDate>Tue, 05 Sep 2017 12:45:33 GMT</pubDate>
            <atom:updated>2017-09-05T12:45:33.843Z</atom:updated>
            <content:encoded><![CDATA[<p>¡Componentes por todos lados!</p><p>Si no leíste la <a href="https://medium.com/angular-argentina/quiero-aprender-a-usar-angular-js-parte-1-73832eccb28d#.8gqezo5lb">primer parte</a>, te recomiendo leerla antes de seguir.</p><p>Como te contaba en el anterior post, uno de los principales bloques o partes de una app Angular son los componentes.</p><p>¿Aun no entendiste que son? Vamos con un ejemplo:</p><p>Supongamos que necesitamos una app que guarde una lista de gastos (algo básico para empezar). La vamos a llamar <strong>Xpenser</strong> y la interfaz seria algo así:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*y-ahs_zSsAzJViBDhiITTQ.jpeg" /><figcaption>Componentes de la aplicacion Xpenser</figcaption></figure><p>Cada recuadro rojo marca un componente. Algunos componentes son contenedores de otros. Como por ejemplo el cuadro rojo que contiene a todos los demas. Este es el componente principal y que representa a toda la aplicacion. Comunmente se lo conoce como AppComponent.</p><h3>Comencemos</h3><p>Primero tenemos que crear el proyecto, sí, con nuestro buen amigo <strong>angular-cli:</strong></p><pre>ng new <strong>xpenser</strong></pre><p>Simple, no? Esto nos genera una carpeta con todos los archivos del proyecto (son muchos pero cada uno cumple una funcion). La estructura deberia ser algo asi:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*Od1A20161gMOEIWOlgUx3A.png" /></figure><p>Es en la carpeta app donde pondremos los componentes y servicios. De hecho el cli nos crea un componente principal llamado AppComponent en app.component.ts y su correspondiente plantilla en el archivo app.component.html</p><p>Luego tendremos dos componentes más, la lista de gastos a la cual llamaremos <strong>ExpenseListComponent </strong>y el formulario para ingresar un nuevo gasto, <strong>ExpenseFormComponent</strong>. Los creamos con la ayuda del cli:</p><pre>c:\LocalViews\xpenser (master) <br>λ <strong>ng generate component expense-list</strong> </pre><pre>installing component<br> create src\app\expense-list\expense-list.component.css <br> create src\app\expense-list\expense-list.component.html <br> create src\app\expense-list\expense-list.component.spec.ts <br> create src\app\expense-list\expense-list.component.ts <br> update src\app\app.module.ts <br> <br>c:\LocalViews\xpenser (master)</pre><p>Como vemos el cli nos genera todos los archivos del coponente. Html para la plantilla, css para los estilos, spec.ts para los tests y ts para la lógica.</p><p>De la misma manera creamos el componente del formulario:</p><pre>c:\LocalViews\xpenser (master)<br>λ <strong>ng generate component expense-form</strong></pre><pre>installing component<br> create src\app\expense-form\expense-form.component.css<br> create src\app\expense-form\expense-form.component.html<br> create src\app\expense-form\expense-form.component.spec.ts<br> create src\app\expense-form\expense-form.component.ts<br> update src\app\app.module.ts</pre><pre>c:\LocalViews\xpenser (master)</pre><p>Cada componente es generado en un directorio dedicado dentro del directorio app.</p><p>Ahora podemos escribir la estructura basica de cada componente:</p><pre><strong>expense-list.component.html</strong></pre><pre>&lt;ul <em>class=</em>&quot;list-group&quot;&gt;<br>  <em>&lt;!-- Por ahora solo un gasto hardcodeado --&gt;<br>  </em>&lt;li <em>class=</em>&quot;list-group-item justify-content-between&quot;&gt;<br>    Viaje<br>    &lt;span <em>class=</em>&quot;badge badge-default badge-pill&quot;&gt;$ 200.00&lt;/span&gt;<br>  &lt;/li&gt;<br>&lt;/ul&gt;</pre><pre><strong>expense-form.component.html</strong></pre><pre>&lt;form <em>class=</em>&quot;form-inline&quot;&gt;<br>  &lt;label <em>class=</em>&quot;sr-only&quot; <em>for=</em>&quot;inlineFormInput&quot;&gt;Gasto&lt;/label&gt;<br>  &lt;input <em>type=</em>&quot;text&quot; <em>class=</em>&quot;form-control col-6&quot; <em>id=</em>&quot;inlineFormInput&quot; <em>placeholder=</em>&quot;Gasto&quot;&gt;<br><br>  &lt;label <em>class=</em>&quot;sr-only&quot; <em>for=</em>&quot;inlineFormInputGroup&quot;&gt;Monto&lt;/label&gt;<br>  &lt;div <em>class=</em>&quot;input-group col-4&quot;&gt;<br>    &lt;div <em>class=</em>&quot;input-group-addon&quot;&gt;$&lt;/div&gt;<br>    &lt;input <em>type=</em>&quot;text&quot; <em>class=</em>&quot;form-control&quot; <em>id=</em>&quot;inlineFormInputGroup&quot; <em>placeholder=</em>&quot;Monto&quot;&gt;<br>  &lt;/div&gt;<br>  &lt;div <em>class=</em>&quot;col-2 text-right&quot;&gt;<br>    &lt;button <em>type=</em>&quot;submit&quot; <em>class=</em>&quot;btn btn-primary&quot;&gt;Guardar&lt;/button&gt;<br>  &lt;/div&gt;<br>&lt;/form&gt;</pre><p>Luego solo nos resta “poner” cada componente en el componente principal (AppComponent):</p><pre><strong>app.component.html</strong></pre><pre>&lt;div <em>class=</em>&quot;container&quot;&gt;<br>  &lt;div <em>class=</em>&quot;row&quot;&gt;<br>    &lt;div <em>class=</em>&quot;col-12&quot;&gt;<br>      &lt;h1 <em>class=</em>&quot;display-2&quot;&gt;Xpenser&lt;/h1&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>  &lt;div <em>class=</em>&quot;row pt-5&quot;&gt;<br>    &lt;div <em>class=</em>&quot;col-12&quot;&gt;<br><strong><em>      &lt;app-expense-list&gt;&lt;/app-expense-list&gt;</em></strong><br>    &lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;div <em>class=</em>&quot;row pt-5&quot;&gt;<br>    &lt;div <em>class=</em>&quot;col-12&quot;&gt;<br>      <strong><em>&lt;app-expense-form&gt;&lt;/app-expense-form&gt;</em></strong><br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>Sí, a nivel de las plantillas los componentes se representan como elementos del DOM (tags).</p><p>Para ver como va quedando nuestra app utilizamos nuveamente el CLI pero esta vez para “servir” los archivos:</p><pre>ng serve</pre><p>Luego navegamos a la url localhost:4200 y deberiamos ver la applicacion.</p><p>Aun nos falta agregar la lógica de cada componente, pero eso lo vamos a hacer en la próxima parte. Por ahora les dejo el enlace a la version del codigo completo hasta el momento:</p><p><a href="https://github.com/AngularArgentina/xpenser/tree/0.1.0">AngularArgentina/xpenser</a></p><p>Nos vemos en la parte 3 …</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f7d8f219177" width="1" height="1" alt=""><hr><p><a href="https://medium.com/angular-argentina/quiero-aprender-a-usar-angular-js-parte-2-2f7d8f219177">Quiero aprender a usar Angular JS (parte 2)</a> was originally published in <a href="https://medium.com/angular-argentina">Angular Argentina</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quiero aprender a usar Angular JS (parte 1)]]></title>
            <link>https://medium.com/angular-argentina/quiero-aprender-a-usar-angular-js-parte-1-73832eccb28d?source=rss-e7ad20e4d2d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/73832eccb28d</guid>
            <category><![CDATA[angularjs2]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[angular2]]></category>
            <dc:creator><![CDATA[Fernando Damian Lopez]]></dc:creator>
            <pubDate>Thu, 10 Nov 2016 02:51:10 GMT</pubDate>
            <atom:updated>2016-11-17T01:42:40.689Z</atom:updated>
            <content:encoded><![CDATA[<h4>O ¿como arranco con esto?</h4><p>¿Entonces queres aprender a usar Angular JS?¿Sabes algo de Javascript? ¿y de Typescript?¿Jugaste con jQuery alguna vez? Si tu respuesta es sí, se te va a hacer un poco más fácil. Sino, vas a tener que aprender en el camino, no va a ser fácil pero con perseverancia (casi) todo se puede.</p><p>Voy a contarte un poco acerca de la segunda versión de este framework. Si bien cambio bastante desde la versión 1 los chicos de Google prometen no hacer mas.</p><h3>Partes de una app en Angular</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*QUn_zBM0SBDRG4TtMBiM2A.png" /><figcaption>Diagrama de arquitectura oficial de Angular JS</figcaption></figure><p>Del diagrama podemos ver tres partes bien diferenciadas, los <strong>componentes </strong>(component), las <strong>plantillas </strong>(template) y los <strong>servicios </strong>(servicio). Hay mas cosas en ese diagrama pero por el momento no le vamos a prestar atención.</p><p>Los <strong>componentes </strong>son bloques de la interfaz de usuario con una funcionalidad especifica. En ellos se escribe la lógica de negocio. Se componen los unos a los otros para formar la vista de tu app.</p><p>Por ejemplo si fuésemos a construir la app web de Youtube un <strong>componente </strong>podria ser la lista de videos, la cual tendría dentro mas <strong>componentes </strong>que serian los videos mismos. ¿Se entiende?</p><p>Los <strong>componentes</strong> se sirven de las <strong>plantillas </strong>para generar la vista. Las cuales tienen el conocimiento de que se va a mostrar y de que forma.</p><p>Luego tenemos a los <strong>servicios </strong>que son todo aquello que conecta los componentes con algo para el intercambio de datos. Por ejemplo puede ser la interfaz entre un <strong>componente</strong> y un api REST.</p><p>Para dar un cierre a esta idea inicial, los <strong>componentes </strong>se valen de los <strong>servicios</strong> para obtener los datos a presentar en las <strong>plantillas.</strong></p><p><strong><em>Es mucho mas complejo que eso pero ya vamos a llegar.</em></strong></p><h3>Angular-CLI, conocé a tu nuevo mejor amigo</h3><p>Gracias a la gente de Google, a partir de la versión 2 angular viene acompaña do de un ayudante a la hora de desarrollar un proyecto en este framework. CLI significa interfaz de linea de comandos, es una herramienta que nos permite crear un nuevo proyecto, generar nuevos bloques, correr un servidor de desarrollo e incluso compilar los archivos para enviar a producción.</p><h4>Instalación</h4><p>Antes que nada, tenes que tener instalado NodeJs. Es gratuito y esta disponible para todas las plataformas. Baja el instalador desde acá: <a href="https://nodejs.org/es/">https://nodejs.org/es/</a></p><p>Luego, la instalación del cli es directa. Simplemente abrimos una terminal y escribimos:</p><pre>npm install -g angular-cli</pre><p>Listo, este proceso puede durar varios minutos. Baja un montón de cosas de la red, necesarias para que todo funcione.</p><p>Luego tenemos un comando para generar un nuevo proyecto:</p><pre><strong>ng new</strong> nombre_del_proyecto</pre><p>Un comando para generar componentes:</p><pre><strong>ng generate component</strong> <em>nombre_del_componente</em></pre><p>Cabe aclarar que al generar el componente, tambien se genera la plantilla.</p><p>Y un comando para generar servicios:</p><pre><strong>ng generate service</strong> nombre_del_servicio</pre><p>Listo! Con esto ya tenes para empezar a meterte en el nuevo mundo de Angular JS, te dejo un enlace a la documentación oficial (solo disponible en ingles) <a href="https://angular.io/docs/ts/latest/">https://angular.io/docs/ts/latest/</a></p><p>Estate atento a la segunda parte.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73832eccb28d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/angular-argentina/quiero-aprender-a-usar-angular-js-parte-1-73832eccb28d">Quiero aprender a usar Angular JS (parte 1)</a> was originally published in <a href="https://medium.com/angular-argentina">Angular Argentina</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java 8 Streams C++ port]]></title>
            <link>https://medium.com/@lopez.fernando.damian/java-8-streams-c-port-9aaaed28b81a?source=rss-e7ad20e4d2d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9aaaed28b81a</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[javastreams]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Fernando Damian Lopez]]></dc:creator>
            <pubDate>Thu, 21 Jul 2016 20:31:50 GMT</pubDate>
            <atom:updated>2017-03-02T15:17:57.568Z</atom:updated>
            <content:encoded><![CDATA[<p>Not long ago I saw a video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1OpAgZvYXLQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1OpAgZvYXLQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1OpAgZvYXLQ%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f12e62077a793add584a4b452085df8/href">https://medium.com/media/6f12e62077a793add584a4b452085df8/href</a></iframe><p>And yes I fall in love with Streams. I daily work with C++ projects and we use a lot of lists and maps within our data structures. And this would make our code prettier and easy to understand. So I tough: Does the cpp standard has something like this? Sadly no.</p><p>Why not to build it? C++11 has already lambdas functions, then let’s do it!</p><h4>A brief introduction</h4><p>For those of you that have no idea about streams here is a brief introduction:</p><p>Stream represents a sequence of objects from a source, which supports aggregate operations. Moreover, it lets you process data in a declarative way.</p><p>Some streams properties:</p><ul><li><strong>Sequence of elements</strong> − A stream provides a set of elements of specific type in a sequential manner. A stream gets/computes elements on demand. It never stores the elements.</li><li><strong>Source</strong> − Stream takes Collections, Arrays, or I/O resources as input source.</li><li><strong>Aggregate operations</strong> − Stream supports aggregate operations like filter, map, limit, reduce, find, match, and so on.</li><li><strong>Pipelining</strong> − Most of the stream operations return stream itself so that their result can be pipelined. These operations are called intermediate operations and their function is to take input, process them, and return output to the target. collect() method is a terminal operation which is normally present at the end of the pipelining operation to mark the end of the stream.</li><li><strong>Automatic iterations</strong> − Stream operations do the iterations internally over the source elements provided, in contrast to Collections where explicit iteration is required.</li></ul><h4>map</h4><p>This method is used to map each element to its corresponding result.</p><h4>filter</h4><p>This method is used to eliminate elements based on a criteria.</p><h4>sum</h4><p>This is used to accumulate the elements into a single one.</p><h4>findFist</h4><p>This method returns the first element matching a given condition.</p><h4>Wait, lambdas in C++? Yes!</h4><p>One of the most exciting features of C++11 is ability to create lambda functions. A lambda function is a function that you can write inline in your source code (usually to pass in to another function, similar to the idea of a <a href="http://www.cprogramming.com/tutorial/functors-function-objects-in-c++.html">functor</a> or <a href="http://www.cprogramming.com/tutorial/function-pointers.html">function pointer</a>). With lambda, creating quick functions has become much easier, and this means that not only can you start using lambda when you’d previously have needed to write a separate named function, but you can start writing more code that relies on the ability to create quick-and-easy functions.</p><p>As a first stage I wanted to create a stream class that can handle std::list with <strong>filter</strong>, <strong>map</strong> and <strong>collect </strong>methods. It should <em>operate over standard lists</em>. And it would let you <em>chain operations</em> in a efficient way by <em>pipelining</em> them.</p><h4>Usage</h4><p>To use it just create a stream object from a list using <strong><em>makeStream </em></strong>static method</p><pre>Stream&lt;int&gt;::makeStream(lTestList)</pre><p>Then apply as many operation as you want (<strong>map, filter, etc.):</strong></p><pre><strong> </strong>.filter([](const int &amp;iValue) { return iValue % 2 == 0; })<br> .map([](const int &amp;iValue) { return iValue * 2; })<br> .map([](const int &amp;iValue) { return iValue + 3; })</pre><p>And finally use one the finalizer methods (<strong>collect, sum, findFirst</strong>):</p><pre>.collect();</pre><p><strong>collect</strong> will return a new list with the applied functions.</p><h4>Todo</h4><p>There are still many things to do, here is a list of some:</p><ul><li>Work with standard vector</li><li>Work with standard map</li><li>Work with standard set</li><li>Work with standard queue</li><li>Test it with real objects and structs</li><li>Add more tests</li><li>Add <strong>reduce</strong> method</li><li>Add <strong>forEach</strong></li><li>Add <strong>findAny</strong></li><li>Infinite streams</li><li>Check performance</li></ul><p>Would you like to help me with this? Here is the github repository:</p><p><a href="https://github.com/fivunlm/cppstreams/tree/v0.0.1">https://github.com/fivunlm/cppstreams/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9aaaed28b81a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[La biblioteca no levanta…]]></title>
            <link>https://medium.com/@lopez.fernando.damian/la-biblioteca-no-levanta-b536a8e53529?source=rss-e7ad20e4d2d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b536a8e53529</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[dynamic-libaries]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Fernando Damian Lopez]]></dc:creator>
            <pubDate>Mon, 11 Jul 2016 11:04:51 GMT</pubDate>
            <atom:updated>2017-09-19T12:09:11.273Z</atom:updated>
            <content:encoded><![CDATA[<p>Muchas veces nos pasa que tenemos un programa con funcionalidades delegadas a una biblioteca en <strong>linux</strong> (un archivo .so) que al cargar la misma falla horriblemente sin especificar el porque. Con este fragmento de código podemos cargar la biblioteca y mostrar el error si lo hubiere:</p><pre>#include &lt;iostream&gt;<br>#include &lt;dlfcn.h&gt;</pre><pre>int main() {<br>    using std::cout;<br>    using std::cerr;</pre><pre>    cout &lt;&lt; &quot;C++ dlopen demo\n\n&quot;;</pre><pre>    // open the library<br>    cout &lt;&lt; &quot;Opening hello.so...\n&quot;;<br>    void* handle = dlopen(&quot;<strong>&lt;&lt;PATH_TO_.SO&gt;&gt;</strong>&quot;, RTLD_NOW);</pre><pre>    if (!handle) {<br>        cerr &lt;&lt; &quot;Cannot open library: &quot;&lt;&lt; dlerror() &lt;&lt; &#39;\n&#39;;<br>        return 1;<br>    }</pre><pre>    // close the library<br>    cout &lt;&lt; &quot;Closing library...\n&quot;;<br>    dlclose(handle);<br>}</pre><p>A este codigo lo guardamos como <strong>main.cpp </strong>y se compila con el comando:</p><pre>g++ main.cpp -ldl main.exe</pre><p>Luego al ejecutar <strong>main.exe </strong>veremos el error por el cual la biblioteca no levanta si lo hubiere.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b536a8e53529" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using App Engine to start a Compute Engine VM]]></title>
            <link>https://medium.com/google-cloud/using-app-engine-to-start-a-compute-engine-vm-be713c98d6a?source=rss-e7ad20e4d2d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/be713c98d6a</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[google-app-engine]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Fernando Damian Lopez]]></dc:creator>
            <pubDate>Tue, 31 Mar 2015 03:27:33 GMT</pubDate>
            <atom:updated>2017-03-02T10:23:27.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_Co4L7jWAEvhv7aAs3sHA.jpeg" /></figure><p>Sometimes we don’t want (or need) a compute engine instance running 24hs every day but we need to run task/s periodically. To solve this we can have an <strong>app engine task</strong> runing using <strong>cron service</strong> to start the <strong>VM instance</strong>. Once the VM has started, it can have a startup script that runs the actual task it was needed for and then stops the machine.</p><h3>VM Start</h3><p>We want to run a scheduled task once a day (at midnight let’s say) in order to start. I will call the task url <em>/vm/start</em> but it could be whatever you want. Here is the cron file:</p><h4>cron.yaml</h4><pre>cron:<br>- description: run instance<br>  url: /vm/start<br>  schedule: every day 00:00</pre><h4>Endpoint handler</h4><p>Once set that we need to hadle the url call on the appengine app. I’m using Flask framework but it should work with whatever you’re using:</p><pre><strong>@app.route(&#39;/vm/start&#39;)</strong><br><strong>def start_vm</strong>():<br>    credentials = AppAssertionCredentials(scope=&#39;https://www.googleapis.com/auth/compute&#39;)<br>    http = credentials.authorize(httplib2.Http(memcache))<br>    compute = discovery.build(&#39;compute&#39;, &#39;v1&#39;, http=http)<br>    <br>    # Start the VM!<br>    result = compute.instances().start(instance=INSTANCE_NAME, zone=INSTANCE_ZONE, project=PROJECT).execute()</pre><pre>    logging.debug(result)<br>    <strong>return </strong>json.dumps(result, indent=4)</pre><p>First you need to get credentials. As we are calling from inside GCP we can use app engine service accounts (you can learn more <a href="https://developers.google.com/api-client-library/python/guide/google_app_engine#service-accounts">here</a>). Then we use google api client to build and use compute engine api. And with that is just as simple as calling the instance start method.</p><h4>Configuring access</h4><p>If you try to run the code as is, you will find a <em>Encountered 403 Forbidden with reason “accessNotConfigured” </em>message on the logs. We need to enable Compute Engine API for our project. To do that go to <strong>API Manager</strong> &gt; <strong>Library</strong> &gt; <strong>Compute Engine API</strong> and click <em>ENABLE</em></p><p>Also when creating the VM, we need to set up access rights to cloud API’s</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*SWvuzYuoxcuGcg91vxozdg.png" /><figcaption>Set up API access rights.</figcaption></figure><p>This is what’s required to start the VM. Once deployed a simple call to <a href="http://your-project.appspot.com/vm/start">http://your-project.appspot.com/vm/start</a> will start the virtual machine.</p><h3>VM Stop</h3><p>Now the startup script should run some process to do the work you want to do on this instance and then as the last line should do something like this:</p><pre>gcloud compute instances stop vm-instance --zone &quot;YOUR-VM-ZONE&quot;</pre><p>This needs to be configured when creating the VM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*4jtXVvTUShV6YZLB1HzHTw.png" /><figcaption>Set up startup script</figcaption></figure><p>If you want to see all the code for this example you can check <a href="https://github.com/fivunlm/app-engine-start-vm">this github repo</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be713c98d6a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/using-app-engine-to-start-a-compute-engine-vm-be713c98d6a">Using App Engine to start a Compute Engine VM</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>