Skip to content

Instantly share code, notes, and snippets.

View emmadesilva's full-sized avatar
🎩
HydePHP.com

Emma De Silva emmadesilva

🎩
HydePHP.com
View GitHub Profile
@emmadesilva
emmadesilva / checksums.php
Created February 20, 2023 11:26
Generate checksums.txt
<?php
$dir = getcwd();
$algos = ['md5', 'sha1', 'sha256', 'sha512'];
$files = explode(',', $argv[1]);
$lines = '';
foreach ($files as $file) {
@emmadesilva
emmadesilva / ANSI.php
Created March 21, 2023 10:20
Simple ANSI PHP Interface
<?php
interface ANSI {
const BLACK = "\033[30m";
const RED = "\033[31m";
const GREEN = "\033[32m";
const YELLOW = "\033[33m";
const BLUE = "\033[34m";
const MAGENTA = "\033[35m";
const CYAN = "\033[36m";
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/styles/dark.min.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<style>.prose :where(pre):not(:where([class~=not-prose] *)) { background-color: #303030 } </style>
<style>pre code.hljs { padding: 0; }</style>
<?php
// Put your input in here
$input = <<<'MARKDOWN'
[![Test & Build](https://github.com/hydephp/develop/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/hydephp/develop/actions/workflows/continuous-integration.yml)
[![Total Downloads on Packagist](https://img.shields.io/packagist/dt/hyde/framework)](https://packagist.org/packages/hyde/framework)
[![License MIT](https://img.shields.io/github/license/hydephp/hyde)](https://github.com/hydephp/develop/blob/master/LICENSE.md)
MARKDOWN;
// Compile to HTML according to pattern:
@emmadesilva
emmadesilva / pint.json
Last active October 10, 2024 09:11
My standard Laravel Pint configuration
{
"preset": "laravel",
"rules": {
"class_attributes_separation" : false
}
}
@emmadesilva
emmadesilva / bash-commands.sh
Last active May 24, 2023 19:58
Useful Bash Commands
# Useful Bash Commands
# SED Templates
sed -i 's/old/new/g' input.txt # Edit within file
sed 's/old/new/g' input.txt > output.txt # Edit to new file
# Add SHA256 checksums for all files to checksums.txt (not recursive)
for i in *; do sha256sum $i >> checksums.txt; done
@emmadesilva
emmadesilva / bytesToHuman.php
Created September 9, 2023 12:09
Laravel bytesToHuman macro
Str::macro('bytesToHuman', /** Format the given number of bytes into a human-readable format. */
function (int $bytes, $precision = 2): string {
for ($i = 0; $bytes > 1024; $i++) {
$bytes /= 1024;
}
return round($bytes, $precision) . ' ' . ['B', 'KB', 'MB', 'GB', 'TB'][$i];
}
);
}
@emmadesilva
emmadesilva / grid-size-range-slider.html
Created September 9, 2023 12:37
Grid Size Range Slider (Vanilla JavaScript, optionally uses Tailwind for default grid styles)
<label for="gridSizeInput">Grid size</label>
<input id="gridSizeInput" type="range" min="1" max="9" value="3" title="3 columns" oninput="setGridSize(this)">
<section class="grid grid-cols-3 gap-4" id="myGrid">
// Items...
</section>
<script>
function setGridSize(input) {
input.title = `${input.value} columns`;
@emmadesilva
emmadesilva / laravel-str-mixins.php
Last active October 25, 2023 15:55
Laravel Str Mixins
Str::macro('bytesToHuman', /** Format the given number of bytes into a human-readable format. */
function (int $bytes, int $precision = 2): string {
for ($i = 0; $bytes > 1024; $i++) {
$bytes /= 1024;
}
return round($bytes, $precision) . ' ' . ['B', 'KB', 'MB', 'GB', 'TB'][$i];
}
);
}
$person = {
string $name = 'Jack';
int $age = 21;
}
echo "$person->name is $person->age years old";