我正在寻找一个regular expression防止特殊字符的东西,只允许字母,数字,短划线( - ),下划线(_)空格.
这个正则表达式工作得很好但它不允许单词之间的空格.
例如,如果输入"123 456",我会定义自定义错误.除了字母,数字,短划线和下划线之外,我如何调整此注册表以允许单词之间的空格.
<input type="text" name="serialNumber" data-ng-model="SerialNumber" ng-pattern="/^[a-zA-Z0-9_-]*$/" maxlength="100"/>
<div data-ng-if="Form.serialNumber.$error.pattern" class="error">Please enter valid serial number</div>
Run Code Online (Sandbox Code Playgroud) 有一个很好的答案来获取字符串的最后一个字符
str='abcd/'
echo "${str: -1}"
Run Code Online (Sandbox Code Playgroud)
如何获取倒数第二个即返回“d”而不是“/”
我想到了以下查询:
context['user_artists'] = Artist.objects.filter(users=current_user).all()
Run Code Online (Sandbox Code Playgroud)
加上模板中的以下用法:
{% if user_artists %}
...
{% for artist in user_artists %}
....
<p class="small">last release: {{ artist.release_groups.last.title }}</p>
<p class="small">date: {{ artist.release_groups.last.release_date }}</p>
Run Code Online (Sandbox Code Playgroud)
对于查询中的每个艺术家,数据库都被点击了3次。我知道可以通过.last在模板中简单保存将其降低到2 ,但这仍然不够快。
我知道我可以这样使用prefetch_related:
Artist.objects.filter(users=current_user).prefetch_realted(`release_groups`).all()
Run Code Online (Sandbox Code Playgroud)
而且我还需要消除他的用法,.last因为它暗示着另一个查询。我可能可以使用模板引擎的slice方法来获取最后一个元素。但是然后我必须对相关关系进行排序:意思是,在访问模板中的它们之前,需要先release_group对其进行排序。这一定不能影响艺术家对象的顺序。release_date
如何才能做到这一点?
如何获取 ag-grid 中应用排序的列列表。有一个 api (onSortChanged) 和一个事件 (sortChanged)。但在这种情况下两者都没有帮助。
我正在尝试进行 hadoop 单节点安装。
我正在关注这篇文章以获取 hadoop 安装说明。我需要做的步骤之一是使用命令格式化 hadoop 文件系统
hduser@dbserver:~/hadoop/conf$ /home/hduser/hadoop/bin/hadoop namenode -format
hduser@dbserver:~/hadoop/conf$ /home/hduser/hadoop/bin/hadoop namenode -format
12/02/06 18:24:31 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = dbserver/127.0.1.1
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 0.20.203.0
STARTUP_MSG: build = http://svn.apache.org/repos/asf/hadoop/common/branches/branch- 0.20-security-203 -r 1099333; compiled by 'oom' on Wed May 4 07:57:50 PDT 2011
************************************************************/
[Fatal Error] core-site.xml:6:1: Content is not allowed in prolog.
12/02/06 18:24:31 FATAL conf.Configuration: error parsing conf file: org.xml.sax.SAXParseException: Content is not allowed in …Run Code Online (Sandbox Code Playgroud) 我有一组单独的json数据,它们每个都有一个时间戳,表示它是以这种确切的格式创建的,例如
[ {"Name": "Jake", "created":"2013-03-01T19:54:24Z" },
{"Name": "Rock", "created":"2012-03-01T19:54:24Z" } ]
Run Code Online (Sandbox Code Playgroud)
因此,我希望在一个函数中使用"created"来计算如果数据从今天开始输入60天或更少,它将以斜体显示.但是,我试过的功能没有效果.我试图在几毫秒内完成计算:
node.append("text")
.text(function(d) { return d.Name; })
.style("font", function (d)
{ var date = new Date(d.created);
var k = date.getMilliseconds;
var time = new Date ();
var n = time.getTime();
if(k > (n - 5184000) ) {return " Arial 11px italic"; }
else { return " Arial 11px " ; }
})
Run Code Online (Sandbox Code Playgroud)
我很好奇我是否真的将数据转换为毫秒.另外,如果我以毫秒为单位获取今天的日期.
提前致谢
编辑:示例 - http://jsfiddle.net/xwZjN/84/
我正试图找到一种方法来使自己成为可能的代码,以便使用多个复杂的查询.
我在MongoDB中有2个文档.第一个是追随者,第二个是事件.
第一个查询:获取特定用户的所有关注者.第二个查询:获取所有关注者的所有事件,并按日期对其进行排序.
我不知道如何进行第二次查询.
也许是这样的:
Event.find({ "$or" : [
{
'userId': followers[0].id,
},
{
'userId': followers[1].id,
},
{
'userId': followers[2].id,
},
]});
Run Code Online (Sandbox Code Playgroud)
但这对我来说并不是一个非常干净的代码.
我想弄清楚如何转换此代码
const Child = ({ match }) => (
<div>
<h3>ID: {match.params.id}</h3>
</div>
)
Run Code Online (Sandbox Code Playgroud)
进入这样的基于类的组件
class Home extends React.Component {
render() {
....
}
}
Run Code Online (Sandbox Code Playgroud)
普通 const 组件我知道如何转换,但我无法理解如何match在基于类的组件中包含参数。
我想将一个指向pcchar 的指针转换为指向piint的点
char *pc;
int *pi;
pi = (int*)pc // compiler complaint about old-style cast
pi = static_cast<int *>(static_cast<void *>(pc)) // no complaint any more but too complex
Run Code Online (Sandbox Code Playgroud)
是否有任何更简单的方法来执行此演员并使编译器保持沉默?
考虑元组列表
[(7751, 0.9407466053962708), (6631, 0.03942129), (7751, 0.1235432)]
Run Code Online (Sandbox Code Playgroud)
如何以第一个数字相似的pythonic方式计算所有元组值的平均值?例如答案必须是
[(7751, 0.532144902698135), (6631, 0.03942129)]
Run Code Online (Sandbox Code Playgroud)