我正在使用这个:
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Run Code Online (Sandbox Code Playgroud)
我有一个如下脚本:
#!/bin/bash
e=2
function test1() {
e=4
echo "hello"
}
test1
echo "$e"
Run Code Online (Sandbox Code Playgroud)
哪个回报:
hello
4
Run Code Online (Sandbox Code Playgroud)
但是如果我将函数的结果赋给变量,e
则不修改全局变量:
#!/bin/bash
e=2
function test1() {
e=4
echo "hello"
}
ret=$(test1)
echo "$ret"
echo "$e"
Run Code Online (Sandbox Code Playgroud)
返回:
hello
2
Run Code Online (Sandbox Code Playgroud)
我听说过在这种情况下使用eval,所以我这样做test1
:
eval 'e=4'
Run Code Online (Sandbox Code Playgroud)
但结果相同.
你能解释一下为什么不修改它吗?我怎么能保存test1
函数的回声ret
并修改全局变量呢?
我有以下代码来测试一些最流行的sklearn python库的ML算法:
import numpy as np
from sklearn import metrics, svm
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
trainingData = np.array([ [2.3, 4.3, 2.5], [1.3, 5.2, 5.2], [3.3, 2.9, 0.8], [3.1, 4.3, 4.0] ])
trainingScores = np.array( [3.4, 7.5, 4.5, 1.6] )
predictionData = np.array([ [2.5, 2.4, 2.7], [2.7, 3.2, 1.2] ])
clf = LinearRegression()
clf.fit(trainingData, trainingScores)
print("LinearRegression")
print(clf.predict(predictionData)) …
Run Code Online (Sandbox Code Playgroud) 我正在使用令人敬畏的插件Chart.js,我正试图在每个百分比内找到显示标签的方式.所以我用Google搜索了,我发现了这个问题:https://github.com/nnnick/Chart.js/pull/35
我做了一个简单的小提琴测试它,但不起作用:http://jsfiddle.net/marianico2/7ktug/1/
这是内容:
HTML
<canvas id="canvas" height="450" width="450"></canvas>
Run Code Online (Sandbox Code Playgroud)
JS
$(document).ready(function () {
var pieData = [{
value: 30,
color: "#F38630",
label: 'HELLO',
labelColor: 'black',
labelFontSize: '16'
}, {
value: 50,
color: "#E0E4CC"
}, {
value: 100,
color: "#69D2E7"
}];
var myPie = new Chart(document.getElementById("canvas").getContext("2d")).Pie(pieData, {
labelAlign: 'center'
});
});
Run Code Online (Sandbox Code Playgroud)
此外,我想知道如何为每个部分显示标签,但在图表之外.由一条线连接.和highcharts.js的图表一样.
顺便说一句,如果你推荐我一个html5图表替代品,包括我上面提到的选项,我会很高兴.我听说过flot插件,但我担心不支持动画......
如果您需要更多信息,请告诉我,我会编辑帖子.
我正在使用令人敬畏的select2控件.
我正在尝试用内容清理和禁用select2,所以我这样做:
$("#select2id").empty();
$("#select2id").select2("disable");
Run Code Online (Sandbox Code Playgroud)
好的,它可以工作,但如果我选择了一个值,所有项目都被删除,控件将被禁用,但仍会显示所选的值.我想清除所有内容,以便显示占位符.这是我做的一个例子,你可以看到这个问题:http://jsfiddle.net/BSEXM/
HTML:
<select id="sel" data-placeholder="This is my placeholder">
<option></option>
<option value="a">hello</option>
<option value="b">all</option>
<option value="c">stack</option>
<option value="c">overflow</option>
</select>
<br>
<button id="pres">Disable and clear</button>
<button id="ena">Enable</button>
Run Code Online (Sandbox Code Playgroud)
码:
$(document).ready(function () {
$("#sel").select2();
$("#pres").click(function () {
$("#sel").empty();
$("#sel").select2("disable");
});
$("#ena").click(function () {
$("#sel").select2("enable");
});
});
Run Code Online (Sandbox Code Playgroud)
CSS:
#sel {
margin: 20px;
}
Run Code Online (Sandbox Code Playgroud)
你对此有什么想法或建议吗?
根据这个答案,我想在一个类中构建一个异步websoket客户端,该类将从另一个文件导入:
#!/usr/bin/env python3
import sys, json
import asyncio
from websockets import connect
class EchoWebsocket:
def __await__(self):
# see: https://stackoverflow.com/a/33420721/1113207
return self._async_init().__await__()
async def _async_init(self):
self._conn = connect('wss://ws.binaryws.com/websockets/v3')
self.websocket = await self._conn.__aenter__()
return self
async def close(self):
await self._conn.__aexit__(*sys.exc_info())
async def send(self, message):
await self.websocket.send(message)
async def receive(self):
return await self.websocket.recv()
class mtest:
async def start(self):
try:
self.wws = await EchoWebsocket()
finally:
await self.wws.close()
async def get_ticks(self):
await self.wws.send(json.dumps({'ticks_history': 'R_50', 'end': 'latest', 'count': 1}))
return await self.wws.receive()
if __name__ …
Run Code Online (Sandbox Code Playgroud) 我需要构建一个多行选择控件.所有<option>
的地方文本的宽度大于300像素(例如)成为有必要的行不超过提到的上限.
这些图像不言自明:
首先我尝试了这个,但是没有用.
<html>
<head>
<style>
option{
width: 100px;
white-space: wrap;
}
</style>
</head>
<body>
<select>
<option>I'm short</option>
<option>I'm medium text</option>
<option>I'm a very very very very very very very very very long text</option>
</select>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我正在使用bootstrap框架,我想也许我可以使用下拉控件来获取结果.我已经尝试设置max-width CSS属性,但它也不起作用......
我怎样才能做到这一点?
我有两个没有分拣的文件有一些共同点.
FILE1.TXT
Z
B
A
H
L
Run Code Online (Sandbox Code Playgroud)
FILE2.TXT
S
L
W
Q
A
Run Code Online (Sandbox Code Playgroud)
我用来删除公共行的方式如下:
sort -u file1.txt > file1_sorted.txt
sort -u file2.txt > file2_sorted.txt
comm -23 file1_sorted.txt file2_sorted.txt > file_final.txt
Run Code Online (Sandbox Code Playgroud)
输出:
B
H
Z
Run Code Online (Sandbox Code Playgroud)
问题是我想保留file1.txt的顺序,我的意思是:
期望的输出:
Z
B
H
Run Code Online (Sandbox Code Playgroud)
我试过的一个解决方案是循环读取file2.txt的所有行:
sed -i '/^${line_file2}$/d' file1.txt
Run Code Online (Sandbox Code Playgroud)
但如果文件很大,性能可能会很糟糕.
我按照以下教程在Cygwin64中安装xgboost python包:
但是当在dmlc-core目录中执行make时,我收到以下错误:
harrison4@mypc ~/xgboost/dmlc-core
$ mingw32-make -j4
g++ -c -O3 -Wall -Wno-unknown-pragmas -Iinclude -std=c++0x -fPIC -DDMLC_USE_HDFS=0 -DDMLC_USE_S3=0 -DDMLC_USE_AZURE=0 -msse2 -o line_split.o src/io/line_split.cc
g++ -c -O3 -Wall -Wno-unknown-pragmas -Iinclude -std=c++0x -fPIC -DDMLC_USE_HDFS=0 -DDMLC_USE_S3=0 -DDMLC_USE_AZURE=0 -msse2 -o recordio_split.o src/io/recordio_split.cc
g++ -c -O3 -Wall -Wno-unknown-pragmas -Iinclude -std=c++0x -fPIC -DDMLC_USE_HDFS=0 -DDMLC_USE_S3=0 -DDMLC_USE_AZURE=0 -msse2 -o input_split_base.o src/io/input_split_base.cc
g++ -c -O3 -Wall -Wno-unknown-pragmas -Iinclude -std=c++0x -fPIC -DDMLC_USE_HDFS=0 -DDMLC_USE_S3=0 -DDMLC_USE_AZURE=0 -msse2 -o io.o src/io.cc
src/io/line_split.cc:1:0: aviso: se descarta -fPIC para el objetivo (todo el código …
Run Code Online (Sandbox Code Playgroud) 我正在使用twitter-bootstrap的进度条控件.
我想垂直对齐它,如下图所示:
我找到了这个帖子,但我担心它现在不起作用了.
所以我这样做:http://tinker.io/e69ff/2
HTML
<br>
<div class="progress vertical">
<div class="bar bar-success" style="width: 70%;"></div>
<div class="bar bar-warning" style="width: 20%;"></div>
<div class="bar bar-danger" style="width: 10%;"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.progress.vertical {
position: relative;
width: 20px;
min-height: 240px;
float: left;
margin-right: 20px;
background: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border: none;
}
Run Code Online (Sandbox Code Playgroud)
你有任何提示或建议吗?如果您需要更多信息,请告诉我,我会编辑帖子.
我正在使用fontawesome,我想添加或删除所选项目的图标.所以我这样做了:http ://jsbin.com/nasixuro/7/edit(感谢@Fares M.)
JS
$(document).ready(function () {
function format_select2_icon(opti) {
if (!opti.id) return opti.text; // optgroup
if ($(opti.element).data('icon') == "1") {
return opti.text + " <i class='fa fa-check'></i>";
} else {
return opti.text;
}
}
$("#sel").select2({
escapeMarkup: function(m) { return m; },
formatResult: format_select2_icon,
formatSelection: format_select2_icon
});
$("#addok").click(function() {
actual_value = $("#sel").find(':selected').text();
if (actual_value.indexOf(" <i class='fa fa-check'></i>") > -1){
alert("asd");
return;
}
newtext = actual_value + " <i class='fa fa-check'></i>";
$("#sel").find(':selected').text(newtext).change();
});
$("#removeok").click(function() {
actual_value= …
Run Code Online (Sandbox Code Playgroud)