我有很多理由使用Intellij IDEA而不是eclipse,但现在我必须在我的团队中使用eclipse.所以我们都知道,Intellij IDEA的键盘图非常方便,它甚至支持eclipse的keymaps.有任何工具或插件能够将Intellij IDEA的键映射导入eclipse吗?
eclipse eclipse-plugin keyboard-shortcuts shortcut intellij-idea
我需要获取 a 的最后四列数据ndarray,大多数情况下代码arr[:, -4:]都可以,但如果数组只有一维,这将抛出IndexError: too many indices。
我的数据是 get with arr = np.loadtxt('test.txt'),所以如果test.txt有不止一行,比如
0 1 2 3 4
0 10 20 30 40
Run Code Online (Sandbox Code Playgroud)
一切都很好,但如果test.txt只有一行,比如
0 1 2 3 4
Run Code Online (Sandbox Code Playgroud)
这会返回array([ 0, 1, 2, 3, 4]),然后arr[:, -4:]会抛出异常,因为它应该是arr[-4:],那么如何让loadtxt返回array([[ 0, 1, 2, 3, 4]])呢?
我想要这样的东西:
old_recordnew_recordold_record我写这样的代码:
ret = nil
// First, Find the obj
obj := &orm.QuerySetObj{}
err2 := this.querySetCollection.With(session).Find(objKey).One(obj)
if nil != err2 {
this.logger.Println("Error find obj")
return
}
ret = obj
// Then, update this obj
obj.updateTime = time.Now().Unix()
err3 := this.querySetCollection.With(session).Upsert(objKey, obj)
if nil != err3 {
this.logger.Println("Error update obj")
return
}
return
Run Code Online (Sandbox Code Playgroud)
但是,我想find和update应该是一个atomic操作,所以我的代码是不是安全.
我怎么能在原子操作中做到这一点
我想声明一个这样的类型:
interface DependData {[key: string]: string};
Run Code Online (Sandbox Code Playgroud)
但是有这样的错误:
Statements are not allowed in ambient contexts
Run Code Online (Sandbox Code Playgroud) 我好奇的存储成本map和slice,所以我写了一个程序来比较大小.我得到了内存大小unsafe.Sizeof(s),但显然是错误的,因为当我改变大小时,输出是相同的.
func getSlice(size int) []int {
t := time.Now()
s := make([]int, size*2)
for i := 0; i < size; i++ {
index := i << 1
s[index] = i
s[index+1] = i
}
fmt.Println("slice time cost: ", time.Since(t))
return s
}
func getMap(size int) map[int]int {
t := time.Now()
m := make(map[int]int, size)
for i := 0; i < size; i++ {
m[i] = i
}
fmt.Println("map time cost: ", time.Since(t))
return m …Run Code Online (Sandbox Code Playgroud) 我有一个koa路由器,我需要调用一个 api 来异步返回结果。这意味着我无法立即得到我的结果,API 会callback url在正常时调用我的。但是现在我必须像同步 api 一样使用它,这意味着我必须等到回调 url 被调用。
我的路由器是这样的:
router.post("/voice", async (ctx, next) => {
// call a API here
const params = {
data: "xxx",
callback_url: "http//myhost/ret_callback",
};
const req = new Request("http://xxx/api", {
method: "POST",
body: JSON.stringify(params),
});
const resp = await fetch(req);
const data = await resp.json();
// data here is not the result I want, this api just return a task id, this api will call my url back
const taskid …Run Code Online (Sandbox Code Playgroud) 我在我的ubuntu机器上安装了一个gem :
gem install tokyocabinet -v '1.29.1'
Run Code Online (Sandbox Code Playgroud)
然后我得到一些错误:
ERROR: Error installing tokyocabinet:
ERROR: Failed to build gem native extension.
$HOME/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150409-9995-bkqyu2.rb extconf.rb
setting variables ...
$CFLAGS = -I. -I/usr/local/include -Wall $(cflags) -fPIC -O2
$LDFLAGS = -L. -fstack-protector -rdynamic -Wl,-export-dynamic -L. -L/usr/local/lib
$libs = -ltokyocabinet -lz -lbz2 -lpthread -lm -lc
checking for tcutil.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more …Run Code Online (Sandbox Code Playgroud) 我想要upsert一个记录列表,所以我有两个选择,一个只使用一个会话,另一个复制每个记录的会话.所以,正如我的观点,第一种方法可能比第二种方法慢,但是第一种方法会导致会话创建太多吗?
1.使用一次
func (this *CvStoreServiceImpl) SetCvJobItemMeasureList(accessToken *base_datatype.ServiceAccessToken, versionPolicy string, jobItemList []*cv_common_type.CvJobItemMeasure) (err error) {
session := this.session.Clone()
defer session.Close()
for _, jobItem := range jobItemList {
objKey := &orm.ItemIdKey{
VersionName: versionPolicy, //XXX
ItemId: jobItem.ItemId,
}
obj := orm.ConvertToCvJobItemMeasureObj(versionPolicy, jobItem)
_, err2 := this.jobMeasureCollection.With(session).Upsert(objKey, obj)
if nil != err2 {
err = &common_error.NamedError{err2.Error()}
this.logger.Println(err2.Error())
}
}
return
}
Run Code Online (Sandbox Code Playgroud)
2.每个记录的复制会话
func (this *CvStoreServiceImpl) SetCvJobItemMeasure(accessToken *base_datatype.ServiceAccessToken, versionPolicy string, jobItem *cv_common_type.CvJobItemMeasure) (err error) {
session := this.session.Clone()
defer session.Close()
objKey := &orm.ItemIdKey{ …Run Code Online (Sandbox Code Playgroud) 我使用的Typescript开发React,我想用childContextTypes在Component:
import * as React from "react";
interface Props {
foo: string;
bar: string;
}
export class Parent extends React.Component<Props, {}> {
constructor(props:Props, context:any) {
super(props, context);
}
static childContextTypes = {
foo: React.PropTypes.string.isRequired,
bar: React.PropTypes.string.isRequired,
}
getChildContext() {
return this.props;
}
render() {
return <Child />
}
}
class Child extends React.Component<{}, {}> {
context: any;
static contextTypes = {
foo: React.PropTypes.string.isRequired,
bar: React.PropTypes.string.isRequired
}
render() {
return <div>Hello, {this.context.foo}, {this.context.bar}</div>; …Run Code Online (Sandbox Code Playgroud) 我想做的是
.txt扩展名的文件.dat文件它可以这样做:
for f in `find . -type f -name "*.txt"`; do cp $f ${f%.txt}.dat; done
Run Code Online (Sandbox Code Playgroud)
我想用 xargs 做到这一点,我试过这个:
find . -type f -name "*.txt" | xargs -i cp {} ${{}%.txt}.dat
Run Code Online (Sandbox Code Playgroud)
我会像这样出错:
bad substitution
Run Code Online (Sandbox Code Playgroud)
关于这个,我有以下问题:
xargs当for loop一件件事情做的时候,事情会并行吗?