From 0d0169f562fbd31c176260c37a282ef40c4b2d2e Mon Sep 17 00:00:00 2001 From: harrylowkey Date: Mon, 22 Jul 2024 01:20:57 +0700 Subject: [PATCH] refactor: code & update some notes --- notes/backend/security/csrf.md | 17 +++++++ notes/backend/sso/sso.md | 8 +-- notes/certifications/ckad/services/command.md | 4 +- ...harding.md => partitioning_vs_sharding.md} | 6 ++- notes/databases/transactions.md | 2 + portfolio/src/helpers/render_badge_classes.py | 4 +- portfolio/src/models/note.py | 1 + portfolio/src/services/note.py | 22 +++++++- portfolio/src/static/note.css | 4 ++ .../src/views/pages/notes/note-card.html | 7 ++- view_counts.txt | 50 ++++++++++--------- 11 files changed, 91 insertions(+), 34 deletions(-) create mode 100644 notes/backend/security/csrf.md rename notes/databases/{partining_vs_sharding.md => partitioning_vs_sharding.md} (96%) diff --git a/notes/backend/security/csrf.md b/notes/backend/security/csrf.md new file mode 100644 index 0000000..d2cb169 --- /dev/null +++ b/notes/backend/security/csrf.md @@ -0,0 +1,17 @@ +# Cross Site Request Forgery + + + + + +Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. With a little help from social engineering (such as sending a link via email or chat), an attacker may trick the users of a web application into executing actions of the attacker’s choosing. + +As represented in this diagram, a Cross Site Request Forgery attack is roughly composed of two parts: + +1. Cross-Site: The user is logged into a website and is tricked into clicking a link in a different website that belongs to the attacker. +The link is crafted by the attacker in a way that it will submit a request to the website the user is logged in to. This represents the “cross-site” part of CSRF. + +2. Request Forgery: The request sent to the user’s website is forged with values crafted by the attacker. +When the victim user opens the link in the same browser, a forged request is sent to the website with values set +by the attacker along with all the cookies that the victim has associated with that website. + diff --git a/notes/backend/sso/sso.md b/notes/backend/sso/sso.md index ab8af51..67b9a32 100644 --- a/notes/backend/sso/sso.md +++ b/notes/backend/sso/sso.md @@ -1,12 +1,12 @@ # SSO 1. Service proivders -- Gmail -- Youtube + - Gmail + - Youtube 2. Identity providers -- Auth0 -- Keycloak + - Auth0 + - Keycloak ## Flow diff --git a/notes/certifications/ckad/services/command.md b/notes/certifications/ckad/services/command.md index 6e010c2..c61d483 100644 --- a/notes/certifications/ckad/services/command.md +++ b/notes/certifications/ckad/services/command.md @@ -1,5 +1,5 @@ -k expose deployment/redis-deployment --port=6379 --target-port=6379 --name=redis --cluster-ip='' +Create a service that expose the deployment with selector "redis-deployment" -- Create a service that expose the deployment with selector "redis-deployment" +` kubectl expose deployment/redis-deployment --port=6379 --target-port=6379 --name=redis --cluster-ip=` kubectl uncordon diff --git a/notes/databases/partining_vs_sharding.md b/notes/databases/partitioning_vs_sharding.md similarity index 96% rename from notes/databases/partining_vs_sharding.md rename to notes/databases/partitioning_vs_sharding.md index 2aecb18..b6fb843 100644 --- a/notes/databases/partining_vs_sharding.md +++ b/notes/databases/partitioning_vs_sharding.md @@ -1,4 +1,8 @@ -# Partioning vs Sharding +# Partitioning vs Sharding + + + + Database partitioning, sharding, and replication are techniques used to manage data in a database to improve performance, scalability, and availability. Here's an overview of each: diff --git a/notes/databases/transactions.md b/notes/databases/transactions.md index d6d4d4a..5141e5f 100644 --- a/notes/databases/transactions.md +++ b/notes/databases/transactions.md @@ -87,9 +87,11 @@ Transactions are executed sequentially ## Isolation levels vs read phenomena +``` | | Dirty read | Non-repeatable read | Phantom read | Default in | | ---------------- | ---------- | ------------------- | ------------ | ---------- | | Serializable | no | no | no | | | Repeatable read | no | no | yes | | | Read committed | no | yes | yes | postgres | | Read uncommitted | yes | yes | yes | | +``` diff --git a/portfolio/src/helpers/render_badge_classes.py b/portfolio/src/helpers/render_badge_classes.py index 29ea96f..ee26f26 100644 --- a/portfolio/src/helpers/render_badge_classes.py +++ b/portfolio/src/helpers/render_badge_classes.py @@ -3,7 +3,7 @@ def render_badge_classes(tag): 'default': 'bg-info text-dark', 'k8s': 'bg-info text-dark', 'docker': 'bg-primary', - 'python': 'badge-soft-danger', + 'python': 'bg-primary', 'lock': 'badge-soft-danger', 'transaction': 'badge-soft-danger', 'database': 'bg-success', @@ -17,7 +17,9 @@ def render_badge_classes(tag): 'concurrency': 'bg-success', 'parallelism': 'bg-warning text-dark', 'devops': 'bg-warning text-dark', + 'csrf': 'bg-warning text-dark', 'argocd': 'badge-soft-danger', + 'security': 'badge-soft-danger', 'helm': 'bg-info text-dark', } diff --git a/portfolio/src/models/note.py b/portfolio/src/models/note.py index 1e414aa..24d37c9 100644 --- a/portfolio/src/models/note.py +++ b/portfolio/src/models/note.py @@ -10,3 +10,4 @@ class Note: description: str tags: str content: str + view_count: str diff --git a/portfolio/src/services/note.py b/portfolio/src/services/note.py index c54142c..29ba802 100644 --- a/portfolio/src/services/note.py +++ b/portfolio/src/services/note.py @@ -1,4 +1,5 @@ import os +import pathlib from datetime import datetime from bs4 import BeautifulSoup, Comment @@ -10,6 +11,10 @@ class NoteBase: NOTES_PER_PAGE = 6 + VIEW_COUNT = {} + + def __init__(self): + self.load_view_count() @staticmethod def read_markdown_file(file_path): @@ -22,6 +27,20 @@ def parse_html_content(markdown_content): html_content = markdown(markdown_content, extensions=[FencedCodeExtension()]) return html_content + def load_view_count(self): + file_path = f'{pathlib.Path(os.path.abspath(os.path.dirname(__file__))).parent.parent.parent}/view_counts.txt' + with open(file_path, 'r') as f: + view_count = f.read() + lines = view_count .strip().split('\n') + + view_count_by_note = {} + + for line in lines: + key, value = line.split(':') + view_count_by_note[key] = int(value) + + self.VIEW_COUNT = view_count_by_note + def extract_published_date(self, soup): comments = soup.find(text=lambda text: isinstance(text, Comment) and 'date:' in text) if not comments: @@ -65,8 +84,9 @@ def fetch_notes(self, file_name=None) -> list[Note] | Note: published_date = self.extract_published_date(soup) or '09 Mar, 2024' description = self.extract_description(soup) tags = self.extract_tags(soup)[:3] + view_count = self.VIEW_COUNT.get(f'notes/{original_title}', 0) - note = Note(title, original_title, file_path, published_date, description, tags, content=html_content) + note = Note(title, original_title, file_path, published_date, description, tags, html_content, view_count) if file_name and file == file_name: return note diff --git a/portfolio/src/static/note.css b/portfolio/src/static/note.css index 6e50f7a..5c11f37 100644 --- a/portfolio/src/static/note.css +++ b/portfolio/src/static/note.css @@ -330,3 +330,7 @@ body { font-size: 0.9rem; } } + +.view_count { + font-size: 80%; +} diff --git a/portfolio/src/views/pages/notes/note-card.html b/portfolio/src/views/pages/notes/note-card.html index 79f3928..a712320 100644 --- a/portfolio/src/views/pages/notes/note-card.html +++ b/portfolio/src/views/pages/notes/note-card.html @@ -1,6 +1,9 @@ diff --git a/view_counts.txt b/view_counts.txt index 06fdf89..8e1d794 100644 --- a/view_counts.txt +++ b/view_counts.txt @@ -1,30 +1,30 @@ -projects/code2image-package:47 +projects/code2image-package:50 notes/seucurity-context-note:14 notes/db-docker:19 -projects/instagram-coding-easily:17 -projects:43 -index:291 +projects/instagram-coding-easily:19 +projects:47 +index:305 notes/command:12 -projects/iscale:17 -projects/what-I-learn:15 +projects/iscale:18 +projects/what-I-learn:18 notes/test-local-package:13 -projects/climate:18 -projects/mcashpay:22 -projects/renyoo:19 -notes:118 +projects/climate:20 +projects/mcashpay:24 +projects/renyoo:22 +notes:133 projects/materiality:17 notes/best-practices:13 notes/migrate_keycloak_database:14 notes/4_performance_efficciency:12 notes/monitor-privoders:12 -notes/6_sustainability:11 +notes/6_sustainability:12 notes/sargable-queries:12 -notes/1_operational_excellence:14 -projects/coders-tokyo-forum-frontend:13 +notes/1_operational_excellence:15 +projects/coders-tokyo-forum-frontend:17 notes/deployment-straties:12 notes/5_cost_optimization:14 -notes/3_reliability:10 -notes/normalization:13 +notes/3_reliability:11 +notes/normalization:14 notes/useful-commands:12 notes/bookmark-volume:14 notes/design-patterns:12 @@ -32,26 +32,30 @@ projects/coders-tokyo-forum-backend:19 notes/reverse-proxy-vs-proxy-server:12 notes/instance-purchasing-option:13 notes/setup-docker-on-ec2-server:15 -notes/volumne_note:13 +notes/volumne_note:14 notes/service-type:12 -notes/microservice:13 -notes/transactions:13 +notes/microservice:14 +notes/transactions:14 notes/relationships-join:13 notes/json_vs_jsonb_type:13 -notes/caching-strategies:16 +notes/caching-strategies:17 notes/2_security:11 notes/query-plan:17 projects/tornomy:24 notes/union_all:11 notes/oci-image:12 notes/indexing:12 -projects/usdol:14 -notes/locking:14 +projects/usdol:16 +notes/locking:16 notes/lambda:27 -notes/sso:13 +notes/sso:16 projects/what-i-learn:2 -projects/portfolio:4 +projects/portfolio:5 notes/argocd-deploy-with-helm:3 notes/argocd-deployment-trategies:3 notes/argocd-install-and-create-release:3 notes/deploy-with-helm.md:2 +notes/concurreny-implementation:17 +notes/install-and-create-release:1 +notes/deployment-trategies:1 +notes/deploy-with-helm:1