Skip to content

Instantly share code, notes, and snippets.

View sentenza's full-sized avatar

Alfredo Torre sentenza

View GitHub Profile
@sentenza
sentenza / pwa.md
Created July 12, 2018 07:43
Writing Progressive Web Apps - Useful online resources
@sentenza
sentenza / quaternions.scala
Created May 26, 2018 21:41 — forked from propensive/quaternions.scala
Quaternions in Scala
object Algebra {
// Build up increasingly complex algebras
trait Magma[T] {
def add(x : T, y : T) : T
}
trait Monoid[T] extends Magma[T] {
def zero : T
}
@sentenza
sentenza / test_extract_thumbnail.php
Created October 26, 2017 11:03
Extract a thumbnail using PHP and FFmpeg
<?php
class Extract {
const FFMPEG_PATH = '/usr/bin/ffmpeg';
public function exec($psSource, $psDest) {
$aOutput = [];
$aError = null;
$sCommand = sprintf("%s -i %s -vframes 1 %s 2>&1", self::FFMPEG_PATH, $psSource, $psDest);
echo 'Executing: ' . $sCommand;
@sentenza
sentenza / formatBytes.php
Created October 26, 2017 08:58
Bytes formatting (KB, MB, GB)
<?php
/**
* Format an amount of bytes using a SI metric conversion
*
* Note: 1024 to express the format in KiB, MiB
*
* @author Alfredo Torre <alfredo@dubishere.com>
* @see https://en.wikipedia.org/wiki/Kibibyte
* @param string/int $pBytes
* @param int $piPrecision

Installing ffmpeg 3.4 and all the needed libraries

Dependencies

# From the official ffmpeg docs
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev \
libsdl1.2-dev libtheora-dev libtool libvorbis-dev pkg-config texinfo zlib1g-dev \
yasm libx264-dev libmp3lame-dev libvpx-dev libfdk-aac-dev
@sentenza
sentenza / scala_algorithms.md
Last active August 20, 2017 12:00
A list of resources and tutorials to start working with Scala and do everything properly

scalalgorithms

A collection of algorithms written in Scala. The target is to make a pure excersize playground for testing data structures and algorithms.

Any external dependency should be possibly avoided.

Sorting

Algorithms to be implemented:

  • quickSort
@sentenza
sentenza / version_natural_sorting_mysql.sql
Created August 15, 2017 14:16 — forked from alfred-dub/version_natural_sorting_mysql.sql
Natural ordering of migrations' versions using MySQL and Postgre
SELECT
SUBSTRING_INDEX(number, '.', 1) AS FIRST_INT,
SUBSTRING_INDEX(SUBSTRING_INDEX(number, '.', 2), '.', -1) AS SECOND_INT,
SUBSTRING_INDEX(number, '.', -1) AS THIRD_INT,
number as VERSION,
description as TITLE
FROM _version
ORDER BY
LENGTH(SUBSTRING_INDEX(number, '.', 1)) DESC,
SUBSTRING_INDEX(number, '.', 1) DESC,
@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 / Chunked.md
Last active July 17, 2017 21:35
PHP and ionic file upload

Transfer-encoding: chunked

When the server needs to send large amount of data, chunked encoding is used by the server because it did not exactly know how big (length) the data is going to be. In HTTP terms, when server sends response Content-Length header is omitted by the server. Instead server writes the length of current chunk in hexadecimal format followed by \r\n and then chunk, followed by \r\n (Content begins with chunk size in hex followed by chunk)

This feature can be used for progressive rendering; however the server needs to flush the data as much as possible so that client can render content progressively (in case of html,css etc)

This feature is often used when server pushes data to the client in large amounts - usually in giga bytes.

Source: https://stackoverflow.com/a/45086785/1977778