Skip to content

Instantly share code, notes, and snippets.

<?php
namespace App\Support;
use InvalidArgumentException;
class Bytes
{
// Most modern systems use base-1000 rather than base-1024 for file size now
protected const BASE = 1000;
<?php
$value = '4 mb';
$units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$aliases = ['k' => 1, 'kiB' => 1, 'm' => 2, 'MiB' => 2, 'g' => 3, 'GiB' => 3, 't' => 4, 'TiB' => 4, 'PiB' => 5, 'EiB' => 6, 'ZiB' => 7, 'YiB' => 8];
preg_match('/([0-9,.]+)\s*([a-z]+)/i', $value, $matches);
[$_, $size, $unit] = $matches;
@inxilpro
inxilpro / Builder.js
Created December 3, 2022 01:56
expo sqlite ORM (work in progress)
import Grammar from './Grammar.js';
import Connection from './Connection.js';
const operators = [
'=', '<', '>', '<=', '>=', '<>', '!=', '<=>',
'like', 'like binary', 'not like', 'ilike',
'&', '|', '^', '<<', '>>', '&~', 'is', 'is not',
'rlike', 'not rlike', 'regexp', 'not regexp',
'~', '~*', '!~', '!~*', 'similar to',
'not similar to', 'not ilike', '~~*', '!~~*',
@inxilpro
inxilpro / Laravel.xml
Created October 19, 2022 21:33
Laravel PhpStorm Code Style
<code_scheme name="Laravel" version="173">
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="USE_TAB_CHARACTER" value="true" />
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
</value>
</option>
<option name="LINE_SEPARATOR" value="&#10;" />
<CssCodeStyleSettings>
<option name="HEX_COLOR_LOWER_CASE" value="true" />
<?php
use Illuminate\Support\Collection;
class Snapshots
{
protected static ?self $instance = null;
public static function instance(): self
{
@inxilpro
inxilpro / README.md
Created July 22, 2022 21:01
Fully namespaced Tailwind config for widget or embeddable component

Sometimes you need to publish a CSS file for 3rd-party consumption (i.e. default styles for an embeddable JS widget). This set up lets you continue to use Tailwind, but scope all your styles to a specific selector.

Simply replace .internachi with your own widget namespace, set up Tailwind as you please, and run generate.sh to build a custom version of your Tailwind styles that won't interfere with other CSS rules (including the Tailwind reset).

<div class="tailwind" x-data="{ age: 0, name: '', coppa: false }">
<div class="border rounded-lg my-12 max-w-md">
<div class="p-6">
<h1
class="mt-0"
x-show="$wizard.current().title !== ''"
x-text="$wizard.current().title"
></h1>
<form x-data="{ name: '', age: null, coppa: false }">
<h1 x-text="$wizard.title"></h1>
<div x-wizard:step>
This step can be completed without doing anything. It's
just informational.
</div>
<div
<?php
// Imagine you have a class that memoizes some data statically (let's assume
// the data is computationally expensive to load)
class ExpensiveDataHelper
{
protected static $expensive_data = null;
public function getExpensiveData()
<?php
namespace Tests\Project;
use RecursiveCallbackFilterIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
use Tests\Constraints;
use Tests\TestCase;