Skip to content

Instantly share code, notes, and snippets.

View slaykachu's full-sized avatar
💭
Wandering how?

Yves slaykachu

💭
Wandering how?
View GitHub Profile
@slaykachu
slaykachu / ssafun.md
Created March 9, 2021 12:46
For a solid grasp of SSA , program in Erlang.

SSA: Static single assignment (compiler technique).

Two Erlang properties make you write in SSA style (some would say force you):

  • immutability
  • the variables defined in a case-clause scope are accessible (some would say leaked, like in Python) in outer scope. Hence you cannot reuse names.

Some would add functional as a required property, but it derives from immutability. Some should better shut-up.

Instead of merely announcing "I've implemented this feature", you could mention victoriously "I mentally applied a dominance algorithm to minimise the number of variables". Audience, both male and female, will faint from exhilaration.

@slaykachu
slaykachu / basic_clean_code.md
Last active February 7, 2021 23:42
Basic Clean Code

According to Dijkstra: “It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”

I think this honour now goes to Java. Robert Martin (Uncle Bob), who seems to be a very nice guy, presented the following abomination as [Clean Code][1], containing very small functions and which reads as a story. No BASIC programmer of my knowledge has ever been perverted that much.

Scroll at bottom for a sane approach of prime numbers generation!

package literatePrimes;

import java.util.ArrayList;
@slaykachu
slaykachu / dependency_dejection.md
Last active January 17, 2021 11:38
Dependency Dejection Blog Post

Engineers like solving problems, hence software engineers like stacking them.

Object A uses code B.
Say then, for testing purpose, you have to use B' instead. So you pass the code to use at A's construction (dependency injection).
A is now harder to construct, so you make a factory. You want to make for all the hours passed studying 'Design Patterns'. All of this becomes complex, so you use a dependency framework.
Later on, you struggle understand what the hell is going on. Hopefully a good salary mitigates the pain.

Alternative: if A needs the result of code B, let the client of A invoke code B et pass the value to A as an input.
If the client is a test, it will invoke code B' instead.

@slaykachu
slaykachu / adt_vs_adt.md
Last active January 29, 2021 07:43
ADT isn't ADT

The first one is Algebraic Data Type. It's like tuples and enums on steroids (and heroine). As a mnemonic device, note that you construct your types/data-structures via algebra-like operators:

  • Aggregation (tuple-like, product-like).
  • Alternatives (enum-like, sum-like). For instance, in haskell,
data BookId = Isbn Int | Doi String
data BookRef = Book String BookId 

BookRef embeds a name (encoded as a string) followed by an ISBN number or a DOI reference (but not both).

@slaykachu
slaykachu / print_tree.md
Last active January 10, 2021 00:52
Toy example showing how to print an ADT in haskell.
-- Toy example showing how to print an ADT.

data Tree a = Nil | Node a (Tree a) (Tree a)
leaf x = Node x Nil Nil

instance (Show a) => Show (Tree a) where
    show (Nil) = "Nil"
    show (Node a l r) = "(Node " ++ show a ++ " " ++ show l ++ " " ++ show r ++ ")" 
@slaykachu
slaykachu / combinatorial_connections.md
Last active May 31, 2020 20:10
Combinatorial Connections Not Concerning Connecticut

Brain isn't a hard drive. For starters, it's moister. It suffers more severe fragmentation issues. Also, you can increase information retention by adding more information. Because connections help to remember. Today, we are going to see the connections between r-simplex, combinations with repetitions, Pascal's triangle, non-decreasing functions and inspector Canardo.

How many ways are there to choose k elements among n distinct gallinaceans, allowing repetitions (à la "sampling with replacement")?

  • For k = 1, that's n. I you disagree, please write a letter to your government.
  • For k = 2, to see what happen, let's enumerate the choices for n = 5 items named a b c d e:
    aa, ab, ac, ad, ae,
 bb, bc, bd, be,
@slaykachu
slaykachu / pijul.md
Created May 22, 2020 12:44
Pijul notes

Trying Pijul, since I like the theory behing it. Here are some WIP notes.

  • Smarter than git for merges, faster than darcs.
  • Developement is stalled.
  • Use .ignore or .pijulignore at repo root with git syntax.
  • Tutorial for git users
  • Interesting discussion involving main author on hackernews
@slaykachu
slaykachu / independence_n_conditioning.md
Created May 21, 2020 15:17
Independence dependent on conditioning

I used to tutor high-school students. One question I liked to ask: “Are two incompatible events independent?”. Bringing those two notions together helped to clarify both of them. In some cases, it could also lead to a profound state of confusion, which is always pleasant to observe.

Now, I’d like to remind you (and future me) of the perils of intuition in probabilities. For instance, conditioning can break independence. If you roll two dice, one fushia and one vert de gris, the events A: “Ace on fushia” and B: “Ace on vert de gris” are independent. Not so much under the condition C: “Sum is even”.

One could reply: “That’s not surprising. Conditioning updates our knowledge of the world and new connections can be established. That’s the basis of bayesian inference.” That would be a pedantic yet appreciable comment. The interesting twist is that dependent events can be made independent under a certain context. In this case we are somehow losing and loosing information.

Another possible oddity: A c

@slaykachu
slaykachu / tree_diameter_bugged.md
Last active October 2, 2019 23:23
Short tree diameter function. Find the bug.

The following function to find the diameter (width) of a tree presents some nice propreties:

  • (Almost) Representation agnostic.
    • The type of nodes (simple int used an index, string identifiant ...) doesn't matter.
    • The dict children might map the leaves to an empty sequence, or not contains them altogether.
  • The code is short, efficient and could be used for competitive programming, if it wasn't bugged.

As an exercice, try to find the design flaw and the real bug hidden in this cute snippet.

import heapq
@slaykachu
slaykachu / debugging_debuggind.md
Last active January 29, 2021 06:05
Debugging the debugging

Or how to turn debugging into a deliberate practice rather than an endless whack-a-mole game.

Try to answer the following questionnaire known in the West as "The six examinations of Shifu Shifu". Although some interrogations seem similar, they can trigger different perspectives and answers.

(Before) Debugging

  • Can an intern do it for you? (Learn to delegate)
  • Is there a more important change to accomplish, that would obsolete the issue? (Don't go unabomber, though)