Skip to content

Instantly share code, notes, and snippets.

View torounit's full-sized avatar

Hiroshi Urabe torounit

View GitHub Profile
@torounit
torounit / grid-cols.md
Last active November 29, 2021 16:13
Grid の width の について
|---| |---| |---| |---| |---| |---| |---| |---| |---| |---| |---| |---|
|---| |---| |---| |---| |---| |---| |---| |---| |---| |---| |---| |---|
|---| |---| |---| |---| |---| |---| |---| |---| |---| |---| |---| |---|

のような Grid の 横幅算出の アルゴリズムについて

全体の横幅を T (100%)、カラムの間の Gap を G、gridの分割数を、S とする。

<?php
add_action( 'admin_enqueue_scripts', function () {
if ( get_option( 'page_on_front' ) === filter_input( INPUT_GET, 'post' ) ) {
wp_add_inline_style(
'wp-edit-post',
'
.block-editor-writing-flow { --block-width: 1136px; }
.wp-block { max-width: var(--block-width); }
'
);
import { registerBlockType } from '@wordpress/blocks';
import { InnerBlocks } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
registerBlockType( 'my/card', {
attributes: {},
category: 'layout',
supports: {
anchor: true,
},
icon: () => (
@torounit
torounit / useMeta.js
Last active September 1, 2020 03:28
useState 風味に WordPressのカスタムフィールドを扱うやつ
import { Fragment, useCallback } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
const useMeta = ( key ) => {
const meta = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( 'core/editor' );
const values = getEditedPostAttribute( 'meta' ) || {};
return values[ key ] || '';
}, [] );
@torounit
torounit / run-httpd-as-ec2-user.sh
Created November 7, 2019 06:37
amimoto で ec2-user する。
#!/usr/bin/env bash
set -e
echo '{
"nginx" : { "config" : { "user" : "ec2-user" } },
"php" : { "config" : { "user" : "ec2-user" } },
"run_list" : [ "recipe[amimoto]" ]
}' > /opt/local/amimoto.json
/opt/local/provision
@torounit
torounit / compose.js
Created December 30, 2018 06:39
compose in '@wordpress/compose' .
import { compose } from '@wordpress/compose'; // compose == lodash.flowRight;
const inc = ( a ) => {
return a + 1;
};
const square = ( a ) => {
return a * a;
};
@torounit
torounit / Unminify.php
Created November 28, 2018 04:19
WordPress の管理画面で React が圧縮されるとデバッグがしづらいので、圧縮前のヤツを読み込むようにするプラグイン。
<?php
/**
* Plugin Name: Unminify vendor scripts.
*/
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
add_action( 'admin_print_scripts', function () {
global $wp_scripts;
unminify_execute( [
'react',
@torounit
torounit / functions.php
Created November 15, 2018 18:39
Gutenberg で選択出来るフォントサイズを変更。
<?php
add_action( 'after_setup_theme', function() {
add_theme_support('editor-font-sizes', [
[
'name' => 'Small',
'size' => 12,
'slug' => 'small'
],
[
@torounit
torounit / browserSync.js
Last active October 14, 2018 16:07
npm scripts
var browserSync = require("browser-sync");
browserSync({
proxy: 'localhost:9292',
files: [
"./css/**/*",
"./js/**/*",
"./images/**/*",
"./fonts/**/*",
"./**/*.php",
]
@torounit
torounit / stop-localize-update.php
Created June 15, 2018 07:22
WordPress のローカライズ版パッケージのアップデートを出さないようにする。
<?php
add_filter( 'core_version_check_locale', function () {
return 'en_US';
});