我查看了大量参考资料,发现 C# 通过 lambda 支持嵌套函数,但我对 C#(以及 .NET)完全陌生。我想编写一个洪水填充实现,其中嵌套子函数可以访问父函数的参数。
理想情况下,它应该是这样的:
private void StartFloodFill(color,otherstuff,pixel)
{
function Recursion(pixel,color)
{
do(otherstuff);
//etc...
Recursion(pixel,color);
}
}
Run Code Online (Sandbox Code Playgroud)
电话Recursion(pixel,color);是我困惑的地方。我无法从函数内部访问对该函数的引用。
我知道应该有一个解决方法,但我不知道那是什么。如何在 C# 中实现上面演示的递归函数?
我正在使用 Node.js 的 Fluent-ffmpeg 模块来转换音频文件。我有一个 .mp3 文件,我想将其转换为 .wma
看起来是这样的:
var proc = new ffmpeg({
source: 'file.mp3',
nolog: false
}).toFormat('wma')
.saveToFile('file.wma', function(stdout, stderr)
{
console.log(stderr);
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,我收到错误:
Run Code Online (Sandbox Code Playgroud)Requested output format 'wma' is not a suitable output format
这是整个错误日志:
ffmpeg version 0.8.9-4:0.8.9-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
built on Nov 9 2013 19:25:10 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead. …Run Code Online (Sandbox Code Playgroud) 我试图通过getUserMedia获取Android设备的相机流来做一些基本的事情.根据我的理解,这应该在我运行的Android Lollipop上得到支持,但即使权限设置为允许视频和音频,我的媒体流请求也会被自动拒绝.
所以我尝试使用Crossonic和Ionic,我可以获得媒体流.数据只是空的.据我所知,这应该得到支持.有没有其他人有使用Cordova/Ionic获取相机视频流数据的经验?
我的代码看起来像这样:
function pathfind (start,end,map)
{
this.Init = function ()
{
this.open_node = new Array();
this.open_node.push(start);
console.log(this.open_node);
this.Loop();
}
this.Loop = function ()
{
//Some code here
}
this.Init();
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,当我将"start"推入this.open_node并记录其值时,我得到"未定义".但是,经过一些错误测试,我意识到这个评论出来了.Loop(); 在this.Init中导致push正常运行,console.log按原样返回[start].任何人都可以解释为什么会发生这种行为?
编辑:我在打电话
pathfind({x:2,y:2},{x:24,y:24},parsemap(25,25));
Run Code Online (Sandbox Code Playgroud) 我从其他Stack Overflow帖子中读到,您可以使用正则表达式来路由各种URL.我之前从未真正使用过RegExps,所以我需要一些帮助.如何路由以/ lobby /后跟十位数字开头的所有网址?像这样
app.get("/lobby/0000000000", function (req, res) ...
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在使用 PeerJS 及其云托管服务器来构建 WebRTC 应用程序。这是我的代码:
navigator.getMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
window.URL = window.URL || window.webkitURL;
var callSettings = {
video: {
mandatory: {
maxWidth: 400,
maxHeight: 300
}
},
audio: true
};
$(document).ready(function ()
{
var videoel = $("#teacher-stream")[0];
$(document).on('click', ".start-call", function () //A button initiates call
{
var peerID = $(this).data('id'); //Button contains ID of peer
navigator.getMedia(callSettings, function (stream)
{
var call = peer.call(peerID, stream);
call.on('stream', function(remoteStream)
{
console.log('stream!');
videoel.src = window.URL.createObjectURL(remoteStream);
//On stream …Run Code Online (Sandbox Code Playgroud) 完全遵循文档,我正在尝试使用流将视频转换写入文件.
var FFmpeg = require('fluent-ffmpeg');
var fs = require('fs');
var outStream = fs.createWriteStream('C:/Users/Jack/Videos/test.mp4');
new FFmpeg({ source: 'C:/Users/Jack/Videos/video.mp4' })
.withVideoCodec('libx264')
.withAudioCodec('libmp3lame')
.withSize('320x240')
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Processing finished !');
})
.writeToStream(outStream, { end: true });
Run Code Online (Sandbox Code Playgroud)
当我使用.saveToFile()时,这种转换非常有效,但会返回
发生错误:ffmpeg退出代码1
当我运行此代码时.我在Windows上使用的是64位的ffmpeg构建从8.1 64位在这里.
我正在尝试将node_module导入TypeScript文件.我正在使用angular2-webpack-starter改编我的项目结构.
import ace from 'brace';
Run Code Online (Sandbox Code Playgroud)
在我的一个文件中给了我
找不到模块'大括号'.
但
var ace = require('brace');
Run Code Online (Sandbox Code Playgroud)
工作良好.根据这个问题,我不应该有任何问题.
我的webpack配置文件是从angular2-webpack-starter复制的.我的tsconfig.json如下
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
},
"files": [
"src/bootstrap.ts",
"src/vendor.ts",
"src/polyfills.ts"
],
"filesGlob": [
"./src/**/*.ts",
"!./node_modules/**/*.ts"
],
"compileOnSave": false,
"buildOnSave": false
}
Run Code Online (Sandbox Code Playgroud)
为什么一个工作而另一个工作?
我仍在计算反应式编程,所以我很确定这是非常基本的,但是对于初学者来说,流转换的数量非常大.
我正在从DOM事件创建一个Observable.此事件应依次触发REST调用,并且在解决此事件之前,将忽略所有其他DOM事件.
const stream = Observable.fromEvent(document, 'some-event')
stream
.flatMap(() => httpRestService())
.subscribe(() => {
})
Run Code Online (Sandbox Code Playgroud)
在最后一个HTTP承诺解决之前,如何忽略流中的事件?
DOM event
A - - - - B - - - - C
HTTP event
D ...........done - C
Run Code Online (Sandbox Code Playgroud) 我仍然无法确定如何在JavaScript中管理范围.在这个特定的例子中,我有一个包含某些属性的绘图函数和一个需要根据数组绘制线条的函数.
function Draw (canvas)
{
this.ctx = canvas.getContext('2d');
this.street_size = 20;
}
Draw.prototype.street = function (MAP)
{
MAP.forEach(function (name)
{
this.ctx.moveTo(name.start.x,name.start.y);
this.ctx.lineTo(name.end.x,name.end.y)
this.ctx.stroke();
});
}
Run Code Online (Sandbox Code Playgroud)
当然,forEach函数中的"this.ctx"返回"undefined".如何确保将Draw()的变量传递给forEach函数(不执行类似ctx = this.ctx的操作)?
我有一个带有百分比宽度的列的表格。如果这些单元格中的内容超过该百分比宽度,我希望它被省略号截断。
根据表格单元格中的 CSS 文本溢出?我应该使用 max-width 属性,但根据如何使用百分比设置表格单元格的最大宽度?我不能用百分比来做。
table {
width: 100%;
}
table td {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
table tr td:nth-of-type(1) {
width: 20%;
}
table tr td:nth-of-type(2) {
width: 30%;
}
table tr td:nth-of-type(3) {
width: 50%;
}Run Code Online (Sandbox Code Playgroud)
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我已经尝试了一百万种方法让护照与我的申请一起工作无济于事.每次尝试登录每个提供商(Facebook,谷歌,Twitter,微软)都会导致如下错误:
XMLHttpRequest cannot load https://www.google.com/accounts/o8/ud?openid.mode=checkid_setup&openid.ns=h…2F%2Ftest.sl%2Fauth%2Fgoogle%2Freturn&openid.realm=http%3A%2F%2Ftest.sl%2F.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://test.sl' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
我的应用程序并不复杂,这里是我的服务器代码的摘要.
var express = require('express');
var ppGoogle = require('passport-google-oauth').OAuth2Strategy;
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/public'));
//There's more config
app.listen(7230);
app.get('/auth/google', passport.authenticate('google'));
app.get('/auth/google/return', passport.authenticate('google', {
successRedirect: '/main',
failureRedirect: '/login'
}));
passport.use(new ppGoogle({
clientID: '',
clientSecret: '',
callbackURL: 'http://test.sl/auth/google/return'
},
function (accessToken, refreshToken, profile, done)
{
console.log('done');
}));
Run Code Online (Sandbox Code Playgroud)
谁知道解决方案?这件事让我抓狂.
我想为我的h1标签添加一个更粗的下划线,所以我在多个Stack Overflow问题中建议使用"border-bottom".但是,边框扩展到文本之外,因此我决定添加display属性"inline-block"以使边框符合文本的边界.然而,这使得元素在内容之后缺少换行符.我知道我总是可以添加"br"标签,但我更愿意将其保留在我的造型中.有什么我能做的吗?这是我目前的CSS:
h1
{
font-weight:normal;
margin-bottom:5px;
border-bottom: 2px solid;
display: inline-block;
}
Run Code Online (Sandbox Code Playgroud) javascript ×5
node.js ×3
css ×2
express ×2
ffmpeg ×2
android ×1
audio ×1
c# ×1
console ×1
cordova ×1
cors ×1
execution ×1
flood-fill ×1
getusermedia ×1
html ×1
import ×1
ionic ×1
passport.js ×1
peerjs ×1
prototype ×1
recursion ×1
regex ×1
routes ×1
rxjs ×1
scope ×1
stream ×1
typescript ×1
underline ×1
webcam ×1
webpack ×1
webrtc ×1