initial
This commit is contained in:
15
application.properties
Executable file
15
application.properties
Executable file
@@ -0,0 +1,15 @@
|
||||
spring.application.name=web-port
|
||||
spring.security.user.name=user
|
||||
spring.security.user.password=user
|
||||
server.port=9000
|
||||
|
||||
|
||||
cors.allowedOrigins=http://localhost:4200,http://localhost:9000
|
||||
|
||||
|
||||
spring.mail.host=smtp.gmail.com
|
||||
spring.mail.port=587
|
||||
spring.mail.username=aphophus03@gmail.com
|
||||
spring.mail.password=wytpzmhhjikrkltk
|
||||
spring.mail.properties.mail.smtp.auth=true
|
||||
spring.mail.properties.mail.smtp.starttls.enable=true
|
||||
122
md-files/advanced-emacs-config.md
Normal file
122
md-files/advanced-emacs-config.md
Normal file
@@ -0,0 +1,122 @@
|
||||
# Setting Up an Advanced Emacs Configuration for Productivity
|
||||
|
||||
I recently spoke about what Emacs is, and how it is useful for productivity. I wanted to write this up again and dive more into the other files that were stored in the `/scripts` directory , as well as how to set it up.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before we begin, ensure you have Emacs installed. You can install Emacs using the following commands based on your operating system:
|
||||
|
||||
- **Ubuntu/Debian:** `sudo apt install emacs`
|
||||
- **MacOS (Homebrew):** `brew install emacs`
|
||||
- **Windows:** Use [MSYS2](https://www.msys2.org/) or install Emacs from [GNU Emacs](https://www.gnu.org/software/emacs/).
|
||||
|
||||
Additionally, ensure that `git` is installed to clone repositories and manage configurations.
|
||||
|
||||
## Download the Configuration Files
|
||||
|
||||
First let's walk through how to set this up.
|
||||
|
||||
Clone the repository or manually download the provided configuration files into your `~/.emacs.d/` directory:
|
||||
|
||||
```sh
|
||||
mkdir -p ~/.emacs.d/
|
||||
cd ~/.emacs.d/
|
||||
```
|
||||
|
||||
The following file should be copied to `~/.emacs.d/`:
|
||||
- `init.el`
|
||||
|
||||
And the following files should be copied into `~/.emacs.d/scripts`:
|
||||
- `auto-comp.el`
|
||||
- `custom-agenda.el`
|
||||
- `displays.el`
|
||||
- `keyboard.el`
|
||||
- `shells.el`
|
||||
- `window.el`
|
||||
|
||||
If you are using `git`, you can clone your repository directly:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/zainezq/dot-files/tree/main/emacs-config
|
||||
```
|
||||
## Understanding the Configuration
|
||||
|
||||
This configuration is modularised for easier maintenance. Each file handles a specific feature:
|
||||
|
||||
### `init.el`: The Core Configuration
|
||||
|
||||
The `init.el` file is the entry point of the configuration. It:
|
||||
- Loads package management (MELPA, `use-package`)
|
||||
- Imports additional modules (`displays`, `shells`, `auto-comp`, `window`, `keyboard`, `custom-agenda`)
|
||||
- Configures UI elements such as themes, icons, and window behavior
|
||||
- Sets up Org mode and language support
|
||||
- Enables Evil mode for Vim-like keybindings
|
||||
|
||||
### `auto-comp.el`: Auto-Completion Setup
|
||||
|
||||
This file configures `company-mode` for autocompletion in Emacs. It:
|
||||
- Loads `company-mode` and `company-box` for a better UI
|
||||
- Sets the minimum prefix length and delay before suggestions appear
|
||||
- Enables backend support for various modes
|
||||
|
||||
### `keyboard.el`: Custom Keybindings
|
||||
|
||||
This file sets up keybindings using the `general.el` package. Some useful shortcuts include:
|
||||
- `SPC .` → Open file finder
|
||||
- `SPC f c` → Open `init.el` for quick edits
|
||||
- `SPC b b` → Switch buffers
|
||||
- `SPC w 1` → Removes (not kills) all buffers except the current one
|
||||
- `SPC t n` → Toggle NeoTree file explorer
|
||||
|
||||
### `window.el`: Window Management
|
||||
|
||||
Defines functions for moving buffers between splits using `windmove`. Functions include:
|
||||
- `buf-move-up` → Swap buffers up
|
||||
- `buf-move-down` → Swap buffers down
|
||||
- `buf-move-left` → Swap buffers left
|
||||
- `buf-move-right` → Swap buffers right
|
||||
|
||||
### `shells.el`: Shell and Terminal Integration
|
||||
|
||||
Configures:
|
||||
- `vterm` as the primary terminal
|
||||
- `eshell-toggle` for quick access to Eshell
|
||||
- `vterm-toggle` for easy terminal toggling
|
||||
|
||||
### `custom-agenda.el`: Org Mode Enhancements
|
||||
|
||||
This file customises Org mode agendas. It:
|
||||
- Configures custom agenda views
|
||||
- Hides the Org agenda startup message
|
||||
- Enables extra features such as displaying scheduled tasks
|
||||
|
||||
### `displays.el`: UI Enhancements
|
||||
|
||||
This file improves the visual experience in Emacs:
|
||||
- Configures `dashboard.el` to show a custom startup screen, you may modify this to your liking, see: [Emacs Dashboard](https://github.com/emacs-dashboard/emacs-dashboard)
|
||||
- Enables `neotree` for file navigation
|
||||
- Hides unnecessary UI elements for a cleaner look
|
||||
|
||||
## Installing Dependencies
|
||||
|
||||
Open Emacs and run the following command to install missing packages:
|
||||
|
||||
```sh
|
||||
M-x package-refresh-contents
|
||||
M-x package-install-selected-packages
|
||||
```
|
||||
|
||||
Alternatively, restart Emacs, and `use-package` will automatically install any missing dependencies.
|
||||
|
||||
If any issues arise, check `*Messages*` buffer (`M-x view-echo-area-messages`) or start Emacs with debugging mode enabled (`emacs --debug-init`). What I tend to do is whenever I encounter any errors, I run emacs in minimal mode: `emacs -Q`, this loads emacs without the init.el file (if I can't pinpoint the exact error).
|
||||
|
||||
## Final Notes
|
||||
|
||||
This configuration optimises Emacs for efficient navigation, organisation, and shell integration.
|
||||
Everybodies configuration will differ based on their needs, so feel free to take and leave the parts as you wish!
|
||||
|
||||
For additional customisation, refer to the official package documentation:
|
||||
- [General.el (Keybindings)](https://github.com/noctuid/general.el)
|
||||
- [Evil Mode (Vim keybindings)](https://github.com/emacs-evil/evil)
|
||||
- [Org Mode](https://orgmode.org/)
|
||||
- [Neotree (File navigation)](https://github.com/jaypei/emacs-neotree)
|
||||
98
md-files/angular-cli-and-routing.md
Executable file
98
md-files/angular-cli-and-routing.md
Executable file
@@ -0,0 +1,98 @@
|
||||
# Angular CLI and Routing
|
||||
|
||||
## Introduction
|
||||
|
||||
Angular is a popular open-source web application framework developed and maintained by Google. It is written in TypeScript and allows developers to build dynamic, single-page web applications (SPAs) with a modular and component-based architecture. Angular provides a powerful set of tools and features for building robust and scalable web applications.
|
||||
|
||||
Key features of Angular include:
|
||||
|
||||
- Two-way data binding
|
||||
- Dependency injection
|
||||
- Directives for extending HTML
|
||||
- Services for reusable business logic
|
||||
- Modular architecture with components
|
||||
- Routing for building SPAs (Single Page Applications)
|
||||
|
||||
## How to use Angular CLI?
|
||||
|
||||
Angular CLI (Command Line Interface) is a command-line tool that simplifies the process of creating, building, testing, and deploying Angular applications. It provides a set of commands to perform various tasks such as creating new projects, generating components, services, modules, and more. The Angular CLI abstracts away many configuration details and helps developers follow best practices.
|
||||
|
||||
To install Angular CLI, you can use the following command:
|
||||
|
||||
```bash
|
||||
npm install -g @angular/cli
|
||||
```
|
||||
|
||||
Now to understand Angular in JHipster, navigate to the `/src/main/webapp/app` directory, where you will find directories and files. This is where the front-end work is done.
|
||||
|
||||
- `/src/main/webapp/app/shared`: Shared components, services, and utilities used across the application.
|
||||
- `/src/main/webapp/app/entities`: Subdirectories for each entity in the application, with components, services, and models specific to that entity.
|
||||
- `/src/main/webapp/app/layouts`: Layout components such as headers, footers, and navigation menus.
|
||||
- `/src/main/webapp/app/admin`: Administrative components and modules.
|
||||
- `/src/main/webapp/app/core`: Core services, interceptors, guards, and modules.
|
||||
- `/src/main/webapp/app/main.ts`: The main entry point for the Angular application.
|
||||
- `/src/main/webapp/app/app.module.ts`: The root module where you define application-wide dependencies and configurations.
|
||||
- `/src/main/webapp/app/app-router.module.ts`: The Angular router module where you define application routes.
|
||||
- `/src/main/webapp/content/css`: CSS stylesheets for styling the application.
|
||||
- `/src/main/webapp/content/images`: Image assets used in the application UI.
|
||||
|
||||
## Creating a new page
|
||||
|
||||
When you want to create a new page within the application, go to the `/src/main/webapp/app` directory, and run the command:
|
||||
|
||||
```bash
|
||||
ng generate component my-new-page
|
||||
```
|
||||
|
||||
This will generate a new component within the app. `ng` automatically generates the `.html`, `.scss`, `.spec.ts`, and the main `.ts` component. We now need to do two things:
|
||||
|
||||
1. Update the routing link by going to the `/app-router.module.ts` file and adding this:
|
||||
|
||||
```typescript
|
||||
{
|
||||
path: 'my-new-page',
|
||||
component: MyNewPageComponent,
|
||||
data: {
|
||||
pageTitle: 'My New Page'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Add a link so the page can be accessed:
|
||||
|
||||
```html
|
||||
<!-- In your navigation component template -->
|
||||
<a routerLink="/my-new-page">My New Page</a>
|
||||
```
|
||||
|
||||
## Imports and @
|
||||
|
||||
- The `import` keyword is used to bring functionality from external modules (Angular modules, components, services, and other features) into your code.
|
||||
|
||||
For example:
|
||||
|
||||
```typescript
|
||||
import { Component } from '@angular/core';
|
||||
```
|
||||
|
||||
- In Angular, the `@` symbol is often used in decorators. Decorators are special types of declarations that can be attached to class declarations, methods, accessors, properties, or parameters. They are used to modify the behavior of the target they decorate.
|
||||
|
||||
Decorators are a way to configure and enhance classes in a declarative manner. They are applied using the `@` symbol followed by the decorator name.
|
||||
|
||||
```typescript
|
||||
@Component({
|
||||
selector: 'jhi-my-new-page',
|
||||
templateUrl: './my-new-page.component.html',
|
||||
styleUrls: ['./my-new-page.component.scss']
|
||||
})
|
||||
export class MyNewPageComponent {
|
||||
// class implementation
|
||||
}
|
||||
```
|
||||
|
||||
In this example, `@Component` is a decorator that is used to define metadata for an Angular component. It specifies the selector, template, and style files for the `MyNewPageComponent`.
|
||||
|
||||
More information on CLI can be found [here](https://angular.io/cli)
|
||||
|
||||
A tutorial on AngularJS can be found [here](https://www.w3schools.com/angular/)
|
||||
|
||||
243
md-files/emacs_config.md
Executable file
243
md-files/emacs_config.md
Executable file
@@ -0,0 +1,243 @@
|
||||
# Crafting a Customised Emacs Configuration for Productivity and Aesthetics
|
||||
|
||||
By Zaine Qayyum
|
||||
|
||||
---
|
||||
|
||||
Emacs is a powerhouse editor that can be tailored to your specific needs, and this blog showcases how I built my Emacs configuration to enhance my productivity and enjoyment. I primarily use Emacs to organise my notes, applications, books, projects and various other things.
|
||||
|
||||
---
|
||||
|
||||
## **1. Package Management**
|
||||
|
||||
The first step in customising Emacs is setting up package management. I’ve used MELPA as my primary package repository:
|
||||
|
||||
```elisp
|
||||
(require 'package)
|
||||
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
|
||||
(package-initialize)
|
||||
```
|
||||
|
||||
The snippet below shows you how to view the available packages.
|
||||
|
||||
```elisp
|
||||
M-x package-list-packages
|
||||
```
|
||||
---
|
||||
|
||||
## **2. Scripts and Custom Modules**
|
||||
|
||||
To keep my configuration modular, I’ve organised custom scripts in a `~/.emacs.d/scripts/` directory:
|
||||
|
||||
```elisp
|
||||
(add-to-list 'load-path "~/.emacs.d/scripts/")
|
||||
(require 'displays)
|
||||
(require 'shells)
|
||||
(require 'auto-comp)
|
||||
(require 'window)
|
||||
(require 'keyboard)
|
||||
(require 'custom-agenda)
|
||||
```
|
||||
|
||||
Each of these are `.el` files, and are being loaded into my main `init.el`
|
||||
|
||||
---
|
||||
|
||||
## **3. General Settings**
|
||||
|
||||
### Startup Optimization
|
||||
|
||||
```elisp
|
||||
(setq inhibit-startup-screen t)
|
||||
```
|
||||
|
||||
I disable the startup screen so that the first thing that loads up is the dashboard (more on this later).
|
||||
|
||||
### Key Bindings
|
||||
|
||||
I use `ESC` as a universal escape key to quit minibuffer prompts:
|
||||
|
||||
```elisp
|
||||
(global-set-key [escape] 'keyboard-escape-quit)
|
||||
```
|
||||
|
||||
As opposed to using `C-g` (boo!!).
|
||||
|
||||
### Interface Tweaks
|
||||
|
||||
|
||||
```elisp
|
||||
(menu-bar-mode -1)
|
||||
(scroll-bar-mode -1)
|
||||
(global-display-line-numbers-mode 1)
|
||||
(global-visual-line-mode t)
|
||||
```
|
||||
|
||||
These settings remove clutter like scrollbars and enable essential features such as line numbers.
|
||||
|
||||
---
|
||||
|
||||
## **4. Org Mode for Organization**
|
||||
|
||||
### Agenda and File Management
|
||||
|
||||
Org mode is central to my workflow. I’ve set up an agenda that pulls from multiple files:
|
||||
|
||||
```elisp
|
||||
(setq org-agenda-files '("~/master-folder/org_files/master.org"
|
||||
"~/master-folder/org_files/deen-org/deen.org"
|
||||
"~/master-folder/org_files/career-org/career.org"))
|
||||
(require 'org)
|
||||
```
|
||||
|
||||
### Enhancing Org Mode Appearance
|
||||
|
||||
- Inline images:
|
||||
|
||||
```elisp
|
||||
(add-hook 'org-mode-hook 'org-display-inline-images)
|
||||
(add-hook 'org-mode-hook
|
||||
(lambda ()
|
||||
(org-display-inline-images t t)))
|
||||
```
|
||||
|
||||
- Bullets and indentation:
|
||||
|
||||
```elisp
|
||||
(use-package toc-org
|
||||
:commands toc-org-enable
|
||||
:init (add-hook 'org-mode-hook 'toc-org-enable))
|
||||
|
||||
(use-package org-bullets)
|
||||
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
|
||||
(add-hook 'org-mode-hook 'org-indent-mode)
|
||||
```
|
||||
|
||||
### Disabling Electric Indent
|
||||
|
||||
Org files often require manual formatting:
|
||||
|
||||
```elisp
|
||||
(electric-indent-mode -1)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **5. Enhancing Visual Appeal**
|
||||
|
||||
I’ve added themes and icons to create a visually appealing environment:
|
||||
|
||||
- **Kaolin Bubblegum Theme:**
|
||||
|
||||
```elisp
|
||||
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
|
||||
(require 'kaolin-themes)
|
||||
(load-theme 'kaolin-bubblegum t)
|
||||
```
|
||||
|
||||
- **All-the-Icons:**
|
||||
|
||||
```elisp
|
||||
(use-package all-the-icons :ensure t :if (display-graphic-p))
|
||||
(use-package all-the-icons-dired
|
||||
:hook (dired-mode . (lambda () (all-the-icons-dired-mode t))))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **6. Roam and Note-Taking**
|
||||
|
||||
Org-roam is perfect for building a network of interconnected notes:
|
||||
|
||||
```elisp
|
||||
(use-package org-roam
|
||||
:ensure t
|
||||
:custom
|
||||
(org-roam-directory "~/master-folder/org_files/org_roam")
|
||||
:config
|
||||
(org-roam-setup))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **7. Language Support**
|
||||
|
||||
I’ve configured Emacs for Haskell development:
|
||||
|
||||
```elisp
|
||||
(use-package haskell-mode)
|
||||
(org-babel-do-load-languages
|
||||
'org-babel-load-languages
|
||||
'((haskell . t)))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **8. Backup Settings**
|
||||
|
||||
To prevent clutter, backups are redirected to the Trash folder:
|
||||
|
||||
```elisp
|
||||
(setq backup-directory-alist '((".*" . "~/.Trash")))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **9. Evil Mode for Vim Lovers**
|
||||
|
||||
Evil mode brings Vim keybindings to Emacs, with additional enhancements:
|
||||
|
||||
```elisp
|
||||
(use-package evil
|
||||
:init
|
||||
(setq evil-want-integration t
|
||||
evil-want-keybinding nil
|
||||
evil-vsplit-window-right t
|
||||
evil-split-window-below t)
|
||||
(evil-mode))
|
||||
|
||||
(use-package evil-collection
|
||||
:after evil
|
||||
:config
|
||||
(setq evil-collection-mode-list '(dashboard dired ibuffer))
|
||||
(evil-collection-init))
|
||||
|
||||
(use-package evil-tutor)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **10. Reloading Configuration**
|
||||
|
||||
For quick testing of changes:
|
||||
|
||||
```elisp
|
||||
(defun reload-init-file ()
|
||||
(interactive)
|
||||
(load-file user-init-file)
|
||||
(load-file user-init-file))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **11. Scripts**
|
||||
|
||||
As previously mentioned, I’ve kept scripts in a `~/.emacs.d/scripts/` directory:
|
||||
|
||||
```elisp
|
||||
(add-to-list 'load-path "~/.emacs.d/scripts/")
|
||||
(require 'displays)
|
||||
(require 'shells)
|
||||
(require 'auto-comp)
|
||||
(require 'window)
|
||||
(require 'keyboard)
|
||||
(require 'custom-agenda)
|
||||
```
|
||||
|
||||
Each of these can be found in my GitHub repository: [emacs-config](https://github.com/zainezq/emacs-config)
|
||||
|
||||
---
|
||||
|
||||
## **12. Conclusion**
|
||||
|
||||
This is the end of my customised Emacs configuration, for more details I would recommend checking out this YouTube series: [DistroTube - Configuring Emacs](https://www.youtube.com/playlist?list=PL5--8gKSku15e8lXf7aLICFmAHQVo0KXX). I hope you find it useful :)
|
||||
126
md-files/guide-to-ssh-keys.md
Executable file
126
md-files/guide-to-ssh-keys.md
Executable file
@@ -0,0 +1,126 @@
|
||||
|
||||
# Guide to SSH Keys and GitLab
|
||||
|
||||
By Zaine Qayyum
|
||||
|
||||
---
|
||||
|
||||
## What are SSH Keys?
|
||||
|
||||
SSH (Secure Shell) keys are a pair of cryptographic keys that can be used to secure communication between two parties. One key is private, and it should be kept secure on your local machine, while the other key is public and can be shared with others. SSH keys are commonly used for authentication, allowing secure access to remote servers and services without the need for a password.
|
||||
|
||||
## Generating SSH Keys
|
||||
|
||||
To generate an SSH key pair, follow these steps:
|
||||
|
||||
### Step 1:
|
||||
|
||||
- Open a terminal on your local machine.
|
||||
- Use the following command to generate a new SSH key:
|
||||
|
||||
`ssh-keygen -t rsa -b 2048 -C "example key"`
|
||||
|
||||
- Press Enter to accept the default file location and provide a secure passphrase when prompted.
|
||||
- Two files, `id_rsa` (private key) and `id_rsa.pub` (public key), will be generated in the `~/.ssh/` directory.
|
||||
|
||||
### Step 2:
|
||||
|
||||
Adding SSH Key to the SSH Agent
|
||||
|
||||
- Start the SSH agent:
|
||||
|
||||
`eval "$(ssh-agent -s)"`
|
||||
|
||||
- Add your private key to the SSH agent:
|
||||
|
||||
`ssh-add ~/.ssh/id_rsa`
|
||||
|
||||
### Step 3:
|
||||
|
||||
Adding SSH Key to GitLab/GitHub
|
||||
|
||||
- Copy the contents of your public key:
|
||||
|
||||
`cat ~/.ssh/id_rsa.pub`
|
||||
|
||||
- Log in to your GitLab/GitHub account.
|
||||
- Navigate to Settings > SSH Keys.
|
||||
- Paste the copied public key into the "Key" field and give it a descriptive title.
|
||||
- Click Add Key.
|
||||
|
||||
## Testing SSH Connection
|
||||
|
||||
To test if your SSH key is set up correctly:
|
||||
|
||||
`ssh -T git@git.test.com`
|
||||
|
||||
You should see a message indicating a successful connection.
|
||||
|
||||
## Using SSH with Git
|
||||
|
||||
- Change the remote URL of your Git repository to use SSH:
|
||||
|
||||
`git clone git@git.test.com/repo`
|
||||
|
||||
Replace repo with the repository you want to clone.
|
||||
|
||||
- Now you can push and pull from GitLab without entering a username and password.
|
||||
|
||||
## Managing Multiple SSH Keys
|
||||
|
||||
If you use multiple SSH keys for different services, you can configure them in the SSH config file:
|
||||
|
||||
1. Open (or create) the SSH config file:
|
||||
|
||||
```
|
||||
nano ~/.ssh/config
|
||||
```
|
||||
|
||||
2. Add the following configuration:
|
||||
|
||||
```
|
||||
Host gitlab.com
|
||||
HostName gitlab.com
|
||||
User git
|
||||
IdentityFile ~/.ssh/id_rsa_gitlab
|
||||
|
||||
Host github.com
|
||||
HostName github.com
|
||||
User git
|
||||
IdentityFile ~/.ssh/id_rsa_github
|
||||
```
|
||||
|
||||
3. Save and exit the file. This allows you to use different SSH keys for different services.
|
||||
|
||||
|
||||
## Troubleshooting SSH Issues
|
||||
|
||||
If you encounter any issues with SSH authentication, try the following:
|
||||
|
||||
1. Ensure the SSH agent is running:
|
||||
|
||||
```
|
||||
eval "$(ssh-agent -s)"
|
||||
```
|
||||
|
||||
2. Verify that your SSH key is added:
|
||||
|
||||
```
|
||||
ssh-add -l
|
||||
```
|
||||
|
||||
3. Check file permissions to ensure the private key is secure:
|
||||
|
||||
```
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
4. Debug SSH connection issues:
|
||||
|
||||
```
|
||||
ssh -vT git@git.test.com
|
||||
```
|
||||
|
||||
5. Ensure your public key is correctly added to GitLab/GitHub.
|
||||
|
||||
By following these steps, you can securely authenticate with GitLab using SSH and make your workflow alot more streamlined.
|
||||
166
md-files/intro-to-agda.md
Executable file
166
md-files/intro-to-agda.md
Executable file
@@ -0,0 +1,166 @@
|
||||
# What is Agda? A Beginner's Guide
|
||||
|
||||
By Zaine Qayyum
|
||||
|
||||
---
|
||||
|
||||
|
||||
Agda is a dependently typed functional programming language and proof assistant. It is widely used in academia and research for writing verified programs and proving mathematical theorems. While it might seem intimidating at first, Agda is both powerful and rewarding once you get the hang of it. In this blog we'll explore what makes Agda special and why you might want to learn it.
|
||||
|
||||
## Why Agda?
|
||||
|
||||
Agda combines programming and theorem proving in a seamless way. Here are some of its features that stand out:
|
||||
|
||||
- **Dependent Types:** Agda allows types to depend on values, which means you can encode intricate properties of data directly into your types, ultimately making it easier to write correct programs.
|
||||
- **Interactive Development:** Agda comes with an interactive environment that helps you construct proofs and debug code incrementally (emacs).
|
||||
- **Strong Typing:** The type system in Agda catches many errors at compile time.
|
||||
- **Extensibility:** Agda has support for Unicode characters and custom operators, proving its flexibility.
|
||||
|
||||
Let’s explore Agda in more detail with some examples.
|
||||
|
||||
---
|
||||
|
||||
## Installing Agda
|
||||
|
||||
To start using Agda, you’ll need to install it. Here’s how:
|
||||
|
||||
1. **Install Haskell:** Since Agda is implemented in Haskell, you’ll need the Haskell Platform or GHC.
|
||||
2. **Install Agda:** You can install Agda via `cabal` or `stack`. For example:
|
||||
|
||||
```bash
|
||||
cabal update
|
||||
cabal install Agda
|
||||
```
|
||||
|
||||
3. **Install the Agda Standard Library:** Clone the Agda Standard Library from its [GitHub repository](https://github.com/agda/agda-stdlib) and include it in your project.
|
||||
|
||||
4. **Editor Support:** Agda works well with Emacs. Make sure you have the Agda mode installed and set up in your Emacs configuration.
|
||||
|
||||
---
|
||||
|
||||
## Writing Your First Agda Program
|
||||
|
||||
Let’s start with a simple example: defining natural numbers.
|
||||
|
||||
```agda
|
||||
module Basics where
|
||||
|
||||
-- Define natural numbers
|
||||
data Nat : Set where
|
||||
zero : Nat
|
||||
suc : Nat -> Nat
|
||||
|
||||
-- Add two natural numbers
|
||||
add : Nat -> Nat -> Nat
|
||||
add zero n = n
|
||||
add (suc m) n = suc (add m n)
|
||||
|
||||
-- Example usage
|
||||
example : Nat
|
||||
example = add (suc (suc zero)) (suc zero)
|
||||
```
|
||||
|
||||
### Explanation
|
||||
|
||||
1. **Module Declaration:** We start by defining a module named `Basics`. Think of it as a namespace.
|
||||
2. **Natural Numbers:** We define `Nat`, a data type with two constructors:
|
||||
- `zero`: Represents 0.
|
||||
- `suc`: Represents the successor of a number (e.g., `suc zero` is 1, `suc (suc zero)` is 2).
|
||||
3. **Addition:** The `add` function recursively adds two natural numbers.
|
||||
4. **Example Usage:** We compute `2 + 1` and store the result in `example`.
|
||||
|
||||
---
|
||||
|
||||
## Dependent Types in Action
|
||||
A dependant type is a type that depends on a value, and this is where Agda really shines. Let’s use dependent types to define vectors, which are lists with a fixed length.
|
||||
|
||||
```agda
|
||||
module Vectors where
|
||||
|
||||
open import Data.Nat
|
||||
open import Data.List
|
||||
|
||||
-- Define a vector
|
||||
data Vec (A : Set) : Nat -> Set where
|
||||
[] : Vec A zero
|
||||
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
|
||||
|
||||
-- Append two vectors
|
||||
append : {A : Set} {m n : Nat} -> Vec A m -> Vec A n -> Vec A (m + n)
|
||||
append [] ys = ys
|
||||
append (x :: xs) ys = x :: append xs ys
|
||||
|
||||
-- Example usage
|
||||
exampleVec : Vec Nat 3
|
||||
exampleVec = 1 :: 2 :: 3 :: []
|
||||
|
||||
exampleAppend : Vec Nat 5
|
||||
exampleAppend = append exampleVec (4 :: 5 :: [])
|
||||
```
|
||||
|
||||
### Explanation
|
||||
|
||||
1. **Vectors:** We define `Vec`, a type for vectors, parameterised by:
|
||||
- `A`: The type of elements in the vector.
|
||||
- `n`: The length of the vector.
|
||||
|
||||
A vector of length 0 is represented by `[]`. A non-empty vector is constructed using `_::_`.
|
||||
|
||||
2. **Append Function:** The `append` function takes two vectors and produces a new vector whose length is the sum of the lengths of the input vectors.
|
||||
3. **Example Usage:** We create a vector of length 3 and append it to another vector.
|
||||
|
||||
---
|
||||
|
||||
## Proving Properties
|
||||
|
||||
In Agda, you can write proofs just like programs. Let’s prove a simple property: adding zero to a number doesn’t change the number.
|
||||
|
||||
```agda
|
||||
module Proofs where
|
||||
|
||||
open import Data.Nat
|
||||
|
||||
-- Proof: n + 0 = n
|
||||
data _≡_ {A : Type} : A → A → Type where
|
||||
refl : (x : A) → x ≡ x
|
||||
|
||||
addZero : (n : Nat) -> add n zero ≡ n
|
||||
addZero zero = refl
|
||||
addZero (suc n) = cong suc (addZero n)
|
||||
|
||||
|
||||
```
|
||||
|
||||
### Explanation
|
||||
|
||||
1. **Equality:** The `≡` type represents equality in Agda. A value of type `x ≡ y` is a proof that `x` equals `y`.
|
||||
2. **Base Case:** For `n = zero`, the proof is trivial (`refl` is a proof that any value equals itself, pronounced reflexivity).
|
||||
3. **Inductive Step:** For `n = suc m`, we use `cong` to show that equality holds by induction.
|
||||
|
||||
---
|
||||
|
||||
## Interactive Development
|
||||
|
||||
Agda’s interactive features are a game changer. While working in Emacs, you can:
|
||||
|
||||
- **Type Check:** Use `C-c C-l` to load your file and check for errors.
|
||||
- **Infer Types:** Place the cursor over an expression and press `C-c C-d` to see its type.
|
||||
- **Fill in Holes:** Use `C-c C-space` to generate code snippets or suggestions for incomplete parts of your program.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Challenges and Tips
|
||||
|
||||
Learning Agda can be challenging, especially if you’re new to dependent types or theorem proving. Here are some tips to make it easier:
|
||||
|
||||
- **Start Small:** Focus on simple programs and proofs before tackling complex ones.
|
||||
- **Use the Standard Library:** The Agda Standard Library contains many useful definitions and functions.
|
||||
- **Leverage the Community:** Join forums and mailing lists to ask questions and share knowledge.
|
||||
- **Practice Regularly:** Like any skill, mastering Agda requires consistent practice.
|
||||
|
||||
---
|
||||
|
||||
## Conclusion
|
||||
|
||||
Agda is a powerful tool for writing correct programs and proving mathematical theorems. While it has a steep learning curve, the benefits of using a dependently typed language are immense. Whether you’re a researcher, a programmer, or a mathematician, Agda offers a unique way to reason about your code and ideas.
|
||||
134
md-files/nginx.md
Executable file
134
md-files/nginx.md
Executable file
@@ -0,0 +1,134 @@
|
||||
# Understanding Nginx: What It Is and How to Use It
|
||||
|
||||
By Zaine Qayyum
|
||||
|
||||
---
|
||||
|
||||
|
||||
In the world of server management, you’ve probably come across **Nginx** (pronounced "engine-x"). But what exactly is Nginx, and why is it such a popular tool among developers and system administrators? In this blog, we’ll break down the basics of Nginx, explore its key features, and guide you on how to use it effectively.
|
||||
|
||||
---
|
||||
|
||||
## What Is Nginx?
|
||||
|
||||
Nginx is an open source web server that can also function as a reverse proxy, load balancer, and HTTP cache. It was originally created in 2004 by Igor Sysoev to address the **C10K problem**; a challenge related to handling 10,000 concurrent connections on a single server.
|
||||
|
||||
What makes Nginx stand out is its event driven (more on this later), asynchronous architecture, which allows it to handle a large number of simultaneous connections efficiently. This has made it a go to choice for high performance websites and applications.
|
||||
|
||||
Some of the most popular companies, like Netflix, Airbnb, and GitHub, use Nginx to serve their web traffic, due to it being lightweight, fast and reliable
|
||||
|
||||
---
|
||||
|
||||
## Key Features of Nginx
|
||||
|
||||
Nginx’s popularity stems from these core features:
|
||||
|
||||
### 1. **Web Server**
|
||||
Nginx serves static content like HTML, CSS, JavaScript, and images.
|
||||
|
||||
### 2. **Reverse Proxy**
|
||||
Nginx can act as a middleman, forwarding client requests to backend servers.
|
||||
|
||||
### 3. **Load Balancing**
|
||||
For applications that rely on multiple servers, Nginx distributes incoming traffic evenly across them, which ensures smooth performance even during high traffics.
|
||||
|
||||
### 4. **HTTP Caching**
|
||||
By caching responses, Nginx can speed up delivery times for frequently accessed resources, reducing load on backend servers.
|
||||
|
||||
### 5. **SSL/TLS Termination**
|
||||
Nginx simplifies secure connections by handling SSL/TLS encryption and decryption, offloading this task from backend servers.
|
||||
|
||||
### 6. **Content Compression**
|
||||
Nginx can compress HTTP responses, reducing bandwidth usage and speeding up page load times.
|
||||
|
||||
---
|
||||
|
||||
## How to Use Nginx
|
||||
|
||||
Now that we understand what Nginx is and why it’s so powerful, let’s look at how you can use it. Below is a simple guide to get you started.
|
||||
|
||||
### Step 1: Install Nginx
|
||||
Installation varies depending on your operating system.
|
||||
|
||||
- **For Ubuntu/Debian:**
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install nginx
|
||||
```
|
||||
|
||||
- **For CentOS/RHEL:**
|
||||
```bash
|
||||
sudo yum install epel-release
|
||||
sudo yum install nginx
|
||||
```
|
||||
|
||||
Once installed, you can start Nginx with:
|
||||
```bash
|
||||
sudo systemctl start nginx
|
||||
```
|
||||
|
||||
### Step 2: Verify Installation
|
||||
To confirm that Nginx is running, open your browser and visit `http://localhost` or your server’s IP address. You should see the default Nginx welcome page.
|
||||
|
||||
### Step 3: Configure Nginx
|
||||
The configuration files for Nginx are located in `/etc/nginx/`.
|
||||
The main file is `nginx.conf`, but you’ll typically work with configuration files under `/etc/nginx/sites-available/` and `/etc/nginx/sites-enabled/`.
|
||||
|
||||
#### Example: Serving a Static Website
|
||||
1. Create a new configuration file:
|
||||
```bash
|
||||
sudo nano /etc/nginx/sites-available/mywebsite
|
||||
```
|
||||
2. Add the following:
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name mywebsite.com www.mywebsite.com;
|
||||
|
||||
root /var/www/mywebsite;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
}
|
||||
```
|
||||
3. Create a symlink and enable the configuration:
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
### Step 4: Set Up a Reverse Proxy
|
||||
To forward traffic to a backend server (e.g., a Node.js app):
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name example.com;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
```
|
||||
Save the file, reload Nginx, and you’re good to go!
|
||||
|
||||
---
|
||||
|
||||
## Tips for Managing Nginx
|
||||
|
||||
- **Check Configuration Before Reloading:**
|
||||
Run `sudo nginx -t` to test for syntax errors.
|
||||
- **Monitor Logs:**
|
||||
Use `tail -f /var/log/nginx/access.log /var/log/nginx/error.log` to troubleshoot issues.
|
||||
- **Secure Your Server:**
|
||||
Always enable SSL/TLS for secure connections. Tools like [Let’s Encrypt](https://letsencrypt.org/) make this process easy.
|
||||
|
||||
---
|
||||
|
||||
## Why Choose Nginx?
|
||||
|
||||
Not only is it a web server, its also a powerful tool that can really optimise your website's performance, as well as improving scalability and enhancing security. It doesn't matter if you are just hosting a simple static website, Nginx will have you covered.
|
||||
|
||||
65
md-files/prefrontal_cortex.md
Executable file
65
md-files/prefrontal_cortex.md
Executable file
@@ -0,0 +1,65 @@
|
||||
### The Brain's Self-Discipline Blueprint: Examining the Prefrontal Cortex and Other Areas
|
||||
|
||||
By Zaine Qayyum
|
||||
|
||||
---
|
||||
|
||||
### **Preface**
|
||||
|
||||
Why is it so difficult to resist a late-night snack or to maintain our self-imposed objectives? Our brains' complex wiring holds the solution. "The Science of Self-Discipline" by Peter Hollins, a book which I was reading, says that it's not just about willpower but also about how well our brain's various components cooperate. This blog will explore the prefrontal cortex and other areas relating to self discipline.
|
||||
|
||||
---
|
||||
|
||||
### **The Brain's CEO: The Prefrontal Cortex**
|
||||
|
||||
Consider your brain's prefrontal cortex (PFC) to be its CEO. It is responsible for "executive functions" such as impulse control, planning, and decision-making. Your PFC is taking over when you fight the need to browse social media while working.
|
||||
|
||||
The PFC's neuroplasticity is one of its best features. This indicates that while heredity (biological inheritance) plays a part in self-discipline, it is not entirely lost because it can become stronger with effort. Research indicates that practices such as mindfulness meditation can expand grey matter in the PFC, improving our capacity to control our behaviour. In the well-known "marshmallow test," kids who were able to postpone gratification by waiting for a second marshmallow ended up with better life outcomes.
|
||||
|
||||
---
|
||||
|
||||
### **Aiding Participants: Additional Brain Areas Impacting Self-Control**
|
||||
|
||||
Other parts of the brain are essential for self-discipline, even if the PFC is the main player:
|
||||
|
||||
- **Amygdala** The amygdala is an almond shaped region in the brain that controls emotions such as anger and fear. The PFC can become overpowered when we are stressed or anxious, and it is the amygdala that overpowers the PFC, ultimately leading to impulsive decisions. For example, the amygdala frequently takes over our reactions before the PFC can calm us down, which is what leads to road rage.
|
||||
|
||||
- **Basal Ganglia**: The basal ganglia helps in automating behaviours and are in charge of habit formation. Self-discipline is made simpler by good habits since they demand less conscious effort, there is a famous arabic saying: ما تكرر تقرر, which translates to "What is repeated becomes established", meaning that the habits we repeat tend to be the habits that stick to us. Building enduring habits can be facilitated by beginning with simple, regular behaviours, like reading for 5 minutes before bed.
|
||||
|
||||
- **Anterior Cingulate Cortex (ACC)**: This area of the brain controls emotional reactions and recognises mistakes. When things get difficult, a functioning ACC keeps us on course and helps us overcome obstacles.
|
||||
|
||||
- **Dopaminergic Pathways (Reward System)**: Dopamine is released during enjoyable activities by the brain's reward system: the nucleus accumbens. This explains the allure of instant gratification, such as checking your phone for notifications.
|
||||
|
||||
---
|
||||
|
||||
|
||||
### **How Self-Discipline Works: A Brain-Based Process**
|
||||
|
||||
Self-discipline is often a tug-of-war between different brain regions. The PFC knows you should wake up early to exercise, but the amygdala prefers the comfort of staying in bed. This internal conflict is why self control can feel so challenging.
|
||||
|
||||
Dopamine, a neurotransmitter, plays a dual role. It motivates you to take action but can also lead to addictive behaviors if not managed well. Gamification, like fitness apps with streaks, uses dopamine to encourage consistent behavior by rewarding small wins.
|
||||
|
||||
The brain will naturally prioritise short term rewards, hence techniques like visualisation and writing can shift this focus, which ultimately will enable the PFC to prioritise long term benefits over instant gratification.
|
||||
|
||||
---
|
||||
|
||||
### **Building Self-Control: Useful Advice**
|
||||
|
||||
The following are some methods to improve self-discipline that have scientific support:
|
||||
|
||||
- **Mindfulness Practices**: Mindfulness enhances the PFC and decreases amygdala activity. Inhaling for four seconds, holding for four, and expelling for six is a basic breathing technique that helps one focus and relax.
|
||||
|
||||
- **Developing Positive Habits**: Apply the "cue-routine-reward" cycle. For instance, put your running shoes by the door (trigger), jog (routine), and then take a cool shower (reward). A good starting place to learn more about habit formation and the intricate science behind it is the famous book of James Clear titled "Atomic Habits"
|
||||
|
||||
- **Managing Stress**: Excessive stress might impair the PFC's ability to regulate. The parasympathetic nervous system can be activated by methods such as splashing cold water to ones face or practicing progressive muscle relaxation, which will help maintain ones composure.
|
||||
|
||||
- **Dopamine Detox**: As mentionned before, this is a double edged sword, one can reduce overstimulation by avoiding social media, binge-watching, or sugary snacks for a set period. This resets the brain’s reward system, making it easier to focus on meaningful tasks.
|
||||
|
||||
---
|
||||
|
||||
### **Conclusion**
|
||||
|
||||
Along with other brain regions, the prefrontal cortex provides the foundation for self discipline. If one actively gets an understanding of how these different parts work together, deliberate steps can be taken to strengthen self control. Start small, pick one of the tips and practice it daily. Over time, these small changes will lead to significant improvements.
|
||||
|
||||
Remember, self-discipline is like a muscle, the more one trains it, the stronger it becomes. As the Stoic philosopher Epictetus said, "No man is free who is not master of himself."
|
||||
|
||||
Reference in New Issue
Block a user