Skip to content

Commit

Permalink
refactor: code & update some notes
Browse files Browse the repository at this point in the history
  • Loading branch information
harrylowkey committed Jul 21, 2024
1 parent 620f3b0 commit 0d0169f
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 34 deletions.
17 changes: 17 additions & 0 deletions notes/backend/security/csrf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Cross Site Request Forgery

<!-- published_date: 21 Jul, 2024 -->
<!-- description: CSRF, XSRF -->
<!-- tags: security, hacking, csrf, xsrf -->

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.

8 changes: 4 additions & 4 deletions notes/backend/sso/sso.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# SSO

1. Service proivders
- Gmail
- Youtube
- Gmail
- Youtube

2. Identity providers
- Auth0
- Keycloak
- Auth0
- Keycloak


## Flow
Expand Down
4 changes: 2 additions & 2 deletions notes/certifications/ckad/services/command.md
Original file line number Diff line number Diff line change
@@ -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 <node-name>
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Partioning vs Sharding
# Partitioning vs Sharding

<!-- published_date: 21 Jul, 2024 -->
<!-- description: Partitioning vs Sharding -->
<!-- tags: database, partition, shard -->

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:

Expand Down
2 changes: 2 additions & 0 deletions notes/databases/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
```
4 changes: 3 additions & 1 deletion portfolio/src/helpers/render_badge_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
}

Expand Down
1 change: 1 addition & 0 deletions portfolio/src/models/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ class Note:
description: str
tags: str
content: str
view_count: str
22 changes: 21 additions & 1 deletion portfolio/src/services/note.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
from datetime import datetime

from bs4 import BeautifulSoup, Comment
Expand All @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions portfolio/src/static/note.css
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,7 @@ body {
font-size: 0.9rem;
}
}

.view_count {
font-size: 80%;
}
7 changes: 5 additions & 2 deletions portfolio/src/views/pages/notes/note-card.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<div class="col-md-6" id="project-items-1">
<a href="{{WEB_URL}}/notes/{{note.original_title}}" class="card-link">
<div class="card">
<div class="card position-relative">
<div class="position-absolute top-0 end-0 p-2">
<span class="badge bg-secondary">{{note.view_count}} Views</span>
</div>
<div class="card-body">
<div class="d-flex mb-3">
<div class="flex-grow-1 align-items-start">
Expand Down Expand Up @@ -34,7 +37,7 @@ <h5 class="mb-1 font-size-17 team-title">{{note.title}}</h5>
{% endfor %}
</div>
</div>
</div><!-- end cardbody -->
</div><!-- end card-body -->
</div><!-- end card -->
</a>
</div>
50 changes: 27 additions & 23 deletions view_counts.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
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
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

0 comments on commit 0d0169f

Please sign in to comment.