Skip to content

Instantly share code, notes, and snippets.

View xxRockOnxx's full-sized avatar

Lemuel Flores xxRockOnxx

View GitHub Profile
@xxRockOnxx
xxRockOnxx / laravel-tinker-login-session.md
Last active May 15, 2024 04:54
Laravel Tinker: login as another user and generate an injectable session cookie

Generating session cookie

  • Enter Laravel Tinker
php artisan tinker
  • Authenticate
@xxRockOnxx
xxRockOnxx / demo.vue
Last active October 4, 2022 13:34
Vue Composition vs Options API
<template>
<UsersRepo>
<template v-slot="{ isLoading, fetch, users }">
<button
v-if="users.length === 0"
@click="fetch"
>
Fetch Users
</button>
@xxRockOnxx
xxRockOnxx / scoped-events.ts
Last active July 5, 2022 10:55
Node.js EventEmitter that scopes events by suffix
import { EventEmitter } from 'events';
export default function scopeEventEmitter(events: EventEmitter, scope: string): EventEmitter {
return {
eventNames: () => events.eventNames().filter((name) => typeof name === 'string' && name.endsWith(`:${scope}`)),
on(event: string, listener) {
events.on(`${event}:${scope}`, listener);
return this;
},
@xxRockOnxx
xxRockOnxx / layouts.ts
Last active April 27, 2020 13:49
React Native Navigation with react-native-vector-icons
interface Layouts {
[name: string]: LayoutRoot;
}
const layouts: Promise<Layouts> = new Promise(resolve => {
Promise.all([
Icon.getImageSource("people"),
Icon.getImageSource("message")
]).then(icons => {
resolve({
@xxRockOnxx
xxRockOnxx / Handler.php
Last active January 20, 2021 21:35
[Laravel] Convert dot array validation error to nested array
<?php
namespace App\Exceptions;
class Handler
{
/**
* Convert a validation exception into a JSON response.
*
* @param \Illuminate\Http\Request $request
@xxRockOnxx
xxRockOnxx / validateDay.php
Last active September 27, 2023 23:40
[Laravel] Custom Validation rule for day of week.
<?php
Validator::extend('day', function($attribute, $value, $parameters, $validator) {
// Laravel uses Carbon. Just `use Carbon\Carbon;` it
$day = Carbon::parse($value)->dayOfWeek;
switch (strtolower($parameters[0])) {
case 'sunday':
return $day == 0;
@xxRockOnxx
xxRockOnxx / Handler.php
Last active July 14, 2018 03:18
[Laravel] Custom Error Page based on route (Public and Admin error page)
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
// Don't forget to add this line as it is used by renderHttpException()
use Symfony\Component\HttpKernel\Exception\HttpException;