FEAT: Working version
This commit is contained in:
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -1,3 +1,3 @@
|
||||
[submodule "quickstart/themes/risotto"]
|
||||
path = quickstart/themes/risotto
|
||||
url = https://github.com/joeroe/risotto.git
|
||||
url = git@github.com:johncosta27/risotto.git
|
||||
|
@ -7,16 +7,8 @@ date = 2023-11-14T17:55:14Z
|
||||
|
||||
---
|
||||
|
||||
I am a Software Engineer, currently working at Decipad. I'm interested in various subjects including: Compilers, Web Development, Distributed System and many more.
|
||||
|
||||
---
|
||||
I am a Software Engineer, currently working at Decipad. I'm interested in various subjects including: Compilers, Linux Servers, Web Development, Distributed System and many more.
|
||||
|
||||
# Projects
|
||||
|
||||
---
|
||||
|
||||
I have some Projects
|
||||
|
||||
- Bruh 1
|
||||
- Bruh 2
|
||||
- Bruh 3
|
||||
I've developed various projects
|
||||
|
BIN
quickstart/content/blog/DeepworkPart1.jpg
Normal file
BIN
quickstart/content/blog/DeepworkPart1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
BIN
quickstart/content/blog/DeepworkPart2.jpg
Normal file
BIN
quickstart/content/blog/DeepworkPart2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
BIN
quickstart/content/blog/DeepworkPart3.jpg
Normal file
BIN
quickstart/content/blog/DeepworkPart3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
BIN
quickstart/content/blog/DeepworkPart4.jpg
Normal file
BIN
quickstart/content/blog/DeepworkPart4.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
BIN
quickstart/content/blog/DeepworkPart5.jpg
Normal file
BIN
quickstart/content/blog/DeepworkPart5.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
BIN
quickstart/content/blog/DeepworkPart6.jpg
Normal file
BIN
quickstart/content/blog/DeepworkPart6.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
132
quickstart/content/blog/Threaded-js.md
Normal file
132
quickstart/content/blog/Threaded-js.md
Normal file
@ -0,0 +1,132 @@
|
||||
+++
|
||||
title = "Threaded JavaScript!"
|
||||
date = "2022-04-10"
|
||||
author = "John Costa"
|
||||
toc = true
|
||||
+++
|
||||
|
||||
For a long time, my language of choice has been JavaScript (and recently TypeScript), this is for both frontend development as well as backend development.
|
||||
|
||||
I enjoy the simplicity of using the same language for both sides of a project and I especially like working with Node.js, a Javascript run time environment with a very sophisticated asynchronous event loop, which makes it perfect for applications such as RESTful APIs which access databases etc...
|
||||
|
||||
However, I have also done backend work using Golang, a strongly typed, compiled, very fast language with a vibrant community and a "do it yourself" attitude, quite the change from Javascript. And something I have touched and enjoyed playing with are go routines, which are a way to create very light weight threads. This works by calling a function as a "go routine", which I think is very elegant. This is managed by the go run-time environment, but it can spawn threads if it needs to - a nice abstraction which means I don't have to handle threads directly - but do have to handle go routines as if they ARE threads.
|
||||
|
||||
But anyways, it left me wondering if I could have threads in JavaScript, which sounds crazy but Node.js has support for this is "Worker Threads". These are threads managed by Node.js which can run a .js file and communicate with its parent - it is quite similar to go routines.
|
||||
|
||||
So I made a small program to calculate the same MD5 hash 1 million times:
|
||||
|
||||
(Note that these files are .mjs files (module JavaScript), Node.js will only run them if you have .mjs as the file extension - All they do is allow the "import" syntax and a few other things).
|
||||
|
||||
```js
|
||||
import crypto from "crypto";
|
||||
|
||||
console.time("Single-Thread");
|
||||
|
||||
const n = 10000000;
|
||||
const string = "Hello World";
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
const hash = crypto.createHash("md5").update(string).digest("hex");
|
||||
}
|
||||
|
||||
console.timeEnd("Single-Thread");
|
||||
```
|
||||
|
||||
Running this program gave me this result:
|
||||
|
||||
```
|
||||
Single-Thread: 1.139s
|
||||
```
|
||||
|
||||
I then modified my code to use worker threads. This splits the work load into 8 worker threads, it gives each thread a start and an end range for the hash - which in total makes 1 million hashes.
|
||||
|
||||
```js
|
||||
import { fileURLToPath } from "url";
|
||||
import { Worker, isMainThread, parentPort, workerData } from "worker_threads";
|
||||
import crypto from "crypto";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const n = 1000000;
|
||||
const THREAD_NUM = 8;
|
||||
const string = "Hello World";
|
||||
|
||||
if (isMainThread) {
|
||||
const threads = new Set();
|
||||
for (let i = 0; i < THREAD_NUM; i++) {
|
||||
threads.add(
|
||||
new Worker(__filename, {
|
||||
workerData: {
|
||||
start: i * (n / THREAD_NUM),
|
||||
end: i * (n / THREAD_NUM) + n / THREAD_NUM,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
console.time("Thread");
|
||||
|
||||
for (const worker of threads) {
|
||||
worker.on("message", (msg) => console.log(msg));
|
||||
worker.on("exit", () => {
|
||||
threads.delete(worker);
|
||||
if (threads.size === 0) {
|
||||
console.timeEnd("Thread");
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (let i = workerData.start; i < workerData.end; i++) {
|
||||
const hash = crypto.createHash("md5").update(string).digest("hex");
|
||||
}
|
||||
|
||||
parentPort.postMessage("Done!");
|
||||
}
|
||||
```
|
||||
|
||||
This results in the following output:
|
||||
|
||||
```js
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Thread: 335.294ms
|
||||
```
|
||||
|
||||
A 4x increase in speed. There is a delay because worker threads actually spawn threads and therefore there is a bit of overhead with the syscall to create these threads.
|
||||
|
||||
This is very clear if we changed the number of hashes to 10 000.
|
||||
|
||||
### Single Thread
|
||||
|
||||
```
|
||||
Single-Thread: 23.476ms
|
||||
```
|
||||
|
||||
### 8 Worker Threads
|
||||
|
||||
```
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Done!
|
||||
Thread: 70.337ms
|
||||
```
|
||||
|
||||
As you can see the single thread beat the 8 threads by almost 4x. This is because it is costly to create a thread outright which is what Node.js seems to be doing.
|
||||
|
||||
## Disclaimer
|
||||
|
||||
The Node.js crypto module is basically a wrapper for the native OpenSSL hashing functions, so I suspect that Node.js is just making a very fast C program do the hard work - but never the less it works very well.
|
||||
|
||||
## Conclusion
|
||||
|
||||
Node.js is a very solid backend technology to perform parallalism, it is not just limited to making RESTful APIs. It can competes with strongly typed and compiled languages such as golang.
|
20
quickstart/content/blog/deepwork-review.md
Normal file
20
quickstart/content/blog/deepwork-review.md
Normal file
@ -0,0 +1,20 @@
|
||||
+++
|
||||
title = "Deepwork - Cal Newport"
|
||||
date = "2022-08-16"
|
||||
author = "John Costa"
|
||||
toc = true
|
||||
+++
|
||||
|
||||
This review is a little different because I wrote it down on paper, here are the pages:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
79
quickstart/content/blog/digital-minimalism-review.md
Normal file
79
quickstart/content/blog/digital-minimalism-review.md
Normal file
@ -0,0 +1,79 @@
|
||||
+++
|
||||
title = "Digital Minimalism - Cal Newport"
|
||||
description = "A book review"
|
||||
tags = ["books"]
|
||||
date = "2022-09-05"
|
||||
author = "John Costa"
|
||||
toc = true
|
||||
+++
|
||||
|
||||
The author of the very popular "Deep work", is a book describing a problem, which is our digital addictions and malpractices, and also how we can adopt the philosophy of "Digital Minimalism", in order to make us use technology in a healthy, and productive way.
|
||||
|
||||
The book opens up by talking about how many of us feel trapped by technology, we have developed unhealthy habits of constant connection and constant scrolling. There have been many articles written about this, and many people have this feeling that technology isn't working for them, but it seems that we are the slaves to it. This is good business on the side of giant technology companies such as Facebook (Meta), which make money from our attention, it is only natural they want us to be constantly attached to our phones.
|
||||
|
||||
Before reading this book, I had thought about this - specially when it comes to short form content such as TikTok, Instagram Reels, you name it... I was extremely concerned about my own well being, because I had never felt such a pull from a piece of social media, I always used it fairly sparingly - but when Instagram Reels came out, I was hooked, pulling around 1 - 2 hours a day just on these short videos, and it showed. I couldn't concentrate on my online lectures, I couldn't learn as quickly as I had done before, nor could I concentrate for as long, so I stopped it. The first step came a while ago, but I used to text my partner on Instagram DMs, and I asked if she would mind switching to Telegram, and the simple act of not opening the app slashed my screen time in half. I am rambling let's get back on track.
|
||||
|
||||
## Digital Minimalism and Digital Declutter
|
||||
|
||||
Digital Minimalism as Newport describes it is:
|
||||
|
||||
> Digital Minimalism is a philosophy towards technology which prioritises digital use to a small number of deeply thought out and efficient activities.
|
||||
|
||||
He backs this up with the following points (I won't go into too much detail here).
|
||||
|
||||
- Clutter is costly
|
||||
- Optimisation is important: Each tool should be finely tool to help you get your work done / have proper leisure.
|
||||
- Intentional is satisfying: Doing things because you want to them is by itself satisfying.
|
||||
|
||||
Newport suggests that we undergo a 30 day digital de-clutter where we remove all non-essential digital technologies from our life. This includes Netflix, most apps (excluding work), TV, and most importantly: Social Media. Newport then suggests that after the 30 days we start to reintroduce some technologies, but we do so with every intention of using them properly, therefore we apply the principles of Digital Minimalism. Newport claims this is important because it shows us what we need and what we don't in our lives.
|
||||
|
||||
I think this might be slightly extreme, I think you can see problems in your current tools and act accordingly, however I haven't had a huge problem with technology - perhaps someone with a greater addiction would benefit from the complete de-clutter.
|
||||
|
||||
## Practices of Digital Minimalism
|
||||
|
||||
### Spend time alone
|
||||
|
||||
With the rise of modern technology, we have almost completely removed solitude. Think about it, when was the last time you were truly alone? No music, no TV, no work, just you? This was a scary realisation for me because the answer was none. I am either always surrounded by friends or see them on social media, or I am listening to music or watching netflix when I'm alone, this means I have spent very little time alone.
|
||||
|
||||
There are great examples that Newport gives in the book about why Solitude is important, but my favourite is that we have very complicated social circuits in our brain, and they are not meant to be on all the time, but they are now a days, constant notifications, alerts, pings, etc...
|
||||
|
||||
Spending time alone can benefit your mental health and it gives you time to realise the person you want to be and actually have a chat with yourself, something I believe (and so does Newport) to be of the utmost importance.
|
||||
|
||||
### Don't click like
|
||||
|
||||
Clicking the like button on social media makes you more committed to social media, interacting with in any way makes you more invested in it, and in recent times we have all heard the odd family member say "Why didn't you like my post?", as clicking twice on a piece of glass shows that I really care for them.
|
||||
|
||||
Social media companies know this, that we now have a certain contract between each other to like and comment on each others posts, and this makes us waste more time online, scrolling to endless posts and double tapping, for most of us it is probably muscle memory, which is just horrifying.
|
||||
|
||||
The reason I read this book WAS because of how social media affected my mental health and how often I was spending on it, after reading the book I uninstalled all social media from my phone and I message my closes friends on WhatsApp or Telegram (or god forbid SMS). And most people will say that they "cannot do it", YES YOU CAN, just try... you'll realise that you don't even care about 90% of the people on social media and all you've been doing is distancing yourself from the relationships you actually want to maintain. Focus on the 10% of people you actually care about, go see them, call them, sending a "heart" on Instagram every once in a while is no way to maintain a relationship.
|
||||
|
||||
### Reclaim leisure
|
||||
|
||||
The one I struggle with the most.
|
||||
|
||||
> Prioritise demanding activity over passive consumption
|
||||
|
||||
Our leisure habits, most often consist of scrolling through Twitter or watching Netflix. This stuff is fine but it has to be kept in check, if this is all we do then it is not okay, you need to have a proper leisure activity, a club or anything really to keep you busy when you are not working, something you really enjoy doing. These also have the benefit of being extremely satisfying compared to just watching Netflix.
|
||||
|
||||
> Seek activities, that require real-world, social interaction
|
||||
|
||||
I, just like many others, love working remotely and love playing some video games with friends (or even by myself) however this cannot replace the leisure you have from playing chess over the board, or going to a badminton club where you have to socialise with your doubles partner. Social interaction in leisure is extremely important.
|
||||
|
||||
### Join the attention resistance
|
||||
|
||||
Many giant social media companies are fighting for your attention, that is their business model, they need your eyes, on your phone, to sell you ads. Don't give it to them.
|
||||
|
||||
Easier said then done but Newport does suggest a couple of things to get you started:
|
||||
|
||||
- Delete social media from your phone (check it on your computer instead).
|
||||
- Use social media like a profession (use it to check on your friends, message someone, don't waste time scrolling).
|
||||
- Embrace slow media (long articles, something that really requires your full attention).
|
||||
- Dumb down your phone (I will go into this last one).
|
||||
|
||||
Your phone, is the closest object to you, maybe the closest object humans have ever had. We are rarely 1 meter from our phone. Phones are amazing inventions, everything you could ever know is just at your finger tips on a device many times more powerful than the moon lander.
|
||||
|
||||
However, it can also be extremely addictive to just stare at the screen for hours, so I (and Newport) suggest you dumb down your phone. For me, I installed Niagra launcher (I have a OnePlus 8 running Android 11), this is a super simple launcher that lists your favourite apps, and the rest are hidden, that's it. This means when you open the phone you go straight to the app you want, you don't scroll for no reason. Something else this has helped me with is removing the apps I was somewhat addicted to (Instagram and YouTube), and put them out of sight, making me less likely to open them.
|
||||
|
||||
## Conclusion
|
||||
|
||||
Digital Minimalism is a great book that I think most people should read, it really exposes our addiction to technology and social media, and how it just isn't okay we spend so much time on it. It helped me form better, healthier habits with technology and in turn I am much happier, more productive, and spend more time doing more meaningful things - But I won't like, I still binge netflix from time to time, I still watch YouTube a TON, but this book has made me much more cautious about this, I can make sure that at least I don't use social media, or that I am aware of how much time I am spending on my phone.
|
@ -1,8 +0,0 @@
|
||||
+++
|
||||
title = 'My First Post'
|
||||
date = 2023-11-14T17:55:14Z
|
||||
+++
|
||||
|
||||
# Hello World
|
||||
|
||||
This is a post
|
51
quickstart/content/blog/the-psychology-of-money.md
Normal file
51
quickstart/content/blog/the-psychology-of-money.md
Normal file
@ -0,0 +1,51 @@
|
||||
+++
|
||||
title = "The Psychology of Money by Morgan Housel - A review"
|
||||
date = "11/2022-11-15"
|
||||
author = "John Costa"
|
||||
toc = true
|
||||
+++
|
||||
|
||||
This book contains 19 chapters, all with a small bit of wisdom about money, all quite useful. Much of what the book covers sounds like common sense if you are already somewhat money savvy, however getting the refresher or the introduction to these topics, is something this book did very well for me.
|
||||
|
||||
A big theme I found in this book was simply: Patience.
|
||||
|
||||
## Patience: Compounding
|
||||
|
||||
Chapter 4 talks about compounding interest, and how wealth is not build over night, but instead takes years and even decades to accumulate, through the power of compounding, this - I believe, is the most important lesson that the book has to teach. It doesn't matter if you invest £1000 today if you won't do anymore for the rest of the year, it is all about continual investments month after month after month, and leaving it. Just leave it, it will grow.
|
||||
|
||||
Housel further proves this point with the beautiful statistic: If you invest over a 20-year period in the US Stock marked, based on historical data you are 100% guaranteed to make money. Even if you bought in the worst possible moment, and also sold in the worst moment, because of the amount of time your money had to grow, it is (historically) impossible to lose money, unless of course you withdraw it early.
|
||||
|
||||
## Patience: Staying wealthy
|
||||
|
||||
In the chapter 5, Housel goes on to discuss the different between getting wealthy, staying wealthy. And similarly to compounding it is about patience.
|
||||
|
||||
It is about being happy with your circumstance and not blowing all your wealth in unnecessary things, and instead, enjoying your wealth reasonably (maybe don't buy a Ferrari, but maybe you can afford an AMG), and continually investing - to make sure you STAY wealthy.
|
||||
|
||||
## Patience: Lifestyle
|
||||
|
||||
Throughout the book, Housel hints at the fact that often people change their life-style depending on how much they make, so even if you make millions, if you are spending millions you are not really wealthy, because you're not accumulating and making money work for you. This relates to the overall theme of patience, as a person must be calm and reasonable about their lifestyle, and very careful about raising it. Because it is easy to go forward, but very difficult to bring down the expensive bills.
|
||||
|
||||
I find it quite interesting how the entire book, doesn't so much talk about making money, or what to do with money, but more so about how people behave with money.
|
||||
|
||||
## Other themes
|
||||
|
||||
The book explores other themes, such as how people think about different assets depending on factors completely unrelated to those assets, for example:
|
||||
|
||||
- People living in 1970, saw the S&P500 Boom, and therefore will for the rest of their lives, believe that is it a good way to invest money.
|
||||
- Someone living during the 2000s .COM crash, might not think the same.
|
||||
- Or if you work in Tech, you are likely to be Bullish on Tech
|
||||
|
||||
There are various factors, but the book showed me that I must think about my own biases, and listen to advice in a reasonable way, instead an emotion, or self-conforming way, because these are dangerous traps, and the short-term suffering of finding out you are biased and forcing yourself to make better decisions, is definitely better than investing in something because you personally think it will work.
|
||||
|
||||
People will also listen to facts, that fit the opinions that they have before, but this is another massive topic which Housel describes quite well (you are more likely to listen to financial advisers that confirm your beliefs). This topic I should write something about.
|
||||
|
||||
All in all, this review was quite rambly, and I didn't cover all the aspects the book talked about, but mostly the ones which I found to be more eye opening in a way. Housel talks about a series of other topics such as:
|
||||
|
||||
- Different goals from other people
|
||||
- Always leaving room for error
|
||||
- Never think something is impossible
|
||||
- Don't be taken by current event, let the markets do their thing
|
||||
|
||||
All of which were really important for me to read as a young person who now actually has some money to start investing into my future. Very good read, and would definitely read more books from Housel - He put complicated topics in a very easily digestible format which I enjoyed.
|
||||
|
||||
8/10
|
85
quickstart/content/blog/therepublic-review.md
Normal file
85
quickstart/content/blog/therepublic-review.md
Normal file
@ -0,0 +1,85 @@
|
||||
+++
|
||||
title = "The Republic by Plate - A recap / review"
|
||||
date = "2020-01-05"
|
||||
author = "John Costa"
|
||||
toc = true
|
||||
+++
|
||||
|
||||
# A summary and review
|
||||
|
||||
**Disclaimer: This book has some fairly rough topics, I'm simply writing a summary and a review**
|
||||
|
||||
## Context
|
||||
|
||||
The Republic was written by Plato in 375 BC, many years ago. In was written in Greece, when the country was made up of various states who were at constant wars with not only each other but with the Persians at the time. This does explain some of the ideas in the book, which would be seen as extreme in any sense of the word.
|
||||
|
||||
This book was written by Plato in the form of a dialogue between Socrates and various other people, however this might be a made up dialogue, it is obviously very hard to confirm whether this is Socrates' thoughts or Plato's, but most likely it is Plato's.
|
||||
|
||||
Plato came from a long line of powerful Athenians who were very involved in politics and were obviously very wealthy, however this was not the path that Plato choose for himself, he would rather become a philosopher and open his famous Academia, which has produced some of the ideas that structure our world today, by producing pupils such as Aristotle, and even Alexander the Great, who went on to shape the world as we know it.
|
||||
|
||||
This should all be kept in context when reading this book as to, understand why Plato thought such extreme ideas were not only true but the best for both the individual and the state, this is extremely important to keep in mind.
|
||||
|
||||
## What is Justice?
|
||||
|
||||
The book basically starts with this question, of what justice is and whether the just man is really the best, happiest and most well of than the unjust man, views challenged by his opponents in the dialogue.
|
||||
|
||||
To solve this question Socrates goes on to describe a city which contains many rules and extreme ideas, this state would be considered a near fascist regism in today's world, but with the failing democracies in Athens, and many starving people in Greece due to poor leadership, we can see why Socrates/Plato think this is the best way to form a city.
|
||||
|
||||
The reason a state is describes is because Socrates tried to compare the individual to the state, and therefore if the state is just, the individual is also just, furthermore if the state is a good one then we can also assume that its people are good. This ideas doesn't quite hold completely in today's world, but there are some parallels to be drawn. For example countries with better education will produce citizens which pollute less, are less likely to be racist amongst other things, although even these assumptions are not always correct.
|
||||
|
||||
So what are these rules? Well we must trace Socrates train of thought as it is the easiest way to understand this topic. Firstly, when forming our state each person will do what they are best at; the example given is that of a show maker, who Socrates claim will produce better shoes if he only focuses on shoe making. This means that our very basic state will consist of farmers, miners, builders and other basic professions.
|
||||
|
||||
However this state is hardly permanent, because it is natural for a state to want to expand, another characteristic of the state drive by individuals. Because of this the state must be ready for war to take over land, this means that we must add to our state, not only do we have regular professions we must also have warriors.
|
||||
|
||||
And this is a big deal, because warriors are obviously more powerful than the regular citizen and therefore Socrates claims that there warriors or as he calls them "Auxiliaries", are restrained in two ways.
|
||||
|
||||
- Education, they are brought up with extensive education and only the best will be able to become part of this Auxiliary class.
|
||||
- Rulers, this is a sub class of the Auxiliary class within the state, the best of the Auxiliaries group will be able to become the rulers of the state, which will command the Auxiliary.
|
||||
|
||||
There is a lot to unpack but starting with education, Plato claims that much of what they are exposed to must be censored; This means that only certain art can be shown or certain poetry can be read. This is an element which is obviously present in our current education systems, we do not expose children of certain things for their own sake, whether this is a good thing or a bad thing is the base for much heated debate and it would be quite difficult to discuss this completely. All I can say is that this book was written many many years ago and therefore is not in line with what we view as a good way of life. This is the reason that Plato saw this censorship as a good thing.
|
||||
|
||||
It was essential for this class system to only work on the basis of whether the individual fits into a certain group or not, therefore Plato comes out with another idea which is very out there. No child should meet their parents and vice versa, they are children of the state which would mean they grow up, loving the state. Again, an idea which could hardly ever be realised and Plato is very aware of this, many passages in the book state that this state is purely one of the mind and will never (really) exist.
|
||||
|
||||
There are a few more rules to bring up, starting with the fact that in this state, private housing is simply banned. People should live together with groups of people who do similar things they do and are of the same class, this brings an idea of collectivism, or as many critics of this book call it: Communism.
|
||||
|
||||
And similarly to private housing, wealth is also not allowed. This is for a number of reasons but most is to prevent people from taking action for personal gain, which is definitely a big problem in modern politics today. This was actually challenged in the book by one of the other characters, because it states that this state could not form any allies because it did not have any gold. Socrates is quick to shut it down by saying that the state has the best soldiers, and does not want wealth, therefore if other states allied with this one, they would keep all of the looting and gold from the enemies.
|
||||
|
||||
## The family
|
||||
|
||||
Plato describes in this book that women are different from men, we can all agree on this. However he did not see any difference in their capacities to be rules, an idea thought to be completely wrong at the time of writing. This is obviously something we all relish, the ability for anyone, regardless of gender or colour to take any job with the only restriction being their own ability to carry out that job (or at least it should).I obviously completely agree with this part of the book, it is perhaps the only part I completely, 100% agree with.
|
||||
|
||||
However, moving on to family, because children do not meet their parents, children are made in "Mating rituals" where the state picks pairs of people, basically to breed the best possible citizens, and eventually the best possible rules. However, very important to note that the citizens are not aware that the pairing are done, to their knowledge they simply won a "lottery", another part of censorship in our state.
|
||||
|
||||
## The ruler
|
||||
|
||||
Plato states that "philosophers should be kings", he also states that this does not happen in the world because those who are most suited for ruling, are the ones less likely to get into politics. Which is argued against but we can see where he is coming from. Philosophers who's only goal in life is to seek the truth, are not interested in politics of the state because it contains too much unmoral activity, campaigning, tactics and other things. This means they are likely never to rule.
|
||||
|
||||
Our state fixes this by having the best performing children, those who are seen to seek good and truth, to be our rulers.
|
||||
|
||||
This is pretty much impossible to achieve in the modern world, or in any world for that matter because it is obviously very hard to describe who is the best and it also begs the question, is the education system proper and a million other questions.
|
||||
|
||||
## Failed states
|
||||
|
||||
Plato talked a lot of failed states, and I feel these were very directed at particular states in ancient Greece. He also states in the Republic that these states would originate from the society he described n the following order
|
||||
|
||||
Timarchy --> Oligarchy --> Democracy --. Tyranny
|
||||
|
||||
Going from least bad to most bad, and each deriving from one another. Plato gives very intresting examples of the kind of person that would live in each one and how they came to be, as their parents represented the prior type of state. This does depend on assumptions made earlier that the state is made of people and therefore the two are very much linked.
|
||||
|
||||
It is worth describing what each of these societies are and a real world example of each.
|
||||
|
||||
Starting with Timarchy, this is the most similar to our state but a few elements started to slip, for example private property is allowed, but most importantly, glory and honour are the leading principles of the state, instead of intelligence and the love for the truth. He gave Sparta as an example, a state which Plato seems to admire, because it is not far from the one he describes in this book. I won't give any real world examples because frankly this was not discussed in great length in the book and I do not know enough about the subject to categorise a single country in the modern world into a Timarchy (However, I believe that WWII Japan might have come close).
|
||||
|
||||
Oligarchy happens when a very small amount of people have control over the state because of huge amounts of wealth, it reminds me of most countries today to some extent, specially the US due to their extensive neo-liberal views, and the huge influences of billionaire donators to political parties, many more countries could be partially categorised as an oligarchy though. Plato said this derived from a Timarchy because of the ever expanding wealth of the political powers in a timarchy.
|
||||
|
||||
Democracy, rated very poorly by Plato, most likely because of Athens, which was a democracy. However Athens was still quite corrupt, and their execution of Socrates probably meant that Plato despised the city, we must also remember this is where he grew up, and witnessed first hand the corruption happening within the state. Democracy then derives from an oligarchy when the poor, which compose the majority of the state finally take over in a sort of revolution. A democracy values personal freedom above everything else and therefore people have a say as to who is in power. This can be a bad thing because populism exists and is described in the Republic (not by that name but as a simple description of it). It is also said that many laws won't be respected because of the personal freedom everyone has in this state.
|
||||
|
||||
This then leaves a Tyranny, and this one is the most interesting one. A Tyranny comes from a democracy because one populist leader is elected who then becomes a tyrant. This is rather interesting because in the dialogue, Plato comes to the conclusion that the tyrant is the least happy man, and also the most unjust. He argues this because he is always looking over his shoulder and fears that injustice happen to them, the reasoning is slightly unclear to me but he arrives at this conclusion.
|
||||
|
||||
Okay so this has gone on to long I would just like to finish my thoughts up.
|
||||
|
||||
The republic is an excellent book to read, it is interesting and logical, it is a window back into ancient Greece and into a way of thinking which is a little different to us today. It is a book which carries some weight and describes some complex topics in a conversation which is very interesting to me, obviously the book suggests a pretty extreme state which does demonstrate its age, but I still think it is very important to look at ways of thinking from the past. I like how many ideas in the book actually have a lot of relevance in today's world, for example Tyranny and the rise of populism which Plato said would happen from a democracy, this has happened all over the world with populist leaders such as Saddam Hussein.
|
||||
|
||||
I also find it interesting how, Plato who lived more than 2000 years ago describes women as being no different then men men when it came to ruling, and it took us so long (up until very recently), to finally see this and allow women in power.
|
||||
|
||||
Overall this book was a brilliant read and very informative in some ways, obviously I disagree with a lot of it, but that does not mean it was a bad book at all, I actually credit most of these disagreements to the age of the book and how different things were 2 millennia ago.
|
102
quickstart/content/projects/XmlParser.md
Normal file
102
quickstart/content/projects/XmlParser.md
Normal file
@ -0,0 +1,102 @@
|
||||
+++
|
||||
title = "Xml Parser"
|
||||
date = "2023-07-27"
|
||||
author = "John Costa"
|
||||
toc = true
|
||||
tags = ["Software"]
|
||||
+++
|
||||
|
||||
---
|
||||
|
||||
- Git Repo: [Here](https://github.com/JohnCosta27/GoXmlParser)
|
||||
|
||||
During my time at university I took a compilers module, it turned out to be my favourite module out of all my 3 years at university, and I had the privilege of being taught by [Elizabeth Scott](https://pure.royalholloway.ac.uk/en/persons/elizabeth-scott), one of the creators of [GLL Parsers](https://www.cs.rhul.ac.uk/research/languages/csle/GLLparsers.html), a parsing algorithm that can parse any context free grammar, it's very cool.
|
||||
|
||||
I did very well in this module, and I really enjoyed it, but it was heavily theoretical, with little to no practical work. This is fine, it taught me a lot of parsing algorithms, and everything I know about grammars and languages.
|
||||
|
||||
So I decided to give it a go and actually write one!
|
||||
|
||||
# XML (like)
|
||||
|
||||
I decided to parse a XML like language. You are probably mostly familiar with XML from its use in HTML.
|
||||
|
||||
```html
|
||||
<hello>World</hello>
|
||||
```
|
||||
|
||||
You have an opening tag, some content in the middle, and a closing tag. However it can get more complicated than that.
|
||||
|
||||
```html
|
||||
<hello hello="world">
|
||||
Some text here
|
||||
<a></a>
|
||||
dsamkdsamdkas
|
||||
|
||||
<b attribute="dksoadisma" />
|
||||
</hello>
|
||||
```
|
||||
|
||||
As you can see, we can have nested structures, attributes on tags, and self closing tags.
|
||||
|
||||
# Building the Parser
|
||||
|
||||
I used Golang to build the parser, it's a language that is familiar to me, extremely permanent and a delight to use.
|
||||
|
||||
I decided to use recursive descent to build the parser, as XML is fairly easy to parse this way, and it becomes less complicated to start my compiler journey using this technique. From my compilers module I knew how to generate recursive descent parsing functions even if I was blind folded for any grammar, so this shouldn't be hard... Right?
|
||||
|
||||
## What I learnt
|
||||
|
||||
### Theory != Practice
|
||||
|
||||
Even though I knew how to generate RDP (Recursive descent parsers), I was always given a grammar to start from. But this was a different problem, I have to create a grammar that cannot be left recursive (RDP limitation), and would parse without ambiguity.
|
||||
|
||||
This turned our harder than I thought, because it's a task that can be done in millions of different ways. In the end I settled for the following grammar.
|
||||
|
||||
```
|
||||
Element ::= OpenTag ElementSuffix
|
||||
OpenTag ::= '<' NAME Attributes
|
||||
Attributes ::= NAME '=' STRING Attributes | EPSILLON
|
||||
ElementSuffix ::= '/>' | Content CloseTag
|
||||
Content ::= DATA Content | Element Content | EPSILLON
|
||||
CloseTag ::= '</' NAME '>'
|
||||
|
||||
// Literals
|
||||
DATA = All the content between '>' and '<'
|
||||
NAME = A continuous string of alphabetical characters
|
||||
STRING = Content inside (and including) ""
|
||||
EPSILLON = null
|
||||
```
|
||||
|
||||
This seems like a good grammar. It allows for all the XML structures we are used to seeing, and it also seemed to have the right mix of parser and lexer complexity. I'll explain what I mean by this.
|
||||
|
||||
### Lexer vs Parser
|
||||
|
||||
Lexer (Lexical Analysis), or Tokenizer takes the raw string input and turns it into meaningful tokens, we saw the tokens I used above:
|
||||
|
||||
- <
|
||||
- \>
|
||||
- />
|
||||
- </
|
||||
- STRING
|
||||
- DATA
|
||||
- NAME
|
||||
|
||||
Some of these are trivial, such as the top 4 on the list, but the rest isn't so easy. String would be an example of a slightly more complex token.
|
||||
|
||||
But when I was first starting, in my head all the hard work would have to be done by the parser and the lexer would basically just pick up single strings of characters. This led me to a rabbit hole of parsing basically single characters as tokens (including spaces!), and writing progressively more complicated grammar rules (and therefore more complicated parser), in order to not have the lexer be complicated.
|
||||
|
||||
But I quickly realised that regular expressions are a tool, and I should use them well. And so that's how I ended up with more complex tokens, and was able to drastically simplify my grammar rules.
|
||||
|
||||
# Semantics
|
||||
|
||||
The last thing I want to talk about was my semantic analysis, which was by far the easiest part of the project, simply because all I have to do is make sure that the opening tags have the correct closing tags associated with them.
|
||||
|
||||
This is implemented using a stack, you push as you see opening tags, pop as you see closing ones, and compare. If you see a closing tag that does not correspond to the top item of the stack then there is something wrong.
|
||||
|
||||
# Future Work
|
||||
|
||||
I am mostly finished with this project. The only thing I would like to add is translation from XML to other languages. This step would be fairly easy because of the AST already being build, and now I simply have to walk it.
|
||||
|
||||
But for other project, I would like to go into the world of programming languages instead of markup languages. To start with I could write a program that compilers down to Golang, and use the already amazing Golang tools to compile the underlying program. But this is for another time.
|
||||
|
||||
If you made it this far, hey thank you for reading, you can always email me at johncosta027@gmail.com for any inquiries, or check out the GitHub repo linked at the top of the article if you have any further coments.
|
6
quickstart/content/projects/_index.md
Normal file
6
quickstart/content/projects/_index.md
Normal file
@ -0,0 +1,6 @@
|
||||
+++
|
||||
title = 'Projects'
|
||||
toc = true
|
||||
+++
|
||||
|
||||
A list of my various projects
|
42
quickstart/content/projects/huffmanz.md
Normal file
42
quickstart/content/projects/huffmanz.md
Normal file
@ -0,0 +1,42 @@
|
||||
+++
|
||||
title = "Huffmanz - Huffman Encoding Implementation in Zig"
|
||||
date = "2023-09-21"
|
||||
author = "John Costa"
|
||||
toc = true
|
||||
tags = ["Software"]
|
||||
+++
|
||||
|
||||
---
|
||||
|
||||
- Link to Repo: [https://github.com/JohnCosta27/Huffmanz](https://github.com/JohnCosta27/Huffmanz)
|
||||
- Link to Video: [https://www.youtube.com/watch?v=D5l5GUuNXB8&ab_channel=JohnCosta](https://www.youtube.com/watch?v=D5l5GUuNXB8&ab_channel=JohnCosta)
|
||||
|
||||
[Huffman Encoding](https://en.wikipedia.org/wiki/Huffman_coding) is an algorithm for compressing text, using a binary tree to shorted the number of bits needed to represent each character. It's one of the first algorithms I learned in Computer Science. I was 14 year old and in Year 9. But until recently it hadn't crossed my mind again.
|
||||
|
||||
Then I found out about [Zig](https://ziglang.org/). A new(ish) language where you manage your own memory, and have access to an incredible compiler that support `comptime`, it's an amazing (and extremely fast) language.
|
||||
|
||||
So I decided to learn both fully, and implemented a huffman encoding algorithm using the zig programming language. Up until this point I haven't worked on a project in a language like zig, which requires memory management and everything that goes along with it. I have also never thought much about huffman encoding, but it's a fairly simple algorithm so it was the perfect project to learn about this language.
|
||||
|
||||
I won't go into much detail about Huffman Encoding, you can find many tutorials that do it better than I ever could. But I will talk about what I think about Zig.
|
||||
|
||||
## Zig - It's great
|
||||
|
||||
I'm not a big language connoisseur, I like things that work, that are simple and have a friendly syntax, so I happen to love (Golang)[https://go.dev/], it's simple, robust and very fast. It's also garbage collected which is a plus.
|
||||
|
||||
I didn't think I was going to be a big fan of Zig, my experience with C has been fine, but I haven't loved it much, and I've never touched C++, but I really enjoyed it.
|
||||
|
||||
### Some things I liked
|
||||
|
||||
- The compiler is fast, and extremely informative, I found that I didn't need to go to the official documentation, the compiler knew what I was trying to do and often led me in the right direction.
|
||||
- Using allocator objects to initialise various data structure is a very nice pattern, one that makes managing memory really not complicated.
|
||||
- Comptime. Absolutely genious!
|
||||
- No secret allocations (looking at you Rust!). You are in control of the allocations completely.
|
||||
|
||||
### Some things I didn't like
|
||||
|
||||
- This isn't a fairly criticism, because it's a fairly new and evolving language, but the LSP isn't the best, it's very fast and when it works it works really well, but it seems to have been lacking some features. The one I missed the most was _hover_, where you can ask the LSP what type something is, it sometimes worked but most of the time it got confused.
|
||||
- Using comptime types and returning a struct from a function seems odd, but also the best way to achieve generic data structures, don't love this pattern and there might be a better way. See the `heap.zig` file in my repo to see what I'm talking about.
|
||||
|
||||
I would say I definitely would love to work more with Zig. It seems like the logical step forward for program that require the blazingly fast speed of no garbage collection. You can already see this happening in [Bun.js](https://bun.sh/), which seems to have great speed advantages (sometimes) compared to Node.js or Deno (even though both are written in a low level language).
|
||||
|
||||
Thank you for reading, if you would like to chat with me. You can email me at `johncosta027@gmail.com`. Or visit my GitHub profile.
|
@ -7,11 +7,13 @@ theme = 'risotto'
|
||||
[[menu.main]]
|
||||
name = 'Blog'
|
||||
pageRef = '/blog'
|
||||
[[menu.main]]
|
||||
name = 'Projects'
|
||||
pageRef = '/projects'
|
||||
|
||||
# Sidebar: about/bio
|
||||
[params.about]
|
||||
title = "John Costa"
|
||||
description = "A really good software engineer"
|
||||
description = "Software Engineer"
|
||||
|
||||
# Sidebar: social links
|
||||
# Available icon sets:
|
||||
@ -21,9 +23,12 @@ description = "A really good software engineer"
|
||||
[[params.socialLinks]]
|
||||
icon = "fa-brands fa-github"
|
||||
title = "GitHub"
|
||||
url = "https://github.com/joeroe/risotto"
|
||||
url = "https://github.com/JohnCosta27/JohnTech"
|
||||
|
||||
[[params.socialLinks]]
|
||||
icon = "fa-solid fa-envelope"
|
||||
title = "Email"
|
||||
url = "mailto:example@example.com"
|
||||
|
||||
[taxonomies]
|
||||
tags = "tags"
|
||||
|
24
quickstart/layouts/index.html
Normal file
24
quickstart/layouts/index.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<html lang="{{- site.Language.Lang -}}">
|
||||
<head>
|
||||
{{- partial "head.html" . -}}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="page__header">{{- partial "header.html" . -}}</header>
|
||||
|
||||
<section class="page__body">{{ .Content }}</section>
|
||||
|
||||
<section class="page__aside">
|
||||
<div class="aside__about">{{- partial "about.html" . -}}</div>
|
||||
<hr />
|
||||
<div class="aside__content">
|
||||
{{- block "aside" . }}{{- end }}{{partial "allTags.html" . -}}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer class="page__footer">{{- partial "footer.html" . -}}</footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
10
quickstart/layouts/partials/allTags.html
Normal file
10
quickstart/layouts/partials/allTags.html
Normal file
@ -0,0 +1,10 @@
|
||||
<h2>All Tags</h2>
|
||||
{{range $name, $taxonomy := .Site.Taxonomies.tags}} {{ $cnt := .Count }} {{ with
|
||||
$.Site.GetPage (printf "/tags/%s" $name) }}
|
||||
<div class="tagbutton">
|
||||
<a href={{ .RelPermalink }} title="All pages with tag <i>{{$name}}</i>"
|
||||
>{{$name}}</a
|
||||
>
|
||||
<span>{{$cnt}}</span>
|
||||
</div>
|
||||
{{end}} {{end}}
|
11
quickstart/layouts/partials/tags.html
Normal file
11
quickstart/layouts/partials/tags.html
Normal file
@ -0,0 +1,11 @@
|
||||
{{ $taxonomy := "tags" }} {{ with .Param $taxonomy }}
|
||||
<h2>Tags</h2>
|
||||
<ul>
|
||||
{{ range $index, $tag := . }} {{ with $.Site.GetPage (printf "/%s/%s"
|
||||
$taxonomy $tag) -}}
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ $tag | urlize }}</a>
|
||||
</li>
|
||||
{{- end -}} {{- end -}}
|
||||
</ul>
|
||||
{{ end }}
|
Submodule quickstart/themes/risotto updated: 4343550d78...49bd72f662
@ -1,11 +1,8 @@
|
||||
---
|
||||
layout: '../../layouts/post.astro'
|
||||
title: 'Deepwork - Cal Newport'
|
||||
date: '16/08/2022'
|
||||
title: "Deepwork - Cal Newport"
|
||||
date: "16/08/2022"
|
||||
---
|
||||
|
||||
# Deepwork - Cal Newport. A review
|
||||
|
||||
This review is a little different because I wrote it down on paper, here are the pages:
|
||||
|
||||

|
||||
|
Reference in New Issue
Block a user