Skip to content

Instantly share code, notes, and snippets.

Avatar
🏭
I'm producing technical debt!

Sebastian Rapetti s3b4stian

🏭
I'm producing technical debt!
  • Olbia, Italy
View GitHub Profile
@s3b4stian
s3b4stian / ordutf8_test.php
Created Dec 9, 2017
ordutf8 refactor spet test
View ordutf8_test.php
<?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 Dec 5, 2017
Return numerical part of the HTML encoding of the Unicode character.
View ordutf8.php
<?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 Nov 5, 2017
Model View Controller Example
View Mvc.php
<?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 {
View strtonum.php
/**
* 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){
View in_range.php
/**
* 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 {
View typed_array_speed_test.php
<?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 Feb 21, 2017
Get appropriate cost for password hashing
View password_get_appropriate_cost.php
/**
* 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 Feb 21, 2017
Function for flatten an array
View array_flatten.php
/**
* 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