Skip to content

Instantly share code, notes, and snippets.

@quanon
quanon / fizzbuzz.py
Last active October 10, 2021 03:43
Python の doctest を試してみる。
import itertools
from collections.abc import Iterator
def fizzbuzz(n: int) -> Iterator[int | str]:
'''
Return the fizzbuzz of n, an exact integer >= 0.
>>> from fizzbuzz import fizzbuzz
>>> [i for i in fizzbuzz(15)]
require 'terminal-table' # https://github.com/tj/terminal-table
N = 30 # 合計人数
# table[n][0] は男子を選ぶ組み合わせの数。
# table[n][1] は女子を選ぶ組み合わせの数。
table = Array.new(N + 1) { Array.new(2, 0) }
# n = 1 のときは男子も女子も 1 通りずつ。
table[1][0] = 1
@quanon
quanon / knapsack.rb
Last active April 7, 2021 03:09
ナップサック問題を動的計画法で解く
require 'delegate'
# https://github.com/tj/terminal-table
require 'terminal-table'
# ナップサック問題(Ruby)
# http://obelisk.hatenablog.com/entry/2017/05/26/162601
# 典型的な DP (動的計画法) のパターンを整理 Part 1 ~ ナップサック DP 編 ~
# https://qiita.com/drken/items/a5e6fe22863b7992efdb
class Item
#
# Sets Prezto options.
#
# Authors:
# Sorin Ionescu <[email protected]>
#
#
# General
#
@quanon
quanon / count.js
Created May 23, 2019 06:19
count_of_search_results
const puppeteer = require('puppeteer');
const columnify = require('columnify');
const url = 'https://www.google.co.jp/';
const args = process.argv.slice(2);
(async () => {
const browser = await puppeteer.launch();
let results = await Promise.all(args.map(async (word) => {
@quanon
quanon / nmap.rb
Created April 12, 2019 08:03
Nmap の結果を見やすくする
#! /usr/bin/env ruby
require 'open3'
class NmapResult
IP_ADDRESS_PATTERN = /\d+\.\d+\.\d+\.\d+/
MAC_ADDRESS_PATTERN = /([\dA-F]{2}:){5}[\dA-F]{2}/
attr_reader :lines
def self.parse(stdout)
# (あえて境界値がうるう日前後になるように) 今日の日付が 2020/02/29 (土) だと仮定する。
today = Date.parse('2020/02/29')
User.order(:birthday).each { |user| puts("#{user.birthday.strftime('%Y/%m/%d')} #{user.name}")}
# 1989/02/28 ピカチュウ
# 1989/03/01 カイリュー
# 2000/02/29 ヤドラン
# 2000/03/01 ピジョン
age_from = 20 # 20 歳から
@quanon
quanon / wc.py
Created February 28, 2019 15:11
import MeCab as mc
from matplotlib import pyplot as plt
from wordcloud import WordCloud
def mecab_analysis(text):
t = mc.Tagger('-Ochasen -d /usr/local/lib/mecab/dic/mecab-ipadic-neologd/')
t.parse('')
node = t.parseToNode(text)
output = []
while node:
const puppeteer = require('puppeteer');
const moment = require('moment');
const today = moment();
const url = 'https://www.panasonic.com/jp/corporate/history/founders-quotes.html';
const titleSelector = '.h2Title';
const bodySelector = '#day-after-day-content';
(async () => {
const browser = await puppeteer.launch();
@quanon
quanon / run.py
Last active February 13, 2019 05:35
「Raspberry Pi 上で J-MOTTO にログインして打刻する Node.js スクリプト」を叩くための Slack Bot
from slackbot.bot import Bot
from slackbot.bot import listen_to
import subprocess
import daemon
def main():
bot = Bot()
bot.run()