Skip to content

Instantly share code, notes, and snippets.

@owenconti
owenconti / 5ec33886f3a5d.yaml
Created May 19, 2020 01:38
GitHub Actions workflow file for a Laravel application
name: Build
on: [push]
jobs:
build-js:
name: Build JS
runs-on: ubuntu-18.04
container: 'ohseemedia/laravel-ci:7.3'
steps:
- uses: actions/checkout@v1
@owenconti
owenconti / 5ec3385104d18.json
Created May 19, 2020 01:37
Signing AWS CloudFront requests with Laravel
{
"Version": "2008-10-17",
"Id": "PolicyForCloudFrontPrivateContent",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXX"
},
@owenconti
owenconti / 5ec3380edaffe.js
Created May 19, 2020 01:36
"Nothing was returned from render." ReactJS error
function App() {
if (props.loading) {
return; // Bad! Should return `null` here instead
}
return null; // Fixed!
}
@owenconti
owenconti / 5ec337df0c9ef.toml
Created May 19, 2020 01:35
My experience with Netlify Dev after a couple of hours of using it
[dev]
publish = "out"
port = 3000
command = "npm start"
@owenconti
owenconti / 5ec33751c2772.js
Created May 19, 2020 01:33
5 keyboard shortcuts to navigate your code faster
const name = "Owen";
console.log(`Hello world!`);
@owenconti
owenconti / 5ec33710af2c1.php
Created May 19, 2020 01:32
How to handle multiple events with a single listener in Laravel
<?php
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
@owenconti
owenconti / 5ec33694dd6fc.js
Created May 19, 2020 01:29
"Rendered fewer hooks than expected." ReactJS error
function MyComponent(props) {
if (props.id) {
// BAD! Hooks cannot be used inside a conditional statement
useEffect(() => {
axios.get(`/api/data?id=${props.id}`);
});
}
// ...render the component
}
@owenconti
owenconti / 5ec336384517f.js
Created May 19, 2020 01:28
"Hooks can only be called inside the body of a function component" ReactJS error
class App extends React.Component {
componentDidMount() {
// BAD!
const [state, setState] = React.useState(null)
}
}
@owenconti
owenconti / 5ec335dd163cb.php
Created May 19, 2020 01:26
Laravel request logger snippet
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Log;
class RequestLogger
{
/** @var int */
@owenconti
owenconti / 5ec3352412de4.php
Created May 19, 2020 01:23
Improving the performance of your Laravel queue
<?php
ProcessPodcast::dispatch($podcast);