diff --git a/content/_index.md b/content/_index.md new file mode 100644 index 0000000..c112c7d --- /dev/null +++ b/content/_index.md @@ -0,0 +1,8 @@ ++++ +title = "Ian Andwati" +description = "Ian's Website" ++++ +I spend my free time working on [hobby projects] and sometimes I [write] about my experiences. In particular, I enjoy learning about programming languages, ,web dev, and how to write fast, robust, and secure code. + +[hobby projects]: https://github.com/andwati +[write]: /posts \ No newline at end of file diff --git a/content/contact.md b/content/contact.md new file mode 100644 index 0000000..392058b --- /dev/null +++ b/content/contact.md @@ -0,0 +1,7 @@ ++++ +title = "Contact" +description = "Let's get in touch." ++++ +You can find me on GitHub as [@andwati]. To email me andwatiian at gmail domain dot com. + +[@andwati]: https://github.com/andwati \ No newline at end of file diff --git a/content/posts/_index.md b/content/posts/_index.md new file mode 100644 index 0000000..6fbd10e --- /dev/null +++ b/content/posts/_index.md @@ -0,0 +1,7 @@ ++++ +title = "Posts" +template = "posts.html" +page_template = "post.html" +sort_by = "date" +insert_anchor_links = "left" ++++ diff --git a/content/posts/generate-django-secret-key.md b/content/posts/generate-django-secret-key.md new file mode 100644 index 0000000..215eb26 --- /dev/null +++ b/content/posts/generate-django-secret-key.md @@ -0,0 +1,40 @@ ++++ +title = "Django Secret Key Tutorial" +description = "Managing secrets" +date = 2022-11-11T15:34:14.160Z +[taxonomies] +tags = ["tutorial", "Django", "Python", ".emv"] ++++ + +Managing the Django SECRET_KEY variable. + + + +The Django `SECRET_KEY` variable is very crucial to your Django application. The secret key must be a large random value and it must be kept secret. Leaking this value to unauthorized people could lead to a security breach. The SECRET_KEY is used in Django for cryptographic signing. It is used to generate tokens and hashes, they can be recreated using this variable. If it is not configured Django throws a `django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty` error + +# Using Environment Variables + +The secret key should not be committed to version control. It is best practice to store the value in a .env file which is added to the .gitignore file to un-track its changes. The values can be loaded programmatically into your settings.py file. + +# Generating A New Secret Key + +This solution is using python's secrets lib on the back + +```python +from django.core.management.utils import get_random_secret_key +# print new random secret key +print(get_random_secret_key()) +``` + +This code can be run in the terminal as a command: + +```python +python -c 'from django.core.management.utils import get_random_secret_key; \ + print(get_random_secret_key())' +``` + +Alternatively, If you are using python 3.6+ then you can use the `secrets.token_hex(\[nbytes=None])` function: + +```python +python3 -c 'import secrets; print(secrets.token_hex(100))' +``` diff --git a/content/posts/hello-world.md b/content/posts/hello-world.md new file mode 100644 index 0000000..78fc610 --- /dev/null +++ b/content/posts/hello-world.md @@ -0,0 +1,35 @@ ++++ +title = "Hello World" +description = "Hello world" +date = 2022-11-04 +[taxonomies] +tags = ["hugo", "blog", "Go"] ++++ + +How it begins + + + +In this post-web2.0 age, people seem to blog less and less, and blogs seem to be dying slowly. People are separated in different Apps where the content is not searchable by search engines. + +However, I still prefer to write using a blog. + +# Why this? + +The best way to learn something is to teach others the knowledge that you have gained. Regurgitating that information will solidify it more firmly in your mind. + +# What I write? + +Mostly random stuff and a few tutorials. I'll see where this goes.Although some of the blog posts may only be helpful to myself, but who knows, I hope they will be helpful to someone else in some day. + +# Static blog generator + +I use hugo as a static site generator.After trying a couple of blogging platforms and trying to build a few from scratch I decided to +throw in the towel and opt in for a ready made solution, no need reinventing the wheel. + +Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again.Hugo provides a robust theming system that is easy to implement but capable of producing even the most complicated websites.Hugo's Go-based templating provides just the right amount of logic to build anything from the simple to complex. For this site I decided to go with the [even theme](https://github.com/olOwOlo/hugo-theme-even). The commenting system is implemented using [Utterances](https://utteranc.es/) + +# Blog site hosting + +The site is hosted on github pages as evident by the \*.github.io domain name.I prefer this mainly because it is free and I don't have +to switch to a different hosting provider. diff --git a/content/posts/install-postgresql-15-on-arch-manjaro-garuda-linux.md b/content/posts/install-postgresql-15-on-arch-manjaro-garuda-linux.md new file mode 100644 index 0000000..d917f20 --- /dev/null +++ b/content/posts/install-postgresql-15-on-arch-manjaro-garuda-linux.md @@ -0,0 +1,167 @@ ++++ +title ="Install PostgreSQL 15 on Arch | Manjaro | Garuda Linux" +description = "Installing postgresql" +date = 2023-02-16T15:34:14.160Z +[taxonomies] +tags = ["postgresql", "archlinux", "manjaro", "garuda", "linux"] ++++ + +Getting PostgreSQL up and running on Arch Linux-based distros + + + +# Overview + +**PostgreSQL** is a powerful open-source relational database management system (RDBMS) that allows you to store and manage large amounts of data. It was first released in 1996 and has become one of the most popular RDBMSs in the world. + +PostgreSQL is designed to handle high levels of **concurrency**, providing features such as **MVCC (multi-version concurrency control)** that allow multiple users to access the same data simultaneously without conflicts. It is also **highly extensible**, with a large number of third-party extensions and libraries available that can be used to add functionality to the core database. + +Some of the key features of PostgreSQL include support for **complex SQL queries**, **advanced indexing** and **query optimization**, **transactional integrity**, and support for a **wide range of programming languages** and development frameworks.PostgreSQL is used by a wide range of organizations, from small businesses to large enterprises, and is particularly popular in industries such as finance, healthcare, and e-commerce, where high levels of data security and reliability are critical. + +In this tutorial, we’ll look at how to install PostgreSQL 15 on Arch Linux, Manjaro, Garuda Linux, or any other Arch-based distro out there. + +# PostgreSQL use cases + +- **E-commerce websites:** PostgreSQL is a popular choice for e-commerce websites because it can handle large amounts of data and supports complex queries. It is used for product catalogs, order management, customer data, and more. +- **Financial institutions:** PostgreSQL is used in financial institutions to store and manage transactional data, such as stock trades, bank transfers, and credit card transactions. It is highly secure and provides features such as transactional integrity and data encryption. +- **Healthcare industry:** PostgreSQL is used in the healthcare industry to store patient data, such as medical records and diagnostic test results. It is also used for research purposes, where large amounts of data need to be stored and analyzed. +- **Government agencies:** PostgreSQL is used by government agencies for a variety of purposes, including managing large datasets, storing and analyzing census data, and managing public health information. +- **Mobile and web applications:** PostgreSQL is often used as a back-end database for mobile and web applications. It provides reliable data storage and retrieval and supports a wide range of programming languages and development frameworks. +- **Geospatial applications:** PostgreSQL has built-in support for geospatial data and is often used for applications that require location-based data, such as mapping and GPS tracking. + +# Why PostgreSQL? + +Postgres offers a lot of advantages that make it an excellent choice for highly transactional environments regardless of application size and data volume. Its rich feature set and flexibility make it a popular choice for a wide range of applications and industries. Some of the top features are: + +- **ACID Compliance:** PostgreSQL is ACID (Atomicity, Consistency, Isolation, Durability) compliant, which means it provides high reliability, consistency, and data integrity, even in the presence of hardware failures, power outages, and other system errors. +- **Extensibility:** PostgreSQL is highly extensible, allowing developers to add new data types, operators, and functions using its extension framework. This makes it easy to customize PostgreSQL to meet the specific needs of your application. +- **Concurrency:** PostgreSQL provides a high level of concurrency, allowing multiple users to access the same data at the same time without conflicts. It uses a Multi-Version Concurrency Control (MVCC) model that enables fast and reliable access to data, even under heavy load. +- **Full-text search:** PostgreSQL provides a powerful full-text search engine that supports advanced search capabilities, such as stemming, ranking, and relevance matching. +- **Advanced indexing:** PostgreSQL provides a wide range of indexing options, including B-tree, Hash, GiST, SP-GiST, GIN, and BRIN. These indexing options allow developers to optimize database performance for their specific use cases. +- **JSON support:** PostgreSQL provides native support for storing and querying JSON data, making it easy to work with modern web and mobile applications that rely on JSON for data exchange. +- **Security:** PostgreSQL provides a high level of security, with features such as SSL support, client authentication, and role-based access control. It also provides encryption for both data at rest and data in transit. +- **Scalability:** PostgreSQL is designed to scale horizontally and vertically, allowing you to add more nodes to a cluster or increase the resources of a single node to handle more load. + +# Install PostgreSQL on Arch | Manjaro | Garuda Linux + +Now with all that fluff out of the way, let's get to business. The steps have been tested on Arch Linux with the KDE desktop. + +> **Note:** Commands that should be run as the *postgres* user are prefixed by `[postgres]$` in this article. + +## Step 1: Installing the PostgreSQL Package + +```shell +$ sudo pacman -Syu postgresql +``` + +This command will update the package database and update all packages on the system then install the PostgreSQL package from your distribution mirrors. Never install a package without updating the system first. On a rolling release, this can lead to an unbootable system. Installing the package will also create a system user called *postgres*. You can now switch to the *postgres* user using a privilege elevation program. + +You can switch to the PostgreSQL user by executing the following command: + +- If you have sudo and are in sudoers + + ```shell + $ sudo -iu postgres + ``` + +- Otherwise using su: + + ```shell + $ su + # su -l postgres + ``` + +## Step 2: Initial Configuration + +Before PostgreSQL can function correctly, the database cluster must be initialized. + +### 2.1 We can confirm the installed PostgreSQL version by running: + +```shell +$ postgres --version ─╯ +postgres (PostgreSQL) 15.1 +``` + +### 2.2 Set applicable entries in **/etc/locale.gen** + +```shell +$ echo "en_US.UTF-8 UTF-8" | sudo tee /etc/locale.gen +``` + +### 2.3 Then run **\*\*locale-gen\*\*** to generate locale settings + +```shell +$ sudo locale-gen +Generating locales... + en_US.UTF-8... done +Generation complete. +``` + +### 2.4 Initialize Postgres Data Directory + +You must first log in as the **postgres** user using the following command before you can initialize PostgreSQL’s data directory: + +```shell +sudo su - postgres +``` + +### 2.5 With the following command, you can now initialize PostgreSQL’s data directory: + +```shell +[postgres]$ initdb -D /var/lib/postgres/data +``` + +### Step 3: PostgreSQL Service Management + +### 3.1 Check PostgreSQL status with the following command: + +```shell +$ systemctl status postgresql ─╯ + postgresql.service - PostgreSQL database server + Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; preset: disabled) + Active: inactive (dead) +``` + +### 3.2 Start the PostgreSQL service by running the following command: + +```shell +sudo systemctl start postgresql +``` + +### 3.3 Enable the PostgreSQL service to start automatically at boot by running the following command: + +```shell +$ sudo systemctl enable postgresql +``` + +### 3.4 Verify that PostgreSQL is running by running the following command: + +```shell +$ sudo systemctl status postgresql ─╯ +● postgresql.service - PostgreSQL database server + Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: disabled) + Active: active (running) since Thu 2023-02-16 22:52:43 EAT; 20s ago + Main PID: 26106 (postgres) + Tasks: 6 (limit: 8790) + Memory: 16.9M + CPU: 113ms + CGroup: /system.slice/postgresql.service + ├─26106 /usr/bin/postgres -D /var/lib/postgres/data + ├─26107 "postgres: checkpointer " + ├─26108 "postgres: background writer " + ├─26110 "postgres: walwriter " + ├─26111 "postgres: autovacuum launcher " + └─26112 "postgres: logical replication launcher " +``` + +# Resources + +- [Arch Linux Wiki](https://wiki.archlinux.org/title/PostgreSQL) +- [Wikipedia](https://en.wikipedia.org/wiki/PostgreSQL) +- [PostgreSQL Documentation](https://www.postgresql.org/docs/) + +# Conclusion + +Installing PostgreSQL on Arch Linux-based distribution is a straightforward process that can be completed in just a few steps. By following the steps outlined above, you can install, configure, and start the PostgreSQL database server on your Arch Linux system. Once installed, you can use PostgreSQL to store, manage, and query data for a wide range of applications and use cases. With its advanced features and high level of extensibility, PostgreSQL is a popular choice for developers and businesses seeking a robust and reliable database management system. + +You can connect to the PostgreSQL server using the psql command-line client or a graphical tool such as pgAdmin. diff --git a/content/posts/integrating-netlify.md b/content/posts/integrating-netlify.md new file mode 100644 index 0000000..08c9d28 --- /dev/null +++ b/content/posts/integrating-netlify.md @@ -0,0 +1,158 @@ ++++ +title = "Integrating Netlify CMS" +description = "Integrating netlify cms" +date = 2022-11-24T15:34:14.160Z +[taxonomies] +tags = ["blog", "hugo", "netlify","netlify-cms","github"] ++++ + +Migrating to a better content management system through Netlify CMS + + + +# Heavy Lifting + +I use [Visual Studio Code](https://code.visualstudio.com/) to manually edit the blog post content on this website. This is quite a hassle because I have to deal with +markdown files. There are many problems with this approach and several gotchas. I have to work on a local site repository to be able to edit the content. My GitHub credentials are also required to push my local changes to my remote repository on GitHub so that it can trigger the build process and publish the site. + +This process has helped me a lot to master markdown syntax and some practice on my git skills. It’s fun to update the website content following these steps but sometimes it can be frustrating. At those times, I really miss the user interface of content management systems. After careful consideration, I moved on with Netlify CMS. At its core, Netlify CMS is an open-source React app that acts as a wrapper for the Git workflow, using the GitHub, GitLab, or Bitbucket API. This provides many advantages, including: + +- **Fast, web-based UI:** With rich-text editing, real-time preview, and drag-and-drop media uploads. +- **Platform agnostic:** Works with most static site generators. +- **Easy installation:** Add two files to your site and hook up the backend by including those files in your build process or linking to our Content Delivery Network (CDN). +- **Modern authentication:** Using GitHub, GitLab, or Bitbucket and JSON web tokens. +- **Flexible content types:** Specify an unlimited number of content types with custom fields. +- **Fully extensible:** Create custom-styled previews, UI widgets, and editor plugins. + +# Redeploying to Netlify + +I decided to move the site from GitHub pages to Netlify hosting to take full control of the platform. Hugo sites on Netlify can benefit from automatic framework detection and control over Hugo version selection. When you link a repository for a project, Netlify tries to detect the framework your site is using. If your site is built with Hugo, Netlify provides a suggested build command and publish directory: Hugo and public. The build process is straight forward but you can add custom options to your `netlify.toml` file, here are my options: + +```toml +[build] +command = "hugo" +publish = "public" + +[build.environment] +HUGO_VERSION = "0.105.0" +``` + +# Setting up Netlify CMS + +You can adapt Netlify CMS to a wide variety of projects. It works with any content written in markdown, JSON, YAML, or TOML files, stored in a repo on GitHub, GitLab, or Bitbucket. You can Netlify CMS to a site that's built with a common static site generator, like Jekyll, Hugo, Hexo, or Gatsby. The official documentation for installing on your website can be found at the [official site](https://www.netlifycms.org/docs/intro/) + +## Steps + +**Step 1** + +Create a static admin folder containing all Netlify CMS files, stored at the root of your published site. Where you store this folder in the source files depends on your static site generator. For Hugo, it is the `static` folder. + +`/static/admin` + +**Step 2** + +Inside the admin folder, create two files: `index.html` and `config.yml`. The first file `admin/index.html` is an entry point to Netlify CMS. You will access the CMS interface from `yourwebsite.com/admin` when everything is ready. + +**Step 3** + +The first file, `admin/index.html`, is the entry point for the Netlify CMS admin interface. Paste this code in index.html and save. This HTML starter page will load the Netlify CMS Javascript file: + +```html + + +
+ + +