小编Kun*_*ngi的帖子

如何比较clojure中的数据结构并突出显示差异

有没有一种很好的方法来打印出clojure数据结构的差异?例如,在Perl中有Test :: Differences,它有很多帮助.

testing clojure

9
推荐指数
2
解决办法
1992
查看次数

HBase中的邻接列表结构

我正在尝试实现以下图形缩减算法

  • 该图是无向加权图
  • 我想剥离只有两个邻居的所有节点
  • 并更新权重

看看下面的插图:

算法减少图形http://public.kungi.org/graph-reduction.png

算法应将上图变换为下图.消除节点2并将边的权重更新为:w(1-3)= w(1-2)+ w(2-3)

由于我有一个非常大的图形,我正在使用MapReduce.

我的问题是如何在HBase中表示图形.我想在HBase中构建一个邻接列表结构,如下所示:

列族:节点,邻居1 - > 2,6,7 ......

有没有更好的方法来做到这一点?

hadoop hbase mapreduce

7
推荐指数
1
解决办法
838
查看次数

Emacs preview-latex minted package 和 -shell-escape

我正在尝试使用带有预览乳胶(Cc Cp Cb)的 emacs 来查看我的文档。首先是我的文档的最小示例:

\documentclass {article}
\usepackage{minted}
\begin{document}
\begin{listing}[H]
\begin{minted}{sql}
  Select * from FOOBAR;
\end{minted}
\caption{Test Query}
\label{code:query}
\end{listing}
\end{document}
Run Code Online (Sandbox Code Playgroud)

我已经尝试将使用 minted(源代码 LaTeX 包)与 emacs/auctex 一起使用,但它似乎不适用于预览乳胶。

我收到以下错误消息:

! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
Run Code Online (Sandbox Code Playgroud)

所以我将我的 latex-mode-hook 更改为以下内容:

(defun kungi/latex-mode-hook ()
  (turn-on-flyspell)
  (auto-complete-mode 1)
  (turn-on-reftex)
  (turn-on-auto-fill-mode)
  (push
   '("Latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
     :help "Run Latexmk on file")
   TeX-command-list)

(eval-after-load "tex"
  '(setcdr (assoc "LaTeX" TeX-command-list)
          '("xelatex -shell-escape %t"
          TeX-run-TeX nil (latex-mode doctex-mode) …
Run Code Online (Sandbox Code Playgroud)

emacs latex auctex

7
推荐指数
1
解决办法
2298
查看次数

为什么Clojure Cookbook中的红黑树错过了重新加工的案例

在使用Clojure Cookbook中的Red-Black Tree实现示例后, 我注意到平衡功能不包含重新着色的情况.(案例1在大多数红黑树文献中,或者也称为插入节点的叔叔是红色的情况).

(defn balance
  "Ensures the given subtree stays balanced by rearranging black nodes
  that have at least one red child and one red grandchild"
  [tree]
  (match [tree]
         [(:or ;; Left child red with left red grandchild
               [:black [:red [:red a x b] y c] z d]
               ;; Left child red with right red grandchild
               [:black [:red a x [:red b y c]] z d]
               ;; Right child red with left red grandchild
               [:black a x …
Run Code Online (Sandbox Code Playgroud)

tree clojure red-black-tree data-structures

7
推荐指数
1
解决办法
471
查看次数

Emacs描述vim的关键

Vim中是否有任何功能向我展示了当前上下文中键盘快捷键的含义?像emacs中的describe-key之类的东西.

我试图找出哪些键可以安全地重新绑定,哪些键绑定到有用的东西.

vim key-bindings

6
推荐指数
2
解决办法
1610
查看次数

Sublime Text 2,就像emacs中的块突出显示一样

是否有一个emacs插件为Sublime Text 2中的代码块创建这些漂亮的垂直线?(参见附页截图我的意思).

在此输入图像描述

emacs configuration sublimetext

6
推荐指数
1
解决办法
2316
查看次数

Vim自动命令生成E488:尾随字符

我正在尝试将以下自动命令插入到Vim中:

autocmd BufEnter *.c :call SourceTagsVim()<CR>

function! SourceTagsVim()
let s:fname = expand('<afile>:p:h') . 'tags.vim'
    if filereadable(s:fname)
        exe 'so ' . s:fname
    else
        echo s:fname " could not be read"
    endif
endfunction
Run Code Online (Sandbox Code Playgroud)

但是vim一直告诉我以下错误信息:

Error detected while processing BufEnter Auto commands for "*.c":
E488: Trailing charcters
Run Code Online (Sandbox Code Playgroud)

但自动命令执行正常.我知道我做错了什么.我还在我的vimrc上使用了dos2unix来确保正确的行结尾.

感谢你的帮助,安德烈亚斯

vim

5
推荐指数
1
解决办法
8057
查看次数

作为Postgres中另一个函数的参数

我可以通过C语言函数API或使用pl/pgsql接受回调函数作为参数在Postgres中创建用户定义的函数吗?

据我所知,没有办法通过C语言API执行此操作,因为它只接受sql数据类型,并且没有数据类型function.但也许我错过了什么?

c sql database postgresql plpgsql

5
推荐指数
2
解决办法
1652
查看次数

为什么您更喜欢:require:refer:all over:cloclore中使用

作者在《Clojure风格指南》中写道:

Prefer using :require :refer :all over :use in ns macro
Run Code Online (Sandbox Code Playgroud)

他没有给出任何解释为什么这是一个好主意。是否有充分的理由避免在ns宏中使用:use?

coding-style clojure

5
推荐指数
2
解决办法
727
查看次数

JTS LineString.getLength() 使用哪个单位

我试图找出 JTS LineString.getLength() 返回哪个单元。

例如:

LineString foo = (initialize line string somehow)
foo.getLength() -> 7.025667228118838E-4
Run Code Online (Sandbox Code Playgroud)

这些是公里?,米?,英尺?

java jts

3
推荐指数
1
解决办法
3128
查看次数

在compojure中测试静态路由

我正在尝试为compojure静态内容路由编写测试。我正在通过直接检查振铃响应来测试路由。

一个最小的工作示例如下:

;; src/testing-webapps.core.clj
(ns testing-webapps.core
  (:use [compojure.core]
        [compojure.route   :as route]))

(defroutes web-app
   (route/resources "/")
   (route/not-found "404"))


;; test/testing-webapps.core_test.clj
(ns testing-webapps.core-test
  (:require [clojure.test :refer :all]
            [testing-webapps.core :refer :all]))

(defn request [resource web-app & params]
  (web-app {:request-method :get :uri resource :params (first params)}))

(deftest test-routes
  (is (= 404 (:status (request "/flubber" web-app))))
  (is (= "404" (:body (request "/flubber" web-app))))
  (is (= 200 (:status (request "/test.txt" web-app)))))
Run Code Online (Sandbox Code Playgroud)

测试404路由效果很好,但调用(request "/test.txt" web-app)会导致出现意外NullPointerException情况ring.middleware.file-info/not-modified-since?

这是堆栈跟踪的顶部:

ERROR in (test-routes) (file_info.clj:27)
Uncaught …
Run Code Online (Sandbox Code Playgroud)

testing clojure compojure

3
推荐指数
1
解决办法
1047
查看次数

使用包含浮点数的 sprintf 创建固定长度输出字符串

我正在尝试创建一个具有以下结构的文件:
- 每行有 32 个字节 - 每行看起来像这样的格式字符串:“%10i %3.7f %3.7f\n”

我的问题如下:当我有一个负浮点数时,该行会变长一个甚至两个字符,因为 - 符号不计入“%3.7f”。

还有比这更好的方法吗?

if( node->lng > 0 && node->lat > 0 ) { 
    sprintf( osm_node_repr, "%10i %3.7f %3.7f\n", node->id, node->lng, node->lat );
} else if (node->lng > 0 && node->lat < 0) {
    sprintf( osm_node_repr, "%10i %3.7f %3.6f\n", node->id, node->lng, node->lat );
} else if (node->lng < 0 && node->lat > 0) {
    sprintf( osm_node_repr, "%10i %3.6f %3.7f\n", node->id, node->lng, node->lat );
} else if ( node->lng < 0 && …
Run Code Online (Sandbox Code Playgroud)

c floating-point printf fixed-length-record

2
推荐指数
1
解决办法
1万
查看次数

为什么试剂不会在状态改变时重新渲染我的试剂形式

我需要创建一个包含选择字段的表单,其中的选项取决于当前可用的邮件帐户。页面加载后,我在 API 请求中检索这些邮件帐户。

以下函数使用 select 元素创建表单。

(defn create-options [mail-accounts]
  (for [m mail-accounts]
    [:option {:key (keyword (str (:id m)))
              :value (:id m)}
     (:name m)]))

(defn render-mail-account-select [mail-accounts]
  (let [form-state (r/atom {})]
    (fn [mail-accounts]
      (let [form [:form.mailing-form.form-horizontal
                  (into [:select.form-control {:field :list :id :mail-account}]
                        (create-options mail-accounts))]]
        (pprint form)
        [bind-fields form form-state]))))
Run Code Online (Sandbox Code Playgroud)

pprint给了我以下输出:

;; Before the mail-accounts are loaded
[:select.form-control {:field :list, :id :mail-account}]

;; After the state update containing the mail accounts
[:select.form-control
 {:field :list, :id :mail-account}
 [:option {:key :24, :value …
Run Code Online (Sandbox Code Playgroud)

clojurescript reagent reagent-forms

1
推荐指数
1
解决办法
1593
查看次数