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
#!/usr/bin/env python3 | |
# Pythonのメジャーな型チェッカーは`B`が`A`を継承していても、 | |
# `list[A]`を受け取る関数に`list[B]`を渡すとエラーを出力します。 | |
# 型システム的な面倒な話は置いておいて、実際にこれがエラーじゃないと問題になってしまう例を示します。 | |
# 別にdataclassでなくても構わないのですが、printのやりやすさで使っています。 | |
from dataclasses import dataclass |
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
/** | |
* Twitterの埋め込みスクリプトをボタンを押さずに取得します。 | |
*/ | |
async function getTwitterEmbed(url) { | |
// TwitterのURLやツイートのURLじゃない場合は`undefined`を返します。 | |
if ( | |
!( | |
(url.hostname === "twitter.com" || url.hostname === "mobile.twitter.com") && | |
/^\/\w+\/status\/\d+/.exec(url.pathname) | |
) |
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
/** | |
* 指定されたURLのタブが既に開かれていればそのタブをアクティブにします。 | |
* 開かれていなければ新規に開きます。 | |
*/ | |
function tabActivateOrCreate(url) { | |
RUNTIME("getTabs", { queryInfo: { url, currentWindow: true } }, ({ tabs }) => { | |
if (!Array.isArray(tabs)) { | |
throw new Error(`tabs is not Array: ${JSON.stringify(tabs)}`); | |
} | |
const tabId = tabs?.[0]?.id; |
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 sys | |
from collections.abc import Iterator | |
def format_line_endings(line: str) -> str: | |
""" | |
一行の文字列を受け取り、文字列の種類によって行末の書式を決定します。 | |
文字列が空行であるか、行自体に意味がありそうなことを示唆している場合は、行末に改行を追加します。 | |
それ以外の場合は、文字列をそのまま返します。 | |
""" |
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
#!/bin/bash | |
# tail使った方が良い。 | |
# [unix - Concatenate multiple files but include filename as section headers - Stack Overflow](https://stackoverflow.com/questions/5917413/concatenate-multiple-files-but-include-filename-as-section-headers) | |
for i in $1/* | |
do | |
echo $i | |
cat "$i" | |
done |
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 Control.Applicative | |
import Control.Monad | |
import qualified Data.List as L | |
main = print (兄弟 sally erica :: [Bool]) | |
兄弟 x y = do | |
xa <- 子の親 x | |
ya <- 子の親 y | |
guard $ xa == ya |
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
{-# LANGUAGE QuasiQuotes #-} | |
-- | テレワーク補助を計算しつつ途中式を見るためのプログラム。 | |
-- 一回出力が証拠付きで出せれば良いだけなので、 | |
-- 真面目に書いてない。 | |
module Main (main) where | |
import Data.Maybe (fromJust) | |
import Data.String.Here | |
import Data.Time.Calendar | |
import Numeric |
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 "topfind" | |
#require "camomile" | |
open CamomileLibrary | |
let print_filter_word () = | |
let rec print_filter_word_sub () = | |
let line = read_line () in | |
let yomi = List.hd (String.split_on_char '\t' line) in | |
if 1 < UTF8.length yomi then print_endline line else (); | |
print_filter_word_sub () in |
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 stateA = { foo: "bar" }; | |
const stateB = stateA; | |
stateB["hoge"] = "huga"; // stateAに対する破壊的変更 | |
console.log("stateA: ", stateA); // stateAが更新されている | |
// コピーしたいならこうする | |
const correctStateA = { foo: "bar" }; | |
const correctStateB = { ...correctStateA }; // 浅いコピー | |
correctStateB["hoge"] = "huga"; // correctStateAには影響が出ない | |
console.log("correctStateA: ", correctStateA); |
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
#!/usr/bin/env python3 | |
import os | |
import subprocess | |
import sys | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.support.ui import WebDriverWait |
NewerOlder