Skip to content

Instantly share code, notes, and snippets.

View cp6's full-sized avatar
🏠
Working from home

corbpie cp6

🏠
Working from home
View GitHub Profile
@cp6
cp6 / tennis_function.php
Created March 2, 2023 01:03
PHP tennis score function
<?php
//$series = [];
//$series = ['Jimmy'];
//$series = ['Lisa'];
//$series = ['Jimmy', 'Lisa'];
//$series = ['Jimmy', 'Lisa', 'Jimmy'];
//$series = ['Jimmy', 'Lisa', 'Jimmy', 'Lisa'];
//$series = ['Jimmy', 'Lisa', 'Jimmy', 'Jimmy'];
//$series = ['Jimmy', 'Jimmy', 'Jimmy'];
@cp6
cp6 / yabs.txt
Last active February 20, 2022 05:15
YABs
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
# Yet-Another-Bench-Script #
# v2022-02-18 #
# https://github.com/masonr/yet-another-bench-script #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
Sun Feb 20 05:07:23 UTC 2022
Basic System Information:
@cp6
cp6 / feet_inches_to_cm.php
Created November 10, 2021 23:44
PHP feet and inches to centimetres conversion function
<?php
function feetInchesToCm(int $feet, int $inches): int
{
return number_format((($feet * 12) + $inches) * 2.54, 0);
}
@cp6
cp6 / pounds_to_kg.php
Created November 10, 2021 23:43
PHP pounds to kilograms conversion function
<?php
function poundsToKg(int $pounds): int
{
return number_format(($pounds * 0.45359237), 0);
}
@cp6
cp6 / pt_time_format.php
Created November 4, 2021 12:47
Convert NBA API clock timestamp format
<?php
$sample1 = "PT12M00.00S";
$sample2 = "PT01M05S";
$sample3 = "PT00M05.30S";
$sample4 = "PT00M00.00S";
function PTFormatAsArray(string $timestamp): array
{
if (str_contains($timestamp, ".")) {
$after_dot = substr($timestamp, strpos($timestamp, ".") + 1);
@cp6
cp6 / datetime_passed_func.php
Last active September 1, 2021 10:40
PHP years, months, weeks, days, hours, minutes and seconds past a date time
<?php
function timeElapsedString(string $past_datetime, bool $full_string = true): string
{
$now = new DateTime;
$difference = $now->diff(new DateTime($past_datetime));
$difference->w = floor($difference->d / 7);
$difference->d -= ($difference->w * 7);
$formats = array(
'y' => 'year',
'm' => 'month',
@cp6
cp6 / index.php
Last active August 31, 2021 13:05
Create video thumbnail from a slider concept
<?php
$file = "jellyfish.mkv";
$thumb_start = "thumbnail1.jpg";
$thumb_finish = "thumbnail2.jpg";
if (isset($_POST['time_string'])) {
if ($_POST['type'] === 'start') {
exec("ffmpeg -y -ss {$_POST['time_string']} -i $file -vframes 1 -q:v 1 $thumb_start");
} else {
exec("ffmpeg -y -ss {$_POST['time_string']} -i $file -vframes 1 -q:v 1 $thumb_finish");
@cp6
cp6 / index.php
Last active August 24, 2021 13:54
Create video thumbnail from slider concept
<?php
$file = "jellyfish.mkv";
$thumb = "thumbnail.jpg";
if (isset($_POST['time_string'])) {
exec("ffmpeg -y -ss {$_POST['time_string']} -i $file -vframes 1 -q:v 1 $thumb");
} elseif (!file_exists("thumbnail.jpg")) {
exec("ffmpeg -y -ss 00:00:01 -i $file -vframes 1 -q:v 1 $thumb");
}
?>
@cp6
cp6 / avoid_file_overwrites.php
Created August 15, 2021 12:50
PHP append version to file name if file already exists
<?php
function AddCopyToFileName(string $file_name): string
{
$ext = pathinfo($file_name, PATHINFO_EXTENSION);//json
if (!str_contains($file_name, '_')) {//OG file name, no _2 etc
$file_name_no_ext = str_replace(".$ext", "", $file_name);//ralphy
$number = 0;
} else {
$number = str_replace(".$ext", "", substr(strrchr($file_name, '_'), 1));
@cp6
cp6 / rdt_comments.php
Created April 5, 2021 02:48
PHP Reddit API get post comments
<?php
function commentData(array $data): array
{
if (isset($data['data']['body'])) {
$d = $data['data'];
if (isset($d['author_flair_richtext'][0])) {
$frt = $d['author_flair_richtext'];
if ($frt[0]['e'] === 'text') {
$flair = $frt[0]['t'];