我有一个启动 python 脚本的 PHP 页面,但 PHP 页面会挂起,直到脚本完成。有没有办法运行脚本而不使其挂起?
PHP代码
该问题发生在alarm_on 的情况下。所有其他情况都工作正常。
<?php
session_start();
if(isset($_COOKIE['userME']))
echo "Hello, ".$_COOKIE['userME'].'<br>';
if(isset($_SESSION['UserData']['Username']) || $passed )// or $logins[$Username] == $Password)
{
if (isset($_POST['submit'])) {
switch ($_POST['submit']) {
case 'room_light':
echo shell_exec("sudo python /home/pi/Desktop/PiControl/room_light.py");
break;
case 'alarm_on':
echo "alarm started";
shell_exec("nohup sudo python /home/pi/Desktop/PiControl/motion_sensor.py &");
echo "alarm on";
break;
case 'alarm_off':
echo "alarm off";
echo shell_exec("sudo pkill -f motion_sensor.py");
break;
}
}
?>
<form method="post">
<input type="submit" name="submit" value="room_light">
<input type="submit" name="submit" value="alarm_on">
<input type="submit" name="submit" value="alarm_off"> …Run Code Online (Sandbox Code Playgroud) 我有这个为我的数组工作:
my_arr.delete_if{|x| x=~/achievement\..*?/}
Run Code Online (Sandbox Code Playgroud)
它删除数组中与模式匹配的所有字符串achievement..是否有类似的单行反向(只接受包含的字符串achievement.?
我试图匹配mathematica表达式1+2和1*2/3....无穷大.有人可以解释为什么我的正则表达式匹配下面的最后一个案例,以及如何修复它以便它只匹配有效的表达式(可能永远延伸)?
perms=["12+2*4","2+2","-2+","12+34-"]
perms.each do |line|
puts "#{line}=#{eval(line)}" if line =~ /^\d+([+-\/*]\d+){1,}/
end
Run Code Online (Sandbox Code Playgroud)
我期望输出为:
12+2*4=20
2+2=4
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取单元格值为1的每一行的列名。但是,我的尝试无效,有人可以提供建议吗?
library(permute)
set.seed(42)
exampledf<- data.frame(allPerms(c(1,2,3,4)))
exampledf<-head(exampledf)
Run Code Online (Sandbox Code Playgroud)
我尝试了这个:
apply(exampledf,2,function(x){
ll<-x[1]==1
which(ll==T)
})
Run Code Online (Sandbox Code Playgroud)
数据集
X1 X2 X3 X4
1 1 2 4 3
2 1 3 2 4
3 1 3 4 2
4 1 4 2 3
5 1 4 3 2
6 2 1 3 4
Run Code Online (Sandbox Code Playgroud)
我的目标:
X1
X1
X1
X1
X1
X2
Run Code Online (Sandbox Code Playgroud) 我试图将列的所有排列作为数据帧传递给函数,但我无法让我的代码正常工作。有人有什么建议吗?
require(combinat)
indicators<-data.frame(a=c(1),b=c(2),c=c(3),d=c(4))
cols<-lapply(1:dim(indicators)[2],function(x)rbind(t(permn(1:(dim(indicators)[2]-x)))))
cols[[2]]
temp<-t(apply(cols[[2]],1,function(x){}))
Run Code Online (Sandbox Code Playgroud)
目标
dataframe containing col:
1
2
3
4
1,2
1,3
1,4
2,3
2,4
....
Run Code Online (Sandbox Code Playgroud)
我的功能:
#takes in dataframe of columns
blackBox<-function(x){}
Run Code Online (Sandbox Code Playgroud)
因为我最初的解释不够清楚:我试图将每种情况下返回的列放入数据帧中,以便我可以对数据做一些事情。
#testing only with the first 12 values because otherwise it takes forever
lapply(v1[1:12],function(x){
colsCombo<-indicators[,c(eval(parse(text=x)))]
colnames(colsCombo)
})
Run Code Online (Sandbox Code Playgroud) 我试图在bash脚本中自动填充文件夹名称.如果我输入完整的文件夹名称一切正常,但我不知道如何自动完成名称.有任何想法吗?
repo() {
cd ~/Desktop/_REPOS/$1
}
Run Code Online (Sandbox Code Playgroud)
我试着阅读这篇SO帖子的想法,但很快就迷路了,因为我还是很吵.
GOAL(上面的repo函数包含在我的bashrc中):
>ls ~/Desktop/_REPOS/
folder1
hellofolder
stackstuff
>repo sta[TAB] fills in as: repo stackstuff
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写我的第一个c#程序,我不能继续得到下面的错误.有人可以解释为什么我收到此错误?声明时,一切都有一种类型,空隙来自哪里?我在https://repl.it/languages/csharp上编写代码,如果它很重要的话.
using System;
using System.Linq;
using System.Collections.Generic;
class MainClass {
public static void Main (string[] args) {
List<string> mylist = new List<string>() { "2","1","2","3","3","4" };
mylist=mylist.Sort();
foreach(var item in mylist)
{
Console.Write(item.ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
Run Code Online (Sandbox Code Playgroud)Cannot implicitly convert type `void' to `System.Collections.Generic.List<string>'
我试图测试一些使用实体框架的代码,但我无法弄清楚如何从单独的 MSTest 项目中引用 EF 上下文类。两个项目都在同一个解决方案中。
无法将 lambda 表达式转换为类型“DbContextOptions”,因为它不是委托类型
在我的测试用例中:
[TestClass]
public class GreenCardUserTest
{
[TestMethod]
public void TestAddUser()
{
// REFERENCE TO OTHER PROJECT. WORKS FINE
AppUserViewModel a = new AppUserViewModel();
//LIKELY INCORRECT attempt to duplicate code from Startup.cs in other project
using (GreenCardContext _gc = new GreenCardContext(options => options.UseSqlServer(Configuration.GetConnectionString("MyConnection"))))
{
new GCLandingUserModel().AddUser(a,_gc);
}
}
}
Run Code Online (Sandbox Code Playgroud)
摘自主项目 Startup.cs(工作正常):
services.AddDbContext<GreenCardContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MyConnection")));
Run Code Online (Sandbox Code Playgroud) 我(据我所知)在我的本地存储库中没有 .gitignore 文件设置,但是当我提交并推送时(即使在执行 git add --all 之后),存储库不会推送 .bat 文件(以及其他几个文件)文件类型)。我在 Windows 上使用 Git bash。
我正在使用的命令:
git add --all
git commit -m "next commit here" .
git push -u origin master
git pull
Run Code Online (Sandbox Code Playgroud) 我遇到麻烦(可能因为我是dplyr的新手)试图重新编码值.我试图按编号拆分参与者,然后将日期值重新编码为1,依此类推.目前是一个月中的某一天....我的目标是让它成为实验的一天.注意:参与者列出的第一个日期应为第1天.
我的尝试:
df<-data.frame(participant_number=c(1,1,1,2,2),month=c(3,3,4,3,3),day=c(6,6,1,7,8))
res<-setDT(df) %>% group_by(participant_number) %>% day
Run Code Online (Sandbox Code Playgroud)
我的目标:
participant_number day month recoded_day
1 6 3 1
1 6 3 1
1 1 4 2
2 7 3 1
2 8 3 2
Run Code Online (Sandbox Code Playgroud)