Ammonite: Script ... does not take arguments (under OS X) - macos

Using ammonite, I am trying to run a script that takes command line arguments. I just can't figure out what I am doing wrong. It works under Linux with a different version of ammonite, but not under OS X using homebrew:
According to the documentation this is how to do it:
val x = 1
#main
def main(i: Int, s: String, path: os.Path = os.pwd) = {
println("hello");
s"Hello! ${s * i} ${path.last}."
}
println("hello 2");
however, the #main annotation does not seem to do anything:
[dmg:/tmp] % amm rip7.sc --i=3 --s='this is the'
hello 2
Script rip7.sc does not take arguments: "--i=3" "--s=this is the"
⌁ [dmg:/tmp] 1 % amm rip7.sc 3 'this is the'
hello 2
Script rip7.sc does not take arguments: "3" "this is the"
The version of amm is (running on mac, using homebrew):
[dmg:/tmp] % amm
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 3.0.0 Java 16.0.1)
#
This same program runs on linux:
% amm /tmp/rip7.sc --i 10 --s 'the end'
Compiling /tmp/rip7.sc
hello 2
hello
"Hello! the endthe endthe endthe endthe endthe endthe endthe endthe endthe end dmg."
ammonite version:
% amm
Loading...
Compiling (synthetic)/ammonite/predef/sourceBridge.sc
Compiling (synthetic)/ammonite/predef/frontEndBridge.sc
Welcome to the Ammonite Repl 2.0.4 (Scala 2.13.1 Java 11.0.11)

I just had the same issue - seems like the brew version has some issues. I brew uninstalled, then followed the explicit instructions in the scala script section:
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/2.4.0/2.13-2.4.0) > /usr/local/bin/amm && chmod +x /usr/local/bin/amm' && amm
Magic! The script works now.

Related

install ipadic on Ubuntu 16.04 for mecab Japanese tokenizer

I am trying to install mecab and the ipadic dictionary as outlined here: http://taku910.github.io/mecab/#install-unix
I was able to successfully download mecab and install it and succesfully downloaded ipadic but get stuck on the second line of instruction below:
% tar zxfv mecab-ipadic-2.7.0-XXXX.tar.gz
% mecab-ipadic-2.7.0-XXXX
% ./configure
% make
% su
# make install
I am getting:
mecab-ipadic-2.7.0-20070801: command not found
I tried chmod -x on it and then tried it but same result.
Any help is appreciated.
Edit (result of cat /etc/mecabrc)
;
; Configuration file of MeCab
;
; $Id: mecabrc.in,v 1.3 2006/05/29 15:36:08 taku-ku Exp $;
;
dicdir = /usr/local/lib/mecab/dic/mecab-ipadic-neologd
; userdic = /home/foo/bar/user.dic
; output-format-type = wakati
; input-buffer-size = 8192
; node-format = %m\n
; bos-format = %S\n
; eos-format = EOS\n
There is no reason to compile from source on Ubuntu 16.04
Simple do:
$ sudo apt-get update
$ sudo apt install mecab mecab-ipadic-utf8
Then test it with
$ echo "日本語です" | mecab
日本 ニッポン ニッポン 日本 名詞-固有名詞-地名-国
語 ゴ ゴ 語 名詞-普通名詞-一般
です デス デス です 助動詞 助動詞-デス 終止形-一般
EOS
If things don't work, you may need to link /etc/mecabrc to the installed dictionary by setting dicdir=SOMEPATH_TO_IPADIC

On bash script, julia issue?

I have written some test script for a new machine, but there's an issue that I don't know if it's julia itself or the way I am writting the script.
The julia program is just
module main_prog
println("Program to heat and test a new machine")
println("Does a lot of diagonalizations")
dim = 10
realiz = 5
for ii in 1:realiz
A = randn(dim,dim)
H = (A + A')/2
eig_problem = eig(H)
end
println("End succesful")
end # module
And my bash script is
#!/bin/bash
for i in `seq 1 2`;
do
mkdir job$i
cp diagg_rmt.jl job$i
cd job$i
/home/user/julia/julia ./diagg_rmt.jl &
cd ..
done
When I runt the script, it gives an strange error:
-bash-4.2$ ERROR: getcwd: no such file or directory (ENOENT)
in uv_error at ./stream.jl:1027
in pwd at ./file.jl:8
in abspath at ./path.jl:108
in _include_dependency at ./loading.jl:127
in include_from_node1 at ./loading.jl:296
in process_options at ./client.jl:280
in _start at ./client.jl:378
I have seen another posts of this happening in Ruby, for example, but no idea
what to do here. I am using CentOS Linux release 7.0.1406 (Core)

run commands in openssl from ruby

I'm trying to run the following commands over ssh in ruby.
[root#test]# /usr/local/ssl/bin/openssl
OpenSSL> version
1.0.2d
OpenSSL> exit
Here's my code :
def execute(cmd)
puts cmd
result = con.exec!(cmd)
result = result.strip! unless result==nil
p "command output execute() :: #{result}"
return result
end
con.execute("/usr/local/ssl/bin/openssl && version && exit")
The first command leads to OpenSSL prompt. How do I run commands in it?

Neovim job control example with ruby

Neovim's job-control example in :help job-control works well for bash scripts. However, I am unable to make it work for ruby. Consider the following example:
set nocp
set buftype=nowrite
call jobstart('shell', 'bash', ['-c', 'for ((i = 0; i < 5; i++)); do sleep 2 && printf "Hello Bash!\n"; done'])
call jobstart('shell', 'ruby', ['-e', '5.times do sleep 2 and puts "Hello Ruby!" end'])
function JobHandler()
if v:job_data[1] == 'exit'
let str = v:job_data[0] . ' exited'
else
let str = join(v:job_data[2])
endif
call append(line('$'), str)
endfunction
au JobActivity shell* call JobHandler()
Running nvim -u NONE -S <filename> produces the following output:
Hello Bash!
Hello Bash!
Hello Bash!
Hello Bash!
Hello Bash!
1 exited
Hello Ruby! Hello Ruby! Hello Ruby! Hello Ruby! Hello Ruby!
2 exited
How do we make the ruby example work like that for bash?
It turns out that ruby's output is being buffered. One has to force it to be flushed in order to see the desired output.
call jobstart('shell', 'ruby', ['-e', '$stdout.sync = true; 5.times do sleep 1 and puts "Hello Ruby!\n" end'])
My original problem was to run a ruby test asynchronously. For it to work, I had to write $stdout.sync = true to a file and require it using -r:
call jobstart('shell', 'ruby', ['-r', '/tmp/opts.rb', '-I', 'test', 'test/unit/user_test.rb'])

How to change rvm gemset over ssh on os x server

ok
I don't know how to change rvm version over ssh under os x server.
What I do:
Login on server over ssh
run script (below) and catch error
Error: 'rvm is not a funciton, many-many-words'
What I have as script:
use File::Spec;
my $server_directory = File::Spec->catfile($ENV{HOME},'MyProject');
my $exec_file = File::Spec->catfile($server_directory,'run_script.rb');
my $run_ruby_script = qq'bundle exec ruby $exec_file'.' '.join(' ',#ARGV);
# reload bash profile
print qx(source $ENV{HOME}/.bash_profile);
print qx(source $ENV{HOME}/.bashrc);
# reload ruby
print qx(source $ENV{HOME}/.rvm/scripts/rvm);
my $ruby_setup = qq([[ -s "$ENV{HOME}/.rvm/scripts/rvm" ]] && source "$ENV{HOME}/.rvm/scripts/rvm");
print $ruby_setup. "\n";
# change directory
chdir($server_directory);
# configure gemset name
my $version = qx(cat .ruby-version);
chomp($version);
my $gemset = qx(cat .ruby-gemset);
chomp($gemset);
my $change_rvm_gemset = qq(rvm use $version\#$gemset);
print qx($ruby_setup && $change_rvm_gemset);
print qx(rvm current);
Ok, after all.
def exec_via_bash(line)
puts %Q(#{line})
exec = 'bash -c "#{line}"'
puts `#{exec}`
end
def RubySetup
# reload bash profile
homedir = ENV['HOME']
exec_via_bash %Q(source #{homedir}/.bash_profile);
exec_via_bash %Q(source #{homedir}/.bashrc);
# reload ruby
exec_via_bash %Q(source #{homedir}/.rvm/scripts/rvm);
ruby_setup = %Q([[ -s "#{homedir}/.rvm/scripts/rvm" ]] && source "#{homedir}/.rvm/scripts/rvm")
puts ruby_setup
ruby_setup
end
if ARGV.empty?
puts "there is not enough arguments passed. maybe you forget ruby file to exec?"
exit(1)
end
ruby_script_path = ARGV.shift;
exec_file_absolute_path = File.expand_path(ruby_script_path)
unless File.exists? exec_file_absolute_path
puts "file #{exec_file_absolute_path} doesn't exists!"
exit(1)
end
exec_file_directory = File.dirname(exec_file_absolute_path)
exec_bundle = %Q'bundle exec ruby #{exec_file_absolute_path}' + ' ' + ARGV.join(' ')
# change directory
Dir.chdir(exec_file_directory);
# print %x(ls);
# configure gemset name
version = %x(cat .ruby-version).strip;
gemset = %x(cat .ruby-gemset).strip;
change_rvm_gemset = %Q(rvm use #{version}\##{gemset});
ruby_setup = RubySetup()
exec_bash_login_line = [ruby_setup, change_rvm_gemset, exec_bundle].join ' && ';
puts 'exec bash login line: ' + exec_bash_login_line
forced = %Q(bash --login -c '#{exec_bash_login_line}');
puts forced, "\n";
puts %x(#{forced});
ok, this script is not a kind of beauty, but it works well.
Example of usage?
ruby script.rb ~/bla/bla/bla/run_your_program.rb --first_argument --second_argument a,b,c --etc
As I said before:
I've already on the server via ssh.
So, I need to run scripts via launchd.
And I should do it with
# part of launchd worker
<string>bash</string>
<string>-c</string>
<string>ruby ~/PathToCharmScript.rb -r a</string>
P.S:
Please, help me with improvements of this script for others!
Here is a gist: wow_this_works

Resources