Skip to content

Instantly share code, notes, and snippets.

View odiak's full-sized avatar

Kaido Iwamoto odiak

View GitHub Profile
@odiak
odiak / purge.js
Last active March 20, 2022 21:23
const fsp = require('fs').promises
async function purge(dir, pictureId) {
const entries = await fsp.readdir(dir, { withFileTypes: true })
let n = 0
await Promise.all(entries.map(async (e) => {
const path = `${dir}/${e.name}`
if (e.isDirectory()) {
n += await purge(path, pictureId)
} else if (e.isFile()) {
@odiak
odiak / each-dir.js
Created November 17, 2021 06:36
Execute same command on multiple directories
#! node
// example:
// each-dir dir1 somewhere/dir2 -- npm ci
const { spawn } = require("child_process");
(async () => {
const args = process.argv.slice(2);
const i = args.indexOf("--");
@odiak
odiak / export-inkdrop.js
Last active November 5, 2021 01:12
Convert Inkdrop's backup to plain Markdown files
// read notes from `data/note` directory and export to `md` directory
const fs = require('fs/promises')
;(async () => {
fs.mkdir('md', { recursive: true })
const list = await fs.readdir('data/note')
const usedNames = new Set()
for (const fileName of list) {
if (!/\.json$/.test(fileName)) continue
import * as t from "io-ts";
const codec = t.type({
a: t.number,
b: t.union([t.string, t.undefined]),
});
console.log(codec.decode({ a: 1 }));
type codec = t.TypeOf<typeof codec>;
// --------------------
# Welcome to Sonic Pi
use_random_seed 1
use_bpm 120
int = 1.0 / 8
d1 = [1, 0, 0, 0, 0.05, 0, 0, 0]
d2 = [0, 0, 0, 0, 1, 0, 0.1, 0]
d3 = [0, 0, 0.05, 0, 0, 0, 0, 0]

コンパイル前

package net.odiak.kotlin_coroutines_experiment

import kotlinx.coroutines.*

suspend fun s1(): Int {
    println("hello")
    delay(1000L)
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
curl https://pyenv.run | bash
cat <<'EOS' >> $HOME/.bashrc
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
#!/usr/bin/env python3
from subprocess import check_output, check_call
from datetime import datetime
import sys
from pathlib import Path
def main() -> None:
datetime_file = Path.home() / 'last-active-timestamp'
pause_file = Path.home() / 'pause-auto-shutdown'
from typing import Tuple
import numpy as np
def n_union_and_intersection(a: np.ndarray, b: np.ndarray) -> Tuple[int, int]:
na = len(a)
nb = len(b)
ia = 0
ib = 0
#!/bin/bash
TIMESTAMP_FILE="/tmp/auto-stop-timestamp"
if [ $(who | wc -l) -gt 0 ]; then
rm -f $TIMESTAMP_FILE
else
now=$(date "+%s")
if [ -f "$TIMESTAMP_FILE" ]; then
echo $now > $TIMESTAMP_FILE