小编use*_*084的帖子

打破子程序

什么是打破子程序并继续处理脚本其余部分的最佳方法?

#!/usr/bin/perl
use strict;
use warnings;

&mySub;

print "we executed the sub partway through & continued w/ the rest 
of the script...yipee!\n";

sub mySub{

    print "entered sub\n";

    #### Options
    #exit; # will kill the script...we don't want to use exit
    #next; # perldoc says not to use this to breakout of a sub
    #last; # perldoc says not to use this to breakout of a sub
    #any other options????

    print "we should NOT see this\n";

}
Run Code Online (Sandbox Code Playgroud)

perl

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

match()对()不起作用,但像'%$ s%'那样

我的表格中有一个全文字段.其中一行是:

"this is the dog that ran over there"
Run Code Online (Sandbox Code Playgroud)

我有以下mysql语句:

SELECT * 
  FROM `table` 
 WHERE MATCH (column) AGAINST ('dog that ran')
Run Code Online (Sandbox Code Playgroud)

...返回0条记录

SELECT * 
  FROM `table` 
 WHERE `column` LIKE '%dog that ran%'
Run Code Online (Sandbox Code Playgroud)

...返回1条记录

为什么不同?他们应该都返回1条记录,对吗?

mysql sql full-text-search sql-like

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

如何(安全地)存储cookie并在用户重新打开浏览器时保持用户登录

如何在仍能访问该密码的同时将用户密码安全地存储在cookie中?我有一个cookie存储密码的用户名和sha1版本但是当我尝试检索它们时,我得到(如预期的)用户名和密码的sha1版本,而不是密码本身.谢谢!

<!DOCTYPE html>
<html>
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
  </head>
<body>

<form id='my_login' name='my_login' action='<?php htmlentities($_SERVER['PHP_SELF'])?>' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
 <label for='username'>Username: </label>
 <input id='username' type='text' name='username' value='<?php if(isset($_COOKIE['username'])) echo htmlentities($_COOKIE['username']); ?>'/>
 <br/>
 <label for='username'>Password: </label>
 <input id='password' type='password' name='password' value='<?php if(isset($_COOKIE['password'])) echo htmlentities($_COOKIE['password']); ?>'/>
 <br/>
  <label for "set_cookie">Remember Me</label>
 <input type="checkbox" name="set_cookie" id="set_cookie" value="1"/>
 <button id='submit' type='submit' name='submit'>login</button>
   </form>

  </body>
  <html>
Run Code Online (Sandbox Code Playgroud)

html php

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

我如何获得纽约市时间?

我经常旅行,但住在纽约,我正试图显示纽约时间,无论我在哪里.我怎么用Python做到这一点?我有以下,这不起作用,给我错误:

 `'module' object is not callable` 
Run Code Online (Sandbox Code Playgroud)

此外,我不确定下面的方法是否会在夏令时之间正确更新:

import pytz
utc = pytz.utc
utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
eastern = pytz.timezone('US/Eastern')
loc_dt = utc_dt.astimezone(eastern)
fmt = '%Y-%m-%d %H:%M:%S %Z%z'
loc_dt.strftime(fmt)
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
3
解决办法
6181
查看次数

如何将会话变量设置为数据库中的值?

newb to python和pyramid/pylons.用户登录后,我想在我的数据库中获取一些数据并将其存储在会话变量中.我已经能够用remember()存储用户的登录ID.使用request.session,我可以设置一个会话变量,只要它是一个字符串,但如果我尝试从我的数据库中检索一些东西,我会收到一个错误:"BadPickleGet: ".这是我的观点的相关部分:

if 'form.submitted' in request.params:
        login = request.params['login']
        password = request.params['password']
        if User.check_password(login, password):
            headers = remember(request, login) # ie dave
            session = request.session
            #session['myvar'] = 'somethinghardcoded' # this works!
            session['myvar'] = User.myfield # this doesn't work!
            session.save()
            return HTTPFound(location=came_from, headers=headers)
Run Code Online (Sandbox Code Playgroud)

python pylons pyramid

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

更新时密码未加密

作为python的新手,我不太清楚为什么我会得到不一致的结果.我注册了一个用户,我的表中的密码最终成为哈希版本.当用户更新其密码时,表中的密码最终为未散列的版本.显然,我想要哈希版本.我究竟做错了什么?(如果重要的话,我正在使用SQLAlchemy和mysql.)

我有以下内容:

def hash_password(password):
    blah, blah, blah # hash my password here
    return hashed_password

class User(Base):
    __tablename__ = 'mytable'
    email = Column('email')
    _password = Column('password')

    def _get_password(self):
        return self._password

    def _set_password(self, password):
        self._password = hash_password(password)
    password = property(_get_password, _set_password)
    password = synonym('_password', descriptor=password)

    def __init__(self, password="", email=""):
        self.email = email
        self.password = password
    @classmethod
    def register(cls, email, password):
        return DBSession.add(User(email=email,password=password)) # this correctly hashes the password

    @classmethod
    def update(cls, email, password):
        return DBSession.query(cls).filter(cls.email == email).update({'password': password}) #password ends up being …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy pyramid

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

如何使文本与图标不重叠?

我有一个HTML输入和一个字体真棒图标.我不想限制用户输入的文本量.相反,我想这样做,以便文本不重叠.fa-comment-o ...任何额外的文本将被隐藏(不是截止,只是隐藏).我可以给出的最好的例子是当你在谷歌中输入一些东西时,文本不会与麦克风重叠,如果关闭它们也不会切割(它们使用图像而我使用的是字体图标).

这是我的小提琴

<div id="container">
    <input id="input"  value="This is some really long text that will almost certainly not fit within the text box. What I'd like to do is not bleed beyond the comment icon."/>
    <i class="fa fa-comment-o"></i>
</div>


#input{
    width: 300px;
    height: 25px;
    margin-right: -30px;

}

.fa-comment-o{
  font-size: 16px;
  color: #333;
  cursor: pointer;
  right: 10px;

}
Run Code Online (Sandbox Code Playgroud)

html css font-awesome

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

Nginx 反向代理到主机中的应用程序

我有一个在 Docker 5000 端口上运行的应用程序。我试图通过 Docker compose 在 nginx 中运行反向代理,但无法与主机的端口 5000 通信。在我的 docker-compose.yml 文件中,我有:

ports:
  - 80:80
  - 443:443
  - 5000:5000
Run Code Online (Sandbox Code Playgroud)

当我尝试运行它时,我得到:

ERROR: for nginx  Cannot start service nginx: driver failed programming external connectivity on endpoint nginx (374026a0d34c8b6b789dcd82d6aee6c4684b3201258cfbd3fb18623c4101): Error starting userland proxy: listen tcp 0.0.0.0:5000: bind: address already in use
Run Code Online (Sandbox Code Playgroud)

如果我注释掉,- 5000:5000我会得到:

[error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream
Run Code Online (Sandbox Code Playgroud)

如何从 Docker nginx 容器连接到主机中已经运行的应用程序?

编辑:

我的 nginx.conf 文件

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events …
Run Code Online (Sandbox Code Playgroud)

webserver reverse-proxy nginx go docker

0
推荐指数
2
解决办法
3978
查看次数