Accio
105 subscribers
43 photos
1 file
81 links
Resources I find useful
github.com/Keivan-sf

Share ur interesting stuff with me:
@ke1vans
Download Telegram
A useful bit trick I missed till now
You already know how to swap two variables without a third one using addition/subtraction or multiplication/division. But the problem is they can cause arithmetic overflow if the values are large enough.

Another way is to use XOR (exclusive OR) to swap variables like so:
x = x ^ y
y = x ^ y
x = x ^ y


#bit_manipulation
๐Ÿ”ฅ1
bc, which stands for basic calculator, is a..... basic calculator.
It's already installed in your linux system and can be used via your terminal. It takes raw infix expressions like below and evaluates them
2 * 3 / (5 - 4) * 2

Actually it's not just a cli application, it's a programming language! You can create a .bc file, give it to the program and then use it. A bc file sample for factorial function:
define f(x){
if(x <= 1) return (1);
return (f(x-1) * x);
}

Now we can run the program with bc fact.bc and use the following expression:
2 * 3 / f(3)
> 1

As you can see f is now recognized. It might not seem much but it will come in handy for simple math/programming problems. You can also define functions as you are giving your inputs to bc (like a repl).
#shell
Both bc and dc (a reverse polish notation calculator) were mainly developed by Lorinda Cherry, A computer scientist who had spent her time in Bell labs and also has developed eqn.

Lorinda passed away in 2022
How should you decide between divide-and-conquer and dynamic programming?

If you are trying to decide between these two you already know your problem has Optimal substructure. Meaning it can be broken into smaller problems and solved by combining the optimal solutions of these subproblems.
Now in order to find out which solution is more suitable you should see if it has Overlapping subproblems or not. A problem has overlapping subproblems when its solution might try to solve some subproblems more than once rather than generating new ones. For example if you go with a divide-and-conquer approach to generate a Fibonacci sequence, you'll be solving overlapping subproblems. e.g.:
F(6) = F(5) + F(4)
Both F(5) and F(4) are gonna try and solve for F(3) separately

In summary:
Going for devide-and-conquer or dynamic programming is normally a good decision if the problem has Optimal substructure.
Going for dynamic programming is normally a good decision if the problem also has Overlapping subproblems.
๐Ÿ‘2๐Ÿ“1
Additionally, a greedy algorithm is usually used to solve a problem with optimal substructure if it produces an optimal solution at each step. For example Dijkstra, Kruskal, and ...

#dp #greedy #devide_and_conquer
In case you missed it, dylanaraps an open source contributor known for creating neofetch, kisslinux, fff and a few other famous projects, archived and abandoned all of his repos two months ago and left the following message on his github readme:
๐Ÿ˜1๐Ÿณ1
YAGNI , โ€œYou Arenโ€™t Gonna Need Itโ€

A good article by Martin Fowler Explaining the balance between trial and error and planning in software development

https://martinfowler.com/bliki/Yagni.html
๐Ÿฅฐ1
Boids algorithm
An algorithm used to simulate the flocking behavior of birds

Thanks to @nottholo for sending this to me who also happens to have a nice demo of this algorithm:
https://tholo.tech/exhibit/boids

#simulation
โค3๐Ÿ“1
Forward error correction codes (FEC)
In coding theory, error correction codes are used to detect and resolve errors on noisy communication lines. They are basically extra data sent to the client along side the original packet in a way that the client can decide whether the packet is valid or not and resolve errors to some extent based on those redundant bits.
A good example of a protocol using FEC would be webRTC, which is based on UDP and is used in platforms like discord, google meet, hangout, and etc. for video/voice calls and live streams.
โค2
The most famous error correction code is the Hamming code. A nice no-nonsense article to learn it:

https://electronicsdesk.com/hamming-codes.html
๐Ÿ‘2
"You don't need" Project
https://github.com/you-dont-need/You-Dont-Need

Handful of repositories dedicated to show how much you can do without the tools you rely on, for example:

- You-Dont-Need-JavaScript
- You-Dont-Need-GUI
- You-Dont-Need-Momentjs
๐Ÿ‘2
Aspect oriented programming
A paradigm to manage cross-cutting concerns. Cross-cutting concerns are aspects of your application that cannot be isolated easily and effect multiple modules/services. For example logging/validation/caching/... . Managing them in a way that separates concerns from your domain logic is crucial. You might have already used this paradigm while working with your framework pipe lines or using nestjs interceptors
#paradigm
Today I doubted the usefulness of REST APIs, but restored my faith again.
If you are unfamiliar with REST:
https://restapitutorial.com/introduction/whatisrest

In general RESTful APIs have many advantages that are just plain useful for most applications. Statelessness, being cacheable and layared are some of their features. But It doesn't really makes you to take the REST paths, since one might say it's more convenient to have routes like
POST /submit-business
POST /deactivate-business

that contain domain related verbs and explain what back-end is going to do, rather than
POST /business
PUT /business/:id

and they wouldn't be wrong. Not only we can have the advantages mentioned earlier, but we could have slight performance gains as well! For example PUT /business/:id would possibly have to check for multiple properties to validate them and then convert it to another object that will be again checked by a query-builder for all of those optional properties and so on until the request life-cycle ends.
But with POST /deactivate-business we are talking about a single property, not a resource, so those problems are non-existent.
One might say HTTP verbs are confusing when we are not using REST, but that cannot be true since REST does not even care about the protocol. In fact it only says to decide upon a general rule and follow it, so I might as well use POST for updates while not violating REST.

What does REST offer that makes it special?
I also happened to read about Liskov-substitution-principle in the Clean Architecture book today, it made me see two of the advantages of having a Resource Based approach on my APIs like REST.

1. A shared logic could exist in the client that does not care about what resource you are referring to, and performs an action (such as delete). This is a pure example of LSP since we made our resources to follow a common interface.

2. Client and server are actually more separated than other approaches. For example if we decide to change the verb submit to create in our domain since we don't want to supervise the submission anymore, we wouldn't need to change anything in the routes if we were using REST in the first place.

#REST #HTTP #API
Since we mentioned Liskov substitution principle, this is Barbara Liskov, who introduced it and was awarded with Turing Award for her contributions.

A nice video to learn about this principle:
https://www.youtube.com/watch?v=gnKx1RW_2Rk
Nixcon 2024 tickets. Need more event organizers like this
#nix
๐Ÿ”ฅ1