Skip to content

Instantly share code, notes, and snippets.

@deguchi
deguchi / build.rb
Created January 4, 2011 07:44
Titanium build server on ruby
# 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
@deguchi
deguchi / window.ts
Last active April 13, 2023 01:31
TypeScript Window
interface Window {
isbn: string
systemNames: any
}
declare var window: Window
@deguchi
deguchi / downloadCSV.js
Last active April 4, 2023 02:12
MoneyForwardの月の収入・支出詳細をCSVでダウンロード
// 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";
const getQueryString = () => {
const params = {}
location.search.substring(1).split('&').forEach((param) => {
const [key, value] = param.split('=')
// @ts-ignore
params[key] = decodeURIComponent(value)
})
return params
}
/*
Unitrad UI APIライブラリ
Copyright (c) 2017 CALIL Inc.
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/
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)
@deguchi
deguchi / calcCheckDigit.ts
Last active July 19, 2021 06:23
モジュラス10 ウェイト2・1分割(Luhn formula)(M10W21)
// モジュラス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) {
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',
'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, {
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) => {