我有一个字符串
"asdf a b c2 "
Run Code Online (Sandbox Code Playgroud)
我想将它拆分成这样的数组:
["asdf", " ", "a", " ", " ", "b", " ", "c2", " "]
Run Code Online (Sandbox Code Playgroud)
使用string.split(" ")删除空格,结果如下:
["asdf", "a", "", "b", "c2"]
Run Code Online (Sandbox Code Playgroud)
我想插入额外的分隔符,例如
string.replace(/ /g, "| |").replace(/||/g, "|").split("|");
Run Code Online (Sandbox Code Playgroud)
但这会产生意想不到的结果.
我有一个响应式幻灯片式布局,每个图像下方都有标题.
我试图让标题与图像的宽度相同.问题是图像被缩放以垂直适合浏览器,我的标题是在缩放之前获得图像的宽度.
#big_container {
display:block;
position:relative;
width:100%;
padding-bottom:40%;
white-space:nowrap;
overflow-x:scroll;
overflow-y:hidden;
}
#big_container>div {
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
}
.little_container {
display:inline-block;
height:100%;
width:100%;
text-align:center;
}
#big_container figure {
display:inline-block;
height:100%;
margin:0;
}
figure img {
max-height:calc(100% - 40px); /* subtract height of caption */
}
figcaption {
display:block;
width:100%;
text-align:left;
box-sizing:border-box;
margin:0;
padding:10px;
line-height:20px;
background-color:#ddd;
}Run Code Online (Sandbox Code Playgroud)
<div id="big_container">
<div>
<div class="little_container">
<figure>
<img src="http://placekitten.com/500/440">
<figcaption>
have a kitty!!1
</figcaption>
</figure>
</div>
<div class="little_container">
<figure>
<img src="http://placekitten.com/450/400">
<figcaption> …Run Code Online (Sandbox Code Playgroud)我正在尝试使用asyncio来进行异步客户端/服务器设置.
出于某种原因,我AssertionError: yield from wasn't used with future在运行客户端时得到了.
搜索此错误并未发生太多变化.
这个错误意味着什么,是什么导致它?
#!/usr/bin/env python3
import asyncio
import pickle
import uuid
port = 9999
class ClientProtocol(asyncio.Protocol):
def __init__(self, loop):
self.loop = loop
self.conn = None
self.uuid = uuid.uuid4()
self.other_clients = []
def connection_made(self, transport):
print("Connected to server")
self.conn = transport
m = "hello"
self.conn.write(m)
def data_received(self, data):
print('Data received: {!r}'.format(data))
def connection_lost(self, exc):
print('The server closed the connection')
print('Stop the event loop')
self.loop.stop()
# note that in my use-case, main() is …Run Code Online (Sandbox Code Playgroud) 我正在创建一个新的按钮元素
$('<button>Remove Entry</button>', { 'type': 'button', 'class': 'delete_button' });
Run Code Online (Sandbox Code Playgroud)
然而,似乎没有定义type或class属性,控制台打印错误说this.parent()不是一个函数(虽然我很肯定我启用了jquery)
我担心我做了一些简单而愚蠢的事,但我似乎找不到任何错误.
我试图这样做:
<div class="figure">
<img src="/some/image.jpg">
<p class="caption">
<span class="caption-text">Some caption of any length</span>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
因此,标题位于阴影框中,与图像的宽度相同.请注意,.figure有时可以在<td>表格内部,以防万一.它也不应超过父元素的宽度(在必要时缩小图像).
这是我到目前为止所拥有的:
.caption-text {
font-size: 14px;
font-family: Lato, proxima-nova, 'Helvetica Neue', Arial, sans-serif;
font-weight: normal;
line-height: 0px;
}
.figure {
max-width: 100%;
display: inline-block;
position: relative;
}
.figure img {
vertical-align: top;
margin-bottom: 3px;
}
.caption {
display: block;
width: 100%;
position: absolute;
padding: 10px;
background-color: #e3e3e3;
box-sizing: border-box;
margin: 0;
}Run Code Online (Sandbox Code Playgroud)
<div style="width:500px">
<h1>Some Title</h1>
<!--part I want to style--> …Run Code Online (Sandbox Code Playgroud)我刚开始使用带有android的cordova.
添加插件时遇到问题.
我使用cordova插件从Win7中的cmd添加org.apache.cordova.camera.它已添加但不在cordova_plugins.js文件中.
当我在cmd中键入cordova运行android时,文件正在更新,但随后我的所有代码都被删除并替换为基于Web的骨架应用程序.为什么会这样?如何自动更新此文件?
这就是我的cordova_plugins.js的样子:
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/org.apache.cordova.dialogs/www/notification.js",
"id": "org.apache.cordova.dialogs.notification",
"merges": [
"navigator.notification"
]
},
{
"file": "plugins/org.apache.cordova.dialogs/www/android/notification.js",
"id": "org.apache.cordova.dialogs.notification_android",
"merges": [
"navigator.notification"
]
},
{
"file": "plugins/org.apache.cordova.vibration/www/vibration.js",
"id": "org.apache.cordova.vibration.notification",
"merges": [
"navigator.notification"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
"org.apache.cordova.dialogs": "0.2.5",
"org.apache.cordova.vibration": "0.3.6"
}
// BOTTOM OF METADATA
});
Run Code Online (Sandbox Code Playgroud)
如你所见,没有相机插件.它被添加到我的项目中,但不在此文件中,这是因为当我尝试在我的js文件中使用它时它不起作用.
我希望你明白我在说什么.
我看到GM_getValue未定义的错误,但我没有补助GM_getValue和GM_setValue与定义的默认值.
示例代码:
// ==UserScript==
// @name SO_test
// @include https://stackoverflow.com/*
// @version 1
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
// Get jQuery thanks to this SO post:
// https://stackoverflow.com/a/3550261/2730823
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function main() {
$("#wmd-input").on("contextmenu", function(e) {
e.preventDefault();
console.log("GM_getValue: " + GM_getValue("extra_markdown", True));
});
}
addJQuery(main); …Run Code Online (Sandbox Code Playgroud) 我试图通过以下方式获得两个日期之间的差异:
date -d $(echo $(date -d "Sun Dec 29 02:22:19 2013" +%s) - $(date -d "Sun Dec 28 03:22:19 2013" +%s) | bc)
Run Code Online (Sandbox Code Playgroud)
但是,这会回来
date: invalid date ‘82800’
Run Code Online (Sandbox Code Playgroud)
为什么会这样,我怎样才能得到理想的结果呢?
运行这样的递归函数(在gcc 7.3.1中编译):
#include <stdio.h>
int arr[] = {5,1,2,6,7,3};
int arraySize = 6;
int recfind(int value, int index)
{
if (arr[index] == value)
return 1;
if (index >= arraySize)
return 0;
// return recfind(value, ++index);
recfind(value, ++index);
}
int main() {
printf("found 6? %d\n", recfind(6, 0));
printf("found 9? %d\n", recfind(9, 0));
}
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
found 6? 1
found 9? 0
Run Code Online (Sandbox Code Playgroud)
为什么这样做?由于recfind未返回递归调用的结果,所以如何选择更高级别调用的返回值?
css ×2
html ×2
javascript ×2
jquery ×2
python ×2
android ×1
bash ×1
c ×1
compression ×1
cordova ×1
css3 ×1
date ×1
file ×1
filesize ×1
filesystems ×1
greasemonkey ×1
recursion ×1
return ×1
return-value ×1
shell ×1