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 / 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 / asyncrequest.js
Created July 4, 2018 04:26 — forked from Abazhenov/asyncrequest.js
Javascript - ES6 - Async function wrapper for fetch requests
const getInfo = async () => {
console.log(await axios.get('/users'))
console.log(await getGroups())
console.log(await getFavorites())
return 'all done';
}
getInfo();
@whoisryosuke
whoisryosuke / esnextbin.md
Created July 10, 2018 23:46 — forked from peduarte/esnextbin.md
Javascript - Vanilla Debounce (from Lodash _.debounce)
@whoisryosuke
whoisryosuke / AttachJwtToken.php
Last active July 23, 2018 22:56 — forked from jgrossi/AttachJwtToken.php
AttachJwtToken.php
<?php
namespace Tests\Traits;
use App\User;
trait AttachJwtToken
{
/**
* @var User
@whoisryosuke
whoisryosuke / FormRequest.php
Last active July 26, 2018 17:38 — forked from sirolad/FormRequest.php
Laravel - Adds validation errors to API. Extend your Form Request with this base/abstract class - via: https://medium.com/@Sirolad/laravel-5-5-api-form-request-validation-errors-d49a85cd29f2
<?php
namespace App\Http\Requests;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Foundation\Http\FormRequest as LaravelFormRequest;
@whoisryosuke
whoisryosuke / GitCommitEmoji.md
Created August 7, 2018 20:12 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
@whoisryosuke
whoisryosuke / findByType.js
Created August 17, 2018 20:02 — forked from MaximeHeckel/findByType.js
Medium - React "sub-components" - findByType function
import React from 'react';
const findByType = (children, component) => {
const result = [];
/* This is the array of result since Article can have multiple times the same sub-component */
const type = [component.displayName] || [component.name];
/* We can store the actual name of the component through the displayName or name property of our sub-component */
React.Children.forEach(children, child => {
const childType =
child && child.type && (child.type.displayName || child.type.name);
if (type.includes(childType)) {
@whoisryosuke
whoisryosuke / Article.js
Created August 17, 2018 20:02 — forked from MaximeHeckel/Article.js
Medium - React "sub-component" - Title sub-component
import React, { Component } from 'react';
import findByType from './findByType';
import css from './somestyle.css';
// We instantiate the Title sub-component
const Title = () => null;
class Article extends Component {
// This is the function that will take care of rendering our Title sub-component
renderTitle() {
const { children } = this.props;
// First we try to find the Title sub-component among the children of Article
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}