我正在尝试创建一个PHP
聊天,所以我server.php
在终端启动服务器,这是听取client
连接:
<?php
function chat_leave( $sock, $chat_id = 0 )
{
if( $chat_room_id[ $chat_id ] )
{
unset( $chat_room_id[ $chat_id ] );
return true;
}
socket_close($sock);
return false;
}
function client( $input )
{
/*
Simple php udp socket client
*/
//Reduce errors
error_reporting(~E_WARNING);
$server = '127.0.0.1';
$port = 9999;
if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
//Communication loop
while(1)
{
//Send the …
Run Code Online (Sandbox Code Playgroud) 我是Java map
和filters
8中的新用户.我目前正在使用Spark ML
库来进行一些ML算法.我有以下代码:
// return a list of `Points`.
List<Points> points = getPoints();
List<LabeledPoint> labeledPoints = points.stream()
.map(point -> getLabeledPoint(point))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
如果数据正确,则函数getLabeledPoint(Point point)
返回new,LabeledPoint
否则返回null.我怎样才能过滤(删除)null
LabeledPoint
对象map
?
我试图用Salt-Api
,所以我创建了一个salt-api.conf
在/etc/salt/master.d/
如下:
external_auth:
pam:
saltuser:
- .*
- '@wheel' # to allow access to all wheel modules
- '@runner' # to allow access to all runner modules
- '@jobs' # to allow access to the jobs runner and/or wheel module
rest_cherrypy:
port: 8000
ssl_crt: /etc/pki/tls/certs/localhost.crt
ssl_key: /etc/pki/tls/certs/localhost.key
disable_ssl: True
webhook_disable_auth: True
webhook_url: /hook
Run Code Online (Sandbox Code Playgroud)
用户输入/etc/salt/master
设置为user: root
.因此,当我尝试使用pam
本地身份验证时,它可以工作:
sudo salt -a pam '*' test.ping
username: saltuser
password: saltuser
minion:
True
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用curl时,它会失败:
curl …
Run Code Online (Sandbox Code Playgroud) 我的构造函数中有以下代码块(这只是一个示例,问题不在于split
,而是抛出一个通用异常.此外,不能使用Boost库.
Transfer::Transfer(const string &dest){
try{
struct stat st;
char * token;
std::string path(PATH_SEPARATOR) // if it is \ or / this macro will solve it
token = strtok((char*)dest.c_str(), PATH_SEPARATOR) //
while(token != NULL){
path += token;
if(stat(path.c_str(), &st) != 0){
if(mkdir(path.c_str()) != 0){
std:string msg("Error creating the directory\n");
throw exception // here is where this question lies
}
}
token = strtok(NULL, PATH_SEPARATOR);
path += PATH_SEPARATOR;
}
}catch(std::exception &e){
//catch an exception which kills …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在python中评估以下函数:
f(x) = (1 + cos(x))^(1/3)
def eval( i ):
return math.pow( (1 + math.cos( i )), 1/3)
Run Code Online (Sandbox Code Playgroud)
它为什么总是归还我1
?我试图计算Right
和Left
积分的近似,并且后者的申请Simpson's Rule
,但Python
似乎不喜欢这样的表达.救命?
*完整代码*
import math
min = 0
max = math.pi / 2
n = 4
delta = ( min + max ) / n
def eval( i ):
return math.pow( (1 + math.cos( i )), 1/3)
def right( ):
R = 0
for i in range(1, n+1):
R += eval( i …
Run Code Online (Sandbox Code Playgroud) 我正在为我正在开发的项目使用Fullcalendar ...我只剩下一个要实现的功能,即将现有事件从其原始位置拖动到另一个时间或日期.我想知道如何获取当前对象信息(标题,新开始时间,旧开始时间,id,url等),因此我可以使用更新的信息更新数据库... Fullcalendar对象中的哪个属性我用?我实施了这个drop
属性;
drop : function(date, allDay) {
// retrieve the dropped element's stored event object
var originalEventObject = $(this).data('eventObject');
// we need to copy it, so that multiple events don't
// have a reference object
var copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
// render the event on the calendar
// the last `true` argument determines if the event `sticks`
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
// if …
Run Code Online (Sandbox Code Playgroud) 我在一个新手Ansible
,所以我写了一个小程序ansible安装一些软件包的依赖关系为系统我写:
---
- hosts: all
user: root
tasks:
- name: install requirements
apt: name={{item}} state=latest update_cache=true
with_items:
- gcc
- python-dev
- python-setuptools
- python-software-properties
Run Code Online (Sandbox Code Playgroud)
当前支持的环境是Ubuntu
、Red Hat
和Mac OS X
。该剧本的当前编写方式仅适用于Ubuntu (Debian)
. 我怎样才能根据操作系统执行那部分代码?为Ubuntu
它apt
,为Red Hat
它yum
,为Mac OS X
brew
。
我正在解析以下AWS
成本实例表:
m1.small 1 1 1.7 1 x 160 $0.044 per Hour
m1.medium 1 2 3.75 1 x 410 $0.087 per Hour
m1.large 2 4 7.5 2 x 420 $0.175 per Hour
m1.xlarge 4 8 15 4 x 420 $0.35 per Hour
Run Code Online (Sandbox Code Playgroud)
有一个包含这些费用的文件:
input = new Scanner(file);
String[] values;
while (input.hasNextLine()) {
String line = input.nextLine();
values = line.split("\\s+"); // <-- not what I want...
for (String v : values)
System.out.println(v);
}
Run Code Online (Sandbox Code Playgroud)
然而,这给了我:
m1.small
1
1
1.7
1
x …
Run Code Online (Sandbox Code Playgroud) 我正在使用Docker-py API来处理和操作Docker
容器.在该函数中API
,put_archive()
函数期望该data
字段以字节为单位.所以,使用tarfile
我有的库:
import tarfile
import io
container = client.create_container(image="myimage", command="/bin/bash")
source = "~/.ssh/id_rsa.pub"
tarfile = create_tar_file(path=source, name="keys.tar")
# tarfile = "keys.tar"
# How can I read the tar file was a BytesIO() object?
data = io.BytesIO()
client.put_archive(container=container, path="/tmp", data=data)
Run Code Online (Sandbox Code Playgroud)
API说:
put_archive
(container
,path
,data
)使用tar存档作为源在现有容器中插入文件或文件夹.
参数:
container(str) - 将提取文件的容器.
path(str) - 将提取文件的容器内的路径.必须存在.
data( …
我Apache Spark
在AWS中创建了一个3节点(1个主节点,2个工作节点)集群.我可以从主服务器向集群提交作业,但是我无法远程工作.
/* SimpleApp.scala */
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
object SimpleApp {
def main(args: Array[String]) {
val logFile = "/usr/local/spark/README.md" // Should be some file on your system
val conf = new SparkConf().setAppName("Simple Application").setMaster("spark://ec2-54-245-111-320.compute-1.amazonaws.com:7077")
val sc = new SparkContext(conf)
val logData = sc.textFile(logFile, 2).cache()
val numAs = logData.filter(line => line.contains("a")).count()
val numBs = logData.filter(line => line.contains("b")).count()
println(s"Lines with a: $numAs, Lines with b: $numBs")
sc.stop()
}
}
Run Code Online (Sandbox Code Playgroud)
我可以从大师那里看到:
Spark Master at spark://ip-171-13-22-125.ec2.internal:7077
URL: spark://ip-171-13-22-125.ec2.internal:7077
REST URL: …
Run Code Online (Sandbox Code Playgroud) java ×4
python ×4
ajax ×1
amazon-ec2 ×1
ansible ×1
apache-spark ×1
byte ×1
c++ ×1
filter ×1
fullcalendar ×1
hadoop ×1
html ×1
java-8 ×1
java-stream ×1
javascript ×1
jquery ×1
json ×1
macos ×1
package ×1
parsing ×1
php ×1
regex ×1
salt-stack ×1
scala ×1
string ×1
tar ×1
ubuntu ×1