Skip to content

Instantly share code, notes, and snippets.

Avatar

Hidetaka Okamoto hideokamoto

View GitHub Profile
@hideokamoto
hideokamoto / format-address.spec.ts
Created Dec 29, 2021
Stripe Connectむけの住所フォーマットに成形するサンプル
View format-address.spec.ts
import { normalizeForStripeConnect } from './format-address.ts'
test.each([
['大阪府堺市北区新金岡町4丁1−8', {
state: "大阪府",
city: "堺市北区",
town: "新金岡町四丁",
line1: "1-8"
}],
["神奈川県横浜市中区本町6丁目50−10", {
View nestjs-serverless.ts
import { NestApplicationOptions, INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { Server } from 'http';
import { ExpressAdapter } from '@nestjs/platform-express';
import * as serverless from 'aws-serverless-express';
import * as express from 'express';
import { APIGatewayProxyEvent, Context, APIGatewayEvent } from 'aws-lambda';
let cachedServer: Server;
View listAllCloudFrontDistributions.ts
import { CloudFront } from 'aws-sdk'
import DistributionSummaryList = CloudFront.DistributionSummaryList
const cfClient = new CloudFront()
/**
* @example
* const distributions = await listAllDistributions()
**/
const listAllDistributions = async (distributions: DistributionSummaryList = [], Marker?: string): Promise<DistributionSummaryList> => {
View invoice.js
Stripe.invoices.update(
'in_xxxx',
{
metadata: {
order_id: '6735'
},
statement_descriptor: 'statement descriptor',
alternate_statement_descriptors: {
kanji: '漢字',
kana: 'カナ'
@hideokamoto
hideokamoto / for-snow-monkey.php
Created Jul 18, 2019
WPでもろもろ使ってるパッチ的なもの
View for-snow-monkey.php
<?php
// 存在しなくなったone-column-fluidをロードしようとしているときのフォールバック
add_filter(
'inc2734_wp_view_controller_layout',
function( $layout ) {
if ( 'one-column-fluid' === $layout ) {
$layout = 'one-column';
}
return $layout;
}
View axios.js
const axios = requier('axios');
// via: https://www.drupal.org/docs/8/core/modules/rest/3-post-for-creating-content-entities
const username = 'admin'
const password = 'xxxxxxx'
const format = 'hal_json'
const endpoint = 'http://example.com'
const newNode = {
_links: {
type: {
@hideokamoto
hideokamoto / file0.txt
Created Nov 16, 2018
SPARQL覚書:プロ野球選手系のもろもろ ref: https://qiita.com/motchi0214/items/2656f2488ff164ce7a4e
View file0.txt
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?name (group_concat(DISTINCT ?teamName; separator = ",") AS ?teams) (group_concat(DISTINCT ?positionName; separator = ",") AS ?positionNames) ?battingSide ?throwingSide ?comment
WHERE {
?link dbo:wikiPageWikiLink <http://ja.dbpedia.org/resource/全球団から本塁打>;
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/BaseballPlayer>;
rdfs:label ?name;
dbo:position ?position;
dbo:battingSide ?battingSide;
dbo:throwingSide ?throwingSide;
rdfs:comment ?comment;
@hideokamoto
hideokamoto / file0.php
Last active Nov 1, 2018
WordPressの管理画面にIntercomのウィジェットを出す時のスニペット ref: https://qiita.com/motchi0214/items/451af013fde2034f436e
View file0.php
<?php
/*
Plugin Name: Admin Intercom Widget
Plugin URI: https://gist.github.com/hideokamoto/c0b9002ad73f145e1c6d6bc3b99f2b7b
Description: 管理画面にIntercomのWidget出すプラグイン
Author: hideokamoto
Version: 0.0.1
*/
final class My_IntercomWidget {
/**
@hideokamoto
hideokamoto / redirect_to_spa.php
Created Aug 10, 2018
ログインしていない時は、SPAに強制リダイレクト
View redirect_to_spa.php
add_action( 'init', 'redirect_to_spa' );
function redirect_to_spa() {
if ( ! is_user_logged_in() ) {
$uri = $_SERVER["REQUEST_URI"];
if ( ! preg_match( '/^\/wp-login.php/', $uri ) && ! preg_match( '/^\/wp-admin/', $uri ) && ! preg_match( '/^\/wp-json/', $uri ) && ! preg_match( '/^\/feed/', $uri ) ) {
$url = 'https://wp-kyoto.net' . $uri;
wp_redirect( $url, 301 );
exit();
}
}
@hideokamoto
hideokamoto / result
Last active Jul 2, 2018
Swaggerの定義情報を読むスクリプト。
View result
React Router Path: /v1/domains/{:domain}
API Path: PUT /v1/domains/{domain}
Parameters
name: domain
in: path
required: true
type: string
React Router Path: /v1/domains/{:domain}