REPL session for a ClojureScript library in the vein of `lein try` - node.js

Sometimes I want to try out a library in a REPL. For example when I need to know the date 100 days from now, I do:
lein try clj-time
(require '[clj-time.core :as t])
(t/plus (t/today) (t/days 100))
Or with boot:
boot -d clj-time repl -e "(require '[clj-time.core :as t])"
(t/plus (t/today) (t/days 100))
This is already great, but this still has a few seconds of start up time.
My question: can I get the same functionality using ClojureScript and Node and perhaps have a faster startup time? How can I get the example above with cljs-time?

You can use Planck with the jar you're wanting to try by adding it to Planck's "classpath" (it's not an actual classpath since there's no JVM involved). See the Planck Dependencies documentation.
E.g.:
planck -c ~/.m2/repository/com/andrewmcveigh/cljs-time/0.4.0/cljs-time-0.4.0.jar

Related

Synchronous pymol

I am trying to load an mrc file, generate the map of it and then save the image, the problem is that it only saves a blank image, the code I run is the following:
from pymol import cmd
cmd.load('./6vof.mrc', ' 6vof')
cmd.volume( '6vof _volume', ' 6vof')
cmd.png('./test.png', 300, 200)
The equivalent code in the interface does work, I wanted to know how I can make the save method wait for the rendering of everything.
Hi Luis José Castillo,
it seems I encountered the same problem as you did.
I wanted to use Pymol from within a Ruby on Rails application and always got his message, when I launched it from within ruby:
CmdLoad: "mypol/4hhb.pdb" loaded as "4hhb".
Ray: render time: 0.02 sec. = 178776.9 frames/hour (0.02 sec. accum.).
The result was a blank transparent png. If I ran it in the command line with the same script I got this message and a perfect png:
CmdLoad: "4hhb.pdb" loaded as "4hhb".
Ray: render time: 4.04 sec. = 890.8 frames/hour (4.04 sec. accum.).
I got this behavoir on Ubuntu 20, Ubuntu 18 Server and in Docker.
I figured out, that the only difference was, I used relative paths from within ruby, but was always running everything in the same folder in the command line.
Well, so I just make this detour for my Rails application and now it does work:
def get_protein_image(pdb_id)
dir_path = get_pdb_file(pdb_id)
`cp lib/png_from_pdb.py #{dir_path} && cd #{dir_path} && pymol protein.pdb png_from_pdb.py -qc`
end
Sorry for the ruby code here, but here the essential solution, try to run everything inside the same folder (I simply delete the tmp subfolder after png generation).
cp lib/png_from_pdb.py #{dir_path} && cd #{dir_path} && pymol protein.pdb png_from_pdb.py -qc
I hope this trick will help you too!
Best regards,
Stephan

Scala.js - pass command line arguments from SBT run

When running the app using the sbt run while developing normal JVM app, I can pass command line arguments using run <args>. When I try the same with Scala.js, I get an error "No valid parser available". When trying runMain variant like runMain Main.main arg, the error is "Expected non-whitespace character", with arrow pointing just behind Main.main.
Is there some way how to pass arguments to the Scala.js / Node.js application when running it from SBT?
(I am using Scala.js 0.6.15).
No, there isn't, because JavaScript does not have a notion of command-line arguments. Node.js does, but only if started from the command-line, and that use case is not supported by the sbt plugin, I'm afraid.
Feel free to file a feature request. I'm not sure it can be accommodated, but we can look into it eventually.
One can define a custom task calling node.js, and parse arguments using SBT parsers. Add this into build.sbt:
import complete.DefaultParsers._
lazy val runa = inputKey[Unit]("Run app with arguments")
runa := {
(fastOptJS in Compile).value // build it first
val args: Seq[String] = spaceDelimited("<arg>").parsed
val npmRun = "node index.js" + args.map("\"" + _ + "\"").mkString(" "," ","")
npmRun.!
}
You also need to create a file index.js in your project root, containing something like this:
require("./target/scala-2.12/xxxx-jsdeps.js");
require("./target/scala-2.12/xxxx-fastopt.js");
In the intervening years, a library has emerged to address this:
https://ben.kirw.in/decline/

Clojurescript + Node.js 0.12.7 issue (error "process.binding('evals') No such module: evals")

I'm trying to use Node.js + ClojureScript, and I found an article for it.
http://www.mase.io/code/clojure/node/2015/01/24/getting-started-with-clojurecript-and-node/
Following the instruction to find this error:
process.binding('evals').NodeScript.runInThisContext.call(
^
Error: No such module: evals
at Error (native)
The issue seems that I need to use old version of node: https://groups.google.com/forum/#!topic/clojurescript/VneLWVpwe6o and https://github.com/kanso/kanso/issues/422
Mine is 0.12.7
pow> node --version
v0.12.7
In this case, I may need to use old version of node, but better yet, is there a way to bypass this issue? If none exists, how to use the old version of node.js in Mac OS X?
Edit
Following https://github.com/creationix/nvm, I could install 0.10.32 version of node.js.
pow> nvm install 0.10.32
pow> node --version
v0.10.32
However, it gives me another error message:
pow> node entrypoint.js
Hello world!
/Users/smcho/Desktop/clojurescript/pow/out/server/cljs/core.js:12133
var fixed_arity = f.cljs$lang$maxFixedArity;
^
TypeError: Cannot read property 'cljs$lang$maxFixedArity' of null
Edit2
The error was because I forgot to update the core.cljs module to include ((set! *main-cli-fn* -main). It's mentioned in the original article, together with https://groups.google.com/forum/#!topic/clojurescript/DYpsiCmsyIs and https://github.com/clojure/clojurescript/wiki/Quick-Start#running-clojurescript-on-nodejs.
From the post, there are two ways to make it working, with Mac OSX, the two approaches require different version of node.js, and this is not clearly explained in the post.
The version that works with old node.js
_project.clj
(defproject pow "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2725"]]
:node-dependencies [[source-map-support "0.2.8"]]
:plugins [[lein-cljsbuild "1.0.4"]
[lein-npm "0.4.0"]]
:source-paths ["src" "target/classes"]
:clean-targets ["out/server/pow" "out/server/pow.js"]
:cljsbuild {
:builds [{:id "server"
:source-paths ["src/server"]
:compiler {
:main pow.core
:output-to "out/server/pow.js"
:output-dir "out/server"
:optimizations :none
:target :nodejs
:cache-analysis true
:source-map true}}
]})
entry.js
// entrypoint.js
require("./out/server/goog/bootstrap/nodejs");
require("./out/server/pow");
require("./out/server/pow/core");
Run the script that executes the old node.js
#!/bin/bash
lein new mies pow
cd pow
cp ../_project.clj project.clj
mkdir src/server
mv src/pow src/server/
lein cljsbuild once
cp ../entrypoint.js .
/Users/smcho/.nvm/v0.10.32/bin/node entrypoint.js
The version that works with new node.js
Modify the _project.clj
:optimizations :simple <-
:source-map "out/server/pow.js.map" <-
Run first part of runme.sh
lein new mies pow
cd pow
cp ../_project.clj project.clj
mkdir src/server
mv src/pow src/server/
MOdify core.clj
(ns pow.core
(:require
[clojure.browser.repl :as repl]))
(enable-console-print!)
(defn -main []
(println "Hello world!"))
(set! *main-cli-fn* -main)
Then the second part of shell script
cd pow
lein cljsbuild once
node out/server/pow.js
One more note
I wanted to use ClojureScript/Node.js in order to test clojureScript code without using web browsers. I found LightTable, and
a good tutorial about it. All I need to is open the LightTable, connect to LightTable UI as an output, then execute the script. So, I have much less reason to use ClojureScript/Node.js as of now.
I fixed this with two steps:
1) Declaring a main function
(ns testproj.core
(:require
[clojure.browser.repl :as repl]))
(enable-console-print!)
(defn -main []
(println "Hello world!"))
(set! *main-cli-fn* -main)
2) Setting optimizations: simple in my project.clj, as noted at the very bottom of this blog post. For reasons unknown to me, optimizations: none breaks things.

"invalid option" error when running cucumber with "--tags"

I've been playing around with Cucumber for about three weeks now, and everything works well, except this little thing here.
Whenever I run my tests with e.g. cucumber checkout.feature --tags #monthly, I get the following on my console after the test have run successfully:
invalid option: --tags
Test::Unit automatic runner.
Usage: /Users/myusername/.rvm/gems/ruby-2.0.0-p0/bin/cucumber [options] [-- untouched arguments]
-r, --runner=RUNNER Use the given RUNNER.
(c[onsole], e[macs], x[ml])
--collector=COLLECTOR Use the given COLLECTOR.
(de[scendant], di[r], l[oad], o[bject]_space)
-n, --name=NAME Runs tests matching NAME.
(patterns may be used).
--ignore-name=NAME Ignores tests matching NAME.
(patterns may be used).
-t, --testcase=TESTCASE Runs tests in TestCases matching TESTCASE.
(patterns may be used).
--ignore-testcase=TESTCASE Ignores tests in TestCases matching TESTCASE.
(patterns may be used).
--location=LOCATION Runs tests that defined in LOCATION.
LOCATION is one of PATH:LINE, PATH or LINE
--attribute=EXPRESSION Runs tests that matches EXPRESSION.
EXPRESSION is evaluated as Ruby's expression.
Test attribute name can be used with no receiver in EXPRESSION.
EXPRESSION examples:
!slow
tag == 'important' and !slow
--[no-]priority-mode Runs some tests based on their priority.
--default-priority=PRIORITY Uses PRIORITY as default priority
(h[igh], i[mportant], l[ow], m[ust], ne[ver], no[rmal])
-I, --load-path=DIR[:DIR...] Appends directory list to $LOAD_PATH.
--color-scheme=SCHEME Use SCHEME as color scheme.
(d[efault])
--config=FILE Use YAML fomat FILE content as configuration file.
--order=ORDER Run tests in a test case in ORDER order.
(a[lphabetic], d[efined], r[andom])
--max-diff-target-string-size=SIZE
Shows diff if both expected result string size and actual result string size are less than or equal SIZE in bytes.
(1000)
-v, --verbose=[LEVEL] Set the output level (default is verbose).
(important-only, n[ormal], p[rogress], s[ilent], v[erbose])
--[no-]use-color=[auto] Uses color output
(default is auto)
--progress-row-max=MAX Uses MAX as max terminal width for progress mark
(default is auto)
--no-show-detail-immediately Shows not passed test details immediately.
(default is yes)
--output-file-descriptor=FD Outputs to file descriptor FD
-- Stop processing options so that the
remaining options will be passed to the
test.
-h, --help Display this help.
Deprecated options:
--console Console runner (use --runner).
I probably didn't need to put all of that here, but I wanted to give you an impression of how much text appears on my screen after each test, which can be a bit distracting.
Here is my setup:
Gemfile
source 'https://rubygems.org'
gem "rspec"
gem "cucumber"
gem "capybara"
gem "capybara-webkit"
gem "selenium"
gem "selenium-client"
gem "selenium-webdriver"
env.rb
require_relative '../../../config.rb'
require 'capybara/cucumber'
require 'capybara/rspec'
Capybara.app_host = AT_ROOT
Capybara.default_driver = :selenium
Capybara.javascript_driver = :webkit
Capybara.default_wait_time = DEFAULT_WAIT_TIME
Capybara.ignore_hidden_elements = IGNORE_HIDDEN_ELEMENTS
# Define window size of the browser here
Capybara.current_session.driver.browser.manage.window.resize_to(DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH)
I couldn't find any connection to the Test::Unit automatic runner in the console output, but apparently it's got something to do with it.
Do you have any idea what that could be? I found some threads related to this issue, but they didn't help me unfortunately.
Thank you
Try
cucumber features -t #monthly

How do I use (require :PACKAGE) in clisp under Ubuntu Hardy?

I am trying to evaluate the answer provided here, and am getting the error: "A file with name ASDF-INSTALL does not exist" when using clisp:
dsm#localhost:~$ clisp -q
[1]> (require :asdf-install)
*** - LOAD: A file with name ASDF-INSTALL does not exist
The following restarts are available:
ABORT :R1 ABORT
Break 1 [2]> :r1
[3]> (quit)
dsm#localhost:~$
cmucl throws a similar error:
dsm#localhost:~$ cmucl -q
Warning: #<Command Line Switch "q"> is an illegal switch
CMU Common Lisp CVS release-19a 19a-release-20040728 + minimal debian patches, running on crap-pile
With core: /usr/lib/cmucl/lisp.core
Dumped on: Sat, 2008-09-20 20:11:54+02:00 on localhost
For support see http://www.cons.org/cmucl/support.html Send bug reports to the debian BTS.
or to pvaneynd#debian.org
type (help) for help, (quit) to exit, and (demo) to see the demos
Loaded subsystems:
Python 1.1, target Intel x86
CLOS based on Gerd's PCL 2004/04/14 03:32:47
* (require :asdf-install)
Error in function REQUIRE: Don't know how to load ASDF-INSTALL
[Condition of type SIMPLE-ERROR]
Restarts:
0: [ABORT] Return to Top-Level.
Debug (type H for help)
(REQUIRE :ASDF-INSTALL NIL)
Source:
; File: target:code/module.lisp
(ERROR "Don't know how to load ~A" MODULE-NAME)
0] (quit)
dsm#localhost:~$
But sbcl works perfectly:
dsm#localhost:~$ sbcl -q
This is SBCL 1.0.11.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (require :asdf-install)
; loading system definition from
; /usr/lib/sbcl/sb-bsd-sockets/sb-bsd-sockets.asd into #<PACKAGE "ASDF0">
; registering #<SYSTEM SB-BSD-SOCKETS {AB01A89}> as SB-BSD-SOCKETS
; registering #<SYSTEM SB-BSD-SOCKETS-TESTS {AC67181}> as SB-BSD-SOCKETS-TESTS
("SB-BSD-SOCKETS" "ASDF-INSTALL")
* (quit)
Any ideas on how to fix this? I found this post on the internet, but using that didn't work either.
The instructions you got mentioned SBCL explicitely, so it's expected that they'll work better using SBCL, I suppose. Some other Lisps don't come with ASDF or don't hook it up to CL:REQUIRE. In the former case, you'll have load ASDF yourself beforehand. In the latter case, you'll need to call (asdf:oos 'asdf:load-op ) instead of (require ).
wget http://cclan.cvs.sourceforge.net/checkout/cclan/asdf/asdf.lisp
It worth checking out clbuild. http://common-lisp.net/project/clbuild/
To get a lisp webserver up and running. You only need:
darcs get http://common-lisp.net/project/clbuild/clbuild
cd clbuild
chmod +x ./clbuild
./clbuild check
./clbuild build slime hunchentoot
./clbuild preloaded
Now a lisp repl will start. There you write:
* (hunchentoot:start-server :port 8080)
Testing that the server answer:
wget -O - http://localhost:8080/
<html><head><title>Hunchentoot</title></head>
<body><h2>Hunchentoot Default Page</h2>
<p>This is the Hunchentoot default page....
try this before anything else:
(require :asdf)
you can steal some ideas from the environment we use. it's available at: darcsweb
see environment.lisp that loads and sets up asdf for us. (sbcl has asdf already loaded)
use clc:clc-require in clisp. Refer to 'man common-lisp-controller'. I had the same error in clisp and resolved it by using clc:clc-require. sbcl works fine with just require though.

Resources