News for hackers. Stuff that matters.
Re:Jsc: My New Best Friend by monkeycantype on Wednesday August 25, 2021 @08:51PM (#28309215)
Javascript is more fun away from the web

The most fun I've ever had programming was in max/msp

https://cycling74.com/

things that are difficult to do in code, processing multiple simultaneous signals is done visually, running lines between object, but when you do want to write code, you open a code window and write javascript, and can then run visual patch cables to your javascript code representing the inputs and outputs.

Re:Jsc: My New Best Friend by rzzzt on Thursday August 26, 2021 @02:17AM (#28311302)
For (guitar) effects processing, there's also JSFX, which uses a scripting language similar to C/Javascript: https://www.cockos.com/EEL2/
Re:Jsc: My New Best Friend by jedimastert on Wednesday August 25, 2021 @09:56PM (#28309681)
Can you do this with PureData too?
Re:Jsc: My New Best Friend by aloupe on Thursday August 26, 2021 @09:44AM (#28314842)
You'd need an external for that, and apparently there is one: https://github.com/mganss/pdjs
Re:Jsc: My New Best Friend by dvhh on Wednesday August 25, 2021 @07:40PM (#28308626)
Also on windows,

C:\Windows\System32\cscript.exe (https://en.wikipedia.org/wiki/Windows_Script_Host)

Which run a less modern version of ECMA script, but does have access to COM objects

Re:Jsc: My New Best Friend by nanis on Wednesday August 25, 2021 @09:04PM (#28309310)
True story: Some years ago, a consulting assignment involved analyzing a bunch of data saved on a slow as molasses NAS using SAS's data format. The work was CPU intensive but IO throughput was the bottleneck. The analysis was close to being embarrassingly parallelizable[1] given an appropriate partitioning of the data.

The only thing installed on the remote system I was given access to via RDP was SAS whose macro facility tends to be cumbersome. Since the original CSV files were also stored on the same NAS, I asked if could have any programming language installed in my home directory (there was absolutely no way for me to upload anything, the system had no internet access other than to allow RDP, and I wasn't going to violate any rules.

The sysadmin head read BOFH for career development in the 90s, so, the answer was a solid no. I had to only use what was available on the system. The problem was simple: Each run took about two days: Start the thing at 7 am one day so you can hope to have the results before 4 pm two days later kind of thing. That's when I remembered `cscript`.

Using that, built a "thing" that orchestrated the copying of data in 100 GB chunks to `%TEMP%` which was still on the precious 256 GB SSD :-), launching multiple jobs etc. Task manager screenshots: https://www.nu42.com/2013/12/happiness-is-making-most-out-of...

In less than a week, jobs were running in four hours. sysadmin remained happily oblivious. Had to explain what I had done to the rest of the group.

[1]: https://en.wikipedia.org/wiki/Embarrassingly_parallel

Re:Jsc: My New Best Friend by cmeacham98 on Thursday August 26, 2021 @03:27AM (#28311675)
I'm not sure if your post was meant to imply this was against the rules but you can upload files via RDP file sharing.
Re:Jsc: My New Best Friend by nanis on Thursday August 26, 2021 @07:28AM (#28313436)
Both file sharing and copy & paste can be disabled.

Yes, this is not as useful as people think it is. In real life, it ends up kneecapping productivity while enabling checkbox driven security.

Regardless, it was also part of the contract that one was not allowed to upload/download or use copy&paste.

I did point out they had forgotten to explicitly prohibit setting up a camera pointed at the screen, but the humor was not appreciated.

Re:Jsc: My New Best Friend by pjmlp on Thursday August 26, 2021 @12:04AM (#28310554)
C# and VB compilers are also available somewhere under system32 for the default .NET version shipped with the OS.
Re:Jsc: My New Best Friend by EvanAnderson on Wednesday August 25, 2021 @11:40PM (#28310383)
There's also the "jsc.exe" JScript.Net compiler included in .NET framework installs. You can access .Net assemblies and APIs. It's handy to have it out-of-the-box on modern Windows machines.
Re:Jsc: My New Best Friend by agumonkey on Wednesday August 25, 2021 @11:03PM (#28310140)
a reminiscence of the pre powershell days I guess
Re:Jsc: My New Best Friend by jay-aye-see-key on Wednesday August 25, 2021 @08:01PM (#28308817)
Tangentially related: jsvu seems to be the easiest way to install most JS engines on most platforms. This can be useful comparing performance or compatibility across JS runtimes without firing up emulators.

https://github.com/GoogleChromeLabs/jsvu

Re:Jsc: My New Best Friend by js2 on Wednesday August 25, 2021 @06:11PM (#28307791)
Not in front of a keyboard, but does tr not work?

    echo "something in turkish" | LC_ALL=tr_TR tr "[:lower:]" "[:upper:]"
Re:Jsc: My New Best Friend by chociej on Wednesday August 25, 2021 @10:54PM (#28310080)
It failed to convert the diacritics for me with LC_ALL="tr_TR.UTF-8" matching my /etc/locale.gen.

Kapı açık -> KAPı AçıK

However this worked: gawk '{ print toupper($0) }'

Re:Jsc: My New Best Friend by js2 on Wednesday August 25, 2021 @11:23PM (#28310259)
Drat, apparently tr (GNU tr anyway) only supports single-byte characters.

https://unix.stackexchange.com/questions/554901/how-to-chang...

Re:Jsc: My New Best Friend by chana_masala on Thursday August 26, 2021 @03:30AM (#28311696)
You had a lot of patient to type that on a mobile device
Re:Jsc: My New Best Friend by js2 on Thursday August 26, 2021 @10:17AM (#28315280)
I was on an iPad w/keyboard, so technically I had a keyboard but not a macOS shell.
Re:Jsc: My New Best Friend by chana_masala on Thursday August 26, 2021 @02:09PM (#28318413)
s/patient/patience/
Re:Jsc: My New Best Friend by amelius on Wednesday August 25, 2021 @04:56PM (#28306875)
Sounds a lot like NodeJS.
Re:Jsc: My New Best Friend by qsort on Wednesday August 25, 2021 @05:14PM (#28307099)
Yeah, there isn't really any reason to use it over something like nodejs, especially since it doesn't look like the code is portable (e.g. print instead of console.log, etc.).

It's not like it's the only scripting language available either, OSX comes with ruby, python2, python3 and perl by default.

Re:Jsc: My New Best Friend by brundolf on Wednesday August 25, 2021 @08:46PM (#28309171)
The big difference is that it comes preinstalled. If you had a whole company on MacBooks but not all of them had Node installed, and you wanted to distribute a script written in JavaScript, this could be handy

Fairly niche, but not useless

I could also imagine some sort of Electron-alternative using the builtin JS interpreter for system stuff alongside the builtin webview for the UI

Re:Jsc: My New Best Friend by amelius on Thursday August 26, 2021 @07:40AM (#28313561)
> The big difference is that it comes preinstalled. If you had a whole company on MacBooks but not all of them had Node installed, and you wanted to distribute a script written in JavaScript, this could be handy

Except when Apple decides to remove it from the default setup.

Re:Jsc: My New Best Friend by ithrow on Wednesday August 25, 2021 @09:01PM (#28309276)
My understanding is that macOS doesn't ship those runtimes anymore.
Re:Jsc: My New Best Friend by zimpenfish on Thursday August 26, 2021 @02:50AM (#28311471)
They're all still in the current Monterey beta (21A5294g) but python2 says (paraphrasing) "this is only for compatibility; it might not be here in future"
Re:Jsc: My New Best Friend by tumultco on Thursday August 26, 2021 @06:26PM (#28321803)
It wasn't in the above list, but Apple did completely remove PHP in Monterey.
Re:Jsc: My New Best Friend by masswerk on Thursday August 26, 2021 @01:30AM (#28311049)
On a current MBA/M1, which came with Big Sur:

  % which perl
  /usr/bin/perl
  % which python2
  /usr/bin/python2
  % which python3
  /usr/bin/python3
  % which ruby
  /usr/bin/ruby
Re:Jsc: My New Best Friend by leshenka on Thursday August 26, 2021 @04:52AM (#28312298)
I like that jsc has global readline() function whereas in Node it's uhhh not so simple to get an input
Re:Jsc: My New Best Friend by cmgxyz on Wednesday August 25, 2021 @06:40PM (#28308089)
Yeah. This is a cool factoid, but for this kind of thing I usually just hop over to whatever browser tab is open and hit F12. If it really needs to be in the terminal, I'd reach for Node, or Deno, or JQ if it's anything to do with manipulating or interrogating JSON.
Re:Jsc: My New Best Friend by Scarbutt on Wednesday August 25, 2021 @07:21PM (#28308447)
You can use javascriptcore in iOS though.
Re:Jsc: My New Best Friend by supernes on Thursday August 26, 2021 @03:18AM (#28311620)
There's a similar tool in GNOME, using Mozilla's runtime

    gjs -c "(() => print('hello'))()"
Re:Jsc: My New Best Friend by cwyptocuwency on Thursday August 26, 2021 @12:52AM (#28310844)
Fun fact: until the most recent versions (0.64 and 0.65), React Native has used JSC as its JS runtime. You can now opt into Hermes (a mobile optimized JS runtime from FB open source) for both Android and iOS (although better supported on Android for now).
Re:Jsc: My New Best Friend by desktopninja on Wednesday August 25, 2021 @10:42PM (#28309999)
Neat. Also if you've got java installed, there's

  jrunscript
  jjs
Both invoke the nashorn javascript engine.
Re:Jsc: My New Best Friend by pjmlp on Thursday August 26, 2021 @12:09AM (#28310600)
That has been dropped in Java 10 and Java 17 is getting released next month, thus only works in what I consider legacy runtimes.

https://openjdk.java.net/jeps/372

Re:Jsc: My New Best Friend by scns on Thursday August 26, 2021 @05:20AM (#28312481)
Well, then it is still on many production systems that still run on Java 8.
Re:Jsc: My New Best Friend by pjmlp on Thursday August 26, 2021 @05:41AM (#28312616)
Yeah, Java's version of Windows XP and Python 2, time to move on.
Re:Jsc: My New Best Friend by justin_oaks on Thursday August 26, 2021 @10:11AM (#28315209)
Not quite. While Java 10 is end-of-life because it isn't an LTS version, Java 8 still is actively supported.
Re:Jsc: My New Best Friend by pjmlp on Thursday August 26, 2021 @12:33PM (#28317135)
Kind of, depends how much one is willing to pay for support.

https://www.oracle.com/java/technologies/java-se-support-roa...

Shops that care about LTS should be on 11 instead of clinging their teeth on 8.

Re:Jsc: My New Best Friend by nanis on Wednesday August 25, 2021 @09:08PM (#28309336)
Cute, but, as I noted elsewhere[1], these kinds of solutions require that you know that you are dealing with text that contains Turkish.

[1]: https://news.ycombinator.com/item?id=28287136

Re:Jsc: My New Best Friend by olliej on Wednesday August 25, 2021 @09:07PM (#28309330)
jsc is primarily a test binary, so it isn't super functional as a general purpose utility.

It is nice to have basic JS functionality on the terminal without installing node, but it has fairly limited functionality

Re:Jsc: My New Best Friend by ilaksh on Wednesday August 25, 2021 @09:03PM (#28309297)
You could also use something like Node.js or Deno.
Re:Jsc: My New Best Friend by slmjkdbtl on Wednesday August 25, 2021 @09:32PM (#28309498)
For embedding JS is there a reason to use Apple JavascriptCore over other libs like quickjs?
Re:Jsc: My New Best Friend by jitl on Wednesday August 25, 2021 @10:20PM (#28309838)
QuickJs is quite slow compared to JIT engines when you’ll have a long running workload. The major advantage of QuickJS is simplicity - its trivial to compile with Emscripten [for example](https://jake.tl/projects/quickjs-emscripten), but if performance is a concern then I’d stick to the JIT engines.
Re:Jsc: My New Best Friend by mshockwave on Wednesday August 25, 2021 @06:32PM (#28307994)
Sounds like the equivalent of the `d8` tool in V8 Javascript engine. Not sure if `d8` shipped with Chromium/Chrome though.