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 / docker-compose.yml
Created April 9, 2018 18:02
Docker Compose file for basic Wordpress projects
my-wpdb:
image: mariadb
ports:
- "8081:3306"
environment:
MYSQL_ROOT_PASSWORD: root
my-wp:
image: wordpress
volumes:
- ./:/var/www/html
@whoisryosuke
whoisryosuke / new-post.php
Created April 9, 2018 20:27
WORDPRESS: Create new post with meta data
<?php
# Credits: https://wordpress.stackexchange.com/questions/106973/wp-insert-post-or-similar-for-custom-post-type
$post_id = wp_insert_post(array (
'post_type' => 'your_post_type',
'post_title' => $your_title,
'post_content' => $your_content,
'post_status' => 'publish',
'comment_status' => 'closed', // if you prefer
@whoisryosuke
whoisryosuke / template.php
Last active April 9, 2018 20:27
WORDPRESS: Check if user has certain role
<?php
# Credit: https://wordpress.stackexchange.com/questions/5047/how-to-check-if-a-user-is-in-a-specific-role
$user = wp_get_current_user();
if ( in_array( 'author', (array) $user->roles ) ) {
//The user has the "author" role
}
?>
@whoisryosuke
whoisryosuke / gatsby-image-example.js
Created April 26, 2018 17:52
Best practice for importing static images into GatsbyJS to ensure lazyloading/scaling. If image is responsive (like background cover image), use sizes property instead of resolutions in query and <Img /> component. See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-image
import React, { Component } from "react";
import Img from "gatsby-image";
export default class Frontpage extends Component {
render() {
return (
<div className="Frontpage pt2">
<Img resolutions={this.props.data.PeaceEmoji.resolutions} alt="Peace sign emoji" />
</div>
);
@whoisryosuke
whoisryosuke / laravel-eager-load-model-relationships.php
Created April 28, 2018 00:13
Laravel - Automatically eager load model relationships by setting a protected $with var on your model -- found via: https://stackoverflow.com/a/25674216
<?php
namespace YourApp;
use Illuminate\Database\Eloquent\Model;
class Posts extends Model
{
/**
* Automagically eager load any Model relationships
@whoisryosuke
whoisryosuke / array-destructuring-in-php7.php
Created May 12, 2018 20:24
Specify the variables for keys in arrays in PHP7 -- found via: https://blog.frankdejonge.nl/array-destructuring-in-php/
<?php
$members = [
[1, 'Seb'],
[2, 'Alex'],
[3, 'Brent'],
];
foreach ($members as [$id, $name]) {
// do stuff with $id and $name
@whoisryosuke
whoisryosuke / array-destructuring-in-php7-specific.php
Created May 12, 2018 20:23
Specify the variables for specific keys in arrays in PHP7 -- found via: https://blog.frankdejonge.nl/array-destructuring-in-php/
<?php
$members = [
['id' => 1, 'name'=> 'Seb', 'twitter' => '@sebdedeyne' ],
['id' => 2, 'name'=> 'Alex', 'twitter' => '@alexvanderbist'],
['id' => 3, 'name'=> 'Brent', 'twitter' => '@brendt_gd'],
];
foreach ($members as ['twitter' => $twitterHandle, 'name' => $firstName]) {
// do stuff with $twitterHandle and $firstName
@whoisryosuke
whoisryosuke / semantic-ui-state-search-dropdown.html
Created May 14, 2018 20:53
Semantic UI - State Search Dropdown (Requires Semantic CSS/JS + jQuery)
<form class="ui form">
<section class="field">
<label for="shipper_state_state">
State:
</label>
<div class="ui fluid search selection dropdown">
<input type="hidden" name="shipper_state_state">
<i class="dropdown icon"></i>
<div class="default text">Select State</div>
<div class="menu">
@whoisryosuke
whoisryosuke / laravel-middleware-specific-methods.php
Created May 15, 2018 23:53
Laravel - Apply Middleware in the Controller to "only" certain methods, or "except" certain methods.
<?php
public function __construct()
{
// Only apply middleware to these methods
$this->middleware('auth', ['only' => ['create', 'store', 'edit', 'delete']]);
// Or exclude middleware from these methods
$this->middleware('auth', ['except' => ['confirmPage', 'confirmOrder', 'invoice']]);
}
@whoisryosuke
whoisryosuke / load-script-on-model-boot.php
Created May 18, 2018 22:00
Laravel - Add a hook script to the Model. In this case, we generate a UUID on creation.
/**
* Setup model event hooks
*/
public static function boot()
{
parent::boot();
self::creating(function ($table) {
// Generate uuid
$table->uuid = Uuid::generate(4);
});