Skip to content

Instantly share code, notes, and snippets.

View lorisleiva's full-sized avatar

Loris Leiva lorisleiva

View GitHub Profile
@lorisleiva
lorisleiva / phpcs.xml
Last active May 4, 2019 14:42
The default PHP Code Style of my Laravel projects.
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Laravel">
<description>The default PHP Code Style of my Laravel projects.</description>
<!-- Files to include. -->
<file>app</file>
<file>config</file>
<file>routes</file>
<file>tests</file>
@lorisleiva
lorisleiva / ArticleUpdateTest.php
Created August 5, 2019 10:16
✅ Set up traits dynamically for tests
<?php
namespace Tests;
use Tests\Authenticated;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ArticleUpdateTest extends TestCase
{
<?php
abstract class Node {}
class Calculator extends Node {
public function __construct(public array $statements){}
}
class Add extends Node {
public function __construct(public Node $left, public Node $right){}
@lorisleiva
lorisleiva / useAutoresizeTextarea.js
Created November 15, 2021 08:39
Auto-resize a textarea based on its content (Vue 3 composition API)
import { watchEffect } from "vue"
export const useAutoresizeTextarea = (element) => {
const resizeTextarea = () => {
element.value.style.height = 'auto'
element.value.style.height = element.value.scrollHeight + 'px'
}
watchEffect(onInvalidate => {
if (! element.value) return
@lorisleiva
lorisleiva / readme.md
Last active December 26, 2021 13:09
Webpack aliases with Laravel Mix

Step 1: configure Webpack aliases

// webpack.mix.js

const mix = require('laravel-mix')
const path = require('path')

// ...
@lorisleiva
lorisleiva / PaymentRequest.js
Created June 4, 2018 22:02
Renderless VueJS component for Payment Requests using Stripe Element
export default {
props: {
stripe: {
type: String,
required: true,
},
options: {
type: Object,
required: true,
}
@lorisleiva
lorisleiva / TweetCard.vue
Last active February 10, 2022 16:06
TweetCard and TweetFormUpdate for Episode 12 of the Solana series.
<script setup>
import { ref, toRefs, computed } from 'vue'
import { useWorkspace } from '@/composables'
import TweetFormUpdate from './TweetFormUpdate'
const props = defineProps({
tweet: Object,
})
const { tweet } = toRefs(props)
// resources/js/models/Model.js
export default class Model {
constructor (attributes = {}) {
this.fill(attributes)
}
static make (attributes = {}) {
return Array.isArray(attributes)
? attributes.map(nested => new this(nested))
@lorisleiva
lorisleiva / js-next-react.md
Last active June 15, 2022 20:00
[Metaplex] Integrate the new JS SDK with React
// resources/js/services/Form.js
import FormErrors from './FormErrors'
export default class {
constructor (initialData = {}, submitCallback = null) {
this._initialData = initialData
this._submitCallback = submitCallback
this.errors = new FormErrors()