Skip to content

Instantly share code, notes, and snippets.

@yokotak0527
yokotak0527 / error-handling.middleware.ts
Last active March 16, 2023 12:35
Koa error handling middleware
import type { Next } from 'koa'
import type { RouterContext } from '@koa/router'
export default async function errorHandling(context:RouterContext, next:Next) {
try {
await next()
} catch(err:any) {
context.type = 'application/json'
context.status =
err.status ||
@yokotak0527
yokotak0527 / change_image_insert_code.php
Last active November 4, 2019 08:07
WordPresの画像をエディタに追加する際 HTML ではなく Markdown にする。
<?php
function change_image_insert_code($html){
$rootURL = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'];
preg_match('/src="([a-z\d:\/.\-\_%~^]+)/i', $html, $src);
$src = str_replace($rootURL, '', $src[1]);
// error_log($html, 3, '/var/www/html/dump.log');
preg_match('/alt="([^"]+)"/', $html, $alt);
$alt = empty($alt[1]) ? '' : $alt[1];
@yokotak0527
yokotak0527 / raedme.md
Last active September 27, 2019 03:50
DockerでWordPressをサクッと立ち上げ

立ち上げ

$ docker run -d --name temp_wp_db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp mysql:5.7 && docker run -d --name temp_wp --link temp_wp_db:db -p 80:80 -e WORDPRESS_DB_PASSWORD=root -e WORDPRESS_DB_HOST=db -e WORDPRESS_DB_NAME=wp wordpress:latest

削除

$ docker rm -f temp_wp_db temp_wp
@yokotak0527
yokotak0527 / webpack.config.js
Last active September 20, 2019 15:43
webpack splitchunk 例
optimization : {
splitChunks : {
name : false,
cacheGroups : {
default : false,
vendors : {
test : /node_modules/,
chunks (chunk) {
return chunk.name !== 'js/preload'
},
@yokotak0527
yokotak0527 / async2sync.js
Last active August 28, 2019 15:46
並列処理を直列処理にする案
function async1 () {
return new Promise(resolve => {
setTimeout(() => {
resolve('async1 done')
}, 3000)
})
}
function async2 () {
return new Promise(resolve => {
setTimeout(() => {
@yokotak0527
yokotak0527 / getfile.js
Created August 23, 2019 10:16
globでファイル一覧取得
// node_modulesを除くjsファイル
glob.sync('{,!(node_modules)/**/}[!_]*.js')
// node_modulesを除くSassファイル (.sassと.scss)
glob.sync('{,!(node_modules)/**/}[!_]*.s[a|c]ss')
@startuml kubernetes components
skinparam monochrome true
skinparam shadowing false
skinparam linetype ortho
skinparam defaultFontName Cica
skinparam noteBackgroundColor white
rectangle kubectl
rectangle "Kubernetes Cluster" {
@yokotak0527
yokotak0527 / v-input.vue
Last active May 26, 2019 12:06
inputタグのradio,checkbox,text(etc.), submit,buttonをまとめたvueテンプレート
<template>
<div>
<v-radio v-if="type === 'radio'" />
<v-checkbox v-else-if="type === 'checkbox'" />
<v-button v-else-if="type === 'button' || type === 'submit'" />
<v-text v-else />
</div>
</template>
<script>

Keybase proof

I hereby claim:

  • I am yokotak0527 on github.
  • I am yokotak0527 (https://keybase.io/yokotak0527) on keybase.
  • I have a public key ASBh0EFyiK1je-2pFf6BsucJLr2rOUl9Rw4LfEneZyHd3go

To claim this, I am signing this object:

@yokotak0527
yokotak0527 / async_series_with_generator.js
Created February 12, 2019 05:43
ジェネレータ関数を使った直接非同期通信
// ジェネレータ関数
const gfn = function * (start, end) {
while(start <= end) {
yield [expect Promise code]
start++
}
}
const g = gfn(1, 10)