Skip to content
View gist:27b0c90caaefb61c3dd0
private JAXPExtensionsProvider getProviderInstance() throws ClassNotFoundException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?> clazz = Class.forName("com.sun.org.apache.xpath.internal.jaxp.JAXPExtensionsProvider");
Constructor[] constructors = clazz.getDeclaredConstructors();
for (int i = 0; i < constructors.length; i++) {
Class[] parameterTypes = constructors[i].getParameterTypes();
if (parameterTypes.length == 2) {
return (JAXPExtensionsProvider) constructors[i].newInstance(functionResolver, false);
} else if (parameterTypes.length == 1) {
return (JAXPExtensionsProvider) constructors[i].newInstance(functionResolver);
}
View HMAC_test.rb
KS = Java::JavaxCryptoSpec::SecretKeySpec
MAC = Java::JavaxCrypto::Mac
ENCODER = Java::SunMisc::BASE64Encoder
seed = "66fbcbf2-74b8-46bf-bf8a-fe925efaaa18-Tue Oct 07 09:04:49 EDT 2014"
secret_key = SKS.new(seed.to_java_bytes, "HmacSHA256")
msg = "[12345]".to_java_bytes
buf = Java::JavaIo::ByteArrayOutputStream.new
buf.write(msg, 0, msg.length)
View sentences.clj
(def sentences "The evening passed quietly, unmarked by anything extraordinary. The acknowledged lovers talked and laughed, the unacknowledged were silent. Darcy was not of a disposition in which happiness overflows in mirth; and Elizabeth, agitated and confused, rather knew that she was happy than felt herself to be so; for, besides the immediate embarrassment, there were other evils before her. She anticipated what would be felt in the family when her situation became known; she was aware that no one liked him but Jane; and even feared that with the others it was a dislike which not all his fortune and consequence might do away.")
View questions2.clj
(defn question2 [she he]
(let [possessive (fn [x] (str x "'s"))
hers (possessive she)
his (possessive he)]
(str "Hey " she ", are " hers " and " his " the same?")))
View right-triangle-test2.clj
(defn right-triangle2? [[a b c]]
(let [a-square (* a a)
b-square (* b b)
c-square (* c c)]
(= (+ a-square b-square) c-square)))
View right-triangle-test.clj
(defn right-triangle? [coll]
(let [a-square (* (nth coll 0) (nth coll 0))
b-square (* (nth coll 1) (nth coll 1))
c-square (* (nth coll 2) (nth coll 2))]
(= (+ a-square b-square) c-square)))
(right-triangle? [1 2 3])
View question.clj
(defn question [she he]
(let [hers (str she "'s")
his (str he "'s")]
(str "Hey " she ", are " hers " and " his " the same?")))
View right-and-left.clj
(defn right-and-left [size]
(letfn
[(go-right [x [start end]]
(cond
(< (inc x) end) (do #_(println "right") (go-right (inc x) [start end]))
(> (dec x) start) (go-left x [start (dec end)])
:else (println "done")))
(go-left [x [start end]]
(cond
(> (dec x) start) (do #_(println "left") (go-left (dec x) [start end]))
View trampoline-able-call.clj
(declare incrementor2 decrementor2)
(defn incrementor2 [n]
(let [_ (print (str n ", "))
next-val (+ n (rand-int 100))]
(if (< -10000 next-val)
#(decrementor2 next-val))))
(defn decrementor2 [n]
(let [_ (print (str n ", "))
View recursive-call.clj
(declare incrementor decrementor)
(defn incrementor [n]
(let [_ (print (str n ", "))
next-val (+ n (rand-int 100))]
(if (< -10000 next-val)
(decrementor next-val))))
(defn decrementor [n]
(let [_ (print (str n ", "))
Something went wrong with that request. Please try again.