Skip to content

Commit

Permalink
docs: update post content (#27)
Browse files Browse the repository at this point in the history
* refactor: remove src barrel file
* feat: add learn content page
* docs: update content
* docs: linting post
* ci: update nextjs analyzer workflow
  • Loading branch information
cseas authored Dec 21, 2024
1 parent 616fecd commit 2e7a9f2
Show file tree
Hide file tree
Showing 28 changed files with 248 additions and 134 deletions.
52 changes: 33 additions & 19 deletions .github/workflows/nextjs_bundle_analysis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: "Next.js Bundle Analysis"
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

name: 'Next.js Bundle Analysis'

on:
pull_request:
branches:
- main
push:
branches:
- main # change this if your default branch is named differently
Expand All @@ -14,22 +15,36 @@ defaults:
# change this if your nextjs app does not live at the root of the repo
working-directory: ./

permissions:
contents: read # for checkout repository
actions: read # for fetching base branch bundle stats
pull-requests: write # for comments

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up node
uses: actions/setup-node@v1
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
node-version: 18

- name: Install dependencies
uses: bahmutov/npm-install@v1

# If pnpm is used, you need to switch the previous step with the following one. pnpm does not create a package-lock.json
# so the step above will fail to pull dependencies
# - uses: pnpm/action-setup@v2
# name: Install pnpm
# id: pnpm-install
# with:
# version: 7
# run_install: true

- name: Restore next build
uses: actions/cache@v2
uses: actions/cache@v3
id: restore-build-cache
env:
cache-name: cache-next-build
Expand All @@ -50,7 +65,7 @@ jobs:
run: npx -p nextjs-bundle-analysis report

- name: Upload bundle
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: bundle
path: .next/analyze/__bundle_analysis.json
Expand Down Expand Up @@ -80,33 +95,32 @@ jobs:
if: success() && github.event.number
run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare

- name: Get comment body
- name: Get Comment Body
id: get-comment-body
if: success() && github.event.number
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
body=$(cat .next/analyze/__bundle_analysis_comment.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$(cat .next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT
echo EOF >> $GITHUB_OUTPUT
- name: Find Comment
uses: peter-evans/find-comment@v1
uses: peter-evans/find-comment@v2
if: success() && github.event.number
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: "<!-- __NEXTJS_BUNDLE -->"
body-includes: '<!-- __NEXTJS_BUNDLE -->'

- name: Create Comment
uses: peter-evans/create-or-update-comment@v1.4.4
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id == 0
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-body.outputs.body }}

- name: Update Comment
uses: peter-evans/create-or-update-comment@v1.4.4
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id != 0
with:
issue-number: ${{ github.event.number }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Code for my personal blog, hosted at [blog.absingh.com][1].
- [ ] Add CI build and test checks
- [ ] Add dependabot
- [ ] use Inter variable font from @next/font
- [ ] dig command, post: powershell-ip

### Runtime software versions

Expand Down
6 changes: 4 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Home, config, getSortedPostsData } from "../src";
import { pageMeta } from "../src/Home/meta";
import { Home } from "../src/Home/Home.js";
import { pageMeta } from "../src/Home/meta.js";
import { config } from "../src/config.js";
import { getSortedPostsData } from "../src/lib/posts.js";

import type { Metadata } from "next";

Expand Down
13 changes: 8 additions & 5 deletions docs/learn/dotnet.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
---
title: ".NET"
date: "2021-04-25"
date: "2024-12-22"
---

SOLID principles
.NET is a software development framework that can be used to build cross-platform applications.

Logging
https://docs.microsoft.com/en-gb/learn/modules/aspnet-logging/
- Start by getting familiar with the C# programming language.
- Learn SOLID principles to understand commonly used best practices.
- [Microsoft Docs: Logging in ASP.NET][1]
- [Create a web API with ASP.NET Core controllers][2]

https://docs.microsoft.com/en-gb/learn/modules/build-web-api-aspnet-core/
[1]: https://docs.microsoft.com/en-gb/learn/modules/aspnet-logging/
[2]: https://docs.microsoft.com/en-gb/learn/modules/build-web-api-aspnet-core/
11 changes: 6 additions & 5 deletions docs/posts/array-reduce.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "How to use Array.reduce() in TypeScript"
date: "2021-04-27"
date: "2024-12-22"
cover: "/covers/typescript.avif"
---

I recently bumped into a use case where I had an array of objects, similar to the one below:
Expand All @@ -13,7 +14,7 @@ const dataArray: Data[] = [
];
```

The problem is to get all the index positions of the array where a key is equal to a particular value. For example, we'd like to get all the indexes where the key `a` is `true`.
The requirement is to get all the index positions of the array where a key is equal to a particular value. For example, we'd like to get all the indexes where the key `a` is `true`.

This can be done in TypeScript with `Array.prototype.reduce()` as follows:

Expand Down Expand Up @@ -45,13 +46,13 @@ The _reducer_ function passed as the first parameter above uses 3 parameters:

Here's how the reducer function used in the example works:

- The initial value of the accumulator is initialized to an emppty array. The accumulator is the value which will eventually contain our result at the end of the processing.
- The initial value of the accumulator is initialized to an empty array. The accumulator is the value which will eventually contain our result at the end of the processing.
- For every element in the array, we check if the element has a key "a" that is true. If yes, we push the index of that element in the accumulator array and return the resulting array for use in the iteration for the next element until we're done walking through the whole original `data` array.
- Finally, the accumulator will contain the list of all the indexes that satisfy the given condition, which is value ultimately returned from our custom `getIndexes()` function.

Have questions? [Discuss on Twitter][1]
> Have questions? [Discuss on Twitter][1]
_References_:
### References

- [MDN Web Docs: Array.prototype.reduce()][2]

Expand Down
18 changes: 12 additions & 6 deletions docs/posts/check-package.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
---
title: "Linting npm packages"
date: "2023-02-23"
title: "[WIP] Linting npm packages"
date: "2023-03-30"
---

Lint npm packages using these sites:
Publishing an npm package is a very different experience from writing locally shared code and can come with a lot of daunting challenges. Thankfully, there are multiple tools out there today that help us validate our published package.

- https://publint.dev/
- https://arethetypeswrong.github.io/
- https://bundlephobia.com/
1. [Publint][1]: This will help identify any errors in the format of your published package, including checking that your package.json metadata is correct and the published files and entrypoints are in a format that will work for various consumers.

2. [Are The Types Wrong][2]: Shipping types with an npm package has become a common requirement as the JavaScript ecosystem has reached wide adoption of TypeScript. This tool by the TypeScript team helps us identify how different moduleResolution settings in the consumer projects will resolve the types from our package and whether any of them might break.

3. [BundlePhobia][3]: Bundle size is often one of the primary concerns of a developer while choosing between two npm packages. This tool helps us analyze the bundle size of our shipped npm package.

[1]: https://publint.dev/
[2]: https://arethetypeswrong.github.io/
[3]: https://bundlephobia.com/
47 changes: 21 additions & 26 deletions docs/posts/git-commands.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: "Git commands I use regularly as a Software Engineer"
date: "2021-05-01"
date: "2023-03-26"
---

There are possibly thousands of "Git cheatsheets" floating all over the internet. Those have never worked for me since you never really need to remember 50 different commands to get everyday work done.
There are possibly thousands of "Git cheatsheets" floating all over the internet. Those have never worked for me since you never need to remember 50 different commands to get everyday work done.

Here are git commands I use regularly in my daily work.

Expand All @@ -13,53 +13,43 @@ Here are git commands I use regularly in my daily work.
git status
```

2. Update master branch (or the branch you want to create a feature branch from)
2. Update main branch (or the branch you want to create a feature branch from)

```bash
git checkout master
git checkout main
git fetch origin
git reset --hard origin/master
git reset --hard origin/main
```

3. Create new feature branch from current branch
3. Create new feature branch from `develop` branch

```bash
git checkout develop
git checkout -b feature/new-feature
```

If you want to specify which branch should the new branch be based on, add it as the last parameter.

```bash
git checkout -b new-feature master
git checkout -b feat/new-feature
```

To get a new branch from a remote source, specify the remote as well.

```bash
git checkout -b new-feature origin/new-feature
```
> A popular convention is to use slash as a separator in branch names as shown above but this can sometimes [cause problems][5] in your DevOps pipelines when branch names are used to tag Docker images. For this reason, I'd recommend using only hyphens in branch names, e.g., feat-new-feature.
4. Push your local changes to a remote branch

Stage
Stage your changes:

```bash
git add --all
```

> I personally like using the VSCode Git UI to preview changes and stage files one by one instead of using the above command. But if you're sure you want to push all your changes, then above command is useful to stage everything instantly.
Commit
Commit to local git:

```bash
git commit -m "Add new-feature"
git commit -m "feat: add new-feature"
```

Push
Push to remote repository:

```bash
git push -u origin new-feature
git push -u origin feat/new-feature
```

> Above push command is needed only once. This is used to create a new branch in the origin remote repository and link it to your local one. Afterwards, you can use `git push` without any parameters.
Expand Down Expand Up @@ -118,8 +108,10 @@ Here are git commands I use regularly in my daily work.

9. Resolve merge conflicts in a Pull Request

Assuming you're trying to merge `feat/new-feature` branch into `develop`:

```bash
git checkout feature/new-feature
git checkout feat/new-feature
git pull origin develop
```

Expand All @@ -128,7 +120,7 @@ Here are git commands I use regularly in my daily work.
```bash
git add .
git commit -m "Resolve PR #12 merge conflicts"
git push origin feature/new-feature
git push origin feat/new-feature
```

> If you're comfortable with the concept of rebase, prefer that way instead as shown in point 6 above.
Expand All @@ -140,6 +132,8 @@ Here are git commands I use regularly in my daily work.
git push -f remote-name branch-name
```

> This will be useful when someone accidentally pushes a commit to a branch they weren't supposed to.
11. Undo last commit. This will effectively reverse the last `git commit` and you won't lose the new changes you made.

```bash
Expand All @@ -160,7 +154,7 @@ Here are git commands I use regularly in my daily work.
- [Feature Branch Workflow][3] when working individually and rapidly pushing new features to production.
- [Forking Workflow][4] when contributing to open-source.

2. Enforce a branch policy for your `master`/`main` & `develop` branches that allows only squash merges. Regular and Rebase merges work fine when everyone in the team knows how to correctly write a git history but more often than not people are just trying to get their code merged one way or the other. A squash merge strategy is one that stays out of your way the most and creates the least problems in a team of developers with varying expertise levels.
2. Enforce a branch policy for your `main` & `develop` branches that allows only squash merges. Regular and Rebase merges work fine when everyone in the team knows how to correctly write a git history but more often than not people are just trying to get their code merged one way or the other. A squash merge strategy is the one that creates the least problems in a team of developers with varying expertise levels.

3. Always make changes in feature branches. Never directly commit to the project's primary branches used for releases and user acceptance tests.
Expand All @@ -170,3 +164,4 @@ Have questions? [Discuss on Twitter][1]
[2]: https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow
[3]: https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow
[4]: https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
[5]: https://community.atlassian.com/t5/Bitbucket-questions/How-to-push-docker-image-tagged-after-git-branch/qaq-p/1548825
21 changes: 14 additions & 7 deletions docs/posts/nodejs-ubuntu.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
title: "Don't install NodeJS from snap store on Ubuntu"
date: "2021-07-30"
title: "Don't install NodeJS from Snap Store on Ubuntu"
date: "2023-03-26"
---

Don't install Ubuntu from snap store
[Snap Store][4] is usually the easiest way of installing software on Ubuntu and the closest option available for someone looking for a [brew][1] alternative for Linux.

If you do, none of the npx commands will work
https://github.com/admc/wd/issues/586#issuecomment-541583962
However, the Snap Store distribution of Node is one we need to be cautious about as it can lead to a multitude of issues.

Easiest way is to install from nodesource LTS
https://github.com/nodesource/distributions#installation-instructions
For example, [none of the npx commands will work][2]. This is because the Snap Store distribution of Node doesn't have the necessary permissions to install npm packages globally.

The recommended way to install Node for Ubuntu users is to use a nodesource LTS distribution instead:

[https://github.com/nodesource/distributions#installation-instructions][3]

[1]: https://brew.sh/
[2]: https://github.com/admc/wd/issues/586#issuecomment-541583962
[3]: https://github.com/nodesource/distributions#installation-instructions
[4]: https://snapcraft.io/store
Loading

0 comments on commit 2e7a9f2

Please sign in to comment.