Skip to content

Instantly share code, notes, and snippets.

View Kovah's full-sized avatar

Kevin Woblick Kovah

View GitHub Profile
@Kovah
Kovah / trend.blade.php
Created December 4, 2024 08:22
Health Dashboard: Trend View Component
@props(['current' => 0, 'previous' => 0, 'negative' => false])
@php
$icon = 'dash';
$class = 'text-gray-500';
$title = 'Not enough data';
if ($current > 0 && $previous > 0) {
$diff = $current - $previous;
$diffPercent = round($diff / $current * 100, 2);
$title = sprintf('Previous: %s = %s', \Illuminate\Support\Number::format(round($previous, 2), locale: 'de_DE'), $diffPercent . '%');
@Kovah
Kovah / Unit.php
Created December 4, 2024 08:15
Health Dashboard: Unit Enum
<?php
namespace App\Modules\AppleHealth\Enums;
enum Unit: string
{
case COUNT = 'count';
case COUNT_PER_MIN = 'count/min';
case COUNT_PER_HOUR = 'count/hr';
case PERCENT = '%';
@Kovah
Kovah / HealthMetric.php
Last active December 4, 2024 08:16
Health Dashboard: Health Metric Model
<?php
namespace App\Modules\AppleHealth\Models;
use App\Modules\AppleHealth\Enums\Unit; // @see https://gist.github.com/Kovah/5a8b17e33ddeca54fd8e4a402a46e158
use Illuminate\Database\Eloquent\Model;
class HealthMetric extends Model
{
public static array $metricUnits = [
@Kovah
Kovah / ProcessImportJob.php
Last active December 4, 2024 08:15
Health Dashboard: Import Job
<?php
namespace App\Modules\AppleHealth\Jobs;
use App\Modules\AppleHealth\Models\HealthMetric; // @see https://gist.github.com/Kovah/3f3ce850f90f9070784f30d6915893da
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
@Kovah
Kovah / env.j2
Last active November 25, 2022 17:53
Linkace Ansible 2022-11 - env.j2
## LINKACE CONFIGURATION
## Basic app configuration
# The application name is used internally and may not be changed
APP_NAME=LinkAce
COMPOSE_PROJECT_NAME={{ docker_compose_project }}
# The URL should be set if you notice issues with URLs generated by Laravel, which might be an issue with
# nginx configuration or the proxy you use.
APP_URL={{ app_url }}
# The environment is usually 'production' but may be changed to 'local' for development
@Kovah
Kovah / vars.yml
Created November 25, 2022 17:50
Linkace Ansible 2022-11 - Vars
---
app_url: "https://linkace.example.com"
proxy_port: 8080
site_root: "/var/www/linkace-demo"
site_domain: "linkace.example.com"
site_ssl_directory: "/"
env_source: "env.j2"
env_destination: "{{ deploy_helper.new_release_path }}/.env"
@Kovah
Kovah / docker-compose.yml.j2
Created November 25, 2022 17:44
Linkace Ansible 2022-11 - docker-compose.yml.j2
---
version: "3"
services:
db:
image: mariadb:10.6
restart: unless-stopped
environment:
- MARIADB_ROOT_PASSWORD=${DB_PASSWORD}
- MARIADB_USER=${DB_USERNAME}
@Kovah
Kovah / playbook.yml
Created November 25, 2022 17:42
Linkace Ansible 2022-11 - Playbook
---
- hosts: linkace
vars_files:
- vars.yml
tasks:
- name: Initialize the deploy root
deploy_helper: path={{ site_root }}
<?php
// Randomizes the names of all files in the current directory
// Use with caution!
$files = scandir(__DIR__);
$files = array_filter($files, fn($file) => !in_array($file, ['.', '..', 'randomize.php', '.DS_Store']));
echo 'Renaming ' . count($files) . 'files now';
shuffle($files);
foreach ($files as $file) {
$new = hash('crc32', $file) . time() . '.' . pathinfo($file, PATHINFO_EXTENSION);
var_dump("Renaming $file to $new");
@Kovah
Kovah / php_tip_natsort.php
Created January 9, 2022 12:25
PHP Tip natsort()
<?php
// @see https://www.php.net/manual/en/function.natsort.php
$numbers = [26, 6, 2, 65];
sort($numbers);
// 2, 26, 6, 65
natsort($numbers);
// 2, 6, 26, 65