TIL: How you can add goatcounter to your Hugo blog

TIL: How you can add goatcounter to your Hugo blog In this TIL post, we will go over how you can add Goatcounter to your Hugo Blog. Goatcounter is an open-source privacy-friendly analytics tool, an alternative to Google Analytics. Goatcounter Account This post assumes you have already created a Goatcounter account, more information here. Luckily it is very easy to add Goatcounter to our blog. First, create a new partial HTML file. ...

TIL: You can use Use `yq` to Mass Edit Markdown Files

TIL you can use yq to mass edit markdown files yq yq is a tool similar to jq except it allows you to edit, JSON, XML and YAML. It has a very similar syntax to parse and edit files as jq does. I was recently adding new open graph images to all of my blog posts. After creating these images and storing them next to the post, where the structure looks like: ...

Why I moved from Gatsby to Hugo for this blog?

About This Site This site was built with hugo and the PaperModX Theme (using a fork of a fork at the moment). I decided to go with an existing theme rather than creating my own this time, to one save time but also to give the site a more consistent feel. I am no designer and I felt my last website (v3), really felt like a bunch of different websites thrown together. ...

TIL: You can Hash `None` in Python? What?

TIL you can hash None in Python Recently I saw some Python code which looked something like: d = { None: "value", "another_key": "another_value", } It had never really occurred to me you could use None (null) as a key to a dictionary before. What this also meant is that None must be hashable as only hashable objects can be keys in a dictionary. These objects include strings, tuples, sets but don’t include lists as they are mutable and not hashable. ...

 2022-11-15 253 words 2 min

TIL: About Conditional Gitconfigs

TIL you can have conditional sections in your .gitconfig As some of you may know, I keep my dotfiles in a git repo. The problem with this approach is that my email in my .gitconfig is set to [email protected]. Where my config looks something like this: [user] email = [email protected] name = Haseeb Majid # ... However, when I am at work I need to use a different email to commit i. ...

 2022-11-12 257 words 2 min

What is a TIL Post?

What is a TIL post? TIL - Stands for today I learnt. These posts will be shorts summaries of something I learnt “today”. The TIL posts have a low barrier to entry and are a lot easier to write. Therefore they should encourage me to post more often. In all my blog posts I try to post about things that I struggled to do. If I struggled to implement a feature or build something. ...

 2022-11-11 220 words 2 min

Using Dotbot with plugins

Previous article This article assumes you are familiar with dotfiles and Dobot. If you want to know more about Dotbot click here In this article I will show you how you can use Dotbot plugins. We can use Dotbot plugins to run new directives such as apt. So we can use the apt package manager, so install packages. Tip One useful use case is when we setup on a new system we may want to make we have some packages installed like vim or make. ...

How to Manage your Dotfiles with DotBot across Devices

Previous article This article assumes you are familiar with dotfiles and Dobot. If you want to know more about Dotbot click here If you are like me you have devices, such as personal desktop and a work laptop. These devices share some dotfiles but also have specific program and applications. For example: Personal Desktop: Linux Work Laptop: Windows (WSL) On Linux I use alacritty and in Windows I use Windows terminal I could copy all my dotfiles over and not worry about which programs exist on which systems. ...

My current VSCode Setup (Extensions and Settings)

Today I will go over my current VSCode setup covering both extensions and settings. Out of date This article may be out of date, by the time you are reading this. It is accurate as of 16th October 2022. Extensions Here we will go over some extensions I find very useful: Full list of my plugins here Better Comments Link: Better Comments As the name implies it improves your comments. Makes them look nicer if you add certain annotations. ...

How to Manage Your Dotfiles With Dotbot

If you’re like me you find yourself moving between multiple systems. Whether that be between my personal desktop and my work laptop or distro hopping on Linux. See relevant meme below: What are dotfiles? Many tools/program store their configuration files as files on your machine. On Linux you will often find these in ~/.config directory. Some common examples of dotfiles: - .vimrc - .bashrc - .gitconfig I wanted to find an easy way to manage my dotfiles and share them between mutiple systems. ...

Running Gitlab CI jobs in Docker using docker-compose

Shameless plug: This is related to a EuroPython 2022 talk I am giving, My Journey Using Docker as a Development Tool. For most of my common dev tasks, I’ve started to rely on docker/docker compose to run commands locally. I have also started using vscode’s .devcontainers, to provide a consistent environment for all developers using a project. The main reason for this is to avoid needing to install dependencies on my host machine. ...

Separate function handler modules when using Python Socketio

In this article I will show you how you can have separate modules for your Socketio event handlers. Rather than keeping them all in the same file. Hopefully this should be a relatively short article, lets get into it Main In this example I will be using SocketIO alongside FastAPI, but you can easily change this code to be SocketIO only. I also will be using a uvicorn to run the server. ...

E2E tests with Gitlab CI services

Background This will be a slightly shorter article. In this article I will show you how I’ve managed to do some end-to-end testing with Gitlab CI services. I’m building a browser-based multiplayer game called Banter Bus. Banter Bus consists of three main components, gui: A SvelteKit based frontend the user will interact with to play the game core-api: A Socketio API written in Python management-api: A simple RESTful API written in Python (FastAPI) Now say I want to write some e2e Cypress tests, that will test all of these components interacting with each other. ...

Testing a socketio Web App written in Python

In this article I will show you how you can test an async Socketio application in Python, where the ASGI server we are running is uvicorn. I will be referring to these tests as integration tests, though depending on who you ask they could be called E2E tests, system tests, slow test etc. What I am referring to is simply testing out the entire “flow” of a socketio event i.e. emitting an event from a client, then receiving it on the web service and for my actual projects interacting with an actual database. ...

Testing a Gatsby application with Cypress on Gitlab CI

In this blog post, we will go over how we can automatically test a Gatsby site end-to-end (e2e), using Cypress on Gitlab CI. Introduction Gatsby Gatsby is a static site generator (SSG) built upon React. It allows us to create “blazing” fast websites. In this example, we will use a simple blog starter template available and add a Cypress test. Cypress Fast, easy and reliable testing for anything that runs in a browser. ...

How to create a Golang Web Application using Fizz

Background A bit of background before we start the article. When I develop a Python web service I use the Connexion library created by Zalando. It’s a great library which is built on top of Flask. It uses an OpenAPI Specification (OAS) file to handle input validation and routing for you. Therefore reducing the boilerplate code you need to write. The main advantage of this is that we have a design-first approach to developing our API. ...

Golang & MongoDB with "Polymorphism" and BSON Unmarshal

Recently I’ve been working on a new personal project called Banter Bus, a browser-based multiplayer game. I’ve been working on a REST API to add new questions to the game. The API is built in Golang and uses MongoDB as the database. Since Golang is a strongly typed language, we will need to specify the structure of the data we expect from the database. This can get tricky if the data varies, such as one field changing. ...

What does yield do in Python

In this article, we will go over what the yield keyword is used for. We will also cover how you can use a yield with a pytest fixture to allow us to “teardown” tests, after all of our tests have run. A common job being removing test data from the database, so that next time your run the tests your tests won’t fail. Due to the database being in a different (unexpected) state. ...

How to add a ToC in Gatsby

A lot of people, I included, are using Gatsby to build their own blogs. One of the things I wanted to add to my blog was a table of contents (ToC) 📝. A ToC will show you all the headings of an article and when you click on a heading it’ll take you directly to that heading. It’s a nice little feature to have on your blog, which makes it easier for users to navigate and find the information they are looking for. ...

How DNS works with Docker

In this article, we will briefly go over what DNS (domain name system) is and explain how it is used in conjunction with Docker 🐳. DNS You can think of DNS like a phonebook, except instead of people’s name and phone numbers, it stores domains names and IP addresses (this can be either IPv4 or IPv6). Where a domain name is used to identify resources i.e. google.com is a domain name. ...

How SOCKS proxies work and using ProxyChains

In this article, we will go over how you can use proxychains to proxy our traffic through a socks proxy. Background Recently, like everyone else, I’ve been working from home a lot more often. This means to access resources at work I need to use a VPN. However, to access some resources, such as production servers from my local machine, I need to use a SOCKS5 proxy. Without using a SOCKS proxy, I would need to do something shown in the diagram below. ...

How to source your Gatsby posts from another repo

In this article, we will go over how you can manage your markdown blog posts from another git repository (repo). Separate to the git repository for your Gatsby site. This is the same process that I use to manage this repo. So what this entails is the source code for my Gatsby site is in a repo called portfolio-site on Gitlab. Then I have another repo for all of my blog posts (in markdown) called articles. ...

Add an 'edit post' button to your Gatsby blog

In this article, we will look at how we can add an “edit post” button, to your Gatsby blog. When this button is clicked it will take the user to your markdown file, on github/gitlab that was used to generate the blog post they are currently viewing. Setup Before we add the edit button to a Gatsby blog, let’s set up a simple Gatsby site using the Gatsby blog starter. You can skip this step and add the button to an existing site. ...

How to auto create MRs in Gitlab

In this article, we will go over how we can use the gitlab-auto-mr CLI script I wrote to help automate your Gitlab workflow. This is a very simple script you can use with Gitlab which will auto-create merge requests (MRs) every time you create a new branch on a project in Gitlab. (Optional) Git Feature Branches Feel free to skip this section if you are already familar with feature branch, skip to the Gitlab Auto MR section ...

How to add offline search to a Gatsby blog

Let’s take a look at how we can add offline local search 🔍 to a Gatsby blog. There are two main types of search we can use an offline search like elasticlunr and external API search engines like ElasticSearch. These are typically more scalable but also more expensive. You can find more info here. In this article, I will show you how to add offline search to your Gatsby blog using elasticlunr. ...