Skip to content

Instantly share code, notes, and snippets.

View atomjoy's full-sized avatar

Atomjoy atomjoy

View GitHub Profile
@atomjoy
atomjoy / Uuid.php
Last active February 19, 2025 20:27
Laravel Uuid model.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Support\Str;
/**
* Uuid class
@atomjoy
atomjoy / Product-attributes.md
Last active February 19, 2025 19:28
Product Attribute Management in Laravel, storing Product attributes such as Size, Color, Weight.

Product Attribute Management in Laravel

Product Attribute Management in Laravel, storing Product attributes such as Size, Color, Weight.

Product variants (many to many)

Products (id, name, desc, visible)
# 1, Shirt, Description, true
# 2, Laptop, Description, true
@atomjoy
atomjoy / InputAttrs.vue
Last active February 17, 2025 13:40
How to catch class attributes in vue 3 components.
<script setup>
import { useAttrs, ref } from 'vue';
const emits = defineEmits(['update:modelValue', 'valid', 'invalid']);
const props = defineProps({
modelValue: [String, Number],
name: { type: String },
label: { type: String },
placeholder: { type: String },
@atomjoy
atomjoy / Icon.vue
Last active February 25, 2025 16:53
Load svg dynamically in Vue 3
<script setup>
import editIcon from '@/assets/svg/edit-svgrepo-com.svg?raw';
</script>
<template>
<div class="svg-icon" v-html="editIcon"></div>
</template>
<style>
.svg-icon {
@atomjoy
atomjoy / singleton.js
Created February 15, 2025 11:30
Js singleton
// First example
export default class Singleton {
number = 0;
constructor() {
if (!!Singleton.instance) {
return Singleton.instance;
}
Singleton.instance = this;
// return this;
}
@atomjoy
atomjoy / Laravel-11-exception-handler.md
Created February 5, 2025 09:53
Laravel 11 Exception Handler with Service Provider.

Laravel 11 Exception Handler

Reportable and renderable methods in exception handler with Laravel 11 service provider (modules).

ExceptionHandlerProvider.php

<?php

namespace App\Providers;
@atomjoy
atomjoy / Upload-avatar-fetch-javascript.md
Last active March 12, 2025 08:26
How to upload avatar using fetch function in JavaScript with Laravel.

Fetch API JavaScript

Upload avatar

Image upload form in html

<img src="/default/avatar.webp" alt="Avatar image" id="avatar">

<form method="post" enctype="multipart/form-data" onsubmit="getData(event)">
@atomjoy
atomjoy / Code-to-json.js
Created January 17, 2025 14:45
Code to json
function jsonEscape(str) {
return str.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
}
function jsonEscapeCode(str) {
return str.replace(/"/g, '\\"').replace(/'/g, "\'");
}
let code = jsonEscapeCode(`<?php
$name = "Benny's";
@atomjoy
atomjoy / Email-html-signatures.md
Last active December 16, 2024 17:41
Podpisy e-mail w formacie HTML

Podpisy email html

  • Używaj tylko inline style w divach i odnośnikach a z box-sizing: content-box
  • Ramki border: do img tylko przez dodatkowy div (w Proton się powielają)
  • Koniecznie box-sizing: content-box i uwzględnianie paddingów i borderów (o2, wp i Yahoo)
  • Yahoo nie obsługuje box-sizing: border-box a Wp i o2 wymusza box-sizing: content-box (gryzie się)
  • Używać szrokości (width:) i wysokości (height:) w pikselach (px) pamiętać o borderach gdy są bez tabel
  • Nie działa height="" w tagach (wp, o2)
  • Nie działa img inline style height: width: (yahoo) dodać height="" i inline style (lub min-width/height, max-width/height)
  • Nie działa width: w procentach % (wp, o2, yahoo) bez box-sizing: content-box (uwzględnić border width trzeba)
@atomjoy
atomjoy / Drivers.md
Created October 28, 2024 12:23
Huawei Laptop Drivers