Skip to content

Instantly share code, notes, and snippets.

View apua's full-sized avatar
💭
Seeking next epic moment

Apua Juan apua

💭
Seeking next epic moment
View GitHub Profile
@apua
apua / base.py
Last active February 21, 2025 16:26
File based inheritance
def get_stages():
return config
@apua
apua / list_queued_jobs.Jenkinsfile
Last active January 14, 2025 09:20
List queued Jenkins jobs
// vim: set filetype=groovy:
pipeline {
agent any
stages { stage('Hello') { steps { script {
// `Jenkins` comes from `jenkins.model.Jenkins`.
Jenkins.get().queue.items.findAll { it.task instanceof org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution.PlaceholderTask } .each { println("${it.task.runId} ${it.task.label}") }
}}}}
}
r"""
>>> f('''
... [variables]
... c = 1
... d.e = 1
... f = ['{g}']
... g = ['{gg}']
... gg = 1
...
... [a]
@apua
apua / __main__.py
Last active October 28, 2024 07:51
Disable output capturing by Robot Framework
"""
The alternative of entry point from `robot`, aims to disable output
capturing in order to make it display everything as usual, while we
usually run single FPGA emulation rather than multiple.
Following are included in this entry point.
0. Implicitly export Python library search path for `Library`.
1. Disable `robot` logger handler "inception" and output capturer
by monkey patching.
@apua
apua / corporation-inc.rst
Last active May 22, 2024 14:45
Corporation Inc.

objectives

  1. WASD
  2. add office
  3. add worker
  4. add IT
  5. add office
  6. add elevator shaft
  7. 5 worker
@apua
apua / pascal.c
Last active February 3, 2024 08:15
Pascal's triangle by dynamic programming
#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];
}
@apua
apua / sh_run.py
Last active December 18, 2023 06:22
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)
@apua
apua / env_logger.py
Last active September 22, 2023 13:51
Refer to Rust `env_logger`
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
@apua
apua / parse_args.sh
Last active August 24, 2023 01:18
shell script with Python argparse
#!/usr/bin/env bash
set -eu
# Parse arguments
# ===============
parse_args() {
local args=`mktemp` parser=$1; shift
python3 -c "$parser" $@ 3>$args