Skip to content

Instantly share code, notes, and snippets.

View Nkzn's full-sized avatar

Yukiya Nakagawa Nkzn

View GitHub Profile
import { Ai } from "@cloudflare/ai";
import { LoaderFunctionArgs } from "@remix-run/cloudflare";
export async function loader({ request, context }: LoaderFunctionArgs) {
const url = new URL(request.url);
const query = url.searchParams.get("query");
if (!query) {
return new Response('Please provide a query parameter', {
status: 400,
@Nkzn
Nkzn / 1_betagaki.tsx
Last active September 3, 2020 05:59
hooksで状態管理
import React from 'react';
function Hoge(props) {
const [count, setCount] = React.useState(0);
const [loading, setLoading] = React.useState(false);
const [error, setError] = React.useState(null);
const [onceLoaded, setOnceLoaded] = React.useState(false);
// 初回読み込み
React.useEffect(() => {
@Nkzn
Nkzn / git-pr-diff.rb
Created August 11, 2020 00:54
Display PRs between commitA and commitB
#! /usr/bin/ruby
# The MIT License (MIT)
# Copyright (c) 2020 Yukiya Nakagawa <[email protected]>
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWI
@Nkzn
Nkzn / Headline.tsx
Created May 12, 2020 02:38
"accessibilityRole: 'heading'" with TypeScript
import React from 'react';
import { StyleProp, TextStyle, StyleSheet } from 'react-native';
import { Headline as PaperHeadline } from 'react-native-paper';
export const Headline = (props: {
style?: StyleProp<TextStyle>;
children: string;
}) =>
React.cloneElement(
<PaperHeadline style={StyleSheet.flatten([styles.headline, props.style])}>
@Nkzn
Nkzn / functions.js
Created April 1, 2020 02:55
ES Modulesで「プライベートメソッドをテストする」をやりたいとき
export function publicFunction() {
}
function complexPrivateFunctionA() {
}
function complexPrivateFunctionB() {
@Nkzn
Nkzn / README.md
Last active March 9, 2020 08:06
Pull Request diff list generator (GitLab ver => https://gist.github.com/Nkzn/c2f916ceb972d77138ba)

git-pr-diff

Usage

  1. Rename git-pr-diff.rb to git-pr-diff.
  2. Move git-pr-diff into PATH ed folder.
@Nkzn
Nkzn / HybridComponent.tsx
Created February 20, 2020 05:08
This is a dream.
import React from 'react';
import { View, Text } from 'react-native';
import { WebView } from 'react-native-webview';
const HybridComponent: React.FC = () => (
<View>
<Text>Rendering as native text with TextView/UIView</Text>
<WebView>
<View>
<Text>Rendering as DOM tree with WebView/WkWebView</Text>
@Nkzn
Nkzn / milkboy.md
Last active February 12, 2020 05:20
たぶんPWAの話

「うちのお客さんがね、Webサービス作りたいゆーんやけど」

「そうなんや」

「ユーザーへの届け方を忘れたらしいねん」

「ユーザーへの届け方を忘れるってどうなってんねん」

「いろいろ聞くんやけどな、全然わからへんねん」

#2d2d2d

@Nkzn
Nkzn / ClassComponent.js
Created May 9, 2019 14:52
コンポーネントがDOMツリーに書き込まれたタイミングで、Reactの外側にコールバックを実行するサンプル
import React from 'react';
export default class ClassComponent extends React.Component {
componentDidMount() {
if (this.ref) {
const event = new CustomEvent('initializedWithClassComponent', { detail: this.ref });
window.dispatchEvent(event);
}
}