Skip to content

Instantly share code, notes, and snippets.

View whoisryosuke's full-sized avatar
👾
Going deep with game development

Ryosuke whoisryosuke

👾
Going deep with game development
View GitHub Profile
@whoisryosuke
whoisryosuke / controller.php
Created May 30, 2018 23:57
Laravel Middleware - Apply middleware to specific controller methods (two ways!)
<?php
public function __construct()
{
// Apply middleware to only certain routes
$this->middleware('auth', ['only' => ['create', 'store', 'edit', 'delete']]);
// Or apply middleware to all routes except these
$this->middleware('auth', ['except' => ['index', 'show']]);
}
@whoisryosuke
whoisryosuke / ProjectController.php
Last active June 1, 2018 17:33 — forked from hanspagel/ProjectController.php
Laravel - API - How to return API Resources with different status codes
<?php
namespace App\Http\Controllers;
use App\Models\Project;
use Illuminate\Http\Request;
class ProjectController extends Controller
{
public function update(Request $request, Project $project)
@whoisryosuke
whoisryosuke / slugify.js
Created June 5, 2018 21:06 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@whoisryosuke
whoisryosuke / module.js
Last active June 5, 2018 21:20
NodeJS - CommonJS Module syntax using `require()` + `module.exports` (instead ES6 version `export default` and `import package from '/package/';) -- slugify credits: https://gist.github.com/mathewbyrne/1280286
module.exports = {
slugify: function(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
};
@whoisryosuke
whoisryosuke / gatsbyjs-pagination-attempt.js
Created June 8, 2018 23:50
GatsbyJS - Pagination attempt. Doesn't work fully, loops oddly
export default class BlogPost extends Component {
constructor(props) {
super(props);
}
render() {
@whoisryosuke
whoisryosuke / Uuids.php
Last active June 25, 2018 17:53
Laravel: UUID trait to add to models to generate a UUID as primary key -- App/Traits/Uuids.php -- https://laravel.com/docs/5.6/helpers#method-str-uuid
<?php
namespace SeshSource\Traits;
use Illuminate\Support\Str;
trait Uuids
{
/**
@whoisryosuke
whoisryosuke / AuthService.js
Created June 25, 2018 22:44
JavaScript - Login utility for OAuth2.0 APIs using JWT tokens (direct token -- not "Sign in with..." style)
// utils/AuthService.js
export default class AuthService {
constructor(domain) {
this.domain = domain || 'http://localhost:5000'
this.fetch = this.fetch.bind(this)
this.login = this.login.bind(this)
this.getProfile = this.getProfile.bind(this)
}
login(email, password) {
@whoisryosuke
whoisryosuke / withAuth.js
Created June 25, 2018 22:45
React - Authentication HOC for protected routes. Uses the OAuth2.0 login utility (AuthService) in the previous Gist.
import React, {Component} from 'react'
import AuthService from './auth'
export default function withAuth(AuthComponent) {
const Auth = new AuthService('http://localhost:5000')
return class Authenticated extends Component {
constructor(props) {
super(props)
this.state = {
isLoading: true
<?php
namespace SeshSource\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreEvents extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
@whoisryosuke
whoisryosuke / gulpfile.js
Created June 27, 2018 21:50
Gulp - SASS - Compile SASS to CSS and a "watch" to compile on save -- `npm install gulp-cli -g` `npm install gulp gulp-sass --save-dev`
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
// Grabs a specific "root" SASS file that imports all the others
// And runs SASS
// Then dumps out to the specificed folder, in this case a WP theme
gulp.task('sass', function () {
return gulp.src('./wp-content/themes/twenty/sass/style.scss')