Clojure in Intelij IDEA - intellij-idea

I opened a Clojure project in Intelij IDEA and everything had been working well until I have made new Clojure workspace and have written some Clojure code in it. When I try to execute this piece of code in REPL I get always the same error. Whatever I write, I get the same error. For example when I try to execute (+ 1 1_ I get the following error:
Syntax error compiling at (test.clj:4:1).
Unable to resolve symbol: + in this context
Has someone already faced this issue?
Here is my project.clj
(defproject test-app "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[cheshire "5.8.1"]
[clojure.java-time "0.3.2"]
[cprop "0.1.13"]
[funcool/struct "1.3.0"]
[luminus-immutant "0.2.5"]
[luminus-transit "0.1.1"]
[luminus/ring-ttl-session "0.3.2"]
[markdown-clj "1.0.7"]
[metosin/muuntaja "0.6.4"]
[metosin/reitit "0.3.1"]
[metosin/ring-http-response "0.9.1"]
[mount "0.1.16"]
[nrepl "0.6.0"]
[org.clojure/clojure "1.10.0"]
[org.clojure/tools.cli "0.4.2"]
[org.clojure/tools.logging "0.4.1"]
[org.webjars.npm/bulma "0.7.4"]
[org.webjars.npm/material-icons "0.3.0"]
[org.webjars/webjars-locator "0.36"]
[org.webjars/webjars-locator-jboss-vfs "0.1.0"]
[ring-webjars "0.2.0"]
[ring/ring-core "1.7.1"]
[ring/ring-defaults "0.3.2"]
[selmer "1.12.12"]]
:min-lein-version "2.0.0"
:source-paths ["src/clj"]
:test-paths ["test/clj"]
:resource-paths ["resources"]
:target-path "target/%s/"
:main ^:skip-aot test-app.core
:plugins [[lein-immutant "2.1.0"]]
:profiles
{:uberjar {:omit-source true
:aot :all
:uberjar-name "test-app.jar"
:source-paths ["env/prod/clj"]
:resource-paths ["env/prod/resources"]}
:dev [:project/dev :profiles/dev]
:test [:project/dev :project/test :profiles/test]
:project/dev {:jvm-opts ["-Dconf=dev-config.edn"]
:dependencies [[expound "0.7.2"]
[pjstadig/humane-test-output "0.9.0"]
[prone "1.6.1"]
[ring/ring-devel "1.7.1"]
[ring/ring-mock "0.3.2"]]
:plugins [[com.jakemccrary/lein-test-refresh "0.24.1"]]
:source-paths ["env/dev/clj"]
:resource-paths ["env/dev/resources"]
:repl-options {:init-ns user}
:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]}
:project/test {:jvm-opts ["-Dconf=test-config.edn"]
:resource-paths ["env/test/resources"]}
:profiles/dev {}
:profiles/test {}})
Everything works fine when I write code in my namespace test-app.routes.home, but when I make new Clojure namespace test.clj in the same routes folder, I cant evaluate code in REPL. When I press ctrl+Enter I get this error:
Syntax error compiling at (test.clj:4:1).
Unable to resolve symbol: + in this context

(Maybe) You need to evaluate your namespace (ns ....) before trying to evaluate any other expression.

Related

Jenkins cannot find file even though it exist in the workplace Selenium File not found: Selenium::WebDriver::Error::InvalidArgumentError)

So I am seeing this below, the file exist and this is the ruby line of code thats supposed to run:
upload = #browser.file_field(:type => 'file', :class => 'react-fine-uploader-file-input')
upload.send_keys("workplace/uploads/test1.mp3")
#browser.button(:class => 'change-file-button').wait_until_present
Jenkins error below in the console output:
File not found: workplace/uploads/test1.mp3
(Selenium::WebDriver::Error::InvalidArgumentError)

Undefined nameToPath when using ClojureScript's :npm-deps

I'm trying to install the Ant Design library via :npm-deps, so in my project.clj I have:
:cljsbuild {:builds {:app
{:source-paths ["src" "env/dev/cljs"]
:compiler
{:main "metro-parks-cljs-components.dev"
:output-to "public/js/app.js"
:output-dir "public/js/out"
:asset-path "js/out"
:source-map true
:optimizations :none
:install-deps true
:npm-deps {:react "^16.8.5"
:react-dom "^16.8.5"
:antd "^3.15.2"
:moment "^2.24.0"}}
...
And in my app code:
(ns metro-parks-cljs-components.event-finder
(:require
...
[reagent.core :as r]
[moment]
[antd :refer [DatePicker Pagination]]))
This compiles but on page load I get:
Error: Undefined nameToPath for module$home$ctamayo$workspace$metro_parks$wp_content$themes$metro_parks$metro_parks_cljs_components$node_modules$antd$es$affix base.js:1357:21
visitNode http://localhost:3449/js/out/goog/base.js:1357
visitNode http://localhost:3449/js/out/goog/base.js:1355
visitNode http://localhost:3449/js/out/goog/base.js:1355
visitNode http://localhost:3449/js/out/goog/base.js:1355
writeScripts_ http://localhost:3449/js/out/goog/base.js:1369
require http://localhost:3449/js/out/goog/base.js:706
<anonymous> http://localhost:3449/index.html:80
Is this a known issue with npm-deps right now? Is there a workaround?
Note: I have looked into using shadow-cljs but I'm hesitant to migrate to a whole new build system due to time constraints.

Fixing rails 5 deprecation warning for matching routes

In my routes.rb file, I have the following
resources :landings, only: [:index],
path: '/golf' do
collection do
get 'break_70', path: 'how-to-break-70'
end
end
which generates a url
/golf/how-to-break-70
After upgrading to Rails 5, this generates the following deprecation message:
DEPRECATION WARNING: Specifying strings for both :path and the route path is deprecated. Change things like this:
match "break_70", :path => "how-to-break-70"
to this:
match "how-to-break-70", :as => "break_70", :action => "break_70"
If I try to follow these directions with
resources :landings, only: [:index],
match: '/golf' do
collection do
match: 'how-to-break-70', as: 'break_70', action: 'break_70'
end
end
then I get the following error
syntax error, unexpected ':', expecting keyword_end
match: 'how-to-break-70', as: 'break_70', action: 'break_70'
How do I modify this route to avoid the deprecation warning?
Updated Answer
I update my answer to fix a little mistake so any reader can see a working code. Thanks #Obromios for the little fix.
In resources it should still be path:.
And in the route definition you have an extra ":" after match. Also you have to specify via: [:get, :post] if you match.
So the final version looks like:
resources :landings, only: [:index], path: '/golf' do
collection do
match 'how-to-break-70', as: 'break_70', action: 'break_70', via: [:get, :post]
end
end
Original Answer
In resources it should still be path:.
And in the route definition you have an extra ":" after match
So the final version looks like:
resources :landings, only: [:index], path: '/golf' do
collection do
match 'how-to-break-70', as: 'break_70', action: 'break_70'
end
end
Not tested, but should work.

why chef-metal-ssh is failed

I was trying to follow https://github.com/double-z/chef-metal-ssh
I'm running the code below, it throws the exception:
[2015-01-19T06:03:39-06:00] ERROR: machineone had an error: ArgumentError: wrong number of arguments (2 for 0)
require 'chef_metal_ssh'
name = "one"
with_ssh_cluster("~/metal_ssh")
machine name do
action [:ready, :converge]
machine_options 'ip_address' => '10.62.56.209',
'ssh_options' => {
'user' => 'root',
'keys' => ['/home/chefuser/test.rsa']
}
files '/remote/path.txt' => { :content => 'foo' }
end
machine_execute name do
command "pwd" # this uses new_daemon_key to register with halo
end
I want to know what's wrong of this code. And I don't understand for with_ssh_cluster("~/metal_ssh") what content should be in "~/metal_ssh"? thanks.
I had to dig a little with the code to understand (I'm not using it).
According to the comment below found here
# cluster_path - path to the directory containing the vagrant files,
# which should have been created with the vagrant_cluster resource.
The "~/metal_ssh" file should be the Vagrantfile path.
chaf-metal-ssh is a driver for chef-metal, I'm not sure you're comfortable with chef-metal, so I would advise starting by reading This and This
I've found that the issue is I was using chef 12.0.3, and in line 109 of /usr/local/rvm/gems/ruby-2.0.0-p598/gems/chef-12.0.3/lib/chef/dsl/recipe.rb
resource.load_prior_resource(type, name)
But in chef-metal-ssh-0.1.2/lib/chef/resource/ssh_cluster.rb:18
it's defined as
def load_prior_resource
Chef::Log.debug("Overloading #{resource_name}.load_prior_resource with NOOP")
end
so it throws
ArgumentError: wrong number of arguments (2 for 0)

clojure.test unable to resolve symbol from `eval`. Works in REPL and lein run

Please bear with this contrived example but it was the simplest thing I could think of to recreate the issue.
(ns something.core)
(defn call-foo [something & args]
(let [a-foo (:foo (eval (:quux something)))]
(apply a-foo args)))
(def Something {
:foo (fn [& args] args)
:bar (fn [something] (call-foo something))
})
(defn make-something []
{:quux 'Something})
Running the following in the REPL or with lein run works well.
(let [subject (make-something)
actual (call-foo subject "hello" "greetings")]
(println actual))
;;=> (hello greetings)
The problem occurs only during this test and executing lein test:
(ns something.core-test
(:require [clojure.test :refer :all]
[something.core :refer :all]))
(deftest a-test
(let [subject (make-something)
actual (call-foo subject "hello" "greetings")]
(is (= ["hello" "greetings"] actual))))
This throws an error. An example output:
ERROR in (a-test) (Compiler.java:6464)
Uncaught exception, not in assertion.
expected: nil
actual: clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: Something in this context, compiling:(/private/var/folders/0n/c7q7860j34xfc2r1x4q51jrh0000gn/T/form-init9215140948330409114.clj:1:6436)
The line "Unable to resolve symbol: Something in this context" makes me think Something is not in context for some reason while I eval in call-foo. But why is this the case only in the test?
The problem is that eval does not see context. Your 'Something resolves in something.core and something.core-test since you have refered all. It won't resolve from whatever namespace where lein test runs its tests.
To fix the immediate problem change
'Something
to
`Something
so that it is namespace-qualified. The test will then run (and fail), but that's another issue (println returns nil for one thing).