小编qed*_*qed的帖子

当有多个时,删除ggplot2中的额外图例

例如:

require(ggplot2)
require(reshape2)
volcano3d <- melt(volcano) 
names(volcano3d) <- c("x", "y", "z") 
v <- ggplot(volcano3d, aes(x, y, z = z)) 
v1 = v +  stat_contour(aes(colour=..level..,size=..level..)) 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

旁边有两个传说,我可以删除其中一个吗?

graphics r ggplot2

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

cin和getline在一个程序中,只有其中一个生效?

这是代码:

#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char const* argv[])
{
    char s1[23];
    char s2[23];
    // cin >> s1;
    cin.getline(s2, 22);
    cout << s1 << endl;
    cout << s2 << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我取消注释该行cin >> s1,那么将跳过getline函数,不知道为什么会发生这种情况.

c++ io

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

何时使用vim.eval以及何时在python-vim中使用vim.command?

来自vim doc:

vim.command(str)                    *python-command*
    Executes the vim (ex-mode) command str.  Returns None.



vim.eval(str)                       *python-eval*
    Evaluates the expression str using the vim internal expression
    evaluator (see |expression|).  Returns the expression result as:
    - a string if the Vim expression evaluates to a string or number
    - a list if the Vim expression evaluates to a Vim list
    - a dictionary if the Vim expression evaluates to a Vim dictionary
    Dictionaries and lists are recursively expanded.
Run Code Online (Sandbox Code Playgroud)

我很难区分这两个,也许是因为我首先不理解表达式和命令之间的区别.对一些例子的解释非常受欢迎.

vim

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

使用智能指针的好处?

以此为例:

#include <memory>
#include <iostream>

int add(int a, int b) {
    return a+b;
}

std::unique_ptr<int> addp(int a, int b) {
    std::unique_ptr<int> ip(new int(a + b));
    return ip;
}

int main(int argc, char const* argv[])
{
    std::cout << add(3, 5) << std::endl;
    std::cout << *(addp(3, 5)) << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

功能addp是否会提高性能,或者换句话说,是否可以避免复制数据?我怀疑结果a+b是在堆栈中,然后以任何方式复制到堆中.

c++ smart-pointers

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

超级函数如何在java中工作?

以下是头部设计模式书中的代码片段:

public class LowerCaseInputStream extends FilterInputStream {

    public LowerCaseInputStream(InputStream in) {
        super(in);
    }

    public int read() throws IOException {
        int c = super.read();
        return (c == -1 ? c : Character.toLowerCase((char)c));
    }

    public int read(byte[] b, int offset, int len) throws IOException {
        int result = super.read(b, offset, len);
        for (int i = offset; i < offset+result; i++) {
            b[i] = (byte)Character.toLowerCase((char)b[i]);
        }
        return result;
    }
}
Run Code Online (Sandbox Code Playgroud)

同一章还有另一个玩具示例:

public class Mocha extends CondimentDecorator {
    Beverage beverage;

    public Mocha(Beverage beverage) { …
Run Code Online (Sandbox Code Playgroud)

java oop decorator

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

使用JavaFx在系统剪贴板上收听

如对此问题的回答所述,可以设置时间轴来检查系统剪贴板中是否有更改:

在JavaFX 8中的时间轴外部设置和使用变量

但是有更好的方法吗?例如,事件监听器?我搜索了JavaFx 8文档,没有发现任何明显有用的东西。

首选使用JavaFx的解决方案,但欢迎所有答案。

java clipboard javafx javafx-8

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

Qt给出了错误的屏幕几何图形?

我试图从PySide获得屏幕分辨率:

class Prog(QtGui.QDialog):
    def __init__(self):
        super().__init__()
        self.timer = QtCore.QTimer()

        desktop = QtGui.QDesktopWidget()
        dim = desktop.availableGeometry(desktop.primaryScreen())
        print(dim)
        print(desktop.width())
        print(desktop.height())
        print(QtGui.QApplication.desktop().screenGeometry())

app = QtGui.QApplication(sys.argv)
prog = Prog()
prog.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)

我在macbook pro上,所以我知道分辨率是2560乘1600,但Qt似乎总是给出错误的答案:

PySide.QtCore.QRect(0, 22, 1440, 874)
1440
900
PySide.QtCore.QRect(0, 0, 1440, 900)
Run Code Online (Sandbox Code Playgroud)

我在这做错了吗?

python qt pyside

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

尽可能让 R 调用 NextMethod

当有下一个类时,我试图让 R 调用 NextMethod:

e = new.env()
class(e) = c(class(e), "c11", "c22")
print.c11 = function(e, ...) {
    print(e$x); 
    tryCatch({
        NextMethod()
    }, warning = function(w) {
    }, error = function(e) {
    }, finally = {
    })
}
print.c22 = function(e, ...) {
    print(e$y)
    tryCatch({
        NextMethod()
    }, warning = function(w) {
    }, error = function(e) {
    }, finally = {
    })
}
e$x = 111
e$y = 222
print(e)
Run Code Online (Sandbox Code Playgroud)

这是一个肮脏的黑客,它将涵盖该方法可能产生的所有错误和警告。如何正确地做到这一点?


上面的代码在没有 tryCatch 块的情况下也能工作,我认为这是因为调用了 print.default 函数。现在从 Hadley 的高级 R 书中举一个例子(修改):

> baz <- …
Run Code Online (Sandbox Code Playgroud)

oop r

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

对clojure中的函数args施加限制

我经常发现自己这样做:

(defn f1 [coll]
  (if (not= (count coll) 2)
    (throw (IllegalArgumentException. "coll must have length 2.")))
  (if (odd? (first coll))
    (throw (IllegalArgumentException. "first elem must be even.")))
  (if (even? (second coll))
    (throw (IllegalArgumentException. "second elem must be odd.")))
  (apply * coll))

(defn f2 [coll]
  (if (not= (count coll) 2)
    (throw (IllegalArgumentException. "coll must have length 2.")))
  (if (odd? (first coll))
    (throw (IllegalArgumentException. "first elem must be even.")))
  (if (even? (second coll))
    (throw (IllegalArgumentException. "second elem must be odd.")))
  (apply + …
Run Code Online (Sandbox Code Playgroud)

clojure

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

在Java中将4个字节合并为一个

这是代码:

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

public class Shiftcodes {
    private Map<byte[], Byte> shiftMap;

    public byte genoByte(byte b1, byte b2, byte b3, byte b4) {
        return (byte) (
                  (b1 << 6)
                | (b2 << 4)
                | (b3 << 2)
                | b4);
    }

    public static void main(String[] args) throws IOException {
        Shiftcodes shiftcodes = new Shiftcodes();
        byte b = shiftcodes.genoByte((byte) 0x01, (byte) 0x11, (byte) 0x00, (byte) 0x10);
        FileOutputStream fileOutputStream = new FileOutputStream("/tmp/x.bin");
        fileOutputStream.write(new byte[] {b});
    }
}
Run Code Online (Sandbox Code Playgroud)

假设每个字节的位都是零,除了最右边的两位,可以是0或1.所以我改变了一点代码:

public class …
Run Code Online (Sandbox Code Playgroud)

java

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

标签 统计

java ×3

c++ ×2

oop ×2

r ×2

clipboard ×1

clojure ×1

decorator ×1

ggplot2 ×1

graphics ×1

io ×1

javafx ×1

javafx-8 ×1

pyside ×1

python ×1

qt ×1

smart-pointers ×1

vim ×1