Skip to content

Instantly share code, notes, and snippets.

View hideokamoto's full-sized avatar

Hidetaka Okamoto hideokamoto

View GitHub Profile
@hideokamoto
hideokamoto / hono.ts
Last active May 18, 2024 14:19
Cloudflare Workers (with Hono)で、WordPressの記事情報を使ったRAGを作るサンプル
import { Hono } from 'hono'
import { CloudflareVectorizeStore } from "langchain/vectorstores/cloudflare_vectorize";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { Document } from 'langchain/document';
import {
RunnablePassthrough,
RunnableSequence,
} from "langchain/schema/runnable";
import { StringOutputParser } from "langchain/schema/output_parser";
@hideokamoto
hideokamoto / LiffProvider.tsx
Created May 12, 2022 08:20
LIFF with Next.js
import { createContext, FC, PropsWithChildren, useContext, useEffect, useRef, useState } from "react";
import { Liff } from '@line/liff'
const LiffContext = createContext<{
liff?: Liff
}>({})
export const useLiff = () => useContext(LiffContext)
export const LiffProvider: FC<PropsWithChildren<{
@hideokamoto
hideokamoto / format-address.spec.ts
Created December 29, 2021 14:36
Stripe Connectむけの住所フォーマットに成形するサンプル
import { normalizeForStripeConnect } from './format-address.ts'
test.each([
['大阪府堺市北区新金岡町4丁1−8', {
state: "大阪府",
city: "堺市北区",
town: "新金岡町四丁",
line1: "1-8"
}],
["神奈川県横浜市中区本町6丁目50−10", {
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;
@hideokamoto
hideokamoto / listAllCloudFrontDistributions.ts
Last active November 6, 2019 05:08
AWS SDK(Node.js) snippets
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> => {
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 July 18, 2019 04:01
WPでもろもろ使ってるパッチ的なもの
<?php
// 存在しなくなったone-column-fluidをロードしようとしているときのフォールバック
add_filter(
'inc2734_wp_view_controller_layout',
function( $layout ) {
if ( 'one-column-fluid' === $layout ) {
$layout = 'one-column';
}
return $layout;
}
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 November 16, 2018 17:02
SPARQL覚書:プロ野球選手系のもろもろ ref: https://qiita.com/motchi0214/items/2656f2488ff164ce7a4e
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 November 1, 2018 06:16
WordPressの管理画面にIntercomのウィジェットを出す時のスニペット ref: https://qiita.com/motchi0214/items/451af013fde2034f436e
<?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 {
/**