Skip to content

Instantly share code, notes, and snippets.

View xumingming's full-sized avatar

James Xu xumingming

  • -
  • -
View GitHub Profile
for (int i = 0; i < 500; i++) {
addMsg("hiveJob_20131107143929108_5711",
"1,1",
LogTypeEnum.LogType_PROGRESS.getType());
addMsg("hiveJob_20131118000642598_6521",
"[2013-11-07 14:32:07]: Stage-1 map = 0%, reduce = 0%",
LogTypeEnum.LogType_LOG.getType());
addMsg("hiveJob_20131118000931098_8247",
"1,1",
LogTypeEnum.LogType_PROGRESS.getType());
@xumingming
xumingming / runner-do-pause-42.clj
Last active December 17, 2015 12:49
core.async.ioc-macros
;; =>
(runner (do (pause 42)))
;; =>
(core.async.ioc_macros_test/runner (runner (do (pause 42)))
nil
(do (pause 42)))
;; =>
(core.async.ioc-macros-test/runner-wrapper
;; Clojure answer for: http://www.atatech.org/qa/detail/13581
(defn succ [str1]
(if (empty? str1)
""
(let [tail-promotions {\Z \A \z \a \9 \0}
head-promotions (assoc tail-promotions \9 \1)
old-last-char (last str1)
new-last-char (char (inc (int old-last-char)))
old-head (subs str1 0 (dec (count str1)))]
(if-not (#{\z \Z \9} old-last-char)
@xumingming
xumingming / clojure-self-print.clj
Last active December 16, 2015 17:41
clojure self print
(let [a "(let [a %c%s%c] (print (format a (char 34) a (char 34))))"] (print (format a (char 34) a (char 34))))
@xumingming
xumingming / resolve-formula.clj
Created March 21, 2013 02:16
求解一元二次方程
(defn resolve-formula [a b c]
(let [m (- (Math/pow b 2) (* 4 a c))]
(if (>= m 0)
(let [sqrt-m (Math/sqrt m)
minus-b (- 0 b)
a-2 (* 2 a)]
[(/ (+ minus-b sqrt-m) a-2) (/ (- minus-b sqrt-m) a-2)])
[nil nil])))
@xumingming
xumingming / nrepl.md
Created February 1, 2013 09:42
nrepl.md

Keys

  • M-x nrepl-jack-in: Launch an nrepl server and a repl client. Prompts for a project root if given a prefix argument.
  • M-x nrepl: Connect to an already-running nrepl server.

Clojure buffer commands:

  • C-x C-e: Evalulate the form preceding point and display the result in the echo area. If invoked with a prefix argument, insert the result into the current buffer.
  • C-M-x: Evaluate the top level form under point and display the result in the echo area. If invoked with a prefix argument, insert the result into the current buffer.
@xumingming
xumingming / how-ring-autoload-works.sh
Last active December 11, 2015 17:08
How ring's autoload works?
<rationalrevolt> With ring, can some one help me understand why passing a var
to run-jetty allows me to reload code and have it reflect
immediately? (run-jetty #'handler {:port 8080 :join? false})
[12:58]
<nDuff> rationalrevolt: passing the var object means it's involved in the
lookup, and can be substituted/replaced. [12:59]
*** bobbrahms1 (~Adium@pool-71-251-206-14.nwrknj.fios.verizon.net) has joined
channel #clojure [13:01]
*** bobbrahms (~Adium@pool-71-251-206-14.nwrknj.fios.verizon.net) has quit:
Read error: Connection reset by peer
@xumingming
xumingming / gist:4418226
Created December 31, 2012 08:00
dubbo error
TimeoutException Waiting server-side response timeout by scan timer. start time: 2012-12-31 15:54:31.917, end time: 2012-12-31 15:54:41.924,
client elapsed: 0 ms, server elapsed: 10007 ms, timeout: 10000 ms, request: Request [id=2, version=2.0.0, twoway=true, event=false, broken=false,
data=RpcInvocation [methodName=subscribe, parameterTypes=[class com.alibaba.dubbo.common.URL, interface com.alibaba.dubbo.registry.NotifyListener],
arguments=[consumer://10.16.24.39/com.alibaba.dubbo.registry.RegistryService?application=dubbo.clj&callbacks=10000&connect.timeout=10000&dubbo=2.5.4-SNAPSHOT
&interface=com.alibaba.dubbo.registry.RegistryService&lazy=true&methods=register,subscribe,unregister,unsubscribe,lookup&pid=22145&reconnect=false
&sticky=true&subscribe.1.callback=true&timeout=10000&timestamp=1356940461399&unsubscribe.1.callback=false, com.alibaba.dubbo.registry.integration.
RegistryDirectory@5d613b53], attachments={sys_callback_arg-1=1566653267, path=com.alibaba.dubbo.registry.RegistryService, interface=co
package com.alibaba.dubbo.demo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.dubbo.common.utils.Assert;
import com.alibaba.dubbo.config.ApplicationConfig;
@xumingming
xumingming / joy-of-clojure-lazy-qsort.clj
Created September 29, 2012 14:16 — forked from killme2008/joy-of-clojure-lazy-qsort.clj
Lazy QuickSort implementation in Clojure, from Joy of Clojure chapter 6.
(ns joy.q)
;; nil
(defn nom [n] (take n (repeatedly #(rand-int n))))
;; #'joy.q/nom
(defn sort-parts [work]
(lazy-seq
(loop [[part & parts] work] ;; Pull apart work - note: work will be a list of lists.
(if-let [[pivot & xs] (seq part)] ;; This blows up unless work was a list of lists.