命題: https://x.com/pipichih/status/1709248514033909778
from functools import partial
from inspect import signature
from os.path import join
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
static void update(int* buffer, size_t last) { | |
buffer[last] = 1; | |
for (size_t k = 1; k < last; k++) | |
buffer[last-k] += buffer[last-k-1]; | |
} |
import subprocess as sp | |
import textwrap | |
cmd = 'squeue --cluster=testbed --Format=jobid:10,partition:15,username:15,account:8,timeused:15,nodelist:15,name:50' | |
cmd = 'env | grep -i VENV' | |
cmd = 'python -c \'import sys; sys.stdout.write("stdout\\n"); sys.stderr.write("stderr\\n")\'' | |
cmd = 'echo -e ""; sleep 1 && echo -e \'fal\\nse\' && false' | |
#sp.run(cmd, shell=1) |
命題: https://x.com/pipichih/status/1709248514033909778
from functools import partial
from inspect import signature
from os.path import join
import logging | |
import os | |
class ColoredFormatter(logging.Formatter): | |
def __init__(self, coloring=True, fmt='%(L)s{asctime} {levelname:<%(T)s} {name}%(R)s {message}', | |
datefmt = '%Y-%m-%dT%H:%M:%SZ', style = '{', *args, **kwargs): | |
if coloring: | |
L, R = map('\033[90m{}\033[m'.format, '[]') | |
T = 15 |
#!/usr/bin/env bash | |
set -eu | |
# Parse arguments | |
# =============== | |
parse_args() { | |
local args=`mktemp` parser=$1; shift | |
python3 -c "$parser" $@ 3>$args |
<script type="module"> | |
window.addEventListener('message', async(event) => { | |
if (event.origin.match(/jenkins.internal.sifive.com/)) return; | |
if (! event.origin.match(/^http:\/\/localhost:|internal.sifive.com/)) return; | |
const path = event.data; | |
const resp = await fetch(path); | |
const json_data = await resp.json(); | |
window.parent.postMessage(json_data, event.origin); | |
}); |
/* | |
* The main purpose of code structure is | |
* (1) to handle different upstream with different strategies, and | |
* (2) to dispatch groups to build and test | |
* (3) with common essential information delivered from upstream. | |
*/ | |
def build_only(kwargs) { | |
build(job: params.DOWNSTREAM_JOB, propagate: false, wait: false, parameters: [ | |
/* Common parameters */ |
# file path: `mod/__main__.py` | |
import argparse, importlib, inspect, sys | |
prog = sys.argv[0] | |
if prog.endswith('__main__.py'): | |
prog = f'python -m {__package__}' | |
else: | |
prog = prog.rsplit('/',1)[-1] |
r""" | |
Ref: https://www.pttweb.cc/bbs/Python/M.1398877470.A.1E7 | |
>>> data = list(range(22)); seglen = 4 | |
>>> list(map(lambda E,T=[0]:T.__setitem__(0,E[1]+(E[0]%seglen and T[0])) or T[0], enumerate(data))) | |
[0, 1, 3, 6, 4, 9, 15, 22, 8, 17, 27, 38, 12, 25, 39, 54, 16, 33, 51, 70, 20, 41] | |
>>> x = [] | |
>>> for i, v in enumerate(data): | |
... x.append(v+x[i-1] if i%seglen!=0 else v) | |
... |
r""" | |
>>> cases = [ | |
... ('', ''), (' ', ''), | |
... ('11 111 010 000 0', 'MORSE'), | |
... ('11111 01111 00111 00011 00001', '01234'), | |
... ('00000 10000 11000 11100 11110', '56789'), | |
... ] | |
... | |
>>> for stream, result in cases: | |
... assert ''.join(decode_stream(stream)) == result |