Skip to content

Instantly share code, notes, and snippets.

View yuta0801's full-sized avatar

yuta yuta0801

View GitHub Profile
@yuta0801
yuta0801 / factorio-server-check.nipp.js
Created October 20, 2019 13:52
A Nipp to check Factorio server status
!(async () => {
document.getElementById('app').style.display = 'none'
document.write('読み込み中...')
const server = 'server_id'
const cors = 'https://cors-anywhere.herokuapp.com/'
const url = cors + 'https://multiplayer.factorio.com/get-game-details/' + server
const data = await fetch(url, { headers: { origin: 'any' } }).then(res => res.json())
// ==UserScript==
// @name Wired Normalizer
// @namespace https://github.com/bromne/wired-normalizer
// @version 1.3.0
// @description WIRED.jp の記事に含まれる「ヴ」を、適当なバ行の文字に変換します。
// @author @bromne, @yuta0801
// @match *://wired.jp/*
// @grant none
// @require //ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// ==/UserScript==
@yuta0801
yuta0801 / useBlur.ts
Created September 16, 2019 06:49
React useEvent hook
import { RefObject } from 'react'
import useEvent from './useEvent'
type Ref = RefObject<Element>
const useBlur = (ref: Ref, callback: () => void) => {
useEvent(ref, 'blur', () => setTimeout(callback))
}
export default useBlur
@yuta0801
yuta0801 / index.js
Created August 25, 2019 08:59
RustよりJSが早かった時のソースコード
var addon = require('../native');
const factorial = (x) => {
let res = x;
let done = false;
while (!done) {
x = x - 1;
res = res * x;
const f1 = <T>(val: T) => val
const f2 = <T>(val: T) => () => val
const t1: 'foo' = f1('foo')
// const f1: <"foo">(val: "foo") => "foo"
const t2: 'foo' = f2('foo')()
// const f2: <string>(val: string) => () => string
// Type 'string' is not assignable to type '"foo"'. ts(2322)
@yuta0801
yuta0801 / piping2sh
Created May 7, 2019 12:14
パイピングサーバーからコマンドを取得して実行するシェルスクリプト
#!/bin/bash -e
if [ $# -ne 1 ]; then
echo "引数(パス)が必要です。" 1>&2
exit 1
fi
CMD=$(curl -m 5 -sS "https://ppng.ml/$1")
read -p "$CMD を実行しますか? (y/N): " YN
@yuta0801
yuta0801 / e-typing.js
Created April 20, 2019 17:23
e-typingのお題をクリップボードにコピーするコード
const cp = copy
const observe = (target, callback) => {
const observer = new MutationObserver(records => {
records.forEach(record => {
if (!record.addedNodes[0]) return
callback(record, () => observer.disconnect())
})
})
observer.observe(target, { childList: true })
}
@yuta0801
yuta0801 / asyncTimerRecursiveFibo.js
Last active January 15, 2020 15:57
Fibonacci number implemented with recursive function async timer recursive function
// Utility function to make fake async processing
const delay = fn => new Promise(r => setTimeout(() => r(fn()), 100))
const isConstant = n => delay(() => n < 2)
const fibo = async n => {
if (await isConstant(n)) return n === 0 ? 0 : 1
const [prev1, prev2] = await Promise.all([fibo(n - 1), fibo(n - 2)])
return delay(() => prev1 + prev2)
}
@yuta0801
yuta0801 / generatorify.js
Created March 23, 2019 10:09
Generatorify EventEmitter
// Referred to https://raw.githubusercontent.com/denoland/deno_std/v0.3.2/http/server.ts
function deferred() {
let resolve, reject
const promise = new Promise((res, rej) => {
resolve = res
reject = rej
})
return {
promise,
@yuta0801
yuta0801 / alert.md
Last active April 12, 2019 08:18
JavaScript Alert Recursion with Goldbach's conjecture

加筆編集しより多くの人に理解できるようにしたものをQiitaに投稿しました。 こっちはリンク、リビジョン確認用に残しますが、これからの修正はQiitaメインになります。 alert無限ループは不正プログラムとして逮捕されるらしいので警察にゴールドバッハ予想を証明してもらおう - Qiita

これは何?

これは以下のツイートに触発されて作ったn回目のアラートダイアログで2n+2を二つの素数の和で表せるかを全探索して表せた場合もう一度アラートダイアログを表示するJavaScriptプログラムだよ

n回目のアラートダイアログで2n+2を二つの素数の和で表せるかを全探索して表せた場合もう一度アラートダイアログを表示するみたいなプログラムを書けば警察がゴールドバッハ解いてくれるのでは

— ほんまか? (@Kory__3) March 4, 2019

それぞれのファイルの説明