Skip to content

Instantly share code, notes, and snippets.

View ronssij's full-sized avatar
🏠
Secretly deleting database 👿

CJ Ronxel ronssij

🏠
Secretly deleting database 👿
View GitHub Profile
@ronssij
ronssij / roman_numerals.php
Last active April 16, 2024 12:21
Laravel collection roman numeral conversion
<?php
$roman = ['i' => 1, 'v' => 5, 'x' => 10, 'l' => 50, 'c' => 100, 'd' => 500, 'm' => 1000];
$value = 'IX';
$result = 0;
$prevValue = 0;
if (preg_match('/[^ivxlcdm]|i{4,}|x{4,}|c{4,}|m{4,}|v{2,}|l{2,}|d{2,}/i', $value)) {
return "invalid format";
@ronssij
ronssij / SequentialIncrementNullColumns.php
Last active February 9, 2024 18:00
Laravel: Sequentially Incrementing Null Columns in a Database
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class SequentialIncrementNullColumns extends Seeder
{
public function run(): void
@ronssij
ronssij / useForm.ts
Created November 30, 2023 05:51
Vue3 Form Composables
const form = <TFormData>(formData: TFormData) => {
const $originalData = useCloneDeep(formData) as object;
const $errors = ref({});
const $busy = ref(false);
let _data = formData as object;
const $setErrors = <TErrors>(errors: object | TErrors) => {
return ($errors.value = errors || {});
};
@ronssij
ronssij / JustifyParagraph.php
Last active February 5, 2024 17:35
Jsutify string in PHP(Laravel)
<?php
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis adipiscing sodales ipsum sem ac. Orci sem nisl rutrum sagittis sed id. In tellus mauris tempor in at. Lorem ac sit tortor, eu sit elementum vestibulum ultrices egestas. In nunc, aliquet nulla quis. Tristique molestie integer ac ullamcorper dolor. Donec id erat turpis lobortis et egestas phasellus. Sit elit suspendisse porttitor egestas. Augue id mollis enim, eget sapien, luctus. Tortor, malesuada morbi et dui pretium adipiscing dui id rhoncus. Vitae et eget luctus ut nec donec. Vulputate pharetra tempus, congue eu commodo praesent imperdiet sapien. Vitae eleifend lobortis tellus enim, aliquam fermentum at venenatis. Mattis fringilla id viverra in metus pharetra, rutrum eget porta.";
$limit = 30;
$lines = [];
$collected = collect([]);
$words = explode(" ", $string);
@ronssij
ronssij / natural_sort_function.php
Created October 4, 2023 17:06
Natural sorting for laravel mysql
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class AddNaturalSortFunction extends Migration
{
/**
@ronssij
ronssij / icon.vue
Created May 20, 2022 20:54
Functional vue icon component
<script>
import { has, map } from 'lodash'
export default {
name: 'AftIcon',
functional: true,
props: {
tag: {
@ronssij
ronssij / icon-colors.js
Last active May 20, 2022 20:52
Extending Tailwind CSS color palattes to create custom prefxied colors.
const plugin = require('tailwindcss/plugin')
/**
* Utlizes tailwind colors config and icon-{color} class is created, analog to bg- and text- classes.
*
* eg. class="icon-white"
*/
const generateColors = (e, colors, prefix) =>
Object.keys(colors).reduce((acc, key) => {
if (typeof colors[key] === 'string') {