Skip to content

Instantly share code, notes, and snippets.

View d4rkne55's full-sized avatar

Dennis Jungbauer d4rkne55

  • Germany
View GitHub Profile
@d4rkne55
d4rkne55 / Time.class.php
Last active July 16, 2020 10:34
Class for working with time data/durations only
<?php
class Time
{
public $h;
public $i;
public $s;
public $f;
private static $unitData = array(
@d4rkne55
d4rkne55 / JsonDumper.class.php
Created September 20, 2019 23:37
Class for dumping/beautifying JSON
<?php
class JsonDumper
{
/** @var string */
private $json;
/** @var int spaces to use for one indentation level */
private $indentation;
@d4rkne55
d4rkne55 / AsciiTable.class.php
Created September 20, 2019 23:31
Class for drawing cool ASCII tables, including data
<?php
class AsciiTable
{
private $rows;
private $columns;
private $headers = array();
private $data = array();
private $separators;
private $headerPadMethod;
@d4rkne55
d4rkne55 / NumberSpell.class.php
Last active September 21, 2019 19:33
Class for getting the spelled out string of a number (was a coding challenge once)
<?php
class NumberSpell
{
public $number;
public $spelled;
private $rules = array(
0 => array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'),
1 => array(null, 'twen', 'thir', 'for', 'fif', null, null, null, null)
@d4rkne55
d4rkne55 / DateIntervalEnhanced.class.php
Last active July 16, 2020 10:38
A DateInterval extension class
<?php
/**
* This class brings support for milliseconds, explicit recalculation of carry-over points
* and human-friendly formatting
*/
class DateIntervalEnhanced extends DateInterval
{
public $ms = 0;
private $unitData = array(
@d4rkne55
d4rkne55 / StringTransform.class.php
Last active October 5, 2018 11:04
Class for some transformations on Strings
<?php
class StringTransform
{
/**
* This Method Converts a String to Title Case
* Not context-aware and just for english.
*
* @param string $str
* @param bool $apStyle use AP-Style title case if true
@d4rkne55
d4rkne55 / Media.class.php
Last active July 15, 2020 18:26
Class with some calculations and informations for media files
<?php
class Media
{
public $calcBase = 1024;
public $fileSize = 0;
public $sizePrefixes = array(
1000 => array(
'',
'K',
@d4rkne55
d4rkne55 / parseColorString.php
Created March 9, 2017 09:28
This function is for parsing legacy color values. It is based on the WHATWG specs.
<?php
function parseColorString($str, $format = 'hex') {
$str = strtolower(trim($str));
// prevent errors for an empty string and ignore 'transparent'
if ($str == '' || $str == 'transparent') {
return false;
}
// replace nonvalid hex characters with 0