(defn namespace-exists?
"check that a namespace has been loaded"
[str-val]
(-> str-val
symbol
find-ns
nil?
not))
(:require [clojure.java.io :as io])
(defn get-file-names [directory-object files-path]
(let [full-directory-path (.getPath directory-object)
get-js-file-path (fn [file]
(str files-path (.getName file)))]
(->> full-directory-path
io/file
file-seq
A colleague and I were using Jedis and wanted to delete multiple keys at once
without using a loop. The version of Jedis we were using has 2 del
functions and the one we wanted use is a java
vararg function and can be found here.
We understood a Java vararg function as a variadic function in Clojure which simply means a function with infinite arity.
Assuming b1
and a1
are keys in redis, the following is what we attempted initially:
(.del jedis "a1" "b1")
The above failed with the following error:
IllegalArgumentException No matching method found: del for class redis.clients.jedis.Jedis clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
clj.user.main=> ((-> "clojure.string/blank?" symbol resolve) "")
true
clj.user.main=> ((-> "clojure.string/blank?" symbol resolve) "ivermac")
false
I used Clojure 1.8.0
. The example above has been influenced by resolve clojure function
Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
The following is a life-saver if you test request objects in django frequently and you don't necessarily need to hit a specific endpoint
from django.test import RequestFactory
request_factory = RequestFactory()
request = request_factory.get('/path', data={'name': u'test'})
search for a file
find / -name <file-name>
search for a directory
find / -type d -name "<directory-name>"
If you are using redis and wanted to check how many open connections are there at the moment, use the client list
command in your redis terminal.
127.0.0.1:6379> client list
id=936 addr=127.0.0.1:61277 fd=8 name= age=3 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
This is a powerful debugging tool especially when you have an app that's using redis and seems to be opening connections without closing them, meaning you run out of memory in your redis host server.
Before getting to this stage, a colleague in the SRE team had used the following command to identify the redis problem
I included a non-Clojurescript directory in the checkout of a clojurescript project and started getting the following error:
Compiling ClojureScript...
WARNING: no :cljsbuild entry found in project definition.
--------------------------------------------------------------------------------
WARNING: your :cljsbuild configuration is in a deprecated format. It has been
automatically converted it to the new format, which will be printed below.
It is recommended that you update your :cljsbuild configuration ASAP.
--------------------------------------------------------------------------------
:cljsbuild