My personal devlog.
You can subscribe to this page via RSS.
This page lists entries for the year 2022, for past entries consult the devlog archive.
du -sh file_path
Explanation
du (disc usage) command estimates file_path space usage
The options -sh are (from man du):
-s, --summarize
display only a total for each argument
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
To check more than one directory and see the total, use du -sch:
-c, --total
produce a grand total
Taken from: https://unix.stackexchange.com/a/185765
I’ve found this neat tool that lets me host multiple ISO files in a single USB drive without having to flash it again and again every time I try to install an OS. Tested for Windows 11, Fedora and Ubuntu. Supposedly, it works with 90%+ distros out there…
This works very much like how we dual boot - I just need to copy the ISO files I want over to the USB drive and that’s it. The ISO will show up as an option to boot into when I boot from the USB drive.
GitHub actions is a CI/CD platform just like Jenkins, CircleCI and others. Its very easy to use since it directly integrates with the repository. Just create a file inside your repo .github/workflows/workflow_name.yml and put the appropriate config. Here’s an example workflow:
name: ci-test # workflow name
# triggers
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test: # job name
runs-on: ubuntu-latest # a GitHub hosted runner
services:
postgres:
# Docker Hub image
image: postgres:11
# Provide the password for postgres
env:
POSTGRES_USER: postgres_user
POSTGRES_PASSWORD: postgres_password
POSTGRES_DB: db_name
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2 # a reusable action, created by GitHub
- name: Set up Go
uses: actions/setup-go@v2 # another reusable action
with:
go-version: 1.17
- name: Install golang-migrate
run: |
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.1/migrate.linux-amd64.tar.gz | tar xvz
sudo mv migrate /usr/bin/
which migrate
- name: Run migrations
run: make migrateup
- name: Test
run: make test # a custom action where we're running custom commands
needs: job_name is specified for any job, then it’ll run the job_name job first and then run the current job (sequentially).container: node:10.18-jessie.runs-on: ubuntu-latestuses: actions/checkout@v2Assume, there are two users Alice and Bob. They both want to exchange some information with each other but they don’t want others to eavsedrop on what they want to talk about. So they decided to encrypt each other’s messages. But there is a problem - how will they share the encryption key (which they’ll use to encrypt their messages) with each other without others getting hold of it?
YouTube - A complete overview of SSL/TLS and its cryptographic system
This is where the Diffie-Hellman algorithm comes in. At first, both Alice and Bob share two numbers that are accessible publicly.
g - base
p - modulus (should be a prime number)
Then, each of them picks a secret number.
Alice picks the secret number - a
Bob picks the secret number - b
After they each select a secret number, they perform the following operation to get a new number - A and B.
For Alice, A = (g^a) mod p
For Bob, B = (g^b) mod p
Next, they send this number to each other publicly.
Note that, even if they share this number publicly, its almost impossible to guess what’s the secret number each of them picked because of loss of information when modded with ‘p’.
After the exchange, Alice now has Bob’s public number/key - B and Bob has Alice’s public number/key - A. They apply the following operation to get a new number that is exactly the same.
For Alice, S = (B^a) mod p
For Bob, S = (A^b) mod p
The number S will be the same for both of them as mentioned earlier!
#!/usr/bin/env python
def diffie_hellman(g: int, p: int, a: int, b: int):
A = (g**a) % p
B = (g**b) % p
S1 = (B**a) % p
S2 = (A**b) % p
assert S1 == S2, "Incorrect implementation, both S1 and S2 should be equal"
return S1
def main():
import random
g = 2
p = 97
for i in range(10):
a = random.randint(1, 100)
b = random.randint(1, 100)
print(diffie_hellman(g, p, a, b))
if __name__ == "__main__":
main()
Output
79
6
75
1
24
70
9
1
81
61