Ket's Site

Welcome to my little corner of the internet. It is essentially just a microblog.

If you wish to follow my ramblings you can sub via Atom, RSS or Mastodon.

All articles

  1. Software Recommendations

    Occasionally I get asked for advice on the best software to use for various tasks, and while I can’t claim to know what is objectively the best software to use for every scenario I can at least provide some information on software I like to use for various daily tasks and a brief description on why I use it.

    Web Browser - Firefox

    Firefox Screenshot Site: mozilla.org

    Cost: Free

    License: Mozilla Public License 2.0

    When the choice of major browsers comes between something primarily developed by people trying to cram advertising into every inch of your life, and something primarily developed by a foundation who's guiding principles promote an "open and accessible" internet where "Individuals’ security and privacy ... are fundamental and must not be treated as optional" that "must enrich the lives of individual human beings" the choice to me becomes very easy.

    Firefox's configuration options are second to none, there is no shortage of plugins for those that like to enhance their browsing experience. I recommend that all Firefox users install the EFF’s “HTTPS Everywhere” plugin to ensure that your connections are always encrypted where possible and also the “Privacy Badger” plugin, which adds extra protection against trackers that appear all over the net.

    People like to compare the speed of browsers to decide which to use, but with first place changing frequently between the various options and the differences in speeds between browsers being marginal it isn't much to go by, particularly when these tests probably don't reflect well in a real use case with the browser set up just how you like it.

    I have heard concerns that web applications may not work correctly or look right in Firefox, but I am happy to report that I have never had any issues of that nature.

    Email Client - Thunderbird

    Site: thunderbird.net

    Cost: Free

    License: Mozilla Public License 2.0

    Though I usually use neomutt to keep an eye on my inboxes Thunderbird is a great option for those looking for a fully featured mail client. Thunderbird is developed by Mozilla and is packed with useful tools. In particular I am very fond of its unified mailbox, its ability to quickly search through and sort thousands of emails with ease and its intuitive user interface.

    Text editor & IDE - Vim

    Site: vim.org

    Cost: Free

    License: Vim License

    My development environment is something I spend a lot of time in, so it is important for it to be streamlined and efficient. Over the years I have experimented with a lot of IDEs and text editors. The likes of Eclipse and Netbeans are great for their out of the box features, but I have had issues with stability when it comes to extending them to support more. Editors like Atom and vscode are a total mess and seem to be far too focussed on flashy features that are ultimately useless, and are ultimately overkill considering the simplicity of their MVPs. Vim is just right.

    For new users Vim can be pretty daunting. Before Vim became my primary editor I tried using it on many occasions, usually giving up after having difficulty with the most basic of tasks like editing a document and saving it, however if you put in just a few minutes to learn how to use it you won’t regret it. For the most basic usage you can edit your file by hitting “i” to go into “insert mode”, hit escape to exit out of insert mode, use “:w” to save (or “write”) your file, and use “:q” to quit Vim. Past that I recommend looking up how to use features such as find and replace, tile management etc as and when you need them. When I committed to using Vim I learned most of the commands and shortcuts I need in day to day development within a couple of days or so, and after that steep leaning curve my development has never been more efficient.

    On the surface Vim is just a simple, terminal based editor but it is capable of big things. I mostly Vim for C++, PHP, and Python development, and it has great syntax highlighting, code completion for all of those once you install the respective plugins required. For C and C++ in particular Vim has great support for Makefiles and GDB, highlighting errors when they occur and allowing you to set breakpoints and other tags for debugging.

    Vim is highly configurable so if you don’t like something it is likely you can change it. If there is something you are missing plugins are also very easy to add.

    Music Player - cmus

    Site: cmus.github.io

    Cost: Free

    License: GPL-2.0

    When I am using my computer I pretty much always have a music player open, so it really doesn’t make much sense to use a music player that uses a lot of system resources; luckily cmus is a nice, capable music player that has a low impact on my system.

    Cmus supports all the major audio formats, online radio streams and even support for cue files, the latter being a feature that I have found difficulty finding in even the biggest audio players.

    Cmus runs in the terminal and may be a little daunting for new users but there really isn’t a lot to learn. For the most basic usage, once you are in cmus you can hit ‘5’ to access the file browser, from which you can play files directly or import them into cmus using the ‘a’ key. Once imported you can hit ‘1’ to view your library where you can use the arrow keys to select an artist, hit ‘tab’ to browse albums and songs by that artist and press ‘enter’ to play the album or song selected. Hitting ‘c’ will pause and play the track, the ‘s’ key will toggle shuffle mode, the ‘r’ key will toggle repeat mode and the ‘plus’ and ‘minus’ keys will set the playback volume. When you are all done you can hit ‘q’ to quit cmus.

    General Media Player - VLC

    Site: videolan.org

    Cost: Free

    License: GPL-2

    VLC is a great choice for video and audio playback. It is probably one of the largest media players out there so its development community is very active, it has out of the box support for all major video formats and can read media disks and subtitle files and with no problems. Though VLC does support playback for media files on the local file system it really comes into its own with its capabilities of media playback over the network, supporting the likes of UPnP and Youtube and can even be used to stream your desktop or movies to other systems on the local network or over the internet. VLC has many options when it comes to configuration and can even be reskinned to make it look any way you like.

    Image editing - GIMP

    Site: gimp.org

    Cost: Free

    License: GPL-3

    Though its name is always sure to give Tarantino fans a little giggle the GNU Image Manipulation Program is a very powerful image editor, boasting many features people think are unique to non-free image editors like Adobe Photoshop. GIMP is great for basic tasks such as colour correction on photos and basic paint-style drawing right up to cutting objects or people out of photos entirely, editing blemishes from photos and scripting the generation of effects and advanced patterns. GIMP has great cross platform compatibility and another highly active development community.

    Office Suite - LibreOffice

    Site: libreoffice.org

    Cost: Free

    License: Mozilla Public License 2.0

    Admittedly there aren’t a lot of options when it comes to full ‘office’ software packages capable of being a replacement to the likes of Microsoft office in the free software world, however LibreOffice, (a fork of OpenOffice) is a great, free replacement with no shortage of useful features across its various tools.

    LibreOffice comes with support for modern Microsoft Office file formats such as docx Word files, xlsx Excel files and pptx PowerPoint files to name a few, so if your colleges, tutors or associates aren’t using LibreOffice there is a very good chance you will still be able to access and edit any documents they send to you.

    If you are switching over from Microsoft Office you may be happy to find LibreOffice has a nice, clean and easy to use interface that is much more like Microsoft Office 2003, before they introduced those ugly, unintuitive “ribbon” menus in Office 2007.

    Another really nice thing about LibreOffice is the built in support for Google Drive and One Drive, meaning that if you, or anybody in your team uses those services you can edit those files directly from LibreOffice rather than having to open up your browser and download files or edit them in their respective browser applications.

    GNU/Linux Distribution - Debian

    Site: debian.org

    Cost: Free

    License: Various, see debian.org/legal/licenses/

    There is plenty of choice when it comes to GNU/Linux distribution, and different distributions fit the specific needs of different users. I use Debian for its stability, making it perfect for use on both my servers and my local system. This stability does come with the shortcoming of packages not always having the latest features, but in my my opinion that isn’t much of a detrimental compromise, and in cases where I would rather have the latest features in a program the option to get compatible binaries straight from the software developer or build binaries from source is always available. Debian’s development community is again a very active one, with a healthy focus on software freedom, transparency of problems and a firm stance on anti discrimination. See debian.org/social_contract. Unlike many distributions Debian isn’t trying to sell you something so its also comforting to know the interests of its developers aligns with that of its casual users.

    At installation Debian offers a “minimal” image which allows you to select which packages you want on your system yourself without the bloatware included with many distributions. As a result of this minimal setup being available my system idles using around just 100MB of memory leaving me with plenty of free memory for heavy tasks; a very nice statistic when a lot of modern systems now use multiple gigs of memory when not doing anything.

    Window manager - I3

    Site: i3wm.org

    Cost: Free

    License: BSD

    I3 is a great window manager for those looking to get the most out of their screen space. Tiling window managers are great for displaying what you want to see in a clutter free way and I3’s configuration is perfect for those that want to customise the look of every corner of their window manager without having to look much further than a couple of config files.


  2. Grip for Markdown Previews with Vim

    Just a little something I have found useful... Rather than using a plugin to provide Markdown previews when editing documentation in Vim, Grip is a great little tool to display previews while cutting out the middle man and keeping Vim light. Grip is available in Debian's apt repositories, simply install with: sudo apt install grip

    You can then view your preview by running grip [path] [port] or grip some/path/README.md 1234

    Then simply go to localhost:port (or localhost:1234) in your web browser to view the preview.


  3. News Bot

    Software Development > News Bot

    Before we we start I would like to make it clear that this is not meant as a tutorial, and is simply an explanation to why and how I did things in this little weekend project as a method of practice documenting my work. That said, if it is in any way useful to you as an example project for something similar, I am happy to answer any questions you may have.

    This entire article and the images included in it are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. The example project included alongside this project is licensed under a GNU General Public License version 3 or later.

    The full source for this project can be found on GitHub.

    As a small weekend project I decided to create a 'bot' that checks news sites for articles about the climate crisis or other related things and posts them on the news board. Now creating a bot to do these things is easy as pie, and a script could probably be written in fifteen minutes, but rather than having the 'bot' post links to articles straight onto the board I wanted to be able to curate its findings so I can manually filter out topics that aren't closely related to subjects of interest, stub articles that simply contain a sentence or two and don't actually say anything of value, or for any other reason I deem them inappropriate. In theory this is very simple, but it did turn a tiny project into something a lot more extensive. This gave me the following requirements for this project: 1 - It must scan news sites of my choosing for potentially relevant news articles, 2 - It must present them to me in a simple way for curating, 3 - It must post links to approved articles on the forum.

    Before jumping into writing code for this project I had to work out the best way for my bot to post topics on the forums. The first option was to create something that could post topics on the front end of the site. The site runs Joomla as its CMS, and within that runs the Kunena component to provide forums, so my second option would be to create something that could create a topic from within Joomla. The third option was to post topics directly into the site's database. Deciding on the third option for ease I started experimenting with creating topics from within the database. Now unfortunately creating a topic from the database on Kunena isn't as simple as just dropping the topic into the 'topics' table, as without the correct requirements being met topics don't show up at all on the front end. Fair enough considering it was never designed to make posting outside of the front end easy. After some playing around I found the following lengthy procedure to be a successful way of creating topics… Procedure for Posting 1) Collect the following values a) Our thread topic, for example "My Test Topic" b) Our thread text, for example "This is the text in my post...", c) The ID of the board we want to post on, found in the table kunena_categories, d) The ID of the user we want to post as, found in the table kunena_users, e) The name of the user we want to post as, found in the table, kunena_users.

    2) Post the topic, with values a, b and c from above; "INSERT INTO kunena_topics (params, posts, rating, category_id, first_post_userid, last_post_userid, first_post_guest_name, last_post_guest_name, first_post_time, last_post_time, subject, first_post_message, last_post_message) VALUES (\"\", 0, 0, c, d, d, e, e, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), a, b, b);"

    3) Record the ID of the topic just created, we will refer to this as 'f' in this example.

    4) Post the topic in kunena_messages, using the values from above; "INSERT INTO kunena_messages (catid, userid, name, time, thread, subject) VALUES (c, d, e, UNIX_TIMESTAMP(), f, a);"

    5) Record the ID of the row we just inserted into kunena_messages, we will refer to this as 'g'.

    6) Post out message in kunena_messages_text; "INSERT INTO kunena_messages_text (message, mesid) VALUES (a, g);"

    7) Update the row we inserted into kunena_topics in step 2 to provide the required post IDs; "UPDATE in5op_kunena_topics SET first_post_id=g, last_post_id=g WHERE id=f;"

    8) Increment the post count and update the last post IDs in the category table; "UPDATE in5op_kunena_categories SET numTopics=numTopics + 1, numPosts=numPosts + 1, last_topic_id=f, last_post_id=g WHERE id=c;"

    Next I wrote a small script to search for potentially relevant news articles. I decided to write this script in Python as it has simple libraries for just about anything you can think of, and thanks to the main news sites still using RSS feeds, gathering articles together couldn't be easier. The example on this image searches the RSS feeds defined in 'sources' for any articles that include a word or phrase defined in Words of Interest ('wois'), then prints the link in question.

    When executed this script will show something like this...

    Great, so at this point we know how to post the topic from within the database, and we know how we are going to gather news articles. Now we just need to work out how we are going to curate the results from our python script before they are posted on the forums. To manage the results I decided I was going to create an Android app, just because I wanted the experience creating something in Android Studio, rather than just using a webview or working in NDK, both of which I have already spent much more time with. For the script to share its results to the Android App I also needed to create a web service. In this case I felt the quickest thing to do would be to post the Python scripts results to my database then provide them to the app via a PHP script. Once things are approved via the app and PHP script it is then up to the Python script to check the 'approved' posts list and create the corresponding topics on the forums. Now I could have just had the app scan the news sites for results, but I wanted to make it a server side script to ensure it is ran regularly and I don't miss anything. Additionally the PHP script could have posted thing straight to the forums, but I decided it might be best to have a small time window in which I could go back and reject results after I have approved them if I make some error or just decide I don't want to include them.

    So at this point we have 3 different programs. The Python script that searches for news articles, puts them on a database, then checks the database for approved results and posts those to the forums. The PHP script that provides results from the database to our mobile app and updates the status of articles in the database upon request of the app. Finally the Java Android app that displays results to a moderator to be approved or rejected. I have retrospectively created a flow chart for main functions of each of these scripts just to make things nice and clear.

    The Python Script (FLOWCHART [svg][png][dia]) The top portion of our python script is dedicated to configuration. The sources lists RSS feeds to monitor along with the name of the feed provider that we want to use as the prefix for the topic name when we post it to the forums. Initially I was just using the designated values for this from the RSS feeds but it proved to provide a little more messy than I wanted. This way seemed like the most elegant option. ‘wois’ lists words of interest. These are the words or phrases that the script will use to decide if the article should be put put on a list for review. In this example we have a few words I initially chose for testing. Something worth noting is that the first value, ‘eco’ was a poor choice of words in this list, as it is commonly used in words like ‘become’, ‘second’ and ‘recognise’. Thus begins the battle for finding words and phrases that are both quite general in the topic of things you want, but not too general that they start selecting a large amount of unrelated articles. The next part of the script has our database info, and the information posting for the bot, such as my Joomla database prefix, my bot’s username and id and the category ID of the board I want to post things to on Kunena forums. Although this script is very specific and its unlikely that anybody would want to download it and use it as is, I felt it worth storing them at the top here anyway just so that I could keep my values secret without any hassle when pushing the script up to GitHub. After this small section of configuration we jump into the first large part of the script, the part that checks for new articles and adds them to the database. This part of the scripts is pretty self explanatory. For each feed entry we go though each article title iterating though each word of interest. If the word of interest is in the article we check if the link for the article has already been popped onto our article list database, If it hasn’t then we add it. The final part of the script then gets a list of articles from the database where the status is ‘3’, or ‘posted’. We then post them to the forum’s database one by one using the ‘Procedure for Posting’ we listed above. This python script is executed every 3 hours by a cron job.

    Before writing things I came up with a quick list of status and action codes that could be common across the scripts. These codes are as follows: Log status codes: 2 - New to DB 3 - Approved 4 - Rejected 5 - Posted

    Articles list status codes: 2 - Not reviewed 3 - Approved 4 - Rejected 5 - Posted

    Request Types: 0 - Check for unreviewed urls 1 - Test Login 2 - Get unreviewed items 3 - Get approved items 4 - Get rejected items (last 10) 5 - Get posted items (last 10) 8 - Approve Item 9 - Reject Item

    The PHP Script (FLOWCHART [svg][png][dia]) The PHP script has a settings file, ‘llgNewsBotSettings.php’ we keep in a ‘local’ directory that cannot be accessed externally via the web server containing the our database information. The main PHP script is ‘llgNewsBotProvider.php’ that can be found in our ‘www’ directory. This script is called from the mobile app and simply checks that the user has provided valid login details in a json format. Once the login information has been confirmed it then does something depending on the ‘requestType’. The request types are defined in our ‘codes’ list above. Request type 0 is reserved for if I wanted to implement mobile notifications when there are new articles on the list later on. At the current time I deemed in unnecessary as I don’t want more notifications and, somewhat sadly, there are pretty much guaranteed to be a few articles on the climate crisis each day, so if I check once a day I can just sort them then. If I started to forget or articles because infrequent then I would add notifications. Request type 1, “Test Login", is used by the app to check if the authentication is successful when a user logs in with a new username or password or when the app loads. Request types 2, 3, 4 and 5 are used to request a list of articles from the articleList database table by status, each one corresponding to their requested article status. Requests for articles with the status of 4, “Rejected" and 5, “Posted" are limited to 10 items. Request types 8 and 9 are used to update the status of an article in the articleList table. Type 8 updates the status of the item defined by the ‘id’ json field to “Approved", and type 9 updtheates them to “Rejected".

    The Java mobile app globals.java (FLOWCHART [svg][png][dia]) The first class I have is the ‘globals’. This class contains some static variables and functions for creating json objects containing our authentication details, a function for posting our requests to the php script, a function to display alert dialogue and finally the asynchronous class that tests for a successful login that is used in the SplashActivity and LoginActivity.

    SplashActivity.java (FLOWCHART [svg][png][dia]) This is the first activity that loads whenever you open the app. It simply loads the LoginActivity if no password has been saved or calls the ‘testLogin’ from our globals class, switching to the login activity if there are any problems, or switching to the MainActivity in the case of a successful login.

    LoginActivity.java (FLOWCHART [svg][png][dia]) This activity has our login forms on the layout. When it loads it shows any warnings that haven’t been displayed left over from the SplashActibity. When the user presses the “login" button it calls the ‘testLogin’ functions, loading the MainActivity on success, or showing a warning containing the reason for not being successful otherwise.

    MainActivity.java (FLOWCHART [svg][png][dia]) This class is the real guts of the app. The layout for it has a list view and a button. The list is used to display lists of articles and the menu, keeping things very simple. When the activity opens it attempts to load a list of “unreviewed" articles. Articles in the list will be displayed with their ID in the news bot’s database, the title of the article and the URL of the article. If you click on one of these items it will clear the list, then show the article you just clicked on the top and displaying the options for the article below. Clicking on an ‘unreviewed’ article will bring up the options ‘Approve’ or ‘Reject’. Articles with an ‘Approved’ status will show the option ‘Reject’. ‘Rejected’ articles will show just show the ‘Approve’ option. ‘Posted’ articles will not show any options. Once in this view, showing the clicked on item at the top, clicking the item again will open the URL in the phone’s web browser. Clicking on the options will set the articles status to that which you chose. Pressing the menu button lists our menu options in the list view that we use for everything else, from here you can select ‘Unreviewed’, ‘Approved’, ‘Rejected’ and ‘Posted’, each bringing up a list of articles with the status you selected. Finally there is a logout option, that clears the saved username and password then switches to the login activity.


  4. Red Dead Redemption 2 - First Thoughts

    I was a massive fan of Red Dead Redemption and waited patiently for its PC release, alas it never came. After many years it went into the cupboard with my Xbox 360 never to be played again, despite the many happy hours I spent trotting around the dessert and reeking havoc in the town of Armadillo. Needless to say I was very happy to hear Red Dead 2 would be coming to PC, and my sister and brother in law kindly bought it for me last night as a birthday/Christmas gift. My first impressions of the game are very good. The Hateful Eight-esque opening didnt necessarily a bad thing, however if I were to create new saves to mess around on I feel it may be a bit frustrating to have to get though that long opening gameplay before I can cause trouble if there is no way to skip it. I am very happy to see more survival elements in this game and I am sure it will make riding around the map trying to make some money and explore every nook and cranny all the more interesting. I cannot speak for the story yet, however I have liked what I have seen so far. The game also looks amazing and the attention to detail is very cool. Rockstar have consistently been releasing amazing games since GTA 4 and I am sure this will be no exception.

    On a side note, every time I jump into a game like this and have to kill wolves a little piece of my heart breaks. They always look far too much like my dog Freki.


  5. Implementing Tiled Map Editor(TMX) Rotation and Flipping

    Tiled Map Editor, available at www.mapeditor.org is a great FOSS map creation tool for tile based games. The Tiled TMX format is very useful and the maps made in it can be easily brought into any project, either by parsing the TMX/XML files generated by Tiled or by copying the generated layers into your project as (when using C or C++ (For other languages you will have to use the equivalent)) a uint32_t array.

    As described in the Tiled documentation the bits at the end of each 32 bit integer that makes up the map are used to store the 'flipping' of each tile. A tile can be flipped in three ways, those being; horizontally, vertically and diagonally. But how do get rotation and flipping in every possible direction from these three bits?

    We will be using this table as a reference to how each rotation and flip can be achieved in the below example project.

    Example Project

    This example project is written in C++ using SDL2 video library. It simply initialises SDL, loads a tile sheet image and renders our Tiled map until the program is closed.

    First we need to create a map. I have created a simple, single layered map that includes a few images in every possible flip combination.

    We will then be copying the relevant information from out of the TMX Tiled map into the project rather than parsing it.

    The next thing to do before we render our map is to bring the 'flip table' from above into our project.

    Once this is done we can then render the tile as we would any other image in our program. In the case of SDL this is done in the line: SDL_RenderCopyEx(renderer, sheet, &srcRect, &destRect, rotate, &centre, flip);

    After compiling the program we can see that the tiles in our SDL window are in the same positions, flips and rotations as in the Tiled map editor.

    For a more in depth look at how we are implementing this table you can find the full example program on GitHub.

    This entire article and the images included in it are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. The example project included alongside this project are licensed under a MIT License.


  6. List of Completed Games

    Looking at my Steam library I started to forget what I had finished, so below is a list of games where I have completed the main story or task to look back on. I will be updating this same list as I play or remember more, rather than making a new list.

    Games I have completed: Among the Sleep Aperture Tag: The Paint Gun Testing Initiative Battlefield: Bad Company 2 Bioshock Driv3r Duke Nukem Forever The Elder Scrolls: Skyrim event[0] Fallout 4 Fallout: New Vegas From Dust Gone Home Grand Theft Auto IV Gunpoint Half-Life Half-Life 2 Half-Life 2: Episode One Half-Life 2: Episode Two Hard West Hotline Miami Hotline Miami 2: Wrong Number Inside Just Cause 2 Left 4 Dead Left 4 Dead 2 Limbo Little Inferno Lumino City Never Alone (Kisima Ingitchuna) No Time To Explain Octodad: Dadliest Catch Portal Portal 2 Postal 2 Retro City Rampage DX Saints Row 2 Shovel Knight: Treasure Trove South Park: The Stick of Truth Spore S.T.A.L.K.E.R.:Shadow of Chernobyl Stardew Valley Super Win the Game Undertale Wolfenstein: The Old Blood Wolfenstein: The New Order World of Goo


Page 1 / 4 > !>