Post B6tpbGbSXq828KY2Pw by p@fsebugoutzone.org
(DIR) More posts by p@fsebugoutzone.org
(DIR) Post #B6soSM6UQl0DTTHzbk by ns@sacred.harpy.faith
1 likes, 0 repeats
so i wrote a programi don't tend to like base plan9 fortune, so i wrote a replacement```#include <u.h>#include <libc.h>#include <bio.h>char *choice[2048];char*dupli (char *s){ char *p; p = malloc (strlen (s) + 1); if (p) strcpy (p, s); return p;}voidusage (void){ print ("usage: nurtune [-k n] [file]"); exits ("usage");}voidmain (int argc, char *argv[]){int i, k, n, m;char *p, *file;Biobuf *f; k = 1; file = "/fd/0"; ARGBEGIN{ case 'k': k = atoi (EARGF (usage())); if (k <= 0) sysfatal ("reservoir size cannot be negative, you stupid fucking nigger"); break; default: usage(); }ARGEND; if (argc > 0) file = argv[0]; if ((f = Bopen (file, OREAD)) == nil) sysfatal ("can't open %s: %r", file); srand (truerand ()); n = 0; while ((p = Brdline (f, '\n')) != nil) { p[Blinelen (f)-1] = 0; if (n < k) choice[n] = dupli ((char*)p); else { i = nrand (n + 1); if (i < k) { free ((void*)choice[i]); choice[i] = dupli ((char*)p); } } n ++; } if (n == 0) sysfatal ("no fortunes found"); m = n < k ? n : k; for (i = 0; i < m; i ++) print ("%s\n", choice[i]); exits (0);}```i hope you like it. i was helped out in some small parts (primarily figuring out the non-1 k handling (i am not as good at c as i should like to be), and secondarily but not unimportantly debugging what ended up being a char instead of a *char) by the deepseek llm, meaning my code is INADMISSIBLE in upstream 9front. INADMISSIBLE I SAY!
(DIR) Post #B6soU3G1TI17bRYaXo by p@fsebugoutzone.org
0 likes, 0 repeats
@HatkeshiatorTND @ns I'm not sure what this is supposed to do that the regular fortune doesn't. What's the plan?
(DIR) Post #B6szNAQDXDrvI9FG8u by p@fsebugoutzone.org
1 likes, 0 repeats
@HatkeshiatorTND @ns > samples more than one line from stdin optionallyAh, nice.> i removed indexing because i dislike it. something like sed `{seq `{wc -l file} | nurtune}}p fileā serves a similar function more transparentlyI'm not certain what nurtune is (random sample?) but you'd have to do `sed -n` or something. I did Fischer-Yates in awk for that and you could do it like `cat $files | randsort | sed 1q` if you wanted to.> i'd have to check on my laptop if `{`{}} works how i expectIt does. :tomduff:'s paper on his shell makes it pretty clear that he was extremely interested in the BNF checking out.randsort
(DIR) Post #B6tp6lXVTUMr6T9gDg by p@fsebugoutzone.org
0 likes, 0 repeats
@HatkeshiatorTND @ns % grep Mac /lib/rob:bwksmug:
(DIR) Post #B6tpbGbSXq828KY2Pw by p@fsebugoutzone.org
1 likes, 0 repeats
@HatkeshiatorTND @ns > because it does the thing i don't want it to do by default.I think `-n` is probably my most frequently used sed flag.