<?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 Yap Jia Hong on Medium]]></title>
        <description><![CDATA[Stories by Yap Jia Hong on Medium]]></description>
        <link>https://medium.com/@yapjiahong2003?source=rss-83dbc73d509a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MUHhVp5g7zaJIOTO</url>
            <title>Stories by Yap Jia Hong on Medium</title>
            <link>https://medium.com/@yapjiahong2003?source=rss-83dbc73d509a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:56:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yapjiahong2003/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[Setting up Neovim for C# development on Windows using OmniSharp]]></title>
            <link>https://yapjiahong2003.medium.com/setting-up-neovim-for-c-development-on-windows-using-omnisharp-ea9e2db64ea?source=rss-83dbc73d509a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea9e2db64ea</guid>
            <category><![CDATA[nvim]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[lsp]]></category>
            <category><![CDATA[neovim]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Yap Jia Hong]]></dc:creator>
            <pubDate>Thu, 04 May 2023 09:06:34 GMT</pubDate>
            <atom:updated>2023-05-04T09:06:34.720Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up Neovim for C# development on Windows using OmniSharp as an LSP</h3><p>I made this to address the difficulties I’ve had with setting up <a href="https://github.com/OmniSharp/omnisharp-roslyn">OmniSharp </a>as my LSP for C# development on Windows and hope that someone will be able to find this useful. Why OmniSharp? It’s officially supported by Microsoft and I needed something stable. That said as of time of writing there is an <a href="https://github.com/OmniSharp/omnisharp-roslyn/issues/2483">issue</a> where the semantic tokens sent by the LSP are incorrect. But it can be fixed with a workaround.</p><p>Something to mention is that I assume you <strong>already have</strong> knowledge of how to configure the bulitin neovim LSP. Other than that you don’t need any other prerequisite knowledge. So, you’ll need two things an installation of OmniSharp and <a href="https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=net70">dotnet</a> (this links to .NET 7.0). This will provide you with access to the dotnet command across all shells in Windows. Installing dotnet is pretty simple and you just click a few buttons and we will use it later.</p><p>To install OmniSharp you can check out the <a href="https://github.com/OmniSharp/omnisharp-roslyn/releases">releases</a> page and install the right version so choose Windows x64, etc and make sure to check for the “-NETx.0” suffix before the file extension where x is presumably the current version. The reason I brought up the suffix is because the folder <strong>must</strong> contain an OmniSharp.dll file. Then you unzip it into some folder and store it somewhere. I stored it in my home directory under the lspfolder and copy the file path.</p><p>To get there you can just cd ~. It should also be the default location that opens when you launch a terminal.</p><p>Now that you have dotnet and OmniSharp installed dive into the neovim side and where you setup your LSPs put in this and in the omnisharp_bin folder paste the path you just copied and add the OmniSharp.dll at the end.</p><pre>if os == &quot;Windows_NT&quot; then<br>  local omnisharp_bin = &quot;&lt;path to OmniSharp install&gt;\\OmniSharp.dll&quot;<br>  <br>  lspconfig.omnisharp.setup {<br>    on_attach = on_attach,<br>    handlers = handlers,<br>    capabilities = capabilities,<br>    cmd = { &quot;dotnet&quot;, omnisharp_bin },<br>  }<br>end</pre><p>The reason I check for my os is because I use my neovim config on both my Windows and Linux machines. The code for this is obtained from the <a href="https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#omnisharp">README</a> file detailing how to setup OmniSharp if you have trouble please refer it as the process may have changed in the future. The next step is to open a .cs file and check if the LSP works by typing in some nonsense code and seeing errors off to the side. As you’re playing around you may notice some errors about highlight groups this issue was mentioned earlier and there is a solution in that same GitHub issue in a <a href="https://github.com/OmniSharp/omnisharp-roslyn/issues/2483#issuecomment-1364720374">comment</a>.</p><p>It is at this point where it gets more “personal” or individual as this is the part where I have issues and if the LSP doesn’t kick in keep reading and I hope I’ll be able to help you solve your problems, anyways, this is what you do. You navigate to where you saved the OmniSharp install and open a shell in that folder, a quick way is to type “cmd” where the file path is then hit enter, like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*eZTcLBDmot3XcNS-6CXuFA.png" /></figure><p>cmd will pop up and you need to run dotnet OmniSharp.dll and in my case I got this error.</p><pre>{&quot;Event&quot;:&quot;log&quot;,&quot;Body&quot;:{&quot;LogLevel&quot;:&quot;INFORMATION&quot;,&quot;Name&quot;:&quot;OmniSharp.Stdio.Host&quot;,&quot;Message&quot;:&quot;Starting OmniSharp on Windows 10.0.19045.0 (x64)&quot;},&quot;Seq&quot;:1,&quot;Type&quot;:&quot;event&quot;}<br>{&quot;Event&quot;:&quot;log&quot;,&quot;Body&quot;:{&quot;LogLevel&quot;:&quot;INFORMATION&quot;,&quot;Name&quot;:&quot;OmniSharp.Services.DotNetCliService&quot;,&quot;Message&quot;:&quot;Checking the &#39;DOTNET_ROOT&#39; environment variable to find a .NET SDK&quot;},&quot;Seq&quot;:2,&quot;Type&quot;:&quot;event&quot;}<br>{&quot;Event&quot;:&quot;log&quot;,&quot;Body&quot;:{&quot;LogLevel&quot;:&quot;INFORMATION&quot;,&quot;Name&quot;:&quot;OmniSharp.Services.DotNetCliService&quot;,&quot;Message&quot;:&quot;Using the &#39;dotnet&#39; on the PATH.&quot;},&quot;Seq&quot;:3,&quot;Type&quot;:&quot;event&quot;}<br>{&quot;Event&quot;:&quot;log&quot;,&quot;Body&quot;:{&quot;LogLevel&quot;:&quot;INFORMATION&quot;,&quot;Name&quot;:&quot;OmniSharp.Services.DotNetCliService&quot;,&quot;Message&quot;:&quot;DotNetPath set to dotnet&quot;},&quot;Seq&quot;:4,&quot;Type&quot;:&quot;event&quot;}<br>{&quot;Event&quot;:&quot;log&quot;,&quot;Body&quot;:{&quot;LogLevel&quot;:&quot;ERROR&quot;,&quot;Name&quot;:&quot;OmniSharp.MSBuild.Discovery.Providers.SdkInstanceProvider&quot;,&quot;Message&quot;:&quot;OmniSharp requires the .NET 6 SDK or higher be installed. Please visit https://dotnet.microsoft.com/download/dotnet/6.0 to download the .NET SDK.&quot;},&quot;Seq&quot;:5,&quot;Type&quot;:&quot;event&quot;}<br>{&quot;Event&quot;:&quot;log&quot;,&quot;Body&quot;:{&quot;LogLevel&quot;:&quot;INFORMATION&quot;,&quot;Name&quot;:&quot;OmniSharp.MSBuild.Discovery.MSBuildLocator&quot;,&quot;Message&quot;:&quot;Located 0 MSBuild instance(s)&quot;},&quot;Seq&quot;:6,&quot;Type&quot;:&quot;event&quot;}<br>Could not locate MSBuild instance to register with OmniSharp.</pre><p>What helped me solve the issue is this line here. {“Event”:”log”,”Body”:{“LogLevel”:”ERROR”,”Name”:”OmniSharp.MSBuild.Discovery.Providers.SdkInstanceProvider”,”Message”:”OmniSharp requires the .NET 6 SDK or higher be installed. Please visit <a href="https://dotnet.microsoft.com/download/dotnet/6.0">https://dotnet.microsoft.com/download/dotnet/6.0</a> to download the .NET SDK.”},”Seq”:5,”Type”:”event” . I simply followed the link and downloaded what was necessary and ran dotnet OmniSharp.dll again and there were no errors and I was able to have auto-complete, etc, working.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea9e2db64ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom error types: How to implement them and why.]]></title>
            <link>https://yapjiahong2003.medium.com/custom-error-types-how-to-implement-them-and-why-44791e6853a1?source=rss-83dbc73d509a------2</link>
            <guid isPermaLink="false">https://medium.com/p/44791e6853a1</guid>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[error-handling]]></category>
            <dc:creator><![CDATA[Yap Jia Hong]]></dc:creator>
            <pubDate>Thu, 13 Apr 2023 13:42:51 GMT</pubDate>
            <atom:updated>2023-04-13T13:43:21.444Z</atom:updated>
            <content:encoded><![CDATA[<p>Having custom error types is something that’s really nice when you’re trying to create a library or some sort of back end you plan to use in your future projects which is exactly what I did and for the purposes of this post I’m going to use it as an example. If you’re curious the create is called <a href="https://github.com/AlphabetsAlphabets/srsa/blob/master/src/errors.rs#L11">srsa</a></p><p>Other than what I just mentioned why would you want to implement a custom error type? (1) Enables the use of ? for error propagation and (2) it helps the end user understand the error better.</p><p>A little bit about ?. ? converts Result&lt;T, E&gt; into E meaning if a Result&lt;T, D&gt; is returned ? won’t work. The compiler will throw an error along the lines of “D can’t be converted to E.” To illustrate when this scenario will pop up take a look at this snippet <a href="https://github.com/AlphabetsAlphabets/srsa/blob/master/src/lib.rs#L64">retrieve_keys</a> .</p><blockquote>If you’d like to know what the ? operator does <em>in </em>detail, please refer to another post.</blockquote><pre>// Get *encrypted* private key first<br>let mut pem = fs::read_to_string(priv_key_path)?;<br><br>// Decrypt encrypted private key<br>let priv_key = RsaPrivateKey::from_pkcs8_encrypted_pem(&amp;pem, password)?;<br>pem.clear();<br>// Then get public key<br>pem = fs::read_to_string(pub_key_path)?;<br>let pub_key = RsaPublicKey::from_public_key_pem(&amp;pem)?;</pre><p>Let’s look at the return types of functions where the `?` operator is used.<br>1. fs::read_to_string returns io::Error<br>2. RsaPrivateKey::from_pkcs8_encrypted_pem(&amp;pem, password) returns pkcs8::Error.<br>3. RsaPublicKey::from_public_key_pem(&amp;pem) returns spki::Error .</p><p>All three return differing Result types. This is where implementing your own error type comes in handy. Since this is a library crate, it’s a good idea to let your end users know exactly what error they’re dealing with.</p><p>A custom error type is just an enum with different variants for each error. This is the implementation of KeyError.</p><pre>pub enum KeyError {<br>    KeyNotFound(String),<br>    PrivateKeyDecryptionFailed(String),<br>    PemDecryptionFailed(String),<br>}</pre><p>It is plenty obvious what is going on to the user. But, how do you convert one error type to another? By implementing the From trait to KeyError. This is how I handle an io::Error .</p><blockquote>For more detail about From or how it works please take a look at the <a href="https://doc.rust-lang.org/std/convert/trait.From.html">docs</a>.</blockquote><pre>impl From&lt;io::Error&gt; for KeyError {<br>    fn from(value: io::Error) -&gt; Self {<br>        Self::KeyNotFound(value.to_string())<br>    }<br>}</pre><p>It’s very simple and all it does is get the message in the io::Error and put it inside Self::KeyNotFound. I do this for all the implementations of From. Lastly, you’ll need to show that information somehow. If someone prints the error it won’t work and you’ll need to implement the Display or Debug trait.</p><p>When you implement the Display trait give the end user information just describe the error. As for the Debug trait, give precise information about the error itself so the developer knows what to do. But, in my case the implementation for Debug and Display are the same since there wasn’t any additional information that could be convey.</p><pre>impl Debug for KeyError {<br>    fn fmt(&amp;self, f: &amp;mut std::fmt::Formatter&lt;&#39;_&gt;) -&gt; std::fmt::Result {<br>        use KeyError::*;<br><br>        let msg = match self {<br>            KeyNotFound(msg) =&gt; format!(&quot;Key not found: {msg}&quot;),<br>            PrivateKeyDecryptionFailed(msg) =&gt; format!(&quot;Key decryption failed: {msg}&quot;),<br>            PemDecryptionFailed(msg) =&gt; format!(&quot;Pem decryption failed: {msg}&quot;),<br>        };<br><br>        write!(f, &quot;{}&quot;, msg)<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44791e6853a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Guide to Automating Data Backups in Linux]]></title>
            <link>https://yapjiahong2003.medium.com/scheduling-pre-shutdown-tasks-with-systemd-92530854335?source=rss-83dbc73d509a------2</link>
            <guid isPermaLink="false">https://medium.com/p/92530854335</guid>
            <category><![CDATA[task-scheduling]]></category>
            <category><![CDATA[systemd]]></category>
            <category><![CDATA[task-scheduler]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Yap Jia Hong]]></dc:creator>
            <pubDate>Wed, 08 Feb 2023 01:40:44 GMT</pubDate>
            <atom:updated>2025-03-21T23:25:38.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWAJQsfWqUeEC10WCYAkXQ.jpeg" /></figure><p>For those who have a free account and have reached the article limit, feel free to read this article in my <a href="https://alphabetsalphabets.hashnode.dev/step-by-step-guide-to-automating-data-backups-in-linux">blog</a> instead.</p><h3>Introduction</h3><p>I keep my notes in an Obsidian vault. While Obsidian offers Obsidian Sync which syncs your notes to the cloud, I could not pay for it because I am a student. What I did was manually push my notes to my private GitHub repository every week. However, one day I was messing around with a shell script that used rm -rf and very <em>stupidly</em> <em>did not test it</em>. This resulted in the loss of three quarters of my notes.</p><p>After that experience all I wanted to do was to be able to have this backup process happen on its own and as frequently as possible. So, I came up with a simple solution: Performing the add, commit and push before the computer can shutdown. This way backups are extremely frequent and damage would be incredibly minimal. This is a suitable use case because I need to move around a lot and as a result I turn off my PC a lot. This means this pre-shutdown task would trigger very often.</p><p>I spent some time looking at options to achieve what I wanted and I managed to find a solution I’m quite happy with. Which is to leverage an init system called systemd.</p><h3>What is systemd?</h3><p>systemd is an init system. It is the first thing that runs when your Linux machine starts (it has a PID of 1). When it runs it will activate other components known as services and there are a lot of them—WiFi, audio, a lot of them. It also has various conditions it keeps track of. To configure a pre-shutdown task, I will leverage this by making a systemd service that runs when it detects the shutdown condition, in addition I can also specify certain things to be available such as WiFi, because an internet connection is required for this.</p><blockquote>This is a super simplified version of what systemd is. If you’d like an accurate technical definition, refer to <a href="https://wiki.archlinux.org/title/Systemd">this</a> article from the Arch wiki.</blockquote><h3>Creating systemd units</h3><p>Tasks ran by systemd are called units and all units have the .service extension. These units are made by users and therefore must be placed in ~/.config/systemd/user/[^1]. Thank the Arch Wiki because there&#39;s a <a href="https://wiki.archlinux.org/title/Systemd#Writing_unit_files">guide</a> that tells you exactly how to write units. Based on the functionality desired I wrote a simple script (stored in ~/script to keep things simple) and then made it executable with chmod u+x &lt;script&gt;.[^2]</p><blockquote>Keep in mind that this script can do literally anything you want, it doesn’t even have to be a .fish script, it can be a python script. Be creative, and see what works for you!</blockquote><p>I named the unit backup.service and placed it in ~/.config/systemd/user. You can name it whatever you want, as long as it&#39;s name clearly describes its purpose. This is the content of the unit.</p><pre>[Unit]<br>Description=Backup obsidian notes before shutdown<br>DefaultDependencies=no<br>Requires=network-online.target<br>After=network-online.target</pre><pre>[Service]<br>Type=oneshot<br>RemainAfterExit=yes<br>ExecStop=fish /home/yjh/scripts/backup.fish</pre><pre>[Install]<br>WantedBy=default.target shutdown.target</pre><blockquote>It took me a while to figure out what the purpose of [Install] is and if you&#39;d like to know more take a look at the <a href="https://man.archlinux.org/man/systemd.unit.5.en#%5BINSTALL%5D_SECTION_OPTIONS">man page</a> for this.</blockquote><p>There are a few items that relate to my use case of (1) running scripts before shutdown and (2) pushing a local repo to a remote repsitory.</p><ul><li>RemainAfterExit, ExecStop is for service units that will run scripts.</li></ul><p>RemainAfterExit[^3] is a must for these service units as it won&#39;t even get into an active state it will always be dead.[^4]</p><ul><li>Requires=<a href="http://network-online.target/">network-online.target</a></li></ul><p>Requires= makes sure that <a href="http://network-online.target/">network-online.target</a> will be started if it isn&#39;t when this service unit activates. This is because to push to remote repository an internet connection is required.</p><ul><li>After=<a href="http://network-online.target/">network-online.target</a></li></ul><p>After= makes sure that <a href="http://network-online.target/">network-online.target</a> has started. If <a href="http://network-online.target/">network-online.target</a> fails to start for whatever reason the script will not be executed.[^5] This ensures that the script will only execute if there is an internet connection otherwise, nothing happens.</p><blockquote>Something very important that I’d like to bring up is the help I received from <a href="https://github.com/dnaka91">dnaka</a> and <a href="https://unix.stackexchange.com/users/332764/freddy">Freddy</a> a unix user who helped me solve this <a href="https://unix.stackexchange.com/a/734710/527572">issue</a>. He also explained that if DefaultDependencies is removed then <a href="http://shutdown.target/">shutdown.target</a> is implicitly included when the service unit is run!</blockquote><h3>Working around user input</h3><p>After <a href="https://github.blog/changelog/2021-08-12-git-password-authentication-is-shutting-down/">password authentication was shutdown</a> in 2021, I decided to use SSH keys for authorisation. However, my SSH keys are password protected which means that user input is required. Inputs which I cannot give because when the system is shutting down the screen goes black. So, a way to circumvent this is to create a new SSH key and only use it for that specific repository. GitHub already has <a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent">documentation</a> on how to do exactly that.</p><h3>Enabling the unit</h3><p>After writing up the service unit they are not detected yet and systemd will need to know about them to do that run sudo systemctl daemon-reload. Then you&#39;ll need to enable it with systemctl --user enable &lt;service&gt; and there will be some output this is what I got.</p><pre>Created symlink /home/yjh/.config/systemd/user/shutdown.target.wants/backup.service → /home/yjh/.config/systemd/user/backup.service.</pre><p>I made some random changes and I restarted my PC. I looked at the repository through my phone and saw a new commit. A huge success!</p><h3>Closing thoughts</h3><p>This actually took me a while to deal with. I spent many hours on this and even skipped class, probably not a smart idea. I was in class sure, but I was at the back doing my own thing. Anyways, the moral of the story is</p><ol><li>Don’t run rm -rf without testing it first.</li><li>Automate backups for redundancy.</li><li>This let me gain more control over my device and it feels really, really good to be a master of my own device to such a specific degree, it is honestly awesome.</li></ol><p>I implemented this about two years ago, and I’ve never been happier at my lack of data loss. I even manually backup my data once every few months to an external drive I carry around everywhere. I’m proud to say that if you threw my laptop into a volcano I would suffer no data loss!</p><p>[1]: <a href="https://wiki.archlinux.org/title/Systemd/User">~/.config/systemd/user/ where the user puts their own units.</a></p><p>[2]: Along side the manuals and wikipages the article on running scripts with systemd by <a href="https://www.golinuxcloud.com/run-script-with-systemd-before-shutdown-linux/">golinuxcloud</a> was also very helpful.</p><p>[3]: About <a href="https://man.archlinux.org/man/systemd.service.5#OPTIONS">RemainAfterExit</a> will require some serching with CTRL+F.</p><p>[4]: <a href="https://man.archlinux.org/man/systemd.service.5#OPTIONS">Type=oneshot and relation to </a><a href="https://man.archlinux.org/man/systemd.service.5#OPTIONS">RemainAfterExit</a>. Will require some searching with CTRL+F.</p><p>[5]: Detailed info on <a href="https://man.archlinux.org/man/systemd.unit.5.en#%5BUNIT%5D_SECTION_OPTIONS">Requires=</a>. Will require searching.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92530854335" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving merge conflicts easily in Neovim with Fugitive]]></title>
            <link>https://yapjiahong2003.medium.com/solving-merge-conflicts-easily-in-neovim-with-fugitive-cb5f4e205e8f?source=rss-83dbc73d509a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb5f4e205e8f</guid>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[workflow]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[neovim]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yap Jia Hong]]></dc:creator>
            <pubDate>Thu, 02 Feb 2023 03:23:56 GMT</pubDate>
            <atom:updated>2023-02-02T03:23:56.261Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will <em>not</em> be a how to for fugitive. If you want to know how to use fugitive to its fullest I highly encourage you to take a look at documentation and help files for Fugitive. However, I will only touch on the bare minimum required to follow along with this article.</p><blockquote>Merge conflicts need to be solved in a case by case basis. What I will show you is how I would solve it with fugitive. The example provided is to get you familiar with the relevant commands.</blockquote><p>First we need to trigger the merge conflict, since this is about integration with fugitive let’s do it all in vim. Run :G merge feature to trigger the merge conflict and run :Gvdiffsplit! to open a three way split.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rDWB8ArOOm5weYJ3Tq4Ywg.png" /></figure><ol><li>The window on the left is the target branch in this case it is called “master”.</li><li>The window in the middle is the working copy with familiar merge conflict prompts.</li><li>The window on the right is the branch being merged into the target branch, master in this case. I named it “B”.</li></ol><p>I want to include changes from both, so, I’ll need to see what my working copy would look like if I applied changes from both branches. Use the :diffget command for this process. This is a very important command and it is simple to use.</p><p>:diffget will apply the changes of <em>only</em> the selected branch onto the working copy. To apply the changes of <em>only</em> the master branch you need to know the name of the buffer. The target branch will have //2 in its name and the branch merging into the target branch will have //3 in its name.</p><p>Use tab complete for the :diffget commad to select the appropriate buffer. Run :buffer and a window will display the names of open buffers.</p><p>First let’s take a look at the changes applied from master.</p><pre># README<br><br>This is for the medium article. I&#39;ll put some random facts here :D  <br>1. Vim fugitive is made by Tim Pope. A very popular and well known plugin author.<br>2. I&#39;ve used Neovim for about two years but have only started to really get to know it this year</pre><p>Now let’s inspect the changes from “B”. The buffer for branch “B” will have //3 in the same so run the same command with the appropriate buffer.</p><pre># README<br><br>While unrelated this line is for merge conflicts to keep things interesting.<br>1. I started programming in the early 2020 around when covid hit my country<br>as I had nothing better to do during quarantine.<br>2. This is from branch &quot;B&quot; :D</pre><p>The next step is identifying changes.</p><ol><li>The sentence before the bullet points has changed.</li><li>The bullet points have also changed.</li></ol><p>The next logical step would be to find out what I want to keep.</p><ol><li>I don’t like either sentence, I’ll change it to “Here are some random facts.”</li><li>I want all the facts from the bullet points minus the “This is from” line from both.</li></ol><p>Now that you know what you want you need to apply to changes from either branch. In my case I used diffget to apply the changes of “B”.</p><pre># README<br><br>While unrelated this line is for merge conflicts to keep things interesting.<br>1. I started programming in the early 2020 around when covid hit my country<br>as I had nothing better to do during quarantine.<br>2. This is from branch &quot;B&quot; :D</pre><p>Now, I want the remaining two points. From “master” which means I’ll need to get to buffer which shows the contents of “master” and copy the two bullet points over, number them properly and remove the “this is from” line.</p><pre># README<br><br>While unrelated this line is for merge conflicts to keep things interesting.<br>1. Vim fugitive is made by Tim Pope. A very popular and well known plugin author.<br>2. I&#39;ve used Neovim for about two years but have only started to really get to know it this year<br>3. I started programming in the early 2020 around when covid hit my country as I had nothing better to do during quarantine.</pre><p>Happy with the changes, I save the file and commit the changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb5f4e205e8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Turning Neovim into an IDE with as little plugins (and setup) as possible.]]></title>
            <link>https://yapjiahong2003.medium.com/turning-neovim-into-an-ide-with-as-little-plugins-and-setup-as-possible-95b78dc75bb4?source=rss-83dbc73d509a------2</link>
            <guid isPermaLink="false">https://medium.com/p/95b78dc75bb4</guid>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[neovim]]></category>
            <category><![CDATA[nvim]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[configuration]]></category>
            <dc:creator><![CDATA[Yap Jia Hong]]></dc:creator>
            <pubDate>Fri, 27 Jan 2023 01:19:34 GMT</pubDate>
            <atom:updated>2023-02-04T13:38:15.907Z</atom:updated>
            <content:encoded><![CDATA[<p>When you’re working in Visual Studio or Visual Studio Code (which isn’t technically an IDE), or JetBrains it has everything setup for you. You don’t need to download anything special. You download the app itself, you open, you code. When moving to Neovim or vim you’ll notice you need to learn how to configure a plugin with either Lua (Neovim only) or Vimscript. A plugin may be written in either one which means plugin authors may provide configuration examples of their plugin in either language which means you’ll need to learn both to some extent, although more recent plugins use Lua now. Which is why I wrote this article, I want to provide a list of plugins that will require minimal setup to use. So that you won’t need to waste time configuring this or that. You install, you code.</p><blockquote>It should be made clear this is not an article about how to configure neovim or vim with lua. But, I will cover the bare minimum required. The purpose of this article is to tell you what plugins to install, a large majority of suggested plugins will work out of the box. If you’d like to learn how to configure neovim with Vimscript or Lua I’ll consider writing an article about it if there are enough requests for one, however, I highly suggest <a href="https://vonheikemen.github.io/devlog/tools/configuring-neovim-using-lua/">this</a> article as it does a great job at providing an introduction.</blockquote><p>So, let’s talk about the biggest feature of an IDE has. LSP and autocomplete. For those that don’t know. There is a difference between autocomplete and LSP, the main one is that auto complete creates a pop-up that lets you choose words most similar to the one your typing. LSP is the one responsible for showing documentation and functions, without it you’ll just have a very fancy text editor. LSP is what you really want, it does symbol searching which means finding function references, where variables are used, etc., and go to definition. Armed with that information, let’s get into the meat and bones of this article.</p><h3>Notes on configuration</h3><p>This applies to both vim and neovim. If you’re new to vim or neovim here’s a few quick tips to get things started. If you’re already familiar with configuration then feel free to skip this section.</p><ol><li>When configuring neovim or vim, after changes are made you’ll need to use the <strong>so % </strong>command for the changes to take affect, this is called sourcing. Commands are started by typing “:” then the command name. In this case :so%.</li><li>Your configuration file is called <strong>.vimrc </strong>(for<strong> </strong>vim) or <strong>init.vim</strong> (for neovim) will live in different locations depending on your operating system. It is important to find out where your configuration file will be at. Please refer to this table from an <a href="https://vi.stackexchange.com/a/12596">SO</a> answer by user <a href="https://vi.stackexchange.com/users/15/jamessan">jamessan</a>. If the file or directory doesn’t exist, create it.</li></ol><pre>OS         | Vim        | nvim<br>-----------|------------|---------------------<br>Windows    | ~/vimfiles | ~/AppData/Local/nvim<br>*nix/macOS | ~/.vim     | ~/.config/nvim</pre><p>3. This applies to neovim only. All lua files will be placed in a folder called “lua” in the same folder where your neovim config file will be at.</p><pre>.<br><br>├── init.vim &lt;-- this is the config file<br>├── lua<br>│  ├── calc.lua<br>│  ├── custom.lua<br>│  ├── dash.lua<br>│  ├── keymaps.lua<br>│  ├── packages.lua<br>│  ├── plugins.lua<br>│  ├── scratchpad.lua<br>│  └── settings.lua<br>├── plugin<br>│  └── packer_compiled.lua</pre><p>For example this is what my nvim directory looks like (with other files removed), all of my lua files are inside the lua folder.</p><p>4. Your lua files will <strong>not</strong> be included in your configurations automatically. They must be explicitly imported. If for example, I want to include the configurations made in <strong>dash.lua </strong>inside <strong>init.vim</strong> I must have the line <strong>lua require(‘dash’)</strong>. It is important that there is no file extension.</p><pre>&quot;Lua<br>lua require(&#39;dash&#39;)<br>lua require(&#39;settings&#39;)<br>lua require(&#39;keymaps&#39;)<br>lua require(&#39;plugins&#39;)<br>lua require(&#39;packages&#39;)<br>lua require(&#39;custom&#39;)</pre><p>I have this at the bottom of my <strong>init.vim</strong> file.</p><h3>Installing plugins</h3><p>You need to install a plugin using a plugin manager. There are many different kinds but I suggest <a href="https://github.com/wbthomason/packer.nvim">packer</a>. Refer to the <a href="https://github.com/wbthomason/packer.nvim#quickstart">quickstart</a> section to have it installed, it is a simple process. After it has been installed, you’ll need to use it and packer is configured using Lua, so, you’ll need to create a file which can be called anything but for the purposes of this article it will be <strong>packages.lua</strong>. I’ve also marked optional plugins which are not required but are nice to have.</p><p>Then paste the following inside <strong>packages.lua. </strong>Since it is a lua file, remember to keep the file inside of the lua folder.</p><pre>vim.cmd [[packadd packer.nvim]]<br><br>return require(&#39;packer&#39;).startup(function(use)<br>  -- Packer can manage itself<br> use &#39;wbthomason/packer.nvim&#39;<br> use {&#39;neoclide/coc.nvim&#39;, branch = &#39;release&#39;}<br> use &#39;https://github.com/tpope/vim-commentary&#39; -- optional<br><br><br> -- git integration (optional)<br> use &#39;https://github.com/lewis6991/gitsigns.nvim&#39;<br> use &#39;https://github.com/tpope/vim-fugitive&#39;<br><br><br> -- Telescope - file browsing<br> use &#39;nvim-lua/popup.nvim&#39;<br> use &#39;nvim-lua/plenary.nvim&#39;<br> use &#39;nvim-telescope/telescope.nvim&#39;<br>end)</pre><p>The plugins have not been installed yet. To install plugins make sure you source the file then run :<strong>PackerInstall</strong>, a window the the left will open and begin installing plugins. To update plugins run <strong>:PackerUpdate.</strong></p><p>Now to explain what each plugin does.</p><blockquote>To clarify I will tell you what plugins you should install, as for how to use them I will not be covering that. As that would add unnecessary bloat to the article, furhtermore, learning how to use a plugin from the repository itself would be much more effective. If you’re worried about documentation, don’t. The authors are all extremely verbose which is a good thing.</blockquote><ol><li><a href="https://github.com/neoclide/coc.nvim">coc.nvim</a> is for autocomplete and LSP. The autocomplete will work out of the box, the LSP will require minor setup. You’ll need to install it and to do that refer to <a href="https://github.com/neoclide/coc.nvim/wiki/Language-servers#adaspark">this</a> page on the repository and follow the links.</li><li><a href="https://github.com/tpope/vim-commentary">vim-commentary</a> is to comment out multiple lines of code at once.</li><li>gitsigns.nvim will provide git symbols the green and yellow lines among other things when editing. Will work out of the box, no setup necessary.</li><li><a href="https://github.com/tpope/vim-fugitive">vim-fugitive</a> is a plugin for git integration within neovim. So, you don’t have to leave neovim and re-enter it.</li><li>popup.nvim and plenary.nvim are required by telescope.nvim.</li><li><a href="https://github.com/nvim-telescope/telescope.nvim">telescope.nvim</a> is a fuzzy finder over a list but has other functionality. the main purpose of telescope is for switching between files. It is highly extensible and has many plugins to support telescope’s integration with other tools. There exists an extension for coc.nvim and it is fantastic.</li></ol><p>All of the plugins listed have reasonable defaults and require no configuration. Except for coc.nvim, even so, the only “configuration” is finding and installing the appropriate language servers which doesn’t take long.</p><p>It is highly recommended that you do in fact look through how to use each plugin in detail. As you will learn how to utlize each of them to their maximum potential. However, this should be done only after you’ve gotten comfortable with using the plugin and have been using it consistently. As there’s no point in investing so much time into something you won’t be using in a while. The plugins listed above are ones that I have used on a daily basis for years and for me taking the time to sift through documentation is an excellent investment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95b78dc75bb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing a basic REST API with Flask and Flask Restful (A flask extension) in Python]]></title>
            <link>https://yapjiahong2003.medium.com/writing-a-basic-rest-api-with-flask-and-flask-restful-a-flask-extension-in-python-24288d61902?source=rss-83dbc73d509a------2</link>
            <guid isPermaLink="false">https://medium.com/p/24288d61902</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[flask-restful]]></category>
            <dc:creator><![CDATA[Yap Jia Hong]]></dc:creator>
            <pubDate>Thu, 11 Feb 2021 10:54:01 GMT</pubDate>
            <atom:updated>2021-02-11T10:54:01.413Z</atom:updated>
            <content:encoded><![CDATA[<p>I won’t be explaining what an API or what a REST api is but here is an amazing explanation by <a href="https://www.craigdennis.me/">Craigs Dennis</a>:</p><p>What is an API:</p><blockquote>Before we begin, let’s talk about what an API is, API stands for application programming interface, an API abstracts away at an interface making things simple, an example is a radio. You know how it works, the volume dial either turns the volume up or down. Do you know how it works? Probably not, me neither. But you know how to operate it. And that is an API.</blockquote><p>What a REST API is (also by Craigs Dennis, and paraphrased):</p><blockquote>REST api is. REST stands for Representational state transfer. REST isn’t a new HTTP protocol, but rather a set of rules that the API must follow to be considered RESTful.</blockquote><p>rules found in <a href="https://en.wikipedia.org/wiki/Representational_state_transfer#Architectural_constraints">this wikipedia page</a>.</p><h3>Prerequisites</h3><p>Installs:</p><ul><li>Flask</li><li>Flask restful</li></ul><p>Knowledge:</p><ul><li>Python, and basics of Python classes</li></ul><p>Next create a python file, call it whatever you want. In my case I’ll call it main.py. First we will create a simple GET request.</p><pre>from flask import Flask<br>from flask_restful import Resource, Api, abort<br><br>app = Flask(__name__)<br>api = Api(app)<br><br># Create an in memory list of books<br>books = {1: {&quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;, &quot;author&quot;: &quot;J.K. Rowling&quot;}}<br><br>class Book(Resource):<br>  def get(self, ID):<br>    if ID not in books:<br>            abort(404, message=f&quot;Book with id &#39;{ID}&#39; not found.&quot;)<br>    return books[ID]<br><br>api.add_resource(Book, &quot;/book/&lt;int:ID&gt;&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>  app.run(debug=True)</pre><p>We first import everything that is necessary in the first two lines. Then instantiate the app, and create an api by creating an instance of the Api class and pass in the instantiated Flask app.</p><p>Then we have to expose an endpoint. With the add_resource() method available via the api instance. Pass in the Book class, and the path to the api. Now let me explain /book/&lt;int:ID&gt;. That argument denotes the url route, in order to access the data. &lt;int:ID&gt; is the parameter, meaning it accepts one <strong>required </strong>parameter that accepts an integer, and is called ID (if you set the variable id in lower case it’s a built-in function). It is worth noting that whatever parameters you pass in the url route, the parameters <strong>must </strong>be reflected in it’s appropriate function. For example: if your path is /book/&lt;string:author&gt;/&lt;int:price&gt;, in your respective function, author and price must be in it like so:</p><pre>get(author, price):<br>    # code here</pre><p>And finally when you run the python file it starts the app in debug mode. It is <strong>imperative </strong>that you leave debug equal to False, only do this during <strong>testing</strong>. As error messages will be available for viewing, potentially <strong>leaking </strong>very sensitive information.</p><p>Now run the file in the terminal, and it should tell you where it is hosted at (most likely 127.0.0.1:5000/ which is localhost, sometimes it’s your IPv4 address in my case it’s my IPv4 address so I censored it)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*_sEK-UJ5VjIOE-3PRQL80A.png" /><figcaption>What the output will look like.</figcaption></figure><p>Go to that link and you will see an error message, that’s because there is no webpage, go ahead and add this to the end of the url book/1 The url should now look like &lt;your-ip&gt;:5000/book/1 hit enter, and you’ll see this on your screen</p><pre>{<br>    &quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;, <br>    &quot;author&quot;: &quot;J.K. Rowling&quot;<br>}</pre><p>It’s worth nothing that if you try and find the book with an id that doesn’t exist it will abort with the abort function, and give an error message. Indicating that the book with that id does not exist. I won’t talk more about the abort function, but for more info read it <a href="https://flask-restful.readthedocs.io/en/latest/api.html?highlight=abort#flask_restful.abort">here</a> from the official docs.</p><p>The returned data is in JSON. And a convention is to send and accept data in the form of JSON as it is now the de facto medium of sharing data for REST APIs, which is denoted by two {}. Now I am going to introduce you to the concept of Create, Read, Update, And Delete (CRUD) operations. Something a REST API <strong>must</strong> be able to do, at least one of. In our case we can read data with a GET request, which fulfills the condition of at least on CRUD operation. Next we will go ahead, and create the create , update , and delete operations. Now each CRUD operation has it’s respective HTTP request that reflects it:</p><ol><li>GET reflects the read operation,</li><li>PUT reflects the create operation,</li><li>POST reflects the update operation,</li><li>and finally, the DELETE request reflects the delete operation.</li></ol><p>So for a quick recap, so far we’ve learnt how to:</p><ol><li>Create an API endpoint, and expose it (Meaning to let it be used by external parties).</li><li>Learn what JSON is, and it’s uses.</li><li>What CRUD is, what it stands for. And which HTTP requests reflects that.</li></ol><p>Now we will create the Create operation, otherwise also known as a PUT request.</p><p>Extend api.py like so:</p><pre>from flask import Flask<br>from flask_restful import Resource, Api, abort</pre><pre>app = Flask(__name__)<br>api = Api(app)</pre><pre>books = {1: {&quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;, &quot;author&quot;: &quot;J.K. Rowling&quot;}}</pre><pre>class Book(Resource):<br>    def get(self, ID):<br>        return books[ID]</pre><pre>def put(self, ID, title, author):<br>        if ID in books:<br>            abort(403, message = f&quot;The book with the id of &#39;{ID}&#39; already exists.&quot;)</pre><pre>books[ID] = {&quot;name&quot;: title, &quot;author&quot;: author}</pre><pre>return books</pre><pre>api.add_resource(Book, &quot;/book/&lt;int:ID&gt;&quot;, &quot;/book/&lt;int:ID&gt;/&lt;string:title&gt;/&lt;string:author&gt;&quot;)</pre><pre>if __name__ == &quot;__main__&quot;:<br>  app.run(debug=True)</pre><p>A new function put is made, that will be responsible with creating a new entry. And in the add_resource() function, add in a new route as shown above. At this point you will need to download a tool called <a href="https://duckduckgo.com/?q=postman+download&amp;t=newext&amp;atb=v252-1&amp;ia=web">Postman</a> (it’s free), you can use cURL but I will not cover it’s equivalent usage, as I do not know how to use cURL. Remember, we added new parameters so that must be reflected in the put method.</p><p>Postman is a very advanced tool to test an api, go ahead and download it, then use the shortcut CTRL+N then select “new request” in the new tab. Name it whatever you want, create a new collection, then click save. Next find the word “GET” and click it, a drop down box will appear, and select “PUT”. And paste in the url where the your API is hosted on in the field where you can see the words “Enter request URL”, followed by /book/2/Doctor Who and the Pirate Plane/Douglas Adams , don’t worry about the spaces, Postman will convert it to “%20” automatically which represents a space. Click send and this should be your output</p><pre>{</pre><pre>    &quot;1&quot;: {</pre><pre>        &quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;,</pre><pre>        &quot;author&quot;: &quot;J.K. Rowling&quot;</pre><pre>        },</pre><pre>    &quot;2&quot;: {</pre><pre>        &quot;name&quot;: &quot;Doctor Who and the Pirate Planet&quot;,</pre><pre>        &quot;author&quot;: &quot;Douglas Adams&quot;</pre><pre>        }</pre><pre>}</pre><p>Go ahead and create a new GET request, and place “2” in the url like so /book/2 and you will get:</p><pre>{</pre><pre>    &quot;name&quot;: &quot;Doctor Who and the Pirate Planet&quot;,</pre><pre>    &quot;author&quot;: &quot;Douglas Adams&quot;</pre><pre>}</pre><p>And with that we are done with the Create part of CRUD. Another note is that these values are stored <strong>in memory</strong>, stop the api, and you’ll need to repeat your steps as are deleted from memory, or alternatively, update the in memory dictionary.</p><p>Now for update:</p><pre>from flask import Flask<br>from flask_restful import Resource, Api, abort</pre><pre>app = Flask(__name__)<br>api = Api(app)</pre><pre># Create an in memory list of books<br>books = {1: {&quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;, &quot;author&quot;: &quot;J.K. Rowling&quot;}}</pre><pre>class Book(Resource):<br>    def get(self, ID):<br>        return books[ID]</pre><pre>def put(self, ID, title, author):<br>        if ID in books:<br>            abort(403, message = f&quot;The book with the id of &#39;{ID}&#39; already exists.&quot;)</pre><pre>books[ID] = {&quot;name&quot;: title, &quot;author&quot;: author}</pre><pre>return books</pre><pre>def post(self, ID, title, author):<br>        if ID not in books:<br>            abort(404, message = f&quot;Book with id &#39;{ID}&#39; does not exist. And therefore, cannot be modified.&quot;)</pre><pre>books[ID] = {&quot;name&quot;: title, &quot;author&quot;: author}</pre><pre>return books</pre><pre>api.add_resource(Book, &quot;/book/&lt;int:ID&gt;&quot;, &quot;/book/&lt;int:ID&gt;/&lt;string:title&gt;/&lt;string:author&gt;&quot;)</pre><pre>if __name__ == &quot;__main__&quot;:<br>  app.run(debug=True)</pre><p>Alright this is where it may get confusing, we have 3 functions within our class but we only have 2 routes. The reason is because the post function shares the same arguments as the put function, which is why they both share routes. And the code is practically identical to the put function.</p><p>Make an update request, and change the doctor who entry to the Da Vinci Code by author Dan Brown. If you decided to add a new entry that’s different. Reference your appropriate id. And your output should be similar to this:</p><pre>{</pre><pre>    &quot;1&quot;: {</pre><pre>        &quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;,</pre><pre>        &quot;author&quot;: &quot;J.K. Rowling&quot;</pre><pre>    },</pre><pre>    &quot;2&quot;: {</pre><pre>        &quot;name&quot;: &quot;The Da vinci Code&quot;,</pre><pre>        &quot;author&quot;: &quot;Dan Brown&quot;</pre><pre>    }</pre><pre>}</pre><p>Now we have covered three-fourths of our CRUD acronym. Now finally for our final operation: Delete with the delete request. Now extend the book class like so.</p><pre>from flask import Flask<br>from flask_restful import Resource, Api, abort</pre><pre>app = Flask(__name__)<br>api = Api(app)</pre><pre># Create an in memory list of books<br>books = {1: {&quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;, &quot;author&quot;: &quot;J.K. Rowling&quot;}}</pre><pre>class Book(Resource):<br>    def get(self, ID):<br>        return books[ID]</pre><pre>def put(self, ID, title, author):<br>        if ID in books:<br>            abort(403, message = f&quot;The book with the id of &#39;{ID}&#39; already exists.&quot;)</pre><pre>books[ID] = {&quot;name&quot;: title, &quot;author&quot;: author}</pre><pre>return books</pre><pre>def post(self, ID, title, author):<br>        if ID not in books:<br>            abort(404, message = f&quot;Book with id &#39;{ID}&#39; does not exist. And therefore, cannot be modified.&quot;)</pre><pre>books[ID] = {&quot;name&quot;: title, &quot;author&quot;: author}</pre><pre>return books</pre><pre>def delete(self, ID):<br>    if ID not in books:<br>            abort(404, message = f&quot;Book with id &#39;{ID}&#39; does not exist. And therefore, cannot be deleted.&quot;)</pre><pre>    del books[ID]</pre><pre>    return books</pre><pre>api.add_resource(Book, &quot;/book/&lt;int:ID&gt;&quot;, &quot;/book/&lt;int:ID&gt;/&lt;string:title&gt;/&lt;string:author&gt;&quot;)</pre><pre>if __name__ == &quot;__main__&quot;:<br>  app.run(debug=True)</pre><p>With that done, go ahead and make a delete request to /book/2 or the appropriate ID and that entry will be deleted, then it will return the list of remaining books, to show you that the edit was in fact, successful.</p><pre>{<br>    &quot;name&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;, <br>    &quot;author&quot;: &quot;J.K. Rowling&quot;<br>}</pre><p>The same reason as to why there are only 2 routes, is the same reason as the above given reason. The DELETE request shares the same number of arguments as the GET request, which is why you do not need to include another route.</p><p>And that means you can create a fully functional REST API with basic CRUD operations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24288d61902" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Heroku to keep your Python scripts running 24/7]]></title>
            <link>https://yapjiahong2003.medium.com/using-heroku-to-keep-your-python-scripts-running-24-7-f4ea3d894027?source=rss-83dbc73d509a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4ea3d894027</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Yap Jia Hong]]></dc:creator>
            <pubDate>Sun, 13 Sep 2020 09:24:15 GMT</pubDate>
            <atom:updated>2020-09-13T09:24:15.585Z</atom:updated>
            <content:encoded><![CDATA[<h3>First let’s talk about what Heroku is</h3><p>Heroku is a cloud platform as a service supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language, but now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go.</p><p>Source: <a href="https://en.wikipedia.org/wiki/Heroku">Wikipedia</a></p><h3>What it can be used for</h3><p>It can be used to host scripts in the above mentioned supported languages, but this article will be focused on Python instead of the other languages. What Heroku can do is your code running 24/7. You may ask what you would use this for.</p><p>I use this to host my Discord bot — Gaiden. You can use Heroku to host other scripts with different functionality. Such as a script to scrape the web for information periodically, and give you updates on whatever it is that you need.</p><h3>Prerequisites needed before beginning the use of Heroku</h3><p>You will need 3 things:</p><ol><li>A Heroku account (<a href="https://signup.heroku.com/login">Sign-up here</a>)</li><li>Git, which is a CLI (<a href="https://git-scm.com/downloads">Install here</a>)</li><li>Create a new app, by clicking on the new icon at the top right.</li><li>Heroku CLI, can be installed after creating your app.</li></ol><p>After signing up, and installing Git. You will need to make a new app, then navigate to the <strong>Deploy </strong>tab scroll until you find <strong>Deployment method</strong>, and click on <strong>Heroku Git</strong>, then install Heroku Git by clicking on the hyperlink and installing the installer. Next follow these steps, do not follow the steps shown in the website. Because I ran into a lot of problems while doing that.</p><h3>An example: hosting a discord bot with Heroku</h3><ol><li>First, navigate to the directory where your python script is located.<br>Open the CLI you usually use in that directory, and do the following command: <strong>pip freeze</strong></li><li>Copy everything in the output and make a file called <strong>requirements </strong>and make sure it’s file extension is <strong>txt.</strong></li><li>Paste the output from <strong>pip freeze</strong>, then add this at the very top of the file “<strong>git+</strong><a href="https://github.com/Rapptz/discord.py"><strong>https://github.com/Rapptz/discord.py</strong></a>” (You do not need this line, if you are not going to host a discord bot. But follow all the other steps) without the quotes. Then save it.</li><li>Next you must go into your CLI and use a command to make a new file called <strong>Procfile </strong>with no file extension. In windows powershell, the command is<strong> new-item Procfile</strong></li><li>Within Procfile enter the following:<br><strong>worker: python (name of script.py)</strong> The name of your file and extension will be inside the brackets. Remove the brackets of course.</li><li>Enter the following commands in order:</li></ol><p>heroku login (When you enter that command, after a few seconds your browser will open and ask for you to login, go ahead and do that).</p><p>git init (Wait 2–3 seconds after you logged in, before inputting this command).</p><p>git add .<br>There may or may not be output, it depends if you have already done this before, or you are writing the code inside of a repository.</p><p>git commit -am “c” (You can write anything between the quotes, it doesn’t matter but whenever you commit you have to have an accompanying message).</p><p>git push heroku master</p><p>After that last command you will see a bunch of output, and you will need to wait for the process to finish. And now for a few more commands before you can finally run your discord bot/script.</p><p>heroku run python3 (script_name.py)</p><p>Then open another instance of your CLI then run: heroku logs -a (name-of-app)</p><p>There will be output, and if you have a message that runs on startup you’ll see the message to confirm that your script is running through Heroku. Next go to your app page, and head over to Resources, and there should be a tab that’s called worker, click on the pencil icon and turn it on, and click confirm.</p><p>In the instance of your CLI where you ran the heroku logs command you will see some more output, and your startup message. This second startup will indicate that your script/bot will be running 24/7.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4ea3d894027" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>