<?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 Anton Myrberg on Medium]]></title>
        <description><![CDATA[Stories by Anton Myrberg on Medium]]></description>
        <link>https://medium.com/@antonmyr?source=rss-b523dff018e8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Anton Myrberg on Medium</title>
            <link>https://medium.com/@antonmyr?source=rss-b523dff018e8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:39:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@antonmyr/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[Receive SMS to a Next.js application]]></title>
            <link>https://medium.com/46-thoughts/receive-sms-to-next-js-application-a3e4d16bf93d?source=rss-b523dff018e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3e4d16bf93d</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[sms]]></category>
            <category><![CDATA[sms-api]]></category>
            <category><![CDATA[serverless-functions]]></category>
            <category><![CDATA[vercel]]></category>
            <dc:creator><![CDATA[Anton Myrberg]]></dc:creator>
            <pubDate>Fri, 04 Feb 2022 10:55:33 GMT</pubDate>
            <atom:updated>2022-02-07T07:55:49.620Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UizBP6UO_qyULMtc-6wo4g.png" /></figure><h3>Receive SMS to Next.js application</h3><p><strong>After this walk-through you will be able to:</strong></p><ol><li>Send an SMS to a virtual number</li><li>Receive the SMS to your Next.js API</li><li>Send an e-mail from your API, containing the SMS message</li></ol><p><strong>The services we’re using:</strong></p><ul><li><a href="https://46elks.com/">46elks</a> to receive SMS</li><li><a href="https://vercel.com/">Vercel</a> to host your webhook and your Next.js application</li><li><a href="https://mailjet.com/">Mailjet</a> to send e-mails</li></ul><p><strong>Prerequisites:</strong></p><ul><li>Next.js application setup with Typescript</li><li>A 46elks account (free) and a 46elks virtual number (not free)</li><li>A Mailjet account (free)</li><li>A Vercel account (free)</li></ul><h3>First step, get the API keys</h3><p>We need the API keys from 46elks and Mailjet.</p><h4>46elks</h4><p>Go to 46elks.com. Your API keys will be found under “<em>Account</em>”.</p><figure><img alt="Screenshot of where to find API keys at 46elks.com" src="https://cdn-images-1.medium.com/max/1024/1*odsF0jZDDMK3X97Z30L_cg.png" /></figure><h4>Mailjet</h4><p>Go to “<em>Account settings</em>”:</p><figure><img alt="Screenshot of arrow pointing at “Account settings”" src="https://cdn-images-1.medium.com/max/1024/1*gx6Jzo-zfvSOitN3Ycr4mw.png" /></figure><p>Press “<em>Master API-Key &amp; Sub API key managemen</em>t”</p><figure><img alt="Screenshot of arrow pointing at where to click." src="https://cdn-images-1.medium.com/max/1024/1*R0U_uRIoHGQjHfWtr_mWSQ.png" /></figure><p>And there you go :)</p><figure><img alt="Screenshot showing API credentials" src="https://cdn-images-1.medium.com/max/1024/1*6jG1_NVsTq3zBO0IwMTf6A.png" /></figure><h3><strong>Create an api route</strong></h3><p>To create an API route in Next.js you simply add a file under the /api directory. I want my route to be /api/sms so I’ll add a sms.tsx file in the /api directory.</p><p>Copy and paste this code to your new file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/279f4d5c1f38c3b5c26a3f074b6b620e/href">https://medium.com/media/279f4d5c1f38c3b5c26a3f074b6b620e/href</a></iframe><p>In order to make it run, you need to install two packages:</p><ol><li>npm install node-mailjet</li><li>npm install --save-dev @types/node-mailjet (if you’re using TypeScript)</li></ol><p>Change &lt;your email&gt;, &lt;your recipients email&gt; and &lt;your recipients name&gt; to your needs.</p><p>Also create a file called .env.local in your project’s root directory, with the following contents:</p><pre>MAILJET_UID=&lt;your mailjet api key&gt;<br>MAILJET_PWD=&lt;your mailjet secret key&gt;</pre><h3>Deploy your code to Vercel</h3><p>In my personal experience, I’ve found that the easiest way to deploy to Vercel is to push everything to Github and then connect your Github account to Vercel.</p><p>Use this command to push your Next.js project to a Github repo.</p><pre># Push an existing repository from the command line <br>git remote add origin <a href="https://github.com/c0ldlimit/vimcolors.git">&lt;</a>your git repo url&gt;<br>git push -u origin master</pre><p>Go to Vercel, “<em>New project</em>” and press “<em>Import Git repository</em>”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZBu9r2MmVWqWsCLKI3CgZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxiKpT4GYR95jn_f743oTA.png" /></figure><p>When you see this page you need to enter your environment variables:</p><figure><img alt="Screenshot showing what it looks at when setting up Next.js project at vercel" src="https://cdn-images-1.medium.com/max/1024/1*Vs3Bh8TFLE87D2FKgXDSjQ.png" /></figure><h4>Environment variables</h4><p>We need environment variables. Both in Vercel and also locally. We already have them locally so what’s left is to enter them into Vercel.</p><p>Enter them in Vercel like this:</p><figure><img alt="Screenshot showing how you can add environment variables" src="https://cdn-images-1.medium.com/max/1024/1*14mCsfBFQ2kCb6iQf81UjA.png" /></figure><p>Go ahead and press “<em>Deploy</em>” after you’ve added these variables.</p><h3>Enter your URL in 46elks</h3><p>When Vercel is done deploying you should see something like this:</p><figure><img alt="Screenshot showing what a successful setup at Vercel looks like." src="https://cdn-images-1.medium.com/max/1024/1*YKBV7k4NfJKDGDZepGDoAw.png" /></figure><p>Press “<em>Visit</em>” to get your public URL to your serverless function.</p><h4>Go to your 46elks account</h4><p>And go to “<em>Numbers</em>”, buy a number if you don’t have one already, and click “<em>edit</em>”. You should see this page:</p><figure><img alt="Screenshot showing where to enter serverless function url" src="https://cdn-images-1.medium.com/max/1024/1*yJ0BtJ9A0AdjnNYhDBd6EQ.png" /></figure><p>Enter &lt;your vercel url&gt;/api/sms into sms_url. This will tell 46elks that when someone sends a SMS to your 46elks number, they should send a request to your Vercel serverless function.</p><h3>Test it</h3><p>When this is done, you can try to send a SMS to your 46elks number and see if you get an E-mail. Mine looks like this:</p><figure><img alt="Screenshot showing successful result" src="https://cdn-images-1.medium.com/max/1024/1*u6MKkCM4IQu_dUouW81P1g.png" /></figure><h3>Concepts</h3><p>We’ve covered how to receive a SMS to your Next.js application using a webhook. And also how to send an e-mail containing the SMS message from your Next.js application.</p><p>I would like to point out that this code works well in most situations, for example, instead of sending an e-mail you could save the SMS to a database.</p><h3>Thank you for reading!</h3><p>I hope this walk-through was helpful, comment if you want more in-depth tutorials on example apps or explanation of how something works etc.</p><p>Find the final code snippet <a href="https://gist.github.com/AntonMyr/e47efbf0b951b070d5e1de6a92ecc443">here</a>.</p><p>I also welcome you to join me for other tutorials.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3e4d16bf93d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/46-thoughts/receive-sms-to-next-js-application-a3e4d16bf93d">Receive SMS to a Next.js application</a> was originally published in <a href="https://medium.com/46-thoughts">46 thoughts</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extend Your Markdown Workflow With Python]]></title>
            <link>https://medium.com/@antonmyr/extend-your-markdown-workflow-with-python-62e0866350c8?source=rss-b523dff018e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/62e0866350c8</guid>
            <category><![CDATA[markdown]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Anton Myrberg]]></dc:creator>
            <pubDate>Fri, 24 Sep 2021 13:00:45 GMT</pubDate>
            <atom:updated>2021-09-24T13:00:45.506Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4hgxjdKv9cZWLoPvR2PWEw.jpeg" /><figcaption>Photo by Wesley Tingey on Unsplash</figcaption></figure><h3>A short tutorial on creating a tag system</h3><h3>Introduction to the problem</h3><p>As a new employee, I take many notes. I open a new markdown document, name it “2021–09–13” (date of the day), and take notes from meetings, write down questions, todos, and problems.</p><p>My notes directory looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*mRd0SQAPWAU8ZjsuWIGDPg.png" /></figure><p>As seen, it’s a mess. The other day I looked for a question I wrote down “a few days ago”. But I just let it slide… I don’t have the time to open 10+ files to look for a little question.</p><p>Can’t this be <em>automated</em> somehow?</p><p>Yes, yes it can. And it should be.</p><h3>The solution</h3><p>Why not extend Markdown with our very own tags?</p><p>Let’s have a script look for start and end tags in a specified folder for that specific week, month, day.</p><p>The result will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4zNI0jxch8HHqp4-eaC7g.png" /></figure><p>Here I’ve assigned the &lt;q q&gt; tags as questions and the r== ==r as reminders. The Python script generated the file &quot;Collected from this week&quot;.</p><h3>The tutorial</h3><p><em>The end product is available </em><a href="https://github.com/AntonMyr/extending-markdown-with-python"><em>here</em></a>.</p><p>Here’s the outline of our script:</p><ol><li>Specify tags we want to look for</li><li>Read files from a specific folder</li><li>Determine if we’re inside or outside a tag</li><li>Gather our result</li><li>Loop through our result and generate a pretty output file</li></ol><h4>Read a file and detect tags</h4><p>We want to collect tags where the open tag is &lt;i and close tag is i&gt;, the &quot;i&quot; is for &quot;idea&quot;.</p><p>Create a markdown file: echo &quot;# This is the title\n\nHere is a line\n\nMarkdown actually uses two newline characters.&quot; &gt; step_1.md</p><p>Create a python script in the same directory and write the following:</p><pre># File: step_1.py<br>markdown_fp = open(&quot;step_1.md&quot;, &quot;r&quot;)<br>​<br>for line in markdown_fp:<br>  print(&quot;Lines: &quot;, line)</pre><p>This is what I got:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*N-uKIQUrsqNbzwNpoj8AIQ.png" /><figcaption>output</figcaption></figure><p>It basically reads line by line.</p><p>Alright, now we want to filter the lines based on what’s inside of them, update the python script with the following:</p><pre># File: step_1.py<br>markdown_fp = open(&quot;step_1.md&quot;, &quot;r&quot;)<br>​<br>for line in markdown_fp:<br>  if &quot;&lt;i&quot; in line:<br>    print(&quot;Includes a starting tag: &quot;, line)<br>  if &quot;i&gt;&quot; in line:<br>    print(&quot;Includes an end tag: &quot;, line)</pre><p>Also, update your Markdown file like this:</p><p>echo &quot;# This is the title\n\nHere is a line\n\nMarkdown actually uses two newline characters. &lt;i A programming tutorial where you just follow along i&gt;&quot; &gt; step_1.md</p><p>I got the following results:</p><pre>╰─$ python step_1.py                                                                                                                                                       <br>Includes a starting tag:  Markdown actually uses two newline characters. &lt;i A programming tutorial where you just follow along i&gt;<br>​<br>Includes an end tag:  Markdown actually uses two newline characters. &lt;i A programming tutorial where you just follow along i&gt;<br></pre><p>Since the start and end tag is in the same line, it prints the same line.</p><h4>Extract the tag information</h4><p>Okay, we can detect tags. It’s a pretty basic job. We now need to extract the actual information.</p><p>To extract the information we:</p><ol><li>Find the position of the first tag.</li><li>Extract everything after.</li><li>Stop extracting when we reach the end tag.</li></ol><p>Alright, new markdown file. Run this command:</p><pre>echo &quot;# Extract my information\n\n## Lorem ipsum?\n\n* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur feugiat arcu condimentum, fermentum augue sit amet, finibus mi. Maecenas fermentum luctus ornare. Vivamus feugiat nibh dui, sollicitudin sagittis metus aliquam et. \n\n* Donec finibus, ligula sit amet rhoncus tempus, augue quam iaculis erat, id lacinia lacus arcu sed purus. Sed gravida consectetur purus imperdiet eleifend. \n\n* &lt;i A programming tutorial where you just follow along i&gt;\n\n&lt;i\n* An idea with multiple\n* Points\n* Could be useful\ni&gt;\n&quot; &gt; step_2.md</pre><p>For the sake of this tutorial, I’ll define three different states.</p><pre>╔═══════════╦═════════════════╦═══════════════╦═══════════════╗<br>║ <strong>Name      </strong>║    <strong>Start tag</strong>    ║    <strong>Extract</strong>    ║    <strong>End tag</strong>    ║<br>╠═══════════╬═════════════════╬═══════════════╬═══════════════╣<br>║ <strong>state</strong>     ║   Outside tag   ║   Inside tag  ║  Inside tag   ║<br>╠═══════════╬═════════════════╬═══════════════╬═══════════════╣<br>║ <strong>action</strong>    ║   &quot;&lt;i&quot; read     ║               ║  &quot;i&gt;&quot; read    ║<br>╚═══════════╩═════════════════╩═══════════════╩═══════════════╝</pre><p>Transform the above table into an if-statement:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05403f7ba595e1a645e40dda04d8fc03/href">https://medium.com/media/05403f7ba595e1a645e40dda04d8fc03/href</a></iframe><p>The pass statement is there temporarily.</p><h3>State: Start tag</h3><p>Here we want to</p><ol><li>Remove everything in the line variable until the &lt;i tag.</li><li>Set the inside_tag variable to True.</li></ol><pre>if start_tag and outside_tag:<br>        # Start tag<br>        tag_start_index = line.index(&quot;&lt;i&quot;) + len(&quot;&lt;i&quot;)<br>        print(&quot;tag_start_index: &quot;, tag_start_index)<br>        print(&quot;Line starting from index: &quot;, line[tag_start_index:])<br>        print(&quot;Original line: &quot;, line[0:])</pre><p>My output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*t2Ugwa6MJN2KifPwWS4Sng.png" /><figcaption>output</figcaption></figure><p>With this in mind we get this:</p><pre>if start_tag and outside_tag:<br>    		# Start tag<br>        tag_start_index = line.index(&quot;&lt;i&quot;) + len(&quot;&lt;i&quot;)<br>        line = line[tag_start_index:]<br>        <br>        # This is where we&#39;ll store the idea<br>			  idea_list.append(&quot;&quot;)<br>        <br>        inside_tag = True</pre><p>Moving on…</p><h3>State: End tag</h3><ol><li>We need to look for the position of the end tag</li><li>Read until that position</li><li>Put the result into the idea_list</li></ol><p>To look for the position we’ll do the same things as in <a href="#State:%20Start%20tag">Start tag</a>, end_tag_index = line.index(&quot;i&gt;&quot;).</p><p>Read until that position: line = line[:end_tag_index].</p><p>Now, a little issue. We don’t know <em>where</em> we want to add the idea in the idea_list. Index 0, index 5? Who knows.</p><p>That’s why we’ll introduce an idea_counter, to keep track of which idea we&#39;re at.</p><p>Of course, we now need to change the inside_tag variable to False, since we&#39;re not <em>inside a tag</em>.</p><p>Here is the sum-up of the above:</p><pre>if end_tag and inside_tag:<br>        # End tag<br>        end_tag_index = line.index(&quot;i&gt;&quot;)</pre><pre>        line = line[:end_tag_index]</pre><pre>        tag_list[idea_counter] += line<br>        idea_counter += 1<br>        inside_tag = False</pre><h3>State: Extract</h3><p>The extraction part is the easiest. We just read the line, and add it to our current idea.</p><pre>if inside_tag:<br>        # Extract<br>        idea_list[idea_counter] += line</pre><p>To see what we got so far, add this to the bottom of your file: print(&quot;Idea_list: &quot;, idea_list).</p><p>I got the following output:</p><pre>╰─$ python step_2.py<br>Idea_list:  [&#39; A programming tutorial where you just follow along &#39;, &#39;\n* And idea with multiple\n* Points\n* Could be useful\n&#39;]</pre><p>And that’s pretty much what it should look like!</p><h4>Creating our output file</h4><p>We got the list with the ideas. Now we need to display them in markdown.</p><ol><li>Close the previous file pointer: markdown_fp.close()</li><li>Open up a new one: output_fp = open(&quot;output.md&quot;, &quot;w&quot;)</li><li>Write the title: output_fp.write(&quot;# Collection of ideas&quot;)</li><li>Loop through the ideas and write them as well:</li></ol><pre>for i, idea in enumerate(idea_list):<br>  output_fp.write(&quot;## Idea %d\n&quot;)<br>  output_fp.write(idea + &quot;\n&quot;)</pre><p>Lastly, close the file pointer: output_fp.close()</p><p>My current step_2.py file looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec4ee39e9e9511dcc34fe6c933cc8b86/href">https://medium.com/media/ec4ee39e9e9511dcc34fe6c933cc8b86/href</a></iframe><p>I created the start_t and end_t variables to make it easier to change tag characters.</p><p>This is my output.md file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*5G_VWz2G-tYSY7iWNgv6yg.png" /></figure><h3>What can we do from here?</h3><p>Well, the basic idea is pretty much done.</p><p>I have created a hulk version of our script which can be seen here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acdc1c20f18225ba7ba1dc57fe3c330b/href">https://medium.com/media/acdc1c20f18225ba7ba1dc57fe3c330b/href</a></iframe><p>It’s even shorter than our step_2.py version. This is because I moved some code to a file called lib.py, where I also created a class I call tag_checker. Now I can just add new tags using tags.add_tag(&quot;name of tag&quot;, &quot;&lt;n&quot;, &quot;n&gt;&quot;).</p><h3>Challenge!</h3><p>Are you new to Python?</p><p>Then I challenge YOU to recreate the class called tag_checker. You should do this just from looking at how I use it in the code snippet above.</p><p>It’s a challenge that could be considered difficult depending on your knowledge level, however, if you read this far, you’re ready!</p><h3>Thank you for reading!</h3><p>This article was my first in a very long time so I appreciate that no one other than you took the time to read it!</p><p>If you’re an experienced programmer, maybe you appreciated the idea of automating your markdown workflow, or you might even think the code looked neat?</p><p>If you’re a beginner programmer I hope it was helpful (and fun!) to follow this tutorial.</p><p>I also welcome you to join me for other tutorials.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62e0866350c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>