小编jop*_*rat的帖子

检查插座是否在bash中关闭?

我有一个指向套接字的文件描述符(下面的示例代码).

exec 3<>/dev/tcp/localhost/9999
echo -e "Some Command\n" >&3
Run Code Online (Sandbox Code Playgroud)

有时该套接字关闭并需要重新打开(重新启动服务器).

如何测试套接字(在这种情况下为fd#3)是否可写?

无论套接字是否已经关闭,回声总是会成功.

sockets linux bash shell

6
推荐指数
1
解决办法
5758
查看次数

seccomp-bpf如何过滤系统调用?

我正在研究seccomp-bpf的实现细节,seccomp-bpf是从3.5版开始引入Linux的syscall过滤机制。我查看了Linux 3.10的kernel / seccomp.c的源代码,并想问一些有关它的问题。

从seccomp.c中,似乎从__secure_computing()中调用seccomp_run_filters()来测试当前进程调用的syscall。但是调查seccomp_run_filters()时,在任何地方都不会使用作​​为参数传递的syscall号。

似乎sk_run_filter()是BPF过滤器机器的实现,但是sk_run_filter()是从seccomp_run_filters()调用的,其中第一个参数(在其上运行过滤器的缓冲区)为NULL。

我的问题是:seccomp_run_filters()如何在不使用参数的情况下过滤系统调用?

以下是seccomp_run_filters()的源代码:

/**
 * seccomp_run_filters - evaluates all seccomp filters against @syscall
 * @syscall: number of the current system call
 *
 * Returns valid seccomp BPF response codes.
 */
static u32 seccomp_run_filters(int syscall)
{
        struct seccomp_filter *f;
        u32 ret = SECCOMP_RET_ALLOW;

        /* Ensure unexpected behavior doesn't result in failing open. */
        if (WARN_ON(current->seccomp.filter == NULL))
                return SECCOMP_RET_KILL;

        /*
         * All filters in the list are evaluated and the lowest BPF return
         * value always …
Run Code Online (Sandbox Code Playgroud)

linux security kernel system-calls seccomp

6
推荐指数
1
解决办法
2234
查看次数

mersenne twister - 有没有办法跳到特定的州?

我对这个问题的正确论坛有点不确定.它介于理论之间.sci./math和编程.

我使用Mersenne-Twister生成伪随机数.现在,从给定的种子开始,我想跳到序列中的第n个数字.

我已经看到了这个:http://www-personal.umich.edu/~wagnerr/MersenneTwister.html,一个方案可能如下:

假设,我只需要来自特定种子s的完整随机序列中的前N个数字. 我将序列分成p个子序列,遍历所有N个数字,并在每个子序列的开头保存随机数生成器的状态向量. 现在要达到第n个数,我将看到n落在第k个子序列中,我将加载该子序列的状态向量并生成m个连续的随机数,其中第k个子序列中的第m个数是与完整序列中的第n个数相同(n = m +(k-1)*N/p).

但状态向量是624 x 4字节长!我想知道是否几乎可以跳转到mersenne-twister生成的序列中的任意元素.

random algorithm mersenne-twister

5
推荐指数
1
解决办法
2581
查看次数

Scala:在运行时获取 mixin 接口

我需要在运行时从给定的类获取所有接口(全部加载在类加载器中)。

例如,如果一个类是这样声明的:

trait B
trait C
trait D    
class A extends B with C with D
Run Code Online (Sandbox Code Playgroud)

我想在运行时获取以下信息:A 依赖于 B、C 和D。java getInterfaces() (或 clapper 库中的interfaces())方法仅给出第一个依赖项,即:A 依赖于 B

有办法实现吗?

我想通过反思,但我不知道如何?

reflection scala mixing traits scala-java-interop

5
推荐指数
1
解决办法
844
查看次数

是否有一些"可自由"的记忆

int main()
{
    char *s1, *sTemp;

    s1 = (char*)malloc(sizeof(char)*7);
    *(s1 + 0) = 'a';
    *(s1 + 1) = 'b';
    *(s1 + 2) = 'c';
    *(s1 + 3) = 'd';
    *(s1 + 4) = 'e';
    *(s1 + 5) = 'f';
    *(s1 + 6) = '\0';

    sTemp = (s1 + 3);

    free(sTemp); // shud delete d onwards. But it doesn't !!

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

你好,

在上面的C中,代码sTemp应指向超出的第3个单元格s1(由'd'占用)所以在调用时free(sTemp)我希望从此位置开始删除某些内容.

(我故意提到' 某事 ',因为我的实验最初的动机是找出free()ing工作的位置)

但是我收到一个SIGABRT在 …

c malloc free pointers memory-management

3
推荐指数
1
解决办法
308
查看次数

在Ubuntu 14.04中Couchdb'init终止于do_boot'错误

我用Ubuntu 14.04安装了couchdb apt-get.

当我尝试运行它时,我收到以下错误:

{"init terminating in do_boot",{{badmatch,{error,{bad_return,{{couch_app,start,[normal,["/etc/couchdb/default.ini","/etc/couchdb/local.ini"]]},{'EXIT',{{badmatch,{error,{error,enoent}}},[{couch_server_sup,start_server,1,[{file,"couch_server_sup.erl"},{line,56}]},{application_master,start_it_old,4,[{file,"application_master.erl"},{line,269}]}]}}}}}},[{couch,start,0,[{file,"couch.erl"},{line,18}]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

我的环境是Erlang:ubuntu 14.04中的R16B03.我使用nginx(启用了ssl).我应该对我的nginx配置文件做些什么吗?

当我这样做时couchdb -b,我得到:

Apache CouchDB needs write permission on the PID file: /var/run/couchdb/couchdb.pid
Run Code Online (Sandbox Code Playgroud)

而且,当我这样做时sudo chown -R couchdb /var/run/couchdb,我得到以下内容:

chown: cannot access ‘/var/run/couchdb’: No such file or directory
Run Code Online (Sandbox Code Playgroud)

ubuntu couchdb ubuntu-14.04

3
推荐指数
1
解决办法
4753
查看次数

Spark 1.2 SQL代码不适用于Spark 1.3 SQL代码

到目前为止,我已经在本地包目录中使用了这个build.sbt

name := "spark27_02"

version := "1.0"

scalaVersion := "2.10.4"

sbtVersion := "0.13.7"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.2.1"

libraryDependencies += "org.apache.spark" %% "spark-streaming" % "1.2.1"

libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.2.1"

libraryDependencies += "org.apache.hadoop" % "hadoop-hdfs" % "2.5.0"
Run Code Online (Sandbox Code Playgroud)

我想试用刚出来的1.3.0版本,所以我使用了所有软件包的1.3.0版本.Spark编译,但SparkSQL没有编译,所以我检查了建议使用的MavenCentral

libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "1.3.0"
Run Code Online (Sandbox Code Playgroud)

但仍然没有工作.我从sbt shell做了更新.顺便说一下使用Scala 2.10.4

我做错了什么傻事?

任何帮助表示赞赏.

编辑引用此build.sbt的spark网页上的示例

name := "Marzia2"

version := "1.0"

scalaVersion := "2.10.4"

sbtVersion := "0.13.7"

libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.3.0"

libraryDependencies += "org.apache.spark" % "spark-streaming_2.10" % …
Run Code Online (Sandbox Code Playgroud)

sbt apache-spark apache-spark-sql

3
推荐指数
1
解决办法
3679
查看次数

sbt,publishLocal,解决错误

我想将我的工件推送到本地ivy存储库,以便将它们用作其他项目中的依赖项.

我的神器的build.scala:

name := "jsonApi"
organization := "com.github.kondaurovdev"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.7"
Run Code Online (Sandbox Code Playgroud)

运行publishLocal任务:

> publishLocal
[info] Packaging /home/user256/Projects/kondaurov/jsonApi/target/scala-2.11/jsonapi_2.11-0.1-SNAPSHOT-sources.jar ...
[info] Wrote /home/user256/Projects/kondaurov/jsonApi/target/scala-2.11/jsonapi_2.11-0.1-SNAPSHOT.pom
[info] :: delivering :: com.github.kondaurovdev#jsonapi_2.11;0.1-SNAPSHOT :: 0.1-SNAPSHOT :: integration :: Mon May 16 12:07:08 MSK 2016
[info] Done packaging.
[info]  delivering ivy file to /home/user256/Projects/kondaurov/jsonApi/target/scala-2.11/ivy-0.1-SNAPSHOT.xml
[info] Main Scala API documentation to /home/user256/Projects/kondaurov/jsonApi/target/scala-2.11/api...
[info] Compiling 51 Scala sources to /home/user256/Projects/kondaurov/jsonApi/target/scala-2.11/classes...
model contains 97 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /home/user256/Projects/kondaurov/jsonApi/target/scala-2.11/jsonapi_2.11-0.1-SNAPSHOT-javadoc.jar ...
[info] Done …
Run Code Online (Sandbox Code Playgroud)

scala publishing ivy sbt

3
推荐指数
1
解决办法
778
查看次数

Laravel中的hasOne关系不起作用?

我有一对一的关系,我想在laravel工作.

我有一个useralert我想要使​​用的表.

的PrimaryKey的UseR表是id在有其他ID叫id_custom.在Alerts表中我id_custom作为主键.

以下是用户模型中的关系:

   public function alerts()
   {
       return $this->hasOne('Alerts', 'id_custom');
   }   
Run Code Online (Sandbox Code Playgroud)

这是警报模型:

class Alerts extends Eloquent
{

    /**
     *
     *
     * The database table used by the model.
     *
     *
     *
     * @var string
     *
     */
    protected $table = 'alerts';
    protected $primaryKey = 'id_custom';

    /**
     *
     *
     * The attributes excluded from the model's JSON form.
     *
     *
     *
     * @var array
     * …
Run Code Online (Sandbox Code Playgroud)

php eloquent laravel-4

2
推荐指数
1
解决办法
3369
查看次数

Scala中嵌套数组上的模式匹配

我想创建一个Any类型的数组,看起来像:

val arr: Array[Any] = Array(Array(1, 2, Array(3)), 4)
Run Code Online (Sandbox Code Playgroud)

然后我想使用此代码使用尾递归使其变平:

def flatten(xs: Array[Any]): Array[Any] = {

    @tailrec
    def makeFlat(xs: List[Any], res: List[Any]): List[Any] = xs match {
      case Nil => res
      case head :: tail => head match {
        case h: Array[Any] => makeFlat(h.toList ::: tail, res)
        case _ => makeFlat(tail, res :+ head)
      }
    }

    makeFlat(xs.toList, Nil).toArray
}  
Run Code Online (Sandbox Code Playgroud)

我正在使用Scala 2.12版本.

当迭代Array(3)从源数组进入内部数组时,模式匹配case h: Array[Any]不起作用.这很奇怪,因为Int延伸Any.我试图调试并意识到这个数组是int[1](原始int数组).

为什么scala决定将它作为原始数组,以及如何弄清楚这种情况?

types scala pattern-matching

2
推荐指数
1
解决办法
498
查看次数