小编cyb*_*ron的帖子

使用 CPAN Perl 安装包

我正在尝试Perl从命令行安装一些库:

perl -MCPAN -e "install XML::Tidy"
Run Code Online (Sandbox Code Playgroud)

但是,我无法:

Warning (usually harmless): 'YAML' not installed, will not store persistent state
Running Build test
t\00pod.t ..... ok
t\00podc.t .... Can't locate Test/Pod/Coverage.pm in @INC (@INC contains: C:\xam
pp\perl\bin\.cpan\build\XML-Tidy-1.12.B55J2qn-y5sVpz\blib\lib C:\xampp\perl\bin\
.cpan\build\XML-Tidy-1.12.B55J2qn-y5sVpz\blib\arch C:/xampp/perl/lib C:/xampp/pe
rl/site/lib .) at t\00podc.t line 1.
BEGIN failed--compilation aborted at t\00podc.t line 1.
t\00podc.t .... Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t\00small.t ... Base class package "XML::XPath" is empty.
    (Perhaps you need to 'use' the …
Run Code Online (Sandbox Code Playgroud)

xampp perl

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

正则表达式的行为不符合预期

我有以下功能,它应该读取.html文件并搜索<input>标签,并将<input type='hidden'>标签注入要显示在页面中的字符串.但是,这个条件永远不会满足:(例如,if语句永远不会被执行.)我的正则表达式出了什么问题?

 def print_choose( params, name ):

   filename = path + name
   f = open( filename, 'r' )
   records = f.readlines()
   print "Content-Type: text/html"
   print
   page = ""
   flag = True
   for record in records:
        if re.match( '<input*', str(record) ) != None:
            print record
            page += record
            page += "<input type='hidden' name='pagename' value='psychology' />"
        else:
            page += record

   print page
Run Code Online (Sandbox Code Playgroud)

谢谢

html python regex

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

Paramiko不执行命令或shell - Python

我正在使用Paramikossh在两台服务器之间运行命令.我的"Master"服务器是一个Fedora 18盒子,我"Slave"是一Windows 7台机器.在其他运行ssh服务器的Windows 7机器中,我安装了FreeSSHd.配置完成后freesshd我可以ssh从Fedora 18机器进入Windows机器并执行命令dir.但是,当我尝试使用时Paramiko,我没有同样的运气:

import paramiko
import os
import errno

"""
written by Philippe Ribeiro

class Connection
stabilishes the ssh connection between two servers
allowing the executing of commands remotely
"""
class Connection:

    def __init__( self, hostname, username, password):
        """Create a ssh client using the paramiko library
        """
        self.host = hostname
        self.user = …
Run Code Online (Sandbox Code Playgroud)

python ssh

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

测量加载页面的时间 - Python

我正在使用webbrowser,所以我可以打开一个 html 来进行我目前正在进行的性能测试。这一小段代码是自动化的开始。该函数的目标perf_measure是返回url完全加载页面所用的时间。

import webbrowser

def perf_measure(url=""):

    try:
        webbrowser.open(url)

    except webbrowser.Error, e:
        print "It couldn't open the url: ", url

url = "www.google.com"
open_browser(url)
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我只需要值,以秒为单位,例如:

www.google.com  Total time to load page in (secs): 2.641
Run Code Online (Sandbox Code Playgroud)

python

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

将 javascript 日期正确格式化为 MySQL

我正在创建一个基于 JavaScript 的日历,使用 full-calendar.js 作为主干。因此,在其他将新event插入 MySQL 数据库中,我有以下代码片段:

$.post("http://localhost/calendar/index.php/calendar/insert_event", 
      { 
        title  : title,
        start  : start,
        end    : end,
        allDay : allDay,
        url    : ''
      }, 
      function(answer) {
        console.log(answer);
      }
); 
Run Code Online (Sandbox Code Playgroud)

startend日期是简单Date()对象:

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
Run Code Online (Sandbox Code Playgroud)

calendar.php控制器中,我得到以下输出:

{"title":"lunch",
 "start":"Tue Oct 08 2013 08:00:00 GMT-0700 (Pacific Standard Time)",
 "end":"Tue Oct 08 2013 08:30:00 GMT-0700 (Pacific Standard Time)",
 "allDay":"false",
 "url":""} …
Run Code Online (Sandbox Code Playgroud)

javascript php mysql codeigniter

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

通配符类型匹配 - Java

为什么以下代码不能编译?

public static <T> void foo_test(List<? extends T> src, List<T> dest) {
   for (T o : src) {
        dest.add(o);
   }
}

public static void main(String [] args) {
   List<Number> numbers = new ArrayList<Number>();
   List<Integer> integers = new ArrayList<Integer>();
   foo_test(numbers, integers);
}
Run Code Online (Sandbox Code Playgroud)

java generics

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

实现alpha等价 - Haskell

那么让我来定义一些事情:

type Name = String

data Exp = Var Name 
         | App Exp Exp
         | Lam Name Exp
  deriving (Eq,Show,Read)
Run Code Online (Sandbox Code Playgroud)

我想定义alpha-equivalence,这是

alpha_eq :: Exp -> Exp -> Bool
-- The terms x and y are not alpha-equivalent, because they are not bound in a lambda abstraction 
alpha_eq (Var x) (Var y) = False
alpha_eq (Lam x e1) (Lam y e2) = False
alpha_eq (App e1 e2) (App e3 e4) = False
Run Code Online (Sandbox Code Playgroud)

例如Lam "x" (Var "x"),Lam …

haskell

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

定义Monad运算符

在Haskell的Monads中,我可以轻松地将运算符定义(>=>)为:

(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
f >=> g = \x -> f x >>= g
Run Code Online (Sandbox Code Playgroud)

我也知道,(>>=)可使用表示(>=>):我们称(>>=)作为(..):

(..) :: Monad m => m a -> (a -> m b) -> m b
m .. k = m >=> \_ -> k
Run Code Online (Sandbox Code Playgroud)

然而有些事情是不对的...有人能指出什么?

monads haskell

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

如何获得C中的"mm信号量"?

如果要remap_pfn_range在实现mmap的自定义内核驱动程序中使用该函数,您就知道必须获取'mm信号量'.但目前尚不清楚如何通过我公开发现的例子来做到这一点.我认为编辑可用的示例会对社区有所帮助,我愿意这样做,但我不知道从哪里开始.

根据文档:只有在调用时保持mm信号量,这才是安全的.

c linux-kernel

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

抑制 argparse 错误消息 - Python

我正在使用 argparse 来解析命令行参数。然而此时,我有一个不寻常的请求:我想抑制错误信息。例如:

 # !/usr/bin/env python
 try:
        parser = argparse.ArgumentParser(description='Parse')
        parser.add_argument('url', metavar='URL', type=str, nargs='+', 
                            help='Specify URL')
 except:
        print("Invalid arguments or number of arguments")
        exit(2)
Run Code Online (Sandbox Code Playgroud)

所以我只希望打印出来"Invalid arguments or number of arguments",别无其他。但是,然后我执行代码,例如:

./foo --BOGUS
Run Code Online (Sandbox Code Playgroud)

我收到完整的使用信息:

usage: foo [-h]
foo: error: too few arguments
foo: Invalid arguments or number of arguments 
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python command-line arguments

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