小编Tom*_*Tom的帖子

git 裸仓库、工作树和跟踪分支

我正在使用一个代码库,我需要为了不同的目的同时在多个分支上工作。所以我克隆到一个裸存储库,然后设置一些工作树:

git clone --bare ssh://git@git.example.com/project/repo repo.git
cd repo.git
git worktree add ../branch-1 branch-1
git worktree add ../branch-2 branch-2
... someone else creates branch-3 and pushes is ...
git fetch origin +refs/heads/*:refs/heads/* --prune
git worktree add ../branch-3 branch-3
Run Code Online (Sandbox Code Playgroud)

现在工作branch-3树没有设置为跟踪远程树并试图让它这样做,我陷入了可怕的混乱。

$ cd ../branch-3
$ git branch -u origin/branch-3
error: the requested upstream branch 'origin/refs/heads/feature/SW-5884-move-database-container-to-alpine-base-2' does not exist
hint: ...<snip>
$ git fetch +refs/heads/*:refs/remotes/origin/* --prune
$ git branch -u origin/branch-3
fatal: Cannot setup tracking information; starting point 'origin/feature/SW-5884-move-database-container-to-alpine-base-2' is not a …
Run Code Online (Sandbox Code Playgroud)

git git-bare git-branch git-worktree

4
推荐指数
3
解决办法
3090
查看次数

如何在Numpy中使用数组作为自己的索引

这适用于MATLAB:

>> p = [1, 0, 2, 4, 3, 6, 5];
>> p(p+1)

ans = 

     0   1   2   3   4   5   6
Run Code Online (Sandbox Code Playgroud)

有没有办法在NumPy中做同样的事情?我无法弄清楚如何:

>>> p = mat([1, 0, 2, 4, 3, 6, 5])
>>> p[p]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\numpy\matrixlib\defmatrix.py", line 305, in __getitem__
    out = N.ndarray.__getitem__(self, index)
IndexError: index (1) out of range (0<=index<0) in dimension 0
>>> p[:,p]
Run Code Online (Sandbox Code Playgroud)

在这一点上,解释器似乎进入了无限循环.这也会导致无限循环:

>>> [p[:,i] for i in p]
Run Code Online (Sandbox Code Playgroud)

但这有效:

>>> [p[:,i] for in …
Run Code Online (Sandbox Code Playgroud)

python numpy matrix indices

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

GTK 树视图样式

简短版本:什么 CSS 选择器可用于设置 GTK TreeView 标题背景的样式?

长版:我试过treeview header, treeview header .button, .button, button, label, GtkTreeView header,header和*作为 Gtk.TreeView 标题的选择器。其中,button用于更改标题(color属性)中文本的颜色而不是背景 ( background-color)。 label更改标题文本后面背景的颜色,但在默认情况下在文本周围留下一个大区域。 *有效,但当然也会改变其他一切。

css treeview gtktreeview pygobject gtk3

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

将DOM XmlElement反序列化为.NET对象

我有一个将数据作为XML DOM模型处理的现有应用程序。我现在想将该数据作为C#对象的集合传递给另一个子系统。

据我所知,我可以将DOM表示序列化为MemoryStream并使用XmlSerializer反序列化流。当然有没有一种方法可以直接处理DOM表示,而无需中间的文本表示?但是我找不到。

如何在DOM表示形式上使用System.Xml.Serialization?

.net c# xml dom xml-deserialization

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

PostgreSQL 继承表和插入触发器

我正在尝试按照此处的建议创建一个用于存储时间序列数据的垂直分区表。

到目前为止,我的架构如下所示:

CREATE TABLE events 
(
     topic text, 
     t timestamp, 
     value integer, 
     primary key(topic, t)
);

CREATE TABLE events_2014 
(
     primary key (topic, t), 
     check (t between '2014-01-01' and '2015-01-01') 
) INHERITS (events);
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试创建一个INSTEAD OF INSERT触发器,以便可以在events表中插入事件,并且该行将最终出现在正确的子表中。但是文档说INSTEAD OF INSERT触发器只能在视图上创建,不能在表(或子表)上创建:

CREATE OR REPLACE FUNCTION insert_events () RETURNS TRIGGER AS $insert_events$ BEGIN
  IF new.t between '2014-01-01' and '2015-01-01' THEN
    INSERT INTO events_2014 SELECT new.*;
  ...
  END IF
  RETURN NULL;
END;
$insert_events$ LANGUAGE PLPGSQL;

CREATE TRIGGER …
Run Code Online (Sandbox Code Playgroud)

sql postgresql partitioning database-trigger

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

类模板成员的特化

我有一个标题包含一个具有模板成员的类和该成员的一些特化:

#include <iostream>
class Foo {
public:
    template<typename T>
    void print(const T& t) {
        std::cout << t << std::endl;
    }
};

template<>
void Foo::print<int>(const int& t) {
    std::cout << t << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

此标头包含在多个源文件中.

如果我将专门化放在类定义中,那么GCC会抱怨:

error: explicit specialization in non-namespace scope ‘class Foo’
Run Code Online (Sandbox Code Playgroud)

但是如果我在类定义之外移动专门化,那么VC++会抱怨多重定义的符号.

什么是这样做的正确方法,两个编译器都会满意?

c++ templates template-specialization

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

临时清除tty

许多命令(例如watch、less)能够暂时清除 tty 以全屏显示信息,然后当命令退出时恢复原始 tty 内容。

有没有办法在 bash 脚本中实现这一目标?

linux bash scripting tty

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

select 语句能保证通道选择的顺序吗?

继此答案之后,如果一个 goroutine 在两个通道上进行选择,是否可以保证以与发送通道相同的顺序选择通道?我对发件人是单线程的情况特别感兴趣。

例如,是否保证此代码始终产生相同的输出:

package main

import (
  "fmt"
  "time"
)

var x, y chan int

func worker() {
  for {
    select {
    case v := <- x:
      fmt.Println(v)
    case v := <- y:
      fmt.Println(v)
    }
  }
}

func main() {
  x = make(chan int)
  y = make(chan int)
  go worker()
  x <- 1
  y <- 2
  <- time.After(1 * time.Second)
}
Run Code Online (Sandbox Code Playgroud)

我的实验似乎表明,这对于无缓冲通道是有保证的,如图所示,但对于缓冲通道则不能保证。有人可以确认吗?

channel go goroutine

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

有没有办法在无限时间内询问 time.After() ?

有没有办法要求time.After()无限量的时间?

动机:我有一个服务,调用者可以从它请求消息,并有一个可选的超时。这样做的明显方法是:

func service(timeout *time.Duration) SomeType {
    var timeout_value time.Duration
    if timeout != nil {
        timeout_value = *timeout
    } else {
        timeout_value = time.Forever /* or something */
    }

    select {
    case value <- some_channel:
        return value
    case <- time.After(timeout_value):
        return nil
    }
}
Run Code Online (Sandbox Code Playgroud)

除了我不知道有没有办法说time.Forever。

time go

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