Skip to content

Instantly share code, notes, and snippets.

View karkowg's full-sized avatar

Gustavo Karkow karkowg

View GitHub Profile
@karkowg
karkowg / gandalf.php
Created July 8, 2024 17:27
Like Gandalf, get a secure pass anywhere with magical links
<?php
namespace App\Support;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Router;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use InvalidArgumentException;
@karkowg
karkowg / helpers.php
Last active June 4, 2024 13:53
dispatch_if/dispatch_unless
<?php
use Illuminate\Foundation\Bus\PendingDispatch;
use Illuminate\Support\Fluent;
if (! function_exists('dispatch_if')) {
function dispatch_if(bool $boolean, mixed $job) : PendingDispatch|Fluent
{
if ($boolean) {
return dispatch($job);
@karkowg
karkowg / machine.js
Last active February 24, 2021 19:30
Generated by XState Viz: https://xstate.js.org/viz
const makeVideoPlayerMachine = ({ mode, inactivityTimeout }) => Machine({
initial: 'paused',
context: {
mode,
inactivityTimeout,
},
states: {
paused: {
on: {
PLAY: 'playing',
@karkowg
karkowg / machine.js
Created January 29, 2021 22:13
Generated by XState Viz: https://xstate.js.org/viz
const askQuestion = (question) => Promise.resolve('asked');
const askQuestionMachine = Machine({
id: 'askQuestion',
initial: 'form',
context: {
question: '',
email: '',
name: '',
},
@karkowg
karkowg / machine.js
Last active February 3, 2021 01:22
Generated by XState Viz: https://xstate.js.org/viz
const needsPin = ctx => [ctx.webcast.isPrivate, ctx.viewer.needsPin].every(Boolean);
const needsRegistration = ctx => [ctx.webcast.hasRegistration, ctx.viewer.needsRegistration].every(Boolean);
const makeWebcastMachine = ({ webcast, viewer }) => Machine({
id: 'webcast',
initial: 'guard',
context: {
viewer: {
email: viewer.email,
name: viewer.name,
@karkowg
karkowg / machine.js
Created November 25, 2020 21:42
Generated by XState Viz: https://xstate.js.org/viz
function randomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function getViewersCount() {
return Promise.resolve(({ viewersCount: randomInt(10) }));
}
const statsMachine = Machine({
id: 'stats',
@karkowg
karkowg / machine.js
Created November 25, 2020 19:26
Generated by XState Viz: https://xstate.js.org/viz
function randomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function getViewersCount() {
return Promise.resolve({ viewersCount: randomInt(10) });
}
const fetchMachine = Machine({
id: 'fetch',
@karkowg
karkowg / machine.js
Last active December 3, 2020 16:14
Generated by XState Viz: https://xstate.js.org/viz
function dayjs() {
return new Date();
}
function goLive(uid) {
return Promise.resolve({ startedAt: dayjs() });
}
function stopLive(uid) {
return Promise.resolve();
@karkowg
karkowg / eloquentHelper.php
Created May 19, 2017 13:16
Eager load helper function for Eloquent ORM
<?php
/**
* Function to wrap select constraints for eager loading
* a relationship when using Eloquent's 'with' method.
*
* @param array $columns Columns to select from the relation table.
* @param bool $distinct Select only distinct rows?
*
* @example

Keybase proof

I hereby claim:

  • I am karkowg on github.
  • I am karkowg (https://keybase.io/karkowg) on keybase.
  • I have a public key ASDhBGKYZ-uUadqaclICvx6upL3S9b7DFP659mB7JosvCgo

To claim this, I am signing this object: