NASA Issues Challenge to US Citizens to Speed Up FUN3D CFD Code by 10000x
nasa.gov8 pointsby balnaphone0 comments
$ cat bbb.ml
#!/usr/bin/env -S "/home/user/.local/bin/o c a m l" -no-version
print_endline "ok";;
$ ls -lh ~/.local/bin/"o c a m l"
lrwxrwxrwx 1 user user 14 Feb 27 07:26 '/home/user/.local/bin/o c a m l' -> /usr/bin/ocaml
$ chmod a+rx bbb.ml
$ ./bbb.ml
ok
$
But if it didn't work, you can get pretty good mileage out of abusing sh to get the job done for many popular languages. #!/usr/bin/env -S "/path/with spaces/my interpreter" --flag1 --flag2
Only if my env didn't have -S support, I might consider a separate launch script like: #!/bin/sh
exec "/path/with spaces/my interpreter" "$0" "$@"
But most decent languages seems to have some way around the issue. #!/bin/sh
""":"
exec "/path/with spaces/my interpreter" "$0" "$@"
":"""
# Python starts here
print("ok")
Ruby #!/bin/sh
exec "/path/with spaces/ruby" -x "$0" "$@"
#!ruby
puts "ok"
Node.js #!/bin/sh
/* 2>/dev/null
exec "/path/with spaces/node" "$0" "$@"
*/
console.log("ok");
Perl #!/bin/sh
exec "/path/with spaces/perl" -x "$0" "$@"
#!perl
print "ok\n";
Common Lisp (SBCL) / Scheme (e.g. Guile) #!/bin/sh
#|
exec "/path/with spaces/sbcl" --script "$0" "$@"
|#
(format t "ok~%")
C #!/bin/sh
#if 0
exec "/path/with spaces/tcc" -run "$0" "$@"
#endif
#include <stdio.h>
int main(int argc, char **argv)
{
puts("ok");
return 0;
}
Racket #!/bin/sh
#|
exec "/path/with spaces/racket" "$0" "$@"
|#
#lang racket
(displayln "ok")
Haskell #!/bin/sh
#if 0
exec "/path/with spaces/runghc" -cpp "$0" "$@"
#endif
main :: IO ()
main = putStrLn "ok"
Ocaml (needs bash process substitution) #!/usr/bin/env bash
exec "/path/with spaces/ocaml" -no-version /dev/fd/3 "$@" 3< <(tail -n +3 "$0")
print_endline "ok";; # bind Alt-e on the command line to replace text with command
_aichat_bash() {
if [[ -n "$READLINE_LINE" ]]; then
READLINE_LINE=$(aichat -e "$READLINE_LINE")
READLINE_POINT=${#READLINE_LINE}
fi
}
bind -x '"\ee": _aichat_bash'
In the example you gave i get: find . -type f -name "*.mp4" -exec ffmpeg -i {} -c:v libaom-av1 -crf 30 -b:v 0 -c:a copy ~/Videos/{}.mkv \;
But if you don't like that you can press Ctrl-Shift-_ (bash has emacs keybindings) to undo and try something else. You can also put a # mark in front and hit enter, then up arrow then Alt-e so you know what created the command. $ cat tst.c
int main () {
int x[10];
return *(x+20);
}
$ gcc -Wall -O2 tst.c
tst.c: In function ‘main’:
tst.c:3:10: warning: array subscript 20 is outside array bounds of ‘int[10]’ [-Warray-bounds=]
3 | return *(x+20);
| ^~~~~~~
tst.c:2:7: note: at offset 80 into object ‘x’ of size 40
2 | int x[10];
| ^ library(readr)
library(dplyr)
library(purrr)
data <- read_csv("input.csv")
chunk_size <- 500
chunks <- split(data, ceiling(seq_along(1:nrow(data))/chunk_size))
iwalk(chunks, ~write_csv(.x, sprintf("data-%04d.csv", .y))) #!/usr/bin/perl -CSD -w -Mstrict -Mwarnings -MText::CSV
# chunk.pl -- split csv files into chunks
# Usage message and exit if needed
if (!@ARGV || $ARGV[0] eq '-h') {
print "Usage: $0 input_csv [chunk_size] [output_filename_format] [separator]\n";
print "Example: $0 input.csv 500 'input-%08d.csv' ','\n";
exit;
}
# Set command-line arguments
my ($INFILE, $CHUNKSIZE, $FMT, $SEP) = @ARGV;
$CHUNKSIZE //= 500;
$FMT //= "data-%08d.csv";
$SEP //= ",";
# Initialize CSV, file handles, and counters
my $csv = Text::CSV->new({ binary => 1, auto_diag => 1, sep_char => $SEP, eol => "\n" });
my ($i, $f, $out) = (0, 1, undef);
open my $in, "<:encoding(UTF-8)", $INFILE or die "Cannot open $INFILE: $!";
# Main loop
while (my $row = $csv->getline($in)) {
if ($i % $CHUNKSIZE == 0) {
close $out if defined $out;
open $out, ">:encoding(UTF-8)", sprintf($FMT, $f++) or die "Cannot open output file: $!";
}
$csv->print($out, $row) or die "Failed to write row: $!";
$i++;
}
# Clean up: close file handles
close $out if defined $out;
close $in;