Skip to content

Instantly share code, notes, and snippets.

[...document.querySelectorAll('#compTblList > tbody > tr > td:nth-child(12)')].forEach(e => {
const match = e.textContent.match(/([\d.]+)x([\d.]+)x([\d.]+)mm/);
if (!match) return;
const [_, w, h, d] = match;
const liter = +w * +h * +d / 100_0000.0;
const literElem = document.createElement('span');
literElem.textContent = `(${liter.toFixed(2)}㍑)`;
const assert = (pred) => { if (! pred) throw new Error("Assertion failed"); };
class Connection {
constructor(prevs, next) {
if (prevs.length != next.weights.length) {
throw new RangeError("prevs length should be equal to next weights length");
}
if (! prevs.map(p => p.weights.length).reduce((x, y) => x && x == y ? x : false)) {
throw new RangeError("all perceptron in prevs should have same weights length");
@syusui-s
syusui-s / slack
Last active September 12, 2019 00:16
A simple script to post a message to slack
#!/bin/sh
# Usage: slack MESSAGE
SLACK_WEBHOOK_URL=""
( [ -n "$1" ] && echo "$1" || cat ) |
jq -Rn '{ "text": input }' |
curl -d '@-' "$SLACK_WEBHOOK_URL"
#include <cassert>
#include <iostream>
#include <type_traits>
#include <optional>
/**
* 篩
*/
template <typename T>
class Refinement {
@syusui-s
syusui-s / kawawatari.rb
Created June 24, 2019 10:30
川渡り問題
#川渡り問題
Entity = Struct.new(:id, :eats) do
def eat?(other)
other.id == eats
end
def inspect
"<E:#{id}>"
end
@syusui-s
syusui-s / timer.js
Last active December 12, 2020 13:28
Webページ上でタイマーを実行するBookmarklet
javascript:(function(){
const timer_min = +prompt('何分?');
const timer_ms = timer_min*60*1000;
const endTime = new Date(Date.now() + timer_ms);
setInterval(() => {
const TIMER_ID = 'tdFljaRoMfOGDAb7MMpCtmxElVGIyiHH';
const now = new Date();
const rest = endTime - now;
STORY = 24;
result = [...document.querySelectorAll('.ytd-thumbnail-overlay-time-status-renderer')].map(e => e.textContent.replace(/\s*/g,"")).map(e => e.split(":").reverse().map((e, i) => +e * 60**i).reduce((l,r) => l+r)).reduce((l,r) => l+r)
sec = parseInt(result % 60);
min = parseInt(result % 3600 / 60);
hour = parseInt(result / 3600);
stories = Math.ceil(result / (STORY*60));
alert(`全部で: ${hour}:${(""+min).padStart(2,0)}:${(""+sec).padStart(2,0)}
1話${STORY}分とすると: ${stories}話分
1クール12話とすると: ${stories/12}クール分`);
use std::iter::Peekable;
fn varint<'a, I: Iterator<Item=&'a u8>>(peekable: &mut Peekable<I>) -> Option<u64> {
if let Some(msb) = peekable.next() {
let length = {
let bits = (msb & 0b1100_0000) >> 6;
((bits & 1) + 1) << (bits & 2)
};
let mut result: u64 = (msb & 0b0011_1111) as u64;
#!/bin/sh
# 保存する間隔(秒数)
INTERVAL_SECONDS="180"
set -xem
azpainter &
pid="${!}"
#include <cstdint>
#include <cassert>
#include <iostream>
template<typename Self>
class Comparable {
public:
virtual auto compare(Self rhs) const -> int64_t = 0;
virtual auto operator<(Self rhs) const -> bool {