arisuchan.xyz arisu
[ tech / cult / art ]   [ λ / Δ ]   [ psy ]   [ random ]   [ meta ]   [ all ]   [ irc ]   [ radio ]
[ tech / cult / art ] [ λ / Δ ] [ psy ] [ r ] [ q ] [ all ]
Arisu Theme Lain Theme


/λ/ - programming

STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS.
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1732336800903-0.png (130.2 KB, 717x976, Capture d’écran du 2024-11….png)

File: 1732336800903-1.png (76.96 KB, 717x599, Capture d’écran du 2024-11….png)

 No.1[Reply]

Glad to see this place back online! Been far too long.
Let's start this board back up with a code review; you show some code you wrote and other brutally tear it to shreds for fun.

Mine is some code I wrote a month or two ago to make my own version of cat(1) that just prints one text file to stdout. I figured it would be a good thing to write before I started some college classes about C.

I also called it p after an old video of Brian Kernighan demonstrating unix pipes and he used a homonymous program to print a file to stdout before using some text processing on it.

Let's all love lain!

 No.11

being that lainchan has nice syntax highlighting for code i modified our vichan instance to support highlighting as well

for example, if you type:

[code php]
some php code…
[/code]

then it renders like this:

	// Fix code markup
	if ($config['markup_code']) {
		foreach ($code_markup as $id => $val) {
			$code = isset($val[2]) ? $val[2] : $val[1];
			$code_lang = isset($val[2]) ? $val[1] : "";

			//$code = "<pre class='code lang-$code_lang'>".str_replace(array("\n","\t"), array("
","	"), htmlspecialchars($code))."</pre>";
			$code = "<pre style='max-width:90em!important';><code class='language-$code_lang'>".str_replace(array("\n","\t"), array("
","	"), htmlspecialchars($code))."</code></pre>";

			$body = str_replace("<code $id>", $code, $body);
		}
	}

if you dont include the language in the code tag highlight.js will try to guess (it doesn't guess perfectly every time but eh)

>that snippet happens to include the change i made in vichans functions.php to enable highlighting with highlight.js and add a scrollbar for code that overflows a posts body


also vichan stripped the <> characters from my code snippet and i dont feel like finding where to disable that after hacking this shit together, feel good though i fixed up a handful of things on the site today just for shits

 No.13

I can't program…. except in x86 but that was years ago and I was never good at it.

 No.15

File: 1736837731241-0.png (31.45 KB, 630x357, 2025-01-14_00-59.png)

File: 1736837731241-1.png (40.16 KB, 590x466, 2025-01-14_01-00.png)

i rarely ever write code by myself nowadays since LLM's came out

just had ChatGPT spit this out for me and figured someone else may find it useful

it runs a short SMART test on all your ZPOOL's disks and sends you an email about any disks that fail SMART checks
set it to run with cron for automated tests/reporting

it requires smartctl and msmtp (and that msmtp is configured to send mail properly)

edit the EMAIL and ZPOOL_NAME variables to match your setup

>the log file output is a bit ugly, but i dont really need logs for this so eh



#!/bin/bash

# Email configuration
EMAIL="[email protected]"  # Your email address
SUBJECT="SMART Errors on $(hostname)"
LOGFILE="/tmp/smartcheck.log"
TMP_EMAIL="/tmp/smart_email.txt"
FAILED_DRIVES=()

# Dynamically retrieve drives from ZFS pool
ZPOOL_NAME="dozer"  # Replace with your ZFS pool name
DRIVES=($(zpool status "$ZPOOL_NAME" | grep -E '^\s+(scsi|ata)-' | awk '{print $1}'))

# Clear previous log
> "$LOGFILE"

echo "SMART check started..."

# Initiate and check each drive
for DRIVE in "${DRIVES[@]}"; do
    DEVICE="/dev/disk/by-id/$DRIVE"

    # Output progress
    echo "$DEVICE - in progress"
    echo "Initiating short SMART test for $DEVICE..." >> "$LOGFILE"
    smartctl -t short "$DEVICE" >> "$LOGFILE" 2>&1

    #echo "Waiting for test to complete for $DEVICE..."
    while true; do
        TEST_STATUS=$(smartctl -a "$DEVICE" | grep '^# 1 ' | awk '{print $5}')
        #echo $TEST_STATUS
        if [[ "$TEST_STATUS" == "Completed" ]] || [[ "$TEST_STATUS" == "Failed" ]]; then
            break
        fi
        #echo "Test in progress for $DEVICE..."
        sleep 10
    done

    echo "Checking results for $DEVICE..." >> "$LOGFILE"
    SMART_OUTPUT=$(smartctl -H "$DEVICE" 2>&1)
    echo "$SMART_OUTPUT" >> "$LOGFILE"

    # Output progress
    echo "$DEVICE - done"

    # Check for errors in the test results
    if echo "$SMART_OUTPUT" | grep -qiE "FAILED|impending|critical|failure"; then
        ERROR_LINE=$(echo "$SMART_OUTPUT" | grep -iE "Health Status:.*|FAILED|impending|critical|failure")
        FAILED_DRIVES+=("$DEVICE: $ERRO
Post too long. Click here to view the full text.

 No.16

File: 1736845678682.jpg (39.81 KB, 500x500, qu9tv.jpg)

ok, i finally figured out what was going on with the stripping/replacing of certain characters within code tags

i had to make this change in functions.php:

before
$code = "<pre style='max-width:90em!important';><code class='language-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), htmlspecialchars($code))."</code></pre>";

after
$code = "<pre style='max-width:90em!important';><code class='language-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), $code)."</code></pre>";


funny enough thats the same line i changed to enable highlighting but my dumb ass did not consider what htmlspecialchars() was doing

previously, code blocks within a posts body had HTML characters double-escaped
HTML renders escaped characters back into their original non-escaped form, but not double-escaped characters

now that those characters are only escaped once, code in code tags wont have any replaced characters (after your browser renders them)

>i also changed max_body from 1800 to 5800 so you can make much longer posts now



Delete Post [ ]
Report Post          
Previous [1] Next | Catalog
[ tech / cult / art ] [ λ / Δ ] [ psy ] [ r ] [ q ] [ all ]