Comments | Types | Standard functions | Tables | Exceptions | Functions | I/O | Regexp | Objects | System
--| # shellcheck shell=bash | |
| # shellcheck disable=SC2004,SC2034 # [$i] indices are fine; ARGS_REST is read by the caller | |
| # | |
| # args.sh — declarative long/short option parser for bash >= 3.2 | |
| # | |
| # Source this file, declare options, parse, then use the variables: | |
| # | |
| # . "$(dirname "$0")/args.sh" | |
| # | |
| # args_init "mytool" "Short description of the tool." |
Comments | Types | Standard functions | Tables | Exceptions | Functions | I/O | Regexp | Objects | System
--| # List to dict | |
| a = [10, 20, 30] | |
| b = {index: value for index, value in enumerate(a)} | |
| # {0: 10, 1: 20, 2: 30} | |
| a = ["a", 1, "b", 2, "c", 3] | |
| b = {a[i]: a[i + 1] for i in range(0, len(a), 2)} | |
| # {"a": 1, "b": 2, "c": 3} |
| nvidia-smi --query-gpu=OPTION,... [--format=csv[,hoheader]] | |
| timestamp - YYYY/MM/DD HH:MM:SS.msec | |
| driver_version | |
| count | |
| name or gpu_name | |
| serial or gpu_serial | |
| uuid or gpu_uuid | |
| pci.bus_id or gpu_bus_id - domain:bus:device.function, in hex | |
| pci.domain |
| import concurrent.futures | |
| import functools | |
| import queue | |
| import subprocess | |
| import random | |
| def pool_wrapper(q_in, q_out, size=5): | |
| def pool_wrapper_inner(func): |
| # Please, check https://github.com/dylanaraps/pure-bash-bible | |
| # It is a great chest of treasures | |
| # | |
| # Functions list: | |
| # | |
| # Strings: | |
| # constainsElement - check if element is in the array | |
| # trim_string - trim spaces from string head and tail | |
| # trim_all - trim ALL spaces | |
| # trim_quotes - trim quotes from string |
| #!/bin/sh | |
| # replace "Nodename=abc Uptime=1 CPUs=128 State=Drain Reason=no cpu detected [12:00]" -> "abc: no cpu detected" | |
| gawk '{print gensub(/NodeName=([[:alnum:]]+).*Reason=([^[]+)\[.*/, "\\1: \\2", "g") }' |
| Cannot connect to any pod - get "Unable to upgrade connection". | |
| Log: | |
| Apr 2 03:42:59 graphit kubelet[18632]: E0402 03:42:59.173155 18632 server.go:253] Unable to authenticate the request due to an error: x509: certificate has expired or is not yet valid | |
| Meanwhile: | |
| CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED | |
| admin.conf Apr 02, 2023 00:29 UTC 364d no | |
| apiserver Apr 02, 2023 00:29 UTC 364d ca no |
| # // # // Implement a function that orders inputs to schedule for min TAT (Turn around time == Total Run Time) | |
| # // # // Input: (list of runtimes, number of parallel buckets) | |
| # // # // Output: Should parallelize individual tasks such that total TAT is minimum. | |
| # // # // Example: | |
| # // # // In: [4, 3, 100, 2, 1], parallel = 2 | |
| # // # // Out: [[100], [4, 3, 2, 1]], TAT: 100 | |
| # // # // [100, 10] -> 100 | |
| # // # // In: [4, 3, 100, 2, 1], parallel = 1 | |
| # // # // Out: [[100, 4, 3, 2, 1]], TAT: 110 | |
| # // # // |
| require 'minitest/autorun' | |
| module Memoization | |
| def memoize(f, injected_cache={}) | |
| m = instance_method(f) | |
| define_method(f) do |*args| | |
| cache = injected_cache.clone | |
| define_singleton_method(f) do |*args| | |
| unless cache[args] | |
| puts "Actually calculating..." |