This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# original https://gist.github.com/715378 | |
# thanks hakobe! | |
# Macで動作確認。Windowsの場合、spawnを使うとよいらしい。 参考: https://gist.github.com/325036 | |
require 'webrick' | |
server = WEBrick::HTTPServer.new({ | |
:DocumentRoot => nil, | |
:BindAddress => '0.0.0.0', | |
:Port => 9090 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Window { | |
isbn: string | |
systemNames: any | |
} | |
declare var window: Window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taken from http://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server | |
function download(filename, text) { | |
const element = document.createElement("a"); | |
element.setAttribute( | |
"href", | |
"data:text/csv;charset=utf-8,\ufeff" + encodeURIComponent(text) | |
); | |
element.setAttribute("download", filename); | |
element.style.display = "none"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getQueryString = () => { | |
const params = {} | |
location.search.substring(1).split('&').forEach((param) => { | |
const [key, value] = param.split('=') | |
// @ts-ignore | |
params[key] = decodeURIComponent(value) | |
}) | |
return params | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Unitrad UI APIライブラリ | |
Copyright (c) 2017 CALIL Inc. | |
This software is released under the MIT License. | |
http://opensource.org/licenses/mit-license.php | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState} from 'react' | |
import useSWR from 'swr' | |
import { fetcher } from './fetcher' | |
const ENDPOINT = 'https://unitrad.calil.jp/v1/' | |
const REGION = 'recipe' | |
export const useSwr = (q: string) => { | |
const [url, setUrl] = useState(`${ENDPOINT}/search?region=${REGION}&free=${encodeURIComponent(q)}`) | |
const [interval, setPollingInterval] = useState(100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// モジュラス10 ウェイト2・1分割(Luhn formula)(M10W21) | |
// 1.数値の各桁に、下の桁から2・1・2・1・…の順番に係数(ウェイト)を掛けます。 | |
// 2.各桁の結果が2桁の場合には、十の位と一の位を分けて足し合わせます(分割)。 | |
// 3.それぞれの合計を求めます。 | |
// 4.合計を10で割り、余りを求めます(モジュラス)。 | |
// 5.この余りを 10 から引いたもの(10 - 余り)がチェックデジットです。ただし余りが0の場合はチェックデジットも「0」になります。 | |
const calcCheckDigit = (code: number) => { | |
const dividedNumber = code.toString().split('').reverse().map((n, index) => { | |
const number = parseInt(n) | |
if (index % 2 === 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { WebClient } = require('@slack/web-api'); | |
require('dotenv').config(); | |
const token = process.env.SLACK_TOKEN; | |
console.log('token', token) | |
const web = new WebClient(token); | |
const slack = async (text) => { | |
const result = await web.chat.postMessage({ | |
text: text, | |
channel: '#bot', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const fs = require('fs'); | |
require('dotenv').config() | |
const Gyazo = require('gyazo-api'); | |
const client = new Gyazo(process.env.GYAZO_TOKEN); | |
const gyazo = async (path) => { | |
return new Promise((resolve, reject) => { | |
client.upload(path, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scrollWindowBy(value: number, duration: number, easingFunc: (t: number) => number) { | |
let startTime: number | |
const startPos: number = window.scrollY | |
const clientHeight: number = window.innerHeight | |
const maxScroll = document.body.scrollHeight - clientHeight; | |
const scrollIntendedDestination = startPos + value; | |
// low and high bounds for possible scroll destinations | |
const scrollEndValue = Math.min(Math.max(scrollIntendedDestination, 0), maxScroll) | |
// create recursive function to call every frame | |
const scroll = (timestamp: number) => { |
NewerOlder