<?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[sergiotapia - Medium]]></title>
        <description><![CDATA[Fitness, cosmic horror, functional programming! Elixir, Ruby and Javascript are my tools! Miami! http://www.github.com/sergiotapia - Medium]]></description>
        <link>https://medium.com/sergiotapia?source=rss----6ee81cb47ea5---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>sergiotapia - Medium</title>
            <link>https://medium.com/sergiotapia?source=rss----6ee81cb47ea5---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:56:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/sergiotapia" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use FontAwesome in your React Native applications (iOS and Android)]]></title>
            <link>https://medium.com/sergiotapia/how-to-use-fontawesome-in-your-react-native-applications-ios-and-android-80933b2ae10d?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/80933b2ae10d</guid>
            <category><![CDATA[fonts]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[font-awesome]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Thu, 02 Aug 2018 13:25:42 GMT</pubDate>
            <atom:updated>2018-08-02T13:25:41.575Z</atom:updated>
            <content:encoded><![CDATA[<p>Usage is pretty simple these days thanks for huge efforts made by the very talented engineers working on React Native.</p><p>Here are the direct steps for using FontAwesome in your react native apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDAP9s5w1xD9HROf-u6nUg.png" /><figcaption>chevronLeft being used in a simple react native app.</figcaption></figure><h3>Install react-native-fontawesome</h3><p><a href="https://github.com/entria/react-native-fontawesome">entria/react-native-fontawesome</a></p><p>yarn add react-native-fontawesome</p><p>This gives you nice components that reference the fontawesome font. You just call the icon that you want using your JSX.</p><pre>import FontAwesome, { Icons } from &quot;react-native-fontawesome&quot;;</pre><pre>&lt;FontAwesome&gt;{Icons.chevronLeft}&lt;/FontAwesome&gt;</pre><p>Pretty tidy.</p><p>We still need to actually install the font file though. That’s the next step.</p><h3>Install the FontAwesome font file in your react native project.</h3><p>Download the <a href="https://fontawesome.com/v4.7.0/">4.7.0 version of FontAwesome</a>, and when you open the folder you will see a .ttf font, this is the font we need to copy over to our project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YXyK_Hon2SRHAQ7-" /></figure><p>Rename this file to <strong>FontAwesome.ttf</strong></p><p>Now go to your React Native project and create a folder at the root called assets/fonts/ and drop the file there. Here’s what your folder structure should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/0*zU8-orxaAOtiYyLl" /></figure><h3>Use react-native link to let your mobile apps use the font file properly.</h3><p>Open up package.json and add a new entry at the root level called rnpm. Add this:</p><pre>...<br>},<br>&quot;rnpm&quot;: {<br>  &quot;assets&quot;: [<br>    &quot;./assets/fonts&quot;<br>  ]<br>},<br>&quot;jest&quot;: {<br>  ...</pre><p>Make <strong>sure</strong> it’s at the root level of the configuration object.</p><p><strong>At this stage, I would highly recommend a git commit. Things can go wrong and hunting down exactly what happened is a HUGE pain without the git to revert. COMMIT NOW.</strong></p><p>Did you commit? Good.</p><p>Now run the react-native link command in your terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s0l7C0CREvmDKN2-" /></figure><p>You can use git status to learn what this command did to your ios and android projects, it’s really nifty!</p><h3>Restart your simulators and bundlers and you’re done!</h3><p>You should now see the chevron in both apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80933b2ae10d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/how-to-use-fontawesome-in-your-react-native-applications-ios-and-android-80933b2ae10d">How to use FontAwesome in your React Native applications (iOS and Android)</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate images with name initials using Elixir and ImageMagick.]]></title>
            <link>https://medium.com/sergiotapia/generate-images-with-name-initials-using-elixir-and-imagemagick-374eca4d14ff?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/374eca4d14ff</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Wed, 21 Feb 2018 16:04:06 GMT</pubDate>
            <atom:updated>2018-02-22T05:10:36.096Z</atom:updated>
            <content:encoded><![CDATA[<p>When a new user signs up to your website, you may want to generate an initial profile picture for them using their initials.</p><p>Here’s a nice way to do it using Elixir, ImageMagick, and a custom font.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wJ7hAeBzSuk9_c44yk0R1Q.png" /><figcaption>Generated this image using ImageMagick and the Source Sans Pro otf font.</figcaption></figure><p>First make sure you have ImageMagick installed. On Mac, it’s pretty easy to just use Homebrew.</p><pre>brew install imagemagick</pre><p>Here’s where the magick (kek) happens.</p><pre>@doc &quot;&quot;&quot;<br>Generates an image using first name and last name of a user using imagemagick&#39;s convert command line tool.<br>&quot;&quot;&quot;<br>@spec create_from_initials(binary, binary) :: {:ok, binary}<br>def create_from_initials(first_name, last_name) when byte_size(first_name) &gt; 0 and byte_size(last_name) &gt; 0 do<br>  size = 512<br>  resolution = 72<br>  sampling_factor = 3<br>  background_color = &quot;#003366&quot;<br>  text_color = &quot;#FFFFFF&quot;<br>  initials = &quot;#{String.at(first_name, 0)}#{String.at(last_name, 0)}&quot;<br>  image_path = System.tmp_dir!() |&gt; Path.join(&quot;#{initials}.png&quot;)</pre><pre>  System.cmd(&quot;convert&quot;, [<br>    # sample up<br>    &quot;-density&quot;,<br>    &quot;#{resolution * sampling_factor}&quot;,<br>    # corrected size<br>    &quot;-size&quot;,<br>    &quot;#{size * sampling_factor}x#{size * sampling_factor}&quot;,<br>    # background color<br>    &quot;canvas:#{background_color}&quot;,<br>    # text color<br>    &quot;-fill&quot;,<br>    text_color,<br>    # font location<br>    &quot;-font&quot;,<br>    Application.app_dir(:my_app, &quot;priv/fonts/SourceSansPro-Regular.otf&quot;),<br>    # font size<br>    &quot;-pointsize&quot;,<br>    &quot;300&quot;,<br>    # center text<br>    &quot;-gravity&quot;,<br>    &quot;center&quot;,<br>    # render text in the center<br>    &quot;-annotate&quot;,<br>    &quot;+0+0&quot;,<br>    &quot;#{initials}&quot;,<br>    # sample down to reduce aliasing<br>    &quot;-resample&quot;,<br>    &quot;#{resolution}&quot;,<br>    image_path<br>  ])<br>  <br>  {:ok, image_path}<br>end</pre><p>Lots of ImageMagick flags, but they’re all commented for you to understand what each does.</p><p>Notice how I placed the custom font file in the priv folder and created a folder called fonts.</p><p>Thanks to Patrick for his <a href="https://stackoverflow.com/questions/31395381/generating-initials-avatar-with-elixir">answer</a> on StackOverflow, I took his initial code and added some tweaks to it to make it easier to configure.</p><p>Hope this helps you out! Leave a 👏if this saved you some time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=374eca4d14ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/generate-images-with-name-initials-using-elixir-and-imagemagick-374eca4d14ff">Generate images with name initials using Elixir and ImageMagick.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Killing all socket connections for a user in Phoenix Framework]]></title>
            <link>https://medium.com/sergiotapia/killing-all-socket-connections-for-a-user-in-phoenix-framework-915148e98186?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/915148e98186</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Sat, 03 Feb 2018 17:56:26 GMT</pubDate>
            <atom:updated>2018-02-16T20:27:28.642Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes you want to cut off all socket connections for a user in your application.</p><p>A specific scenario: You deactivate a user, and while you protect your APIs from deactivated users, that socket is still open and they can still receive live events being broadcasted.</p><p>If they refresh the page you’re fine, because that socket is protected against deactivated users.</p><p>But while that authenticated window is open, they can still get data.</p><p>Here’s how you can effectively kill all open socket connections for a user.</p><pre>alias MyApp.Web.Endpoint</pre><pre>def deactivate(conn, %{&quot;id&quot; =&gt; user_id}) do<br>  with {:ok, _user} &lt;- MyApp.deactivate(user_id) do<br>    Endpoint.broadcast(&quot;user_socket:#{user_id}&quot;, &quot;disconnect&quot;, %{})<br>    json(conn, %{message: &quot;User has been deactivated.&quot;})<br>  else<br>    _ -&gt; not_found_error(conn)<br>  end<br>end</pre><p>Just broadcast that event from your controller and you’re all set.</p><p>Of course you should add some authentication and authorization to this. Can this user deactivate people? Can he only deactivate people within his organization? Can he deactivate himself (woah!)?</p><p>I hope this puts you on the right path, enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=915148e98186" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/killing-all-socket-connections-for-a-user-in-phoenix-framework-915148e98186">Killing all socket connections for a user in Phoenix Framework</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</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 show all Ecto query data in iex.]]></title>
            <link>https://medium.com/sergiotapia/how-to-show-all-ecto-query-data-in-iex-3900a429821e?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/3900a429821e</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[ecto]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Sat, 20 Jan 2018 01:56:54 GMT</pubDate>
            <atom:updated>2018-01-20T01:56:54.549Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s a quick tip for those times when you’re querying Ecto data in iex.</p><p>You’re running a query in your terminal using iex -S mix, and the data you’re getting back is truncated at the end.</p><pre>%MyApp.Accounts.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded, &quot;users&quot;&gt;,<br>  confirmation_code: nil, desktop_notification_preference: &quot;everything&quot;,<br>  disabled: false, email: &quot;<a href="/service/mailto:example@email.com">example@email.com</a>&quot;, ...},<br> %MyApp.Accounts.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded, &quot;users&quot;&gt;,<br>  confirmation_code: nil, desktop_notification_preference: &quot;everything&quot;,<br>  disabled: false, ...},<br> %MyApp.Accounts.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded, &quot;users&quot;&gt;,<br>  confirmation_code: nil, desktop_notification_preference: &quot;everything&quot;, ...},<br> %MyApp.Accounts.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded, &quot;users&quot;&gt;,<br>  confirmation_code: nil, ...},<br> %MyApp.Accounts.User{__meta__: #Ecto.Schema.Metadata&lt;:loaded, &quot;users&quot;&gt;, ...},<br> %MyApp.Accounts.User{...}, ...]</pre><p>Here’s how you can get all the query data rendered in your terminal — no longer truncated!</p><pre>MyApp.User |&gt; MyApp.Repo.all |&gt; IO.inspect(limit: :infinity)</pre><p>The will cause all the data to be rendered <strong>completely</strong> in the terminal.</p><p>Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3900a429821e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/how-to-show-all-ecto-query-data-in-iex-3900a429821e">How to show all Ecto query data in iex.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</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 block Chinese IP addresses in Phoenix Framework.]]></title>
            <link>https://medium.com/sergiotapia/how-to-block-chinese-ip-addresses-in-phoenix-framework-4e5f432275a1?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/4e5f432275a1</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[network-security]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Wed, 20 Dec 2017 20:50:51 GMT</pubDate>
            <atom:updated>2017-12-20T20:50:51.153Z</atom:updated>
            <content:encoded><![CDATA[<p>Everyone has been in this situation at least once.</p><p>You’re relaxing, enjoying a nice afternoon working on a feature and suddenly you start seeing a bunch of traffic China doing all sorts of interesting things in your application.</p><p>Mitigation steps should be done at the web server level first and foremost. But sometimes that isn’t available to you — say if you’re hosted on Heroku.</p><blockquote>If you do have access to your web server, you can use this handy list to configure your block list at the web server level. <a href="http://www.parkansky.com/china.htm">http://www.parkansky.com/china.htm</a></blockquote><p>I’m going to show you how to block access at the code level, in your application.</p><h3>What we’re going to use</h3><ul><li><a href="https://github.com/michalmuskala/plug_attack">plug_attack</a> — this allows us to write a Plug that will allow specific connections.</li><li><a href="https://github.com/grych/ip2country">ip2country</a> — this will allow us to transform an IP octet into a country code. Nifty!</li><li><a href="https://github.com/ajvondrak/remote_ip">remote_ip</a> — this automatically overwrites the conn.remote_ip with the value in the X-Forwarded-For header that places like Heroku uses. We need to know if someone came from China or not.</li></ul><p>Add these packages to your mix.exs file and run mix deps.get.</p><pre>{:plug_attack, &quot;~&gt; 0.3.0&quot;},<br>{:ip2country, &quot;~&gt; 1.1&quot;},<br>{:remote_ip, &quot;~&gt; 0.1.4&quot;}</pre><h3>Create your Plug.</h3><pre>defmodule MyApp.Plug.PlugAttack do<br>  import Plug.Conn<br>  use PlugAttack<br>  <br>  rule &quot;deny china&quot;, conn do<br>    ip_address = conn.remote_ip |&gt; Tuple.to_list |&gt; Enum.join(&quot;.&quot;)<br>    allow IP2Country.whereis(ip_address) not in [:CN]<br>  end<br>end</pre><h3>Add your Plug to your endpoint.ex file.</h3><p>You want to ideally nuke the bad actor’s connection as fast as possible to make way for real customers.</p><p>Adding it to the endpoint.ex file before anything else, will mean that the conn is halted before any other step is taken. Perfect!</p><pre>plug MyApp.Plug.PlugAttack</pre><p>At this point you will be blocking Chinese IP addresses.</p><p>There’s one more step you need to take, making sure you get the remote_ip correctly.</p><p>Let’s just call the remote_ip plug right before our PlugAttack module.</p><pre>plug RemoteIp<br>plug MyApp.Plug.PlugAttack</pre><p>That’s all you need to do to block Chinese IP addresses in Phoenix Framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5f432275a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/how-to-block-chinese-ip-addresses-in-phoenix-framework-4e5f432275a1">How to block Chinese IP addresses in Phoenix Framework.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Validate valid URL in Elixir.]]></title>
            <link>https://medium.com/sergiotapia/validate-valid-url-in-elixir-d5f8aef5964c?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/d5f8aef5964c</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Mon, 18 Sep 2017 14:37:49 GMT</pubDate>
            <atom:updated>2017-09-19T21:20:47.030Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s a quick snippet for you guys. Sometimes you need to know if a URL is valid or not.</p><p>A simple way to do this is by using the <a href="https://hexdocs.pm/elixir/URI.html#parse/1">URI.parse/1</a> function.</p><pre>defmodule MyApp.Helpers.UrlValidator do<br>  def valid_https://medium.com/url(url) do<br>    case URI.parse(url) do<br>      %URI{scheme: nil} -&gt; {:error, &quot;No scheme&quot;}<br>      %URI{host: nil} -&gt; {:error, &quot;No host&quot;}<br>      _ -&gt; {:ok, url}<br>    end<br>  end<br>end</pre><p>To call it just do this:</p><pre>MyApp.Helpers.UrlValidator.valid_url(https://medium.com/&quot;https://google.com&quot;)</pre><p>It’ll return either {:ok, &quot;https://google.com&quot;} or {:error, error_string} .</p><p>Hope this helps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5f8aef5964c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/validate-valid-url-in-elixir-d5f8aef5964c">Validate valid URL in Elixir.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phoenix Framework — Direct Uploading to Amazon S3.]]></title>
            <link>https://medium.com/sergiotapia/phoenix-framework-uploading-to-amazon-s3-e70657bd2013?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/e70657bd2013</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[amazon-s3]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Sat, 05 Aug 2017 17:17:49 GMT</pubDate>
            <atom:updated>2017-08-05T17:24:37.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*LJy3CSjxbpcsK165R5zemQ.png" /></figure><p>Today I want to teach you guys how to upload files to Amazon S3 for your Phoenix application.</p><p>We’ll set up uploads to go like this:</p><ul><li>User tells the backend, “I want to upload picture.jpeg!”</li><li>Backend tells the user, “Alright you have my permission but ONLY for that filename with that extension. Here’s a token, enjoy.”</li><li>User uses that signed token and pushes the file to our S3 bucket.</li></ul><p>The benefit of using this approach is that your user sees a snappier upload. The file doesn’t need to be passed through our backend. Your resources don’t get bogged down when a lot of people want to upload things. It’s a win-win.</p><h3>Route, controller, and json view.</h3><p>Let’s create a route people can hit to receive a signed token.</p><pre>post &quot;/upload-signature&quot;, UploadSignatureController, :create</pre><p>Users will need to pass in two params:</p><ul><li>filename</li><li>mimetype</li></ul><p>Our controller action looks like this:</p><pre>def create(conn, %{&quot;filename&quot; =&gt; filename, &quot;mimetype&quot; =&gt; mimetype}) do<br>  conn<br>  |&gt; put_status(:created)<br>  |&gt; render(&quot;create.json&quot;, signature: sign(filename, mimetype))<br>end</pre><p>In our upload_signature_view.ex file, we need to create our create.json render. This is just a simple return.</p><pre>def render(&quot;create.json&quot;, %{signature: signature}) do<br>  signature<br>end</pre><h3>Signing filename and mimetype for secure uploads.</h3><p>At this point we’re ready to dive into the meat of the signature generation: the sign function that’s being invoked in the controller.</p><p>These functions can be placed in our UploadSignatureController file.</p><pre>defp sign(filename, mimetype) do<br>  policy = policy(filename, mimetype)<br><br>  %{<br>    key: filename,<br>    &#39;Content-Type&#39;: mimetype,<br>    acl: &quot;public-read&quot;,<br>    success_action_status: &quot;201&quot;,<br>    action: &quot;https://s3.amazonaws.com/#{System.get_env(&quot;S3_BUCKET_NAME&quot;)}&quot;,<br>    &#39;AWSAccessKeyId&#39;: System.get_env(&quot;AWS_ACCESS_KEY_ID&quot;),<br>    policy: policy,<br>    signature: hmac_sha1(System.get_env(&quot;AWS_SECRET_ACCESS_KEY&quot;), policy)<br>  }<br>end<br><br>defp now_plus(minutes) do<br>  import Timex<br>  now<br>  |&gt; shift(minutes: minutes)<br>  |&gt; format!(&quot;{ISO:Extended:Z}&quot;)<br>end<br><br>defp hmac_sha1(secret, msg) do<br>  :crypto.hmac(:sha, secret, msg)<br>  |&gt; Base.encode64<br>end<br><br>defp policy(key, mimetype, expiration_window \\ 60) do<br>  %{<br>    # This policy is valid for an hour by default.<br>    expiration: now_plus(expiration_window),<br>    conditions: [<br>      # You can only upload to the bucket we specify.<br>      %{bucket: System.get_env(&quot;S3_BUCKET_NAME&quot;)},<br>      # The uploaded file must be publicly readable.<br>      %{acl: &quot;public-read&quot;},<br>      # You have to upload the mime type you said you would upload.<br>      [&quot;starts-with&quot;, &quot;$Content-Type&quot;, mimetype],<br>      # You have to upload the file name you said you would upload.<br>      [&quot;starts-with&quot;, &quot;$key&quot;, key],<br>      # When things work out ok, AWS should send a 201 response.<br>      %{success_action_status: &quot;201&quot;}<br>    ]<br>  }<br>  # Let&#39;s make this into JSON.<br>  |&gt; Poison.encode!<br>  # We also need to base64 encode it.<br>  |&gt; Base.encode64<br>end</pre><p>Looks crazy, but take a minute to digest what’s happening at each line, there’s some helpful comments.</p><p>Now you can use the returned token to upload your file to your S3 bucket. You can use something like Dropzone, jQuery Uploader, or whatever you need.</p><p>Many thanks to ElixirSips for this terrific article, I used it as inspiration to simplify it a little bit and apply it to my project.</p><p><a href="https://www.dailydrip.com/topics/elixirsips/drips/direct-uploads-with-s3-in-a-phoenix-api">[ElixirSips 274] Direct Uploads with S3 in a Phoenix API</a></p><p>Enjoy fast uploads and an even faster Phoenix API!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e70657bd2013" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/phoenix-framework-uploading-to-amazon-s3-e70657bd2013">Phoenix Framework — Direct Uploading to Amazon S3.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</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 version your Phoenix Framework API.]]></title>
            <link>https://medium.com/sergiotapia/how-to-version-your-phoenix-framework-api-10e86e866577?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/10e86e866577</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 00:00:04 GMT</pubDate>
            <atom:updated>2017-07-11T00:00:03.667Z</atom:updated>
            <content:encoded><![CDATA[<p>Versioning your API is very important as it allows you to scope implementations to a specific number in case you want to change the way things are done later down the line.</p><p>This is a short article that will show you how to version the API in your Phoenix Framework application.</p><p>In your router.ex file, scope the API to a specific version.</p><pre>scope &quot;/api/v1&quot;, MyApp.Web.Api.V1, as: :api_v1 do<br>  pipe_through :api</pre><pre>  get &quot;/articles/:id/content&quot;, ArticleController, :content<br>end</pre><p>Next, place your controller in this sort of structure for convenience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*eF9IipmOihcNLKsLSFtskA.png" /></figure><p>Your controller needs to be namespaced properly as well.</p><pre>defmodule MyApp.Web.Api.V1.ArticleController do<br>  use MyApp.Web, :controller</pre><pre>  def content(conn, params) do<br>    text conn, &quot;It&#39;s working&quot;  <br>  end<br>end</pre><p>That’s all there is to it! You now have a nicely versioned API.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10e86e866577" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/how-to-version-your-phoenix-framework-api-10e86e866577">How to version your Phoenix Framework API.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</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 send emails from Phoenix using Elixir and Mandrill.]]></title>
            <link>https://medium.com/sergiotapia/how-to-send-emails-from-phoenix-using-elixir-and-mandrill-8efbeb069a04?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/8efbeb069a04</guid>
            <category><![CDATA[mailchimp]]></category>
            <category><![CDATA[email]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Sun, 09 Jul 2017 03:14:58 GMT</pubDate>
            <atom:updated>2017-07-09T04:17:48.129Z</atom:updated>
            <content:encoded><![CDATA[<p>Sending out emails using Mandrill is great for both sides of your team. Your designers/marketing team can build out an email using Mailchimp’s great UI designer. You can send out emails by just replacing merge_vars.</p><p>It’s a win-win!</p><p>Here’s how you can send out emails from your Phoenix Elixir application.</p><p>First let’s install the bamboo package from thoughtbot. Add the package and whichever version is latest to your mix.exs file.</p><pre>{:bamboo, &quot;~&gt; 0.8&quot;}</pre><p>Install it.</p><pre>mix deps.get</pre><p>Now we need to create a .env file so you can safely set your Mandrill API key without saving it to your git repository.</p><p>Inside of your .env file, paste this in:</p><pre>export MANDRILL_API_KEY=mykeygoeshere</pre><p>Make sure you source the .env file in your terminal window so when you run mix phx.server your project picks up the env var properly.</p><pre>source .env</pre><p>Finally, let’s configure bamboo to use this environment variable API key.</p><pre>config :my_app, MyApp.Mailer,<br>  adapter: Bamboo.MandrillAdapter,<br>  api_key: System.get_env(&quot;MANDRILL_API_KEY&quot;)</pre><h3>Create a base mailer.</h3><p>This mailer module is going to be in charge of actually sending out the emails, but it’s very small. Create a file called mailer.ex somewhere in your /lib folder.</p><pre>defmodule MyApp.Mailer do<br>  use Bamboo.Mailer, otp_app: :my_app<br>end</pre><p>And you’re done. Let’s try sending out an email now.</p><h3>Sending out an email.</h3><p>Sending an email is very easy, succinct and testable. We’ll create a simple email that sends out a confirmation code given a user. Module can be anything, but in this example I’m using Phoenix 1.3 and contexts to organize my code.</p><pre>defmodule MyApp.User.Onboarding.Email do<br>  import Bamboo.Email<br>  import Bamboo.MandrillHelper<br><br>  def confirmation_code_email(user) do<br>    new_email()<br>    |&gt; template(&quot;My Mandrill Template Name&quot;)<br>    |&gt; to(user.email)<br>    |&gt; from(&quot;hello@myapp.com&quot;)<br>    |&gt; subject(&quot;Here&#39;s your confirmation code&quot;)<br>    |&gt; put_param(&quot;global_merge_vars&quot;, [<br>      %{<br>        &quot;name&quot;: &quot;confirmationCode&quot;,<br>        &quot;content&quot;: user.confirmation_code<br>      }<br>    ])<br>    |&gt; MyApp.Mailer.deliver_later<br>  end<br>end</pre><p>Notice how we’re using the previously created MyApp.Mailer module at the end there.</p><p>That’s all there is to it, you’re sending emails now!</p><h3>Unit Testing Phoenix Framework emails</h3><p>How do we test these emails though? It’s really simple and Bamboo comes with testing support out of the box.</p><p>First let’s setup the MyApp.Mailer module to use a different adapter when in test mode. Inside test.exs, let’s do this:</p><pre>config :my_app, MyApp.Mailer,<br>  adapter: Bamboo.TestAdapter</pre><p>And our test:</p><pre>defmodule MyApp.User.Onboarding.EmailTest do<br>  use ExUnit.Case, async: true<br>  use Bamboo.Test<br>  import MyApp.Factory<br><br>  describe &quot;Example email test&quot; do<br>    test &quot;sends an email confirmation code&quot; do<br>      user = insert(:user, %{email: &quot;abc@email.com&quot;, confirmation_code: &quot;123123&quot;})<br>      email = MyApp.User.Onboarding.Email.confirmation_code_email(user)<br>      assert_delivered_email(email)<br>    end<br>  end<br>end</pre><p>The assert_delivered_email function is part of the Bamboo.Test module, that’s why we’re bringing it into our test up top.</p><p>I hope this helps you out in sending emails from a Phoenix Framework application. The Bamboo package is really top-tier and made handling emails really nice. Be sure to leave them a star on the repo:</p><p><a href="https://github.com/thoughtbot/bamboo">thoughtbot/bamboo</a></p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8efbeb069a04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/how-to-send-emails-from-phoenix-using-elixir-and-mandrill-8efbeb069a04">How to send emails from Phoenix using Elixir and Mandrill.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</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 setup your own Kadira instance on a VPS like DigitalOcean.]]></title>
            <link>https://medium.com/sergiotapia/how-to-setup-your-own-kadira-instance-on-a-vps-like-digitalocean-75ef1458adbd?source=rss----6ee81cb47ea5---4</link>
            <guid isPermaLink="false">https://medium.com/p/75ef1458adbd</guid>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[kadira]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sergio Tapia]]></dc:creator>
            <pubDate>Thu, 22 Jun 2017 20:06:01 GMT</pubDate>
            <atom:updated>2017-07-01T19:55:42.062Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iyizded5ZkrSxzJwyi321g.png" /><figcaption>Want your own Kadira? Read this guide!</figcaption></figure><p>Kadira is a great performance tracking application for Meteor apps.</p><p>Unfortunately it was recently shut down, but luckily it was open sourced for anyone to self-host.</p><p>In this guide I’ll show you from A to Z how to get Kadira running on a DigitalOcean droplet. It’ll take you around an hour to get everything up and running.</p><p>Many thanks to Michael Lazarski for his original guide. I used it as the foundation to this guide and expanded upon it.</p><p><a href="https://medium.com/@foodfitnesscode/setting-up-kadira-on-a-ubuntu-16-04-server-part-1-a821cdddd1e6">https://medium.com/@foodfitnesscode/setting-up-kadira-on-a-ubuntu-16-04-server-part-1-a821cdddd1e6</a></p><h3>Create your DigitalOcean droplet.</h3><p>Pick Ubuntu 16.04 x64 for the OS. I created the 2GB ram droplet ($20/month), you can choose whatever fits your needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3c6iK2sKliPQfPy1e-50Q.png" /><figcaption>You can chose whichever droplet size fits your needs.</figcaption></figure><p>You’ll get your credentials via email. Login to your VPS and setup your initial password when prompted.</p><blockquote>Heads up: I’m not a devops guys, I know enough to be dangerous and get the job done but that’s the limit. We’re going to use root for everything and this guide assumes that. If you use a specific “kadira” system account, this guide may not work out for you.</blockquote><p>Let’s update our droplet to have everything we need installed.</p><pre>sudo apt-get update<br>sudo apt-get upgrade<br>sudo apt-get install ufw<br>sudo ufw allow OpenSSH<br>sudo ufw allow 543<br>sudo ufw allow 4000<br>sudo ufw allow 11011<br>sudo apt-get install nginx<br>sudo apt-get install git<br>sudo apt-get install nodejs<br>sudo apt-get install npm<br>sudo apt-get install python<br>curl https://install.meteor.com/ | sh</pre><h3>Installing MongoDB into our droplet.</h3><p>These commands are all each one line, try to copy them over to a text editor first to format them properly.</p><pre>sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6</pre><p>Create the list file for MongoDB.</p><pre>echo &quot;deb [ arch=amd64,arm64 ] <a href="http://repo.mongodb.org/apt/ubuntu">http://repo.mongodb.org/apt/ubuntu</a> xenial/mongodb-org/3.4 multiverse&quot; | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list</pre><p>Reload your local packages.</p><pre>sudo apt-get update</pre><p>Install MongoDB.</p><pre>sudo apt-get install -y mongodb-org</pre><p>And finally run it.</p><pre>sudo service mongod start</pre><p>If everything was configured properly, you should be able to use the Mongo instance by using the mongo command.</p><pre>root@hostname:~# mongo<br>MongoDB shell version v3.4.5<br>connecting to: mongodb://127.0.0.1:27017<br>MongoDB server version: 3.4.5</pre><p>Kadira requires something special from Mongo in order to work. We need to configure replication sets.</p><pre>sudo nano /etc/mongod.conf</pre><p>Make sure you have this somewhere in that configuration file.</p><pre>replication:<br>  replSetName: &quot;kadira&quot;</pre><p>Finally turn on replication for your Mongo instance.</p><pre>mongo admin --eval &#39;rs.initiate({_id: &quot;kadira&quot;, members:[{_id : 0, host : &quot;localhost:27017&quot;},]})&#39;</pre><p>And set it up as a slave.</p><pre>mongo admin --eval &#39;rs.slaveOk()&#39;</pre><p>Create the necessary MongoDB collections.</p><p>Let’s create the collections Kadira needs from our Mongo instance. Each command is a single line.</p><pre>mongo</pre><pre>use kadiraApps<br>db.createUser({ user: &quot;admin&quot;, pwd: &quot;admin&quot;, roles: [ &quot;readWrite&quot;, &quot;dbAdmin&quot; ]})</pre><pre>use kadiraData<br>db.createUser({ user: &quot;admin&quot;, pwd: &quot;admin&quot;, roles: [ &quot;readWrite&quot;, &quot;dbAdmin&quot; ]})</pre><h3>Optimizing MongoDB for performance.</h3><p>You can add some optimizations for our Mongo instance.</p><pre>sudo nano /etc/init.d/disable-transparent-hugepages</pre><p>Paste this in that file:</p><pre>#!/bin/bash<br>### BEGIN INIT INFO<br># Provides:          disable-transparent-hugepages<br># Required-Start:    $local_fs<br># Required-Stop:<br># X-Start-Before:    mongod mongodb-mms-automation-agent<br># Default-Start:     2 3 4 5<br># Default-Stop:      0 1 6<br># Short-Description: Disable Linux transparent huge pages<br># Description:       Disable Linux transparent huge pages, to improve<br>#                    database performance.<br>### END INIT INFO</pre><pre>case $1 in<br>  start)<br>    if [ -d /sys/kernel/mm/transparent_hugepage ]; then<br>      thp_path=/sys/kernel/mm/transparent_hugepage<br>    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then<br>      thp_path=/sys/kernel/mm/redhat_transparent_hugepage<br>    else<br>      return 0<br>    fi</pre><pre>echo &#39;never&#39; &gt; ${thp_path}/enabled<br>    echo &#39;never&#39; &gt; ${thp_path}/defrag</pre><pre>re=&#39;^[0-1]+$&#39;<br>    if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]<br>    then<br>      # RHEL 7<br>      echo 0  &gt; ${thp_path}/khugepaged/defrag<br>    else<br>      # RHEL 6<br>      echo &#39;no&#39; &gt; ${thp_path}/khugepaged/defrag<br>    fi</pre><pre>unset re<br>    unset thp_path<br>    ;;<br>esac</pre><p>Make it executable.</p><pre>sudo chmod 755 /etc/init.d/disable-transparent-hugepages</pre><p>Enable it on boot.</p><pre>sudo update-rc.d disable-transparent-hugepages defaults</pre><p>Reboot the system and make sure you restart Mongo afterwards.</p><pre>sudo reboot now</pre><h3>Setting up nginx for the project.</h3><p>We already have nginx installed from a previous step earlier in this guide. Now we’re going to configure it. Basically we want two things to happen:</p><ul><li>Port 80 routes internally to port 4000 for the kadira-ui project.</li><li>Port 11011 is routed to the kadira-engine project.</li></ul><p>First let’s remove the default pages.</p><pre>sudo rm /etc/nginx/sites-enabled/default</pre><p>Create a new block for the kadira-ui project.</p><pre>sudo nano /etc/nginx/sites-available/kadira</pre><p>Paste this inside.</p><pre>server_tokens off; # for security-by-obscurity: stop displaying nginx version</pre><pre># this section is needed to proxy web-socket connections<br>map $http_upgrade $connection_upgrade {<br>        default upgrade;<br>        &#39;&#39;      close;<br>}<br># HTTP<br>server {<br>        listen 80 default_server;<br>        listen [::]:80 default_server ipv6only=on;</pre><pre># pass requests to Meteor<br>        location / {<br>            proxy_pass http://127.0.0.1:4000;<br>            proxy_http_version 1.1;<br>            proxy_set_header Upgrade $http_upgrade; #for websockets<br>            proxy_set_header Connection $connection_upgrade;<br>            proxy_set_header X-Forwarded-For $remote_addr;<br>            proxy_set_header Host $host;<br>        }<br>}</pre><pre># HTTPS server<br>server {<br>    listen 443 default_server http2; # we enable SPDY here<br>    server_name [::]:443 default_server; # this domain must match Common Name (CN) in the SSL certificate</pre><pre>root html; # irrelevant<br>    index index.html; # irrelevant</pre><pre># config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security<br>    # to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping<br>    add_header Strict-Transport-Security &quot;max-age=31536000;&quot;;</pre><pre># If your application is not compatible with IE &lt;= 10, this will redirect visitors to a page advising a browser update<br>    # This works because IE 11 does not present itself as MSIE anymore<br>    if ($http_user_agent ~ &quot;MSIE&quot; ) {<br>        return 303 https://browser-update.org/update.html;<br>    }</pre><pre># pass all requests to Meteor<br>    location / {<br>        proxy_pass http://127.0.0.1:4000;<br>        proxy_http_version 1.1;<br>        proxy_set_header Upgrade $http_upgrade; # allow websockets<br>        proxy_set_header Connection $connection_upgrade;<br>        proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP</pre><pre># this setting allows the browser to cache the application in a way compatible with Meteor<br>        # on every applicaiton update the name of CSS and JS file is different, so they can be cache infinitely (here: 30 days)<br>        # the root path (/) MUST NOT be cached<br>        if ($uri != &#39;/&#39;) {<br>            expires 30d;<br>        }<br>    }<br>}</pre><p>Enable the new Kadira UI.</p><pre>sudo ln -s /etc/nginx/sites-available/kadira /etc/nginx/sites-enabled/</pre><p>Test to make sure the nginx configuration isn’t broken.</p><pre>sudo nginx -t</pre><p>Now we’re going to configure the kadira-engine block.</p><pre>sudo nano /etc/nginx/sites-available/kadira-engine</pre><p>Paste this in.</p><pre># this section is needed to proxy web-socket connections<br>map $http_upgrade $connection_upgrade {<br>        default upgrade;<br>        &#39;&#39;      close;<br>}</pre><pre># HTTPS server<br>server {<br>    listen 543 default_server http2; # we enable SPDY here<br>    server_name [::]:543 default_server; # this domain must match Common Name (CN) in the SSL certificate</pre><pre>root html; # irrelevant<br>    index index.html; # irrelevant</pre><pre># config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security<br>    # to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping<br>    add_header Strict-Transport-Security &quot;max-age=31536000;&quot;;</pre><pre># If your application is not compatible with IE &lt;= 10, this will redirect visitors to a page advising a browser update<br>    # This works because IE 11 does not present itself as MSIE anymore<br>    if ($http_user_agent ~ &quot;MSIE&quot; ) {<br>        return 303 https://browser-update.org/update.html;<br>    }</pre><pre># pass all requests to Meteor<br>    location / {<br>        proxy_pass http://127.0.0.1:11011;<br>        proxy_http_version 1.1;<br>        proxy_set_header Upgrade $http_upgrade; # allow websockets<br>        proxy_set_header Connection $connection_upgrade;<br>        proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP</pre><pre># this setting allows the browser to cache the application in a way compatible with Meteor<br>        # on every applicaiton update the name of CSS and JS file is different, so they can be cache infinitely (here: 30 days)<br>        # the root path (/) MUST NOT be cached<br>        if ($uri != &#39;/&#39;) {<br>            expires 30d;<br>        }<br>    }<br>}</pre><p>Enable the kadira-engine block.</p><pre>sudo ln -s /etc/nginx/sites-available/kadira-engine /etc/nginx/sites-enabled/</pre><p>Test the nginx configuration.</p><pre>sudo nginx -t</pre><p>If everything went well you can now restart nginx!</p><pre>sudo systemctl restart nginx</pre><h3>Cloning the open source Kadira project.</h3><p>We’re going to clone the open source Kadira project onto our droplet and run it.</p><p>First let’s make sure we’re cloning it to the right place.</p><pre>cd ~/<br>git clone <a href="https://github.com/lampe/kadira-server.git">https://github.com/lampe/kadira-server.git</a></pre><p>Let’s dive into the kadira-server folder and edit the init-shell.sh file.</p><pre>cd kadira-server/<br>chmod +x init-shell.sh<br>sudo nano init-shell.sh</pre><p>Paste this in. Note that you’ll need to have your AWS credentials, and your droplet’s IP address for this file. Have those handy.</p><pre># DB settings export APP_MONGO_URL=&quot;mongodb://admin:admin@localhost:27017/kadiraApps&quot;<br>export APP_MONGO_OPLOG_URL=&quot;mongodb://localhost:27017/local&quot;<br>export DATA_MONGO_URL=&quot;mongodb://admin:admin@localhost:27017/kadiraData&quot;<br>export MAIL_URL=&quot;smtp://postmaster%40kadira.io:<a href="/service/mailto:9jx4fqhdfbg5@smtp.mailgun.org">9jx4fqhdfbg5@smtp.mailgun.org</a>:587&quot;</pre><pre># Engine settings<br>export ENGINE_PORT=11011<br>export EXPORT_OPTIONS_URL=&quot;<a href="http://159.203.112.108:11011/">http://[YOUR DROPLET IP]:11011</a>&quot;</pre><pre># UI settings<br>export UI_PORT=4000<br>export UI_URL=&quot;<a href="http://localhost:$UI_PORT">http://localhost:$UI_PORT</a>&quot;</pre><pre># CPU Profiler needs a s3 bucket<br>export AWS_DEFAULT_REGION=&quot;eu-central-1&quot;<br>export AWS_ACCESS_KEY_ID=&quot;[YOUR AWS ACCESS KEY]&quot;<br>export AWS_SECRET_ACCESS_KEY=&quot;[YOUR AWS SECRET ACCESS KEY]&quot;</pre><pre># Monitoring Setup<br>export LIBRATO_EMAIL<br>export LIBRATO_TOKEN</pre><p>At this point we’re just about finished. Now we need to go through each microservice Kadira has and set it up as a managed service and we’re all set.</p><p>Let’s wrap this up!</p><h3>Kadira Engine</h3><pre>cd ~/kadira-server/kadira-engine<br>npm install<br>source ../init-shell.sh<br>chmod +x run.sh</pre><p>Run it manually to see if everything is work as expected.</p><pre>./run.sh</pre><p>Create a service for kadira-engine.</p><pre>sudo nano /etc/systemd/system/kadira-engine.service<br></pre><p>Paste this in.</p><pre>[Unit]<br>Description=kadira-engine<br>[Service]<br>Type=simple<br>User=root<br>WorkingDirectory=/root/kadira-server<br>ExecStart=/bin/bash -c &quot;source /root/kadira-server/init-shell.sh; cd /root/kadira-server/kadira-engine; ./run.sh&quot;<br>Restart=on-abort<br>[Install]<br>WantedBy=multi-user.target</pre><p>Start the service.</p><pre>systemctl start kadira-engine.service</pre><p>Check it’s status.</p><pre>systemctl status kadira-engine.service</pre><p>Finally enable it.</p><pre>systemctl enable kadira-engine.service</pre><h3>Kadira RMA</h3><p>We need to create a new records in our Mongo instance for Kadira RMA to work properly.</p><pre>mongo<br>use kadiraData</pre><pre>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;1min&#39;,provider:&#39;methods&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;1min&#39;,provider:&#39;errors&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;1min&#39;,provider:&#39;pubsub&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;1min&#39;,provider:&#39;system&#39;,shard:&quot;one&quot;}})</pre><pre>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;3hour&#39;,provider:&#39;methods&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;3hour&#39;,provider:&#39;errors&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;3hour&#39;,provider:&#39;pubsub&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;3hour&#39;,provider:&#39;system&#39;,shard:&quot;one&quot;}})</pre><pre>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;30min&#39;,provider:&#39;methods&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;30min&#39;,provider:&#39;errors&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;30min&#39;,provider:&#39;pubsub&#39;,shard:&quot;one&quot;}})<br>db.mapReduceProfileConfig.insert({lastTime: new Date(), _id:{profile:&#39;30min&#39;,provider:&#39;system&#39;,shard:&quot;one&quot;}})</pre><p>Now let’s setup the project.</p><pre>cd ~/kadira-server/kadira-rma<br>npm install<br>source ../init-shell.sh<br>chmod +x run.sh</pre><p>Run it manually to see if everything is work as expected.</p><pre>./run.sh</pre><p>Create a service for kadira-rma.</p><pre>sudo nano /etc/systemd/system/kadira-rma.service</pre><p>Paste this in.</p><pre>[Unit]<br>Description=kadira-rma<br>[Service]<br>Type=simple<br>User=root<br>WorkingDirectory=/root/kadira-server<br>ExecStart=/bin/bash -c &quot;source /root/kadira-server/init-shell.sh; cd /root/kadira-server/kadira-rma; ./run.sh&quot;<br>Restart=on-abort<br>[Install]<br>WantedBy=multi-user.target</pre><p>Start the service.</p><pre>systemctl start kadira-rma.service</pre><p>Check it’s status.</p><pre>systemctl status kadira-rma.service</pre><p>Finally enable it.</p><pre>systemctl enable kadira-rma.service</pre><h3>Kadira UI</h3><p>We need to configure a few extra files for this project.</p><p>Start by editing the settings.json file.</p><pre>cd ~/kadira-server/kadira-ui<br>sudo nano settings.json</pre><p>Then make sure the file contents look like this:</p><pre>{<br>  &quot;public&quot;: {<br>    &quot;tender&quot;: {<br>      &quot;key&quot;: &quot;405871e6-4816-4d44-a0f3-860c0e988078&quot;<br>    },<br>    &quot;s3Url&quot;: &quot;<a href="https://stitch-kadira.s3.eu-central-1.amazonaws.com/">https://[YOUR BUCKET NAME HERE].s3.[YOUR BUCKET REGION HERE].amazonaws.com/</a>&quot;,<br>    &quot;intercom&quot;: {},<br>    &quot;loginState&quot;: {<br>      &quot;domain&quot;: &quot;&quot;,<br>      &quot;cookieName&quot;: &quot;kadira-dev-login-state&quot;<br>    }<br>  },</pre><pre>&quot;tender&quot;: {<br>    &quot;secret&quot;: &quot;71825e70-d11d-489b-b273-2afdca024fd6&quot;<br>  },</pre><pre>&quot;stripe&quot;: {<br>    &quot;kadirahq&quot;: {<br>      &quot;apiKey&quot;: &quot;sk_test_22QITCBPhqEaEKjHXK5BBwO8&quot;,<br>      &quot;publishableKey&quot;: &quot;pk_test_Tc1iVNRP9p8o7zgYWoWjZnm4&quot;,<br>      &quot;appName&quot;: &quot;KadiraHQ&quot;,<br>      &quot;appLogo&quot;: &quot;<a href="https://kadira.io/favicon.ico">https://kadira.io/favicon.ico</a>&quot;<br>    }<br>  },</pre><pre>&quot;meteorDevelopers&quot;: {<br>    &quot;clientId&quot;: &quot;HcempmSyaawiyb4G4&quot;,<br>    &quot;secret&quot;: &quot;snC3snsmTebC8HHCwwhqhHaAzAFxtFsQRL&quot;<br>  }<br>}</pre><p>Then edit run.sh to allow for superuser functionality since we’re running everything using the root user.</p><pre>#!/bin/bash</pre><pre>MONGO_URL=$APP_MONGO_URL \<br>MONGO_OPLOG_URL=$APP_MONGO_OPLOG_URL \<br>MONGO_SHARD_URL_one=$DATA_MONGO_URL \<br>MAIL_URL=$MAIL_URL \<br>ROOT_URL=$UI_ROOT_URL \<br>meteor --allow-superuser  --port $UI_PORT --settings ./settings.json $@</pre><p>Let’s install the dependencies now.</p><pre>npm install<br>source ../init-shell.sh<br>chmod +x run.sh</pre><p>Run it manually to see if everything is work as expected.</p><pre>./run.sh</pre><p>Create a service for kadira-ui.</p><pre>sudo nano /etc/systemd/system/kadira-ui.service</pre><p>Paste this in.</p><pre>[Unit]<br>Description=kadira-ui<br>[Service]<br>Type=simple<br>User=root<br>WorkingDirectory=/root/kadira-server<br>ExecStart=/bin/bash -c &quot;source /root/kadira-server/init-shell.sh; cd /root/kadira-server/kadira-ui; ./run.sh&quot;<br>Restart=on-abort<br>[Install]<br>WantedBy=multi-user.target</pre><p>Start the service.</p><pre>systemctl start kadira-ui.service</pre><p>Check it’s status.</p><pre>systemctl status kadira-ui.service</pre><p>Finally enable it.</p><pre>systemctl enable kadira-ui.service</pre><h3>Kadira API</h3><pre>cd ~/kadira-server/kadira-api<br>npm install</pre><p>Create a service for kadira-api.</p><pre>sudo nano /etc/systemd/system/kadira-api.service</pre><p>Paste this in.</p><pre>[Unit]<br>Description=kadira-api<br>[Service]<br>Type=simple<br>User=root<br>WorkingDirectory=/root/kadira-server<br>ExecStart=/bin/bash -c &quot;source /root/kadira-server/init-shell.sh; cd /root/kadira-server/kadira-api; ./run.sh&quot;<br>Restart=on-abort<br>[Install]<br>WantedBy=multi-user.target</pre><p>Start the service.</p><pre>systemctl start kadira-api.service</pre><p>Check it’s status.</p><pre>systemctl status kadira-api.service</pre><p>Finally enable it.</p><pre>systemctl enable kadira-api.service</pre><h3>Kadira Alertsman</h3><pre>cd ~/kadira-server/kadira-alertsman<br>npm install</pre><p>Create a service for kadira-api.</p><pre>sudo nano /etc/systemd/system/kadira-alertsman.service</pre><p>Paste this in.</p><pre>[Unit]<br>Description=kadira-alertsman<br>[Service]<br>Type=simple<br>User=root<br>WorkingDirectory=/root/kadira-server<br>ExecStart=/bin/bash -c &quot;source /root/kadira-server/init-shell.sh; cd /root/kadira-server/kadira-alertsman; ./run.sh&quot;<br>Restart=on-abort<br>[Install]<br>WantedBy=multi-user.target</pre><p>Start the service.</p><pre>systemctl start kadira-alertsman.service</pre><p>Check it’s status.</p><pre>systemctl status kadira-alertsman.service</pre><p>Finally enable it.</p><pre>systemctl enable kadira-alertsman.service</pre><h3>We’re done with project setup!</h3><p>Now you need to create an account so you can use the Kadira app in the browser. The easiest way is to add the code to automatically create an account.</p><pre>sudo nano ~/kadira-server/kadira-ui/server/methods/account.js</pre><p>Paste this in somewhere in the file.</p><pre>Meteor.startup(() =&gt;{<br>  Accounts.createUser({<br>    username: &#39;someusername&#39;,<br>    email: &#39;test@email.com&#39;,<br>    password: &quot;somepassword&quot;<br>  })<br>})</pre><p>Reload the page a few times: <a href="http://your-ip-address:4000/">http://your-ip-address:4000</a></p><p>Then go back to edit the same file and remove that code you just added. It’s no longer needed.</p><p>Try logging into your account now you should be able to sign in and create a project to get your Kadira keys.</p><h3>Hooking up your Meteor project to your personal Kadira instance.</h3><p>This is it! You made it this far, get ready for some sweet performance analytics!</p><p>In your settings.json file, make sure you have a Kadira option.</p><pre>&quot;kadira&quot;: {<br>    &quot;appId&quot;: &quot;[your-app-id]&quot;,<br>    &quot;appSecret&quot;: &quot;[your-app-secret]&quot;,<br>    &quot;options&quot;: {<br>      &quot;endpoint&quot;: &quot;<a href="http://159.203.112.108:11011/">http://[your-ip-address]:11011</a>&quot;<br>    }<br>  }</pre><p>Run your Meteor project using the settings flag.</p><pre>meteor run --settings settings.json</pre><p>And you’re done!</p><p>I hope you enjoyed this guide and it helped you save some time. Leave a ❤️ if you liked it, thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75ef1458adbd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sergiotapia/how-to-setup-your-own-kadira-instance-on-a-vps-like-digitalocean-75ef1458adbd">How to setup your own Kadira instance on a VPS like DigitalOcean.</a> was originally published in <a href="https://medium.com/sergiotapia">sergiotapia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>