Skip to content

Instantly share code, notes, and snippets.

View s3b4stian's full-sized avatar
🏭
I'm reducing technical debt!

Sebastian Rapetti s3b4stian

🏭
I'm reducing technical debt!
  • Olbia, Italy
View GitHub Profile
@s3b4stian
s3b4stian / ordutf8_test.php
Created December 9, 2017 10:44
ordutf8 refactor spet test
<?php
function ordutf8_step1(string $char) : int
{
$code = ord(substr($char, 0, 1));
if ($code >= 128) {
if ($code < 224)
$bytesnumber = 2;
@s3b4stian
s3b4stian / ordutf8.php
Last active December 5, 2017 19:17
Return numerical part of the HTML encoding of the Unicode character.
<?php
/**
* Return numerical part of the HTML encoding of the Unicode character.
*
* @param string $char
* @return int
*/
function ordutf8(string $char) : int
{
@s3b4stian
s3b4stian / Mvc.php
Last active November 5, 2017 22:10
Model View Controller Example
<?php
/**
* Parent class for custom model classes.
*
* This class was implemented like part of Observer pattern
* https://en.wikipedia.org/wiki/Observer_pattern
* http://php.net/manual/en/class.splsubject.php
*/
class Model implements SplSubject {
/**
* Convert number given as string to the proper type (int or float).
* https://secure.php.net/manual/en/language.types.type-juggling.php
*
* @param string $string Number as string ex '1.0', '0.9' etc
* @return int|float
*/
function strtonum(string $string)
{
if (fmod((float)$string, 1.0) === 0.0){
/**
* Check if value is between given range.
*
* @param mixed $value
* @param mixed $min
* @param mixed $max
*
* @return bool
*/
function in_range($value, $min, $max): bool {
<?php
//change for point to correct directory
include '../linna-array/src/TypedArray.php';
include '../linna-array/src/TypedObjectArray.php';
use Linna\TypedArray;
use Linna\TypedObjectArray;
$cicles = 500000;
@s3b4stian
s3b4stian / password_get_appropriate_cost.php
Created February 21, 2017 21:37
Get appropriate cost for password hashing
/**
* Get appropriate cost
*
* This code will benchmark your server to determine how high of a cost you can
* afford. You want to set the highest cost that you can without slowing down
* you server too much.
*
* @param int $time_limit Time limit in milliseconds
* @param int $algo Algoritm, default PASSWORD_DEFAULT
* @return int
@s3b4stian
s3b4stian / array_flatten.php
Created February 21, 2017 21:35
Function for flatten an array
/**
* Flatten an array
* Example array [1, [2, 3, 4], [5, 6], [7, [8, 9]], 10] becomes
* [1, 2, 3, 4, 5, 6, 7, [8, 9], 10]
* Work only for one level
*
* @param array $array Array to flatten
* @return array
*/
function array_flatten(array $array): array