Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

corbpie cp6

🏠
Working from home
View GitHub Profile
View yabs.txt
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
# 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 Nov 10, 2021
PHP feet and inches to centimetres conversion function
View feet_inches_to_cm.php
<?php
function feetInchesToCm(int $feet, int $inches): int
{
return number_format((($feet * 12) + $inches) * 2.54, 0);
}
@cp6
cp6 / pounds_to_kg.php
Created Nov 10, 2021
PHP pounds to kilograms conversion function
View pounds_to_kg.php
<?php
function poundsToKg(int $pounds): int
{
return number_format(($pounds * 0.45359237), 0);
}
@cp6
cp6 / pt_time_format.php
Created Nov 4, 2021
Convert NBA API clock timestamp format
View pt_time_format.php
<?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 Sep 1, 2021
PHP years, months, weeks, days, hours, minutes and seconds past a date time
View datetime_passed_func.php
<?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 Aug 31, 2021
Create video thumbnail from a slider concept
View index.php
<?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 Aug 24, 2021
Create video thumbnail from slider concept
View index.php
<?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 Aug 15, 2021
PHP append version to file name if file already exists
View avoid_file_overwrites.php
<?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 Apr 5, 2021
PHP Reddit API get post comments
View rdt_comments.php
<?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'];
@cp6
cp6 / pdo_insert_loop.php
Last active Apr 5, 2021
PHP PDO insert from a loop
View pdo_insert_loop.php
<?php
$db = new PDO("mysql:host=127.0.0.1;dbname=test;charset=utf8mb4", 'root', '');
$db->beginTransaction();
$insert = $db->prepare("INSERT IGNORE INTO `objects` (`id`, `color`) VALUES (?, ?);");
$test_array = ['Red', 'Orange', 'Pink', 'Lime', 'Yellow', 'Gold', 'Green', 'Blue', 'Purple', 'Maroon', 'Silver', 'Aqua'];
$id = 0;
foreach ($test_array as $c) {