package net.odiak.kotlin_coroutines_experiment
import kotlinx.coroutines.*
suspend fun s1(): Int {
println("hello")
delay(1000L)
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 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()) { |
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
#! 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("--"); |
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
// 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 |
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 * 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>; | |
// -------------------- |
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
# 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] |
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
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 -)" |
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 | |
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' |
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
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 |
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 | |
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 |
NewerOlder