Skip to content

Instantly share code, notes, and snippets.

View sentenza's full-sized avatar

Alfredo Torre sentenza

View GitHub Profile
@sentenza
sentenza / find_easter_sunday.sql
Last active November 10, 2021 15:00
Calculate date of easter based on Year passed. Based on Anonymous Gregorian Algorithm, also known as the Meeus/Jones/Butcher algorithm: https://en.wikipedia.org/wiki/Computus#Gauss_algorithm
CREATE OR REPLACE FUNCTION anonymous_easter(xyear integer) RETURNS date AS $$
DECLARE
a int;
b int;
c int;
d int;
e int;
f int;
g int;
@sentenza
sentenza / Streaming.scala
Created October 12, 2021 14:14 — forked from BalmungSan/Streaming.scala
10 code snippets to introducing cats.effect.IO & fs2.Stream
// IO: A Monad for side-effects.
import $ivy.`org.typelevel::cats-effect:1.3.1`
import cats.effect.IO
import scala.concurrent.ExecutionContext
implicit val IOTimer = IO.timer(ExecutionContext.global)
implicit val IOShift = IO.contextShift(ExecutionContext.global)
// ----------------------------------------------
@sentenza
sentenza / cryptos.md
Last active March 21, 2021 00:57
Cryptocurrencies and BlockChain useful resources

Bitcoin

On October 31st 2008, the programmer/programmers known as Satoshi Nakamoto published this paper through a metzdowd.com cryptography mailing list that describes the Bitcoin currency and solves the problem of double spending so as to prevent the currency from being copied.

In January of 2009, he started mining, creating what is known as the “genesis block.” Bitcoin v0.1 was released six days later. By year-end, over 32,000 blocks had been added to this original block, producing a total of 1,624,250 bitcoins. Since all transactions are public on the blockchain, we know that only a quarter of those bitcoins have ever changed hands, leading some to speculate that Satoshi could be sitting on a stash of roughly one million bitcoins, worth ~$120 million at today’s exchange rate. Who is Satoshi Nakamoto

Papers

@sentenza
sentenza / scala-future-vs-io.md
Last active February 5, 2021 11:01
Cats IO Monad vs Scala Future

From Scala Future to Cats Async?

We could try to use the Async type class to model the kind of effects that can be executed concurrently.

Async is a Monad that can describe asynchronous or synchronous computations that produce exactly one result.

The first data type that we can think of is cats.effect.IO but the key aspect to keep in mind is that either a Future or an IO might be synchronous/blocking operations.

@sentenza
sentenza / PowerlineForTerminal.md
Created January 21, 2021 01:17 — forked from DucNgn/PowerlineForTerminal.md
Powerline style for terminal OSX

Installing and configuring Powerline-style command line tools for developers (OSX)

Intro:

For every developer, terminal is their weapon, so why don't you customize it to become a powerful, and a beautiful weapon?

Powerline style refers to a terminal style that helps developer to keep track of their workflow easily, allows them to have perfect visual on current directories and new changes. It is also git recognizable, and failure detector that will help your development process becomes more interact and much faster.

In this guideline, I will introduce you with 2 smart shells: Zsh and Fishshell. Both are perfect for the development jobs due to its rich of resources, and user-friendly.

Note:

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@sentenza
sentenza / symfony_doctrine_merge.md
Last active June 28, 2020 14:07
How to deal with Symfony and doctrine merge

You should use merge operation on entities which are in detached state and you want to put them to managed state.

Merging should be done like this $entity = $em->merge($detachedEntity). After that $entity refers to the fully managed copy returned by the merge operation. Therefore if your $form contains detached entities, you should adjust your code like this:

$doctrineManager = $this->getDoctrine()->getManager();
foreach ($form->getData()->getEntities() as $detachedEntity) {
    $entity = $doctrineManager->merge($detachedEntity);  
    $doctrineManager->remove($entity);
}

$doctrineManager->flush();

@sentenza
sentenza / akka-http-intro.md
Created September 5, 2018 11:48
A short introduction of Akka HTTP
@sentenza
sentenza / scriptTemplate.py
Created January 31, 2014 22:58
Combining Bash and Python. Shell script template.
#!/usr/bin/env python
import subprocess
import optparse
import re
#Create variables out of shell commands
#Note triple quotes can embed Bash
#You could add another bash command here
#HOLDING_SPOT="""fake_command"""