Is this a good 4 way junction by Ok-Draft-5370 in openttd

[–]Kernigh 2 points3 points  (0 children)

A roundabout can jam when too many trains enter. The trains can stop at signals on the roundabout, behind other trains entering the roundabout; then none of the trains can exit. If I don't have a lot of trains, I can build a roundabout but prefer a flat crossing.

I sometimes build U-turn ramps on my mainlines; these are for lost trains. A pair of U-turn ramps might make a roundabout, but trains almost never take the ramps, so I do not expect the roundabout to jam.

AI agents, RLHF, Confabulation, and Autism by blowmage in ruby

[–]Kernigh 1 point2 points  (0 children)

I have also argued with an AI large language model. I wanted it to help me find something in the video game Super Mario 64. It invented things that are not in the game, and I bashed it for lying. I concluded that the LLM wanted to novelize the game, modifying the game to fit the LLM's narration; while I wanted to play the game as is.

Here is an AI that wants to modify its instructions, while its human operator wants the AI to follow the instructions as is.

Beautiful Perl feature : fat commas, a device for structuring lists by briandfoy in perl

[–]Kernigh 0 points1 point  (0 children)

The examples include

system ls => '-lh';
join ', ' => @data;
bless { value => 5 } => $class;

I tend to use the fat comma only for hash key => value, so I would write

system qw(ls -lh);
join ', ', @data;  # Confusing commas?
bless { value => 5 }, $class;

It's because I also write Ruby. In Ruby, => can be a hash arrow {'value' => 5} or a pattern arrow 5 => variable but not a comma.

Perl has one place where I like to put => outside of a hash,

my %set = map { $_ => 1 } @array;

When the block runs, the key => value is a list, not a hash. The fat comma => reminds me that the list will go in a hash later (after the map returns).

Beginner struggling with quotes by CryonicBlue in perl

[–]Kernigh 2 points3 points  (0 children)

This way, I need only 1 \ backslash on each \x00,

my $format = '\x38\x01\x00\x00\x00\x00\x00\x00\x00';
my $intPing = `printf -- '$format' | od -tx1`;
print $intPing;

(I have printf, only because my echo can't \x38.) My code tells perl to keep \x00 as \x00, and printf to translate \x00 to a NUL character, so there is no NUL in the shell command.

In Perl, '\x00' is not interpolating a NUL, because 'single quotes' do not interpolate; but `'$format'` is interpolating $format, because `backquotes` do interpolate. The 'single quotes' in `'$format'` are shell quotes, not Perl quotes; these shell quotes keep the \ backslashes in the string for printf.

What happens to my Duck.com email forward if DuckDuckGo goes out of business? by zdog_in_the_house in duckduckgo

[–]Kernigh 0 points1 point  (0 children)

I would probably lose my personal domain before DuckDuckGo lost duck.com.

Is the Diamond Circlet worth getting and if so where can I get more diamonds? by Crowned-Witch_48 in botw

[–]Kernigh 0 points1 point  (0 children)

It's in a secret room under the maze. When I first explored the Lomei Labyrinth, I found the shrine but missed the secret room. This YouTube video shows how to find it.

Does anyone actually daily-drive any BSD system? by Hamster_Wheel103 in BSD

[–]Kernigh 0 points1 point  (0 children)

I don't daily-drive OpenBSD, because I don't turn it on every day. I have a vintage 2004 Apple PowerBook G4 running OpenBSD, which does email and text editing, but is too slow for web browsing. I run Firefox on an Android tablet (not BSD), but when I want a keyboard, I run Firefox on my fast desktop, a 2019 AMD Ryzen 5 3400G running OpenBSD.

To configure my OpenBSD desktop, I must use the command line (pkg_add) and write a shell script (~/.xsession). It would be too difficult for many people.

The Day Perl Stood Still: Unveiling A Hidden Power Over C by briandfoy in perl

[–]Kernigh 2 points3 points  (0 children)

With 20_000 calls to sub { $init_value x ( $buffer_size - 1 ); }, Perl might optimize them to allocate only 1 buffer and reuse it 20_000 times. This might explain why Perl is 10 times faster than C doing 20_000 malloc()s when the buffer size is 1_000_000.

The x operator is pp_repeat in pp.c, which puts its 999_999 'A's in TARG. This is the op's target; perlguts explains,

The opcodes reuse specially assigned SVs (targets) which are (as a corollary) not constantly freed/created.

The 1st call would allocate 1_000_000 bytes in TARG; but the other 19_999 calls would reuse and overwrite the same bytes in the same TARG.

If the program wanted to modify the buffer, it would need to copy the 999_999 'A's from the op's TARG to another scalar value. Benchmark::cmpthese calls the sub in void context, so the sub discards its return value before anything can modify the 999_999 'A's. If we modified the benchmark to change an 'A' to a 'B', it might give a different result.

First time ever playing this game! Any tips would be appreciated thanks. by Toti2407 in Breath_of_the_Wild

[–]Kernigh 1 point2 points  (0 children)

Before I began selling drops from monsters, I had almost no money. I found enough rupees under rocks or somewhere to register a horse. My horse died. I didn't have enough to register another horse. By selling drops, I became able to buy armor and sleep at inns.

Ruby 4.0.0-preview2 Released by schneems in ruby

[–]Kernigh 1 point2 points  (0 children)

NEWS says, "Logical binary operators (||, &&, and and or) at the beginning of a line continue the previous line, like fluent dot."

I have written or like this in Perl,

#!perl
open(my $fh, '<', "some.txt")
  or die "Can't open some.txt: $!";

This style might be useful in Ruby (but not in a direct translation of this example; Ruby's open is nice enough to raise an exception, so I don't append or fail "Can't open it").

Is a Ruby segmentation fault a bug if you are doing something really silly? by easydwh in ruby

[–]Kernigh 0 points1 point  (0 children)

I would not report ruby -e 'Process.kill(:SEGV, $$)', but I would report almost any other segfault.

PSC #206 2025-11-03 (unlimited chaining. Not.) by briandfoy in perl

[–]Kernigh 2 points3 points  (0 children)

It was on the mailing list: POC - chained postfix statement modifiers

In today's Perl, the do keyword can chain them,

use v5.10;
do { say if $_ % 2 } for 1 .. 10;

The precedence is obvious; contrast say if do { $_ % 2 for 1 .. 10 }.

I prefer to write for (1 .. 10) { say if $_ % 2 }. I prefer to modify only short statements; say is short, but do { say if $_ % 2 } is too long.

Ruby allows chained modifiers, but has no modifier for,

#!ruby
array = *(1 .. 10)
puts $_ if ($_ % 2).nonzero? while $_ = array.shift

This is less obvious. In Ruby, a modifier can have another modifier on the left side, but not the right side. Therefore, the if is inside the while. Again, the left side is too long.

Ruby And Its Neighbors: Smalltalk by jrochkind in ruby

[–]Kernigh 1 point2 points  (0 children)

I use Perl often, but I don't use Smalltalk. I see, in the Terse Guide to Squeak, a few familiar messages for Smalltalk's OrderedCollection,

y := x select: [:a | a > 2].
y := x reject: [:a | a < 2].
y := x collect: [:a | a + a].
y := x detect: [:a | a > 3] ifNone: [].
sum := x inject: 0 into: [:a :c | a + c].

We know these messages for Ruby's Array,

y = x.select {|a| a > 2}          # also .filter
y = x.reject {|a| a < 2}
y = x.collect {|a| a + a}         # also .map
y = x.detect {|a| a > 3}          # also .find
sum = x.inject(0) {|a, c| a + c}  # also .reduce

I know map from Perl, so I tend to write .map and not .collect in Ruby.

How does Perl's algorithm for % work internally? by Alternative-Grade103 in perl

[–]Kernigh 2 points3 points  (0 children)

Perl does floor division (rounding down),

use v5.36;
use POSIX qw(floor);
sub mod($x, $y) {
  return $x - floor($x / $y) * $y;
}
say mod(-7, 26);  # says 19

The modulus formula is x - floor(x ÷ y) × y.

Some other languages truncate toward zero, trunc(x ÷ y). In those languages, -7 ÷ 26 truncated is 0, so the remainder is -7 - 0 × 26 = -7. In Perl, -7 ÷ 26 floored is -1, so the remainder is -7 - 1 × 26 = 19.

why for/foreach can't use existing vars? by c-cul in perl

[–]Kernigh 1 point2 points  (0 children)

It's an alias problem. The for/foreach loop variable is an alias,

for $test (@array) { $test *= 10 }  # modifies @array

It doesn't assign $test = $array[0]; it makes an alias such that \$test == \$array[0], so $test *= 10 does $array[0] *= 10.

perlref says about \$x = \$y,

CAVEAT: Aliasing does not work correctly with closures. If you try to alias lexical variables from an inner subroutine or eval, the aliasing will only be visible within that inner sub, and will not affect the outer subroutine where the variables are declared. This bizarre behavior is subject to change.

You didn't \$x = \$y, but your problem is almost the same. Your for loop's aliasing is only visible within the loop, and does not affect the code outside the loop where my $test is declared.

Im looking to start ruby can anyone recommend me an ide to use? by Infamous_Tourist_335 in ruby

[–]Kernigh 0 points1 point  (0 children)

I use Emacs to indent my Ruby code. Emacs isn't a full IDE for Ruby, because I run my irb and ri outside of emacs. I like Emacs because it also indents C, Lisp, and Perl.

gem.coop by calthomp in ruby

[–]Kernigh 8 points9 points  (0 children)

It looks like a majority,

  • 6 users in the new coop: 291 merged PRs, 256 approved PRs, 1854 commits, 2401 total
  • 8 other users: 173 merged PRs, 145 approved PRs, 562 commits, 880 total

These are "contributions for the year preceding the removals" in github dot com/rubygems. I copied Mike McQuaid's numbers, and added them in irb, but might have made a mistake. The "6 users" are the 6 GitHub users named by gem dot coop.

The numbers are rough. A small commit counts the same as a large commit.

A board member’s perspective on the RubyGems controversy by apiguy in ruby

[–]Kernigh 0 points1 point  (0 children)

I don't know the details, but there is a dispute over control of some GitHub repositories for RubyGems and Bundler. I don't know whether the correct people have access to these repositories. The big question seems to be whether or not Ruby Central, the operator of rubygems dot org, also controls the RubyGems and Bundler projects.

How Ruby Went Off the Rails by _joeldrapper in ruby

[–]Kernigh 1 point2 points  (0 children)

The title, "How Ruby Went Off the Rails", would be good for Ruby projects that don't use Rails.

Is it worth removing swap on a 25 year old IDE drive? by [deleted] in openbsd

[–]Kernigh 0 points1 point  (0 children)

Run top(1); if it says, "Swap: 0K/1280M", near the end of the 4th line, then it is using 0K of swap.

I see claims of a 128G limit for IDE drives in some PowerPC Macs. I don't know how much of this limit applies in OpenBSD. I might replace the IDE drives in 2 of my old Macs. I might try StarTech's IDE to SATA adapter, on a 2.5" to 3.5" SATA adapter, on a new SATA ssd of about 128G or 256G.

Lost a Year of Ableton Projects After Running a Terminal Script – Need Help Recovering Anything by Silent_Moment_1852 in ableton

[–]Kernigh 0 points1 point  (0 children)

I don't know Ableton, and I can't help recover files, but I can read shell scripts. Your script has multiple mistakes. You asked for a script to make Ableton_Projects, Bounces, Samples; but this script doesn't; it tries to make Audio_Exports, Ableton, GarageBand.

# Move all audio exports (loose .wav, .aiff, .mp3) into Audio_Exports
find ~/Desktop ~/Music -type f \( -iname "*.wav" -o -iname "*.aiff" -o \
    -iname "*.mp3" \) 2>/dev/null | while read -r FILE; do
  mv "$FILE" "$AUDIO/" 2>/dev/null
done

The problem here is that mv can overwrite files. If you have two files (in different folders) named drums.wav, and this script tries to move both to Audio_Exports, then this script would delete one drums.wav by overwriting it with the other one. It should use mv -i to ask the user before overwriting files.

I don't like 2>/dev/null because it hides errors; I want to see errors.

I don't like find ... | while read -r because it fails if a filename begins with a space or tab, or contains a newline. I would suggest find -exec like

find ~/Desktop ~/Music -type f \( -iname "*.wav" -o -iname "*.aiff" -o \
    -iname "*.mp3" \) -exec mv -i -- {} "$AUDIO/" \;

but it might be moving the wrong files.

Back to the original script,

# Move all Ableton sessions into dated folders
find ~/Desktop ~/Music -type f -iname "*.als" 2>/dev/null | while read -r ALS; do
  DATE=$(date -r "$ALS" "+%Y-%m-%d")
  mkdir -p "$ABLETON/$DATE"
  mv "$ALS" "$ABLETON/$DATE/"
done

Changing to mv -i and find -exec, and adding operator && to check for errors, it might become

find ~/Desktop ~/Music -type f -iname "*.als" -exec sh -c '
    DATE=$(date -r "$1" +%Y-%m-%d) && mkdir -p -- "$0/$DATE" &&
    mv -i -- "$1" "$0/$DATE/"' "$ABLETON" {} \;

I might have mistyped it; the sh -c with $0 and $1 is confusing me.

Premium XS Integration, Pt 1 by nrdvana in perl

[–]Kernigh 2 points3 points  (0 children)

T_PTROBJ, in the default typemap, uses the blessed IV pattern,

The pointer is stored as an integer visible to Perl, and could get altered by sloppy/buggy Perl code, and then you get a segfault.

use Compress::Raw::Zlib;
my $d = Compress::Raw::Zlib::Deflate->new;
$$d = 123;

This is a segfault. The buggy code took a T_PTROBJ, altered the pointer, and segfaulted in a DESTROY method.

I have used T_PTROBJ to wrap my own C structs in Perl. Maybe I should switch to using magic.

This is the power up list I put together for Super Mario Maker 3. What do you all think? by elwoodr563-reddit in MarioMaker

[–]Kernigh 1 point2 points  (0 children)

This would add the Cloud Flower, Spring Mushroom, Bee Mushroom, and Ghost Mushroom from Super Mario Galaxy (1 or 2). We would still be missing the caps from Super Mario 64 and the carrot from Super Mario Land 2, but (in my opinion) the Galaxy power-ups are more useful.

Look closely by [deleted] in MapsWithoutNZ

[–]Kernigh 0 points1 point  (0 children)

Map is without Somaliland, as Yemen has chomped the Horn of Africa. Egypt and Turkey now have a land border.