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 / 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 / docker-compose.yml
Last active March 10, 2019 23:27
Docker 🐳 - Wordpress easy-mode server. Drop this into the wordpress project root, run `docker-compose up -d`, go to http://localhost:8080 👍⚡️
version: "2"
services:
my-wpdb:
image: mariadb
ports:
- "8081:3306"
environment:
MYSQL_ROOT_PASSWORD: root
my-wp:
image: wordpress
@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 / nextjs-hoc-authorization.js
Created June 26, 2018 22:24
ReactJS - NextJS - A HOC for wrapping NextJS pages in an authentication check. Checks for getInitialProps on the child component and runs it, so you still get SSR from the page. Also includes a user agent for Material UI.
import React, {Component} from 'react'
import Router from 'next/router'
import AuthService from './AuthService'
export default function withAuth(AuthComponent) {
const Auth = new AuthService('http://localhost')
return class Authenticated extends Component {
static async getInitialProps(ctx) {
// Ensures material-ui renders the correct css prefixes server-side
@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')
@whoisryosuke
whoisryosuke / css-animation-60fps-hover-slideup.scss
Last active June 28, 2018 22:49
CSS - Animation - Button slides up on hover (60FPS)
a.button
{
// Needs to be a block element or wont transform
display:inline-block
-webkit-transform: translateY(0);
transform: translateY(0);
transition: transform .2s linear;
&:hover
{

Setting up ESLint + Airbnb:

  1. cd coding-directory
  2. npm init -y
  3. npm i -D eslint eslint-config-airbnb-base eslint-plugin-import
  4. touch .eslintrc.js
  5. Inside eslint file: module.exports = { "extends": "airbnb-base" };

Installing ESLint: