Skip to content

Instantly share code, notes, and snippets.

Avatar

Loris Leiva lorisleiva

View GitHub Profile
View nodes-visitors-2.php
<?php
// Nodes.
abstract class Node implements Visitable {}
class Number extends Node {
public function __construct(public float $value){}
public function accept(Visitor $visitor) {
return $visitor->visitNumber($this);
}
View nodes-visitors-1.php
<?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 / toSqlWithBindings.php
Last active Jan 26, 2021
A little macro to get the SQL from a query builder without the annoying "?".
View toSqlWithBindings.php
<?php
use Illuminate\Database\Eloquent\Builder;
Builder::macro('toSqlWithBindings', function () {
$bindings = array_map(
fn ($value) => is_numeric($value) ? $value : "'{$value}'",
$this->getBindings()
);
View Model.js
// 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))
View Form.js
// 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()
@lorisleiva
lorisleiva / readme.md
Last active Aug 4, 2020
Webpack aliases with Laravel Mix
View readme.md

Step 1: configure Webpack aliases

// webpack.mix.js

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

// ...
@lorisleiva
lorisleiva / workflow.yaml
Last active Jan 18, 2020
🐳 GitHub Actions using Laravel Docker
View workflow.yaml
name: My Workflow
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container:
image: lorisleiva/laravel-docker:7.4
steps:
- uses: actions/checkout@v2
@lorisleiva
lorisleiva / ArticleUpdateTest.php
Created Aug 5, 2019
Set up traits dynamically for tests
View ArticleUpdateTest.php
<?php
namespace Tests;
use Tests\Authenticated;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ArticleUpdateTest extends TestCase
{
@lorisleiva
lorisleiva / phpcs.xml
Last active May 4, 2019
The default PHP Code Style of my Laravel projects.
View phpcs.xml
<?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 / GoogleApiAccess.md
Last active Apr 8, 2021
This gist describes two processes allowing us to access the Google API and to register some webhooks
View GoogleApiAccess.md

Access Google API credentials and domain verification

This gist describes two processes allowing us to access the Google API and to register some webhooks. At the end of both processes we will obtain all variable needed to start using their API and we will have whitelisted all necessary URL to get started. We will be using the Google Calendar API and the Google Plus API to access the email address of the user.

This gist has been created as an Appendix to this article (part 1) and this article (part 3).

Note that, I will be using a randomly generated ngrok domain during this presentation. Simply replace b3093b51.ngrok.io with your domain name