Best Practices for API Key Safety

https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety

echo "export SOME_API_KEY='yourkey'" >> ~/.zshrc
# or .~/bashrc

and the script can then just read the key

key="$SOME_API_KEY"

Note that the key is still stored in plain text.

Something about encryption here.

Chessboard.js and fen-to-svg.py

The easiest way to embed a chess board on your site.

https://chessboardjs.com/download

Ruy Lopez example:

Multiple boards

Notes:

  • If one doesn’t know js that well, this is pain to setup
  • Pieces are pngs for some reason, why not svgs? (FIXED)

Relevant Code of this post

Where chessboard part (js, img, css) is hosted on ‘my’ server in /public/js/chessboard/..

    ## Ruy Lopez example:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <link rel="stylesheet" href="/public/js/chessboard/css/chessboard-1.0.0.min.css">
    <script src="/public/js/chessboard/js/chessboard-1.0.0.min.js"></script>

    <div id="ruyLopez" style="width: 550px"></div>

    <script>
    var config = {
    pieceTheme: '/public/js/chessboard/img/chesspieces/svg/{piece}.svg',
    position: 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R',
    draggable: true,
    dropOffBoard: 'trash'
    }
    var board = Chessboard('ruyLopez', config)
    </script>

    ## Multiple boards

    <div id="board1" style="width: 200px; display: inline-block;"></div>
    <div id="board2" style="width: 200px; display: inline-block;"></div>
    <div id="board3" style="width: 200px; display: inline-block;"></div>

    <script>
    var board1 = Chessboard('board1', {
    position: 'start',
    pieceTheme: '/public/js/chessboard/img/chesspieces/svg/{piece}.svg',
    showNotation: false
    })

    var board2 = Chessboard('board2', {
    position: 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R',
    pieceTheme: '/public/js/chessboard/img/chesspieces/svg/{piece}.svg',
    showNotation: false
    })

    var board3 = Chessboard('board3', {
    position: 'r1k4r/p2nb1p1/2b4p/1p1n1p2/2PP4/3Q1NB1/1P3PPP/R5K1',
    pieceTheme: '/public/js/chessboard/img/chesspieces/svg/{piece}.svg',
    showNotation: false
    })
    </script>

FEN to svg chessboard using python

Using venv:

# make folder to host virtual enviroment
mkdir chess && cd chess
python3 -m venv .
source ./bin/activate
which python
# should return non-system-wide binary:
/home/b/chess/bin/python
python3 -m pip install --upgrade pip
pip install python-chess

Get this script in the chess directory as well:
https://gist.github.com/bngsudheer/47a150aa8ac3d2dcc9f8a0c34dbafa80

Run as:

python ./fen-to-svg.py 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3' test

And voila:

r . b q k b n r
p p p p . p p p
. . n . . . . .
. B . . p . . .
. . . . P . . .
. . . . . N . .
P P P P . P P P
R N B Q K . . R

to remove coordinates and border, the modified fen-to-svg.py script would look like:

import chess, sys
import chess.svg

# Install python-chess to your Python3 virtualenv
# virtualenv -p python3 ~/path/to/myvenv
# source /path/to/myvenv/bin/activate
# Usage: python3 fen-to-svg.py 'myfenstring' outputfilename
# or /path/to/myvenv/bin/python3 fen-to-svg.py 'myfenstring' outputfilename
fen = sys.argv[1]
file_name = '{}.svg'.format(sys.argv[2])

board = chess.Board(fen)

boardsvg = chess.svg.board(board = board, coordinates = False, borders = False)
with open(file_name, "w") as f:
    f.write(boardsvg)

rendering as:

r . b q k b n r
p p p p . p p p
. . n . . . . .
. B . . p . . .
. . . . P . . .
. . . . . N . .
P P P P . P P P
R N B Q K . . R

Amiga boink restored

boinkEvee_ps2.png-p0q4ycrD8wLiY0r-md
Similar 4k version of it. boinkEvee2_ps.png-i1JcoqPBwcYeQl9-md
^Blender eevee + some post.
3440x1440 version with some post exposure change.

image-nohash-th image-nohash-th
^Just a sphere with some blendkit materials.

2024, 4k cycles
image-nohash-md

Original post date: 2020-11-02

fastfetch

A better neofetch?

https://github.com/fastfetch-cli/fastfetch?tab=readme-ov-file

fastfetch scrot

Shfmt

It uses tabs by default, to use 4 spaces:

shfmt -i 4 script > out

shfmt formats shell programs. If the only argument is a dash (‘-‘) or no arguments are given, standard input will be used. If a given path is a directory, all shell scripts found under that directory will be used.

shfmt --help

Blurp last or middle frame or scene detected frames to tty, update 3

Scripts

3 simple scripts to blurp last or middle or scene detected frames to tty.
edit: There is also a version of scene detected that generates some html < This is the hero version.

Bug hunt (sceneFrameMitHtml)

edit: Known bugs: When the scene counter reaches 1000, things break. edit2: Most likely, almost certainly the bug is already at the ffmeg line:

# first frame, I want as well
ffmpeg -hide_banner -loglevel panic -i "$1" -vf "${crop}" -vframes 1 -pix_fmt rgb24 "$tmp/make/000.png" || exit

# scene detect
ffmpeg -hide_banner -loglevel info -nostats -i "$1" -threads 0 -vf "${crop},select=gt(scene\,0.4)",showinfo -pix_fmt rgb24 -vsync vfr "$tmp/make/%03d.png" 2> "$tmp/detect.log" >/dev/null &    
pid="$!"

where %03d can obviously only host 999 numbers, duh. FIX THE SCRIPT.

edit3: Another bug was in this grep:

var="$(grep "n: \+$frame " "$tmp/detect.log")"

but detect.log gaining 1000ths detection will actually not match (there is no space no more in front of the number), possible solution would be:

# \s matches any whitespace chars (including newline, tab), and you can use * to match ZERO or more of them
var="$(grep "n:\s*$frame " "$tmp/detect.log")";

Probably fixed.

Demos & screenshots

lastFrame demo
image-nohash-md

sceneFrame demo
https://www.youtube.com/watch?v=VzYZWDprddI

p.s. Also tested with kitty term and seems to work fine
image-nohash-md

(This post and scripts were first posted 22. 6. 2022.)

EVERYTHING EVERYWHERE ALL AT ONCE (the script)

img

Wikipedia:

The film explores philosophical themes such as existentialism, nihilism, surrealism, and absurdism, as well as themes such as neurodivergence, depression, generational trauma, and Asian American identity.

The shooting script (pdf).