我有一小段代码检查IP地址的有效性:
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
stat=1
else
stat=0
fi
fi
return $stat
}
Run Code Online (Sandbox Code Playgroud)
但我在bash条件中的使用存在问题.我已经尝试了很多技术来测试它的返回值,但是大多数技术都失败了.
if [[ !$(valid_ip $IP) ]]; then
if [[ $(valid_ip IP) -eq 1 ]]; then
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我该怎么办?
编辑
根据你的建议我使用了类似的东西:
if valid_ip "$IP" ; then
... do stuff
else
perr "IP: \"$IP\" is not a …
Run Code Online (Sandbox Code Playgroud) 我找到了以下2段代码:
http://en.cppreference.com/w/cpp/thread/lock
void assign_lunch_partner(Employee &e1, Employee &e2)
{
// use std::lock to acquire two locks without worrying about
// other calls to assign_lunch_partner deadlocking us
{
// m is the std::mutex field
std::unique_lock<std::mutex> lk1(e1.m, std::defer_lock);
std::unique_lock<std::mutex> lk2(e2.m, std::defer_lock);
std::lock(lk1, lk2);
// ...
}
}
Run Code Online (Sandbox Code Playgroud)http://www.amazon.com/C-Concurrency-Action-Practical-Multithreading/dp/1933988770
void swap(X& lhs, X&rhs){
if(&lhs == &rhs)
return;
// m is the std::mutex field
std::lock(lhs.m, rhs.m);
std::lock_guard<std::mutex> lock_a(lhs.m, std::adopt_lock);
std::lock_guard<std::mutex> lock_b(rhs.m, std::adopt_lock);
swap(lhs.some_detail, rhs.some_detail);
}
Run Code Online (Sandbox Code Playgroud)我想问一下使用2个版本中的任何一个有什么区别和后果?(先锁定或首先创建std::lock_guard
或std::unique_lock
?)
我有一个非常简单的类,我想用它作为另一个的子类.但当我把它的代码放在父类的时候,我得到:
非静态变量,不能从静态上下文引用
另一方面,当我把子GenTest
类的类代码放在"父级"类代码之外时 - JavaApp1
我没有得到这个错误.
public class JavaApp1 {
class GenTest {
@Deprecated
void oldFunction() {
System.out.println("don't use that");
}
void newFunction() {
System.out.println("That's ok.");
}
}
public static void main(String[] args) {
GenTest x = new GenTest();
x.oldFunction();
x.newFunction();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我正在尝试使用内置Sum()
函数来汇总浮点数列表,但我一直收到此错误:
错误CS1061:'System.Collections.Generic.List'不包含'Sum'的定义,并且没有可以找到接受类型'System.Collections.Generic.List'的第一个参数的扩展方法'Sum'(你是否遗漏了) using指令或汇编引用?)(CS1061)
我有
using System.Collections;
using System.Collections.Generic;
Run Code Online (Sandbox Code Playgroud)
在文件的开头:
代码:
List<float> x = new List<float>();
x.add(5.0f);
//..
float f = x.Sum();
Run Code Online (Sandbox Code Playgroud) 我已经成功部署了以下集群:
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 30000
listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
protocol: tcp # Optional, defaults to tcp
- role: worker
Run Code Online (Sandbox Code Playgroud)
然后是一个非常简单的部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hostname-deployment
labels:
app: hostname
spec:
replicas: 2
selector:
matchLabels:
app: hostname
template:
metadata:
labels:
app: hostname
spec:
containers:
- name: hostname
image: hostname:0.1
ports:
- containerPort: 80
Run Code Online (Sandbox Code Playgroud)
和一项服务:
apiVersion: v1
kind: Service
metadata:
name: hostname-service
spec: …
Run Code Online (Sandbox Code Playgroud) <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#000"
android:centerColor="#00000000"
android:endColor="#000"
android:angle="270"
android:dither="true"
/>
</shape>
Run Code Online (Sandbox Code Playgroud)
这是我尝试的代码,但它最终成为纯黑色.
我有一个带有电子邮件地址的大文件,我想知道它们中有多少是这个文件.如何使用Windows命令行执行此操作?
我试过这个,但它只打印匹配的行.(顺便说一句:所有电子邮件都包含在一行中)
findstr /c:"@" mail.txt
我想获得相对于父级或DOM中任何其他元素的鼠标坐标,this
但我不断得到
Uncaught TypeError: Object [object Array] has no method 'getBoundingClientRect' d3.v3.min.js:1
H d3.v3.min.js:1
vo.mouse d3.v3.min.js:3
(anonymous function) index.html:291
(anonymous function)
Run Code Online (Sandbox Code Playgroud)
我的代码:
.on("mouseup", function(d){
var th = d3.select( this );
var coordinates = [0, 0];
coordinates = d3.mouse( d3.select("body") );
console.log( coordinates[1] );
console.log( window );
//th.attr("cy", d3.mouse),
//d.newY = th.attr("cy");
console.log(d);
});
Run Code Online (Sandbox Code Playgroud)
据我所知,我只能得到相对于我附加.on("mouseup", ...)
事件监听器的元素的鼠标坐标.
有没有办法让这些坐标相对于DOM中的其他元素?
我想要一个带有指针成员变量的类.该指针应指向可以堆栈分配或堆分配的对象.但是,此指针不应具有任何所有权.换句话说,当指针超出范围时,根本不应该调用delete.我认为原始指针可以解决问题...但是,我不确定是否有比原始指针更好的C++ 11方法?
例:
class foo{
public:
bar* pntr
};
int main(){
bar a;
foo b;
b.pntr=&a;
}
Run Code Online (Sandbox Code Playgroud) 我的笔记本电脑上有个人小git存储库.我刚刚提交了更改并检查了我没有任何提交 - 每个已分阶段和已修改的文件已被提交.
之后我将这个仓库中的所有文件复制到另一个位置并繁荣!我有未提交的更改.
我相信我错过了一些基本的git规则.任何人都可以建议我吗?
c++ ×2
c++11 ×2
android ×1
bash ×1
c# ×1
command-line ×1
commit ×1
conditional ×1
coordinates ×1
copy ×1
copy-paste ×1
d3.js ×1
docker ×1
file ×1
find ×1
git ×1
gradient ×1
java ×1
javascript ×1
kind ×1
kubernetes ×1
list ×1
locking ×1
mouse ×1
mutex ×1
non-static ×1
pointers ×1
port ×1
repository ×1
return-value ×1
shape ×1
shell ×1
string ×1
subclass ×1
sum ×1
windows ×1