昨天我看到了一个关于在Java中实现经典链表的SO问题.这显然是来自本科数据结构课程的作业.在所有语言中都可以轻松找到列表,树等的问题和实现.
我一直在学习Java lambdas并尝试在每个机会使用它们来获得我的手指.这个问题让我想知道:我如何编写自定义列表或树,以便在所有Java 8 lambda机器中使用它?
我看到的所有示例都使用内置集合.那些对我有用.我更好奇的是教授数据结构的教授应该如何重新思考他们的技术来反映lambdas和函数式编程.
我从一开始就开始了Iterator
,但它看起来并不完整.
有人有建议吗?
我写了一些脚本来获取 aws ec2 实例的所有用户数据,并回显到 local.json。当我安装 node.js 模块时,所有这些都会发生。我不知道如何删除 json 文件中的最后一个逗号。这是 bash 脚本:
#!/bin/bash
export DATA_DIR=/data
export PATH=$PATH:/usr/local/bin
#install package from git repository
sudo -- sh -c "export PATH=$PATH:/usr/local/bin; export DATA_DIR=/data; npm install git+https://reader:secret@bitbucket.org/somebranch/$1.git#$2"
#update config files from instance user-data
InstanceConfig=`cat /instance-config`
echo '{' >> node_modules/$1/config/local.json
while read line
do
if [ ! -z "$line" -a "$line" != " " ]; then
Key=`echo $line | cut -f1 -d=`
Value=`echo $line | cut -f2 -d=`
if [ "$Key" = "Env" ]; then
Env="$Value" …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个需要运行shell脚本的OS X App.这是我的快速代码:
func runTask(arguments: [String]) {
output.string = ""
task = NSTask()
task.launchPath = "/bin/bash"
task.arguments = arguments;
errorPipe = NSPipe()
outputPipe = NSPipe()
task.standardError = errorPipe
task.standardOutput = outputPipe
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(didCompleteReadingFileHandle(_:)), name: NSFileHandleReadCompletionNotification, object: task.standardOutput!.fileHandleForReading)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(didCompleteReadingFileHandle(_:)), name: NSFileHandleReadCompletionNotification, object: task.standardError!.fileHandleForReading)
errorPipe.fileHandleForReading.readInBackgroundAndNotify()
outputPipe.fileHandleForReading.readInBackgroundAndNotify()
task.launch()
}
func didCompleteReadingFileHandle(sender: NSNotification) {
let data: NSData = sender.userInfo![NSFileHandleNotificationDataItem] as! NSData;
let string = NSString(data: data, encoding: NSUTF8StringEncoding)!
// The output property is a NSTextView object
output.string?.appendContentsOf(String(string))
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试调用该runTask
方法: …
我想在声音播放完成后激活一个功能.我认为需要包含NSTimer,但我不确定如何实现它.如果你能给我一些有用的代码,那将会很有帮助.
我正在尝试以编程方式更改选项卡,如下所示:
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#step1" data-toggle="tab" >Step 1</a></li>
<li><a href="#step2" data-toggle="tab" >Step 2</a></li>
</ul>
<div class="tab-content" id="tabs">
<div id="step1" class="tab-pane fade in active">
</div>
<div id="step2" class="tab-pane fade">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS(在一定条件下):
$('a[href="#step2"]').tab('show');
Run Code Online (Sandbox Code Playgroud)
这不起作用,我收到错误消息:TypeError: $(...).tab is not a function
有任何想法吗?
编辑:
可以肯定的是,根据引导程序网站,我还在我的 _Layout 文件中包含了以下内容:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
Run Code Online (Sandbox Code Playgroud) 我正按照以下说明按照说明获取Twitter API的仅限应用程序身份验证的持有人令牌:
https://dev.twitter.com/oauth/application-only
但是,每次我使用curl进行描述的请求时,都会返回"400 Bad request"状态并返回一个空响应体.谁能看到我做错了什么?
我正在curl
考虑这样做,这样可以更容易地做出正确的请求.第一:
$ export CONSUMER_KEY="[...]"
$ export CONSUMER_SECRET="[...]"
Run Code Online (Sandbox Code Playgroud)
显然我已经在那里省略了这些价值观,但那些是我从https://apps.twitter.com/获得的那些我在我创建的应用程序的"密钥和访问权限"选项卡上获得的 - 他们来自这里有两个编辑部分:
然后我提出请求:
curl --trace-ascii curl-trace \
-X POST \
--data 'grant_type=client_credentials' \
-H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \
-H "User-Agent: YNR Twitter ID mapper v0.0.1" \
-H "Authorization: Basic $(echo -n "$CONSUMER_KEY:$CONSUMER_SECRET" | base64)" \
'https://api.twitter.com/oauth2/token'
Run Code Online (Sandbox Code Playgroud)
然而,这始终返回400 Bad请求和空体,即使发送到服务器的内容完全符合文档所要求的内容.为了显示这一点,curl-trace
来自命令文件的相关输出是:
== Info: Hostname was NOT found in DNS cache
== Info: Trying 104.244.42.194...
== Info: Connected to api.twitter.com (104.244.42.194) port 443 (#0)
[... …
Run Code Online (Sandbox Code Playgroud) 我在PyQt(通常是一个测验游戏)中制作了一个多页面应用程序。
因此,现在每当用户犯错或正确回答问题时,它就会调用正确/错误函数。
错误的回答功能:
def incorrect(self):
self.pic3.hide()
self.que1.hide()
self.answ.hide()
self.answ1.hide()
self.answ2.hide()
self.pic4.setGeometry(0, 0, 1280, 800)
self.pic4.show()
self.goback.show()
self.cont = QtGui.QPushButton(self)
self.cont.setObjectName('cont')
self.cont.setStyleSheet("#cont {background-image: url(':/images/Continue.png'); border: none; }"
"#cont:hover { background-image: url(':/images/Continue1.png'); }"
"#cont:pressed { background-image: url(':/images/Continue2.png'); }")
self.cont.setGeometry(980, 610, 300, 300)
self.cont.clicked.connect(self.question2)
self.cont.show()
self.heart2.hide()
#self.heart1.hide()
if ( self.heart2.isHidden() and self.heart1.isHidden() ):
gameover()
else:
pass
Run Code Online (Sandbox Code Playgroud)
所以我要在此函数中创建多个“ cont”小部件,其目的是因为我希望它继续针对特定的问题(如果用户在问题1处失败或成功,则应该继续对问题2进行回答)。
但是为此,应该有一个代码来确定是否从button1或button2调用了不正确的答案功能,单击时两个按钮都连接到同一插槽,如果从button1调用了它,它将显示cont按钮,单击该按钮时将显示question2小部件。 (Question2页)。
但是,如果它是从button2调用的,它将显示cont2按钮,单击该按钮将显示问题3页面。
它在代码中应该看起来像这样:
if self.connected from button1: …
Run Code Online (Sandbox Code Playgroud) 我正在研究一个项目,因为我在javascript中的知识非常有限,我决定使用owlcarousel
.一切都很好,但现在我遇到了问题.
我将点设置为true但它们没有出现.到目前为止我的工作如下:
.container {
width: 90%;
margin: 0 auto;
}
/*Text over image*/
.item {
width: 100%;
}
.item img {
display: block;
max-width:100%;
}
/*Carousel Nav Buttons*/
.carousel-nav-left{
height: 30px;
font-size: 30px;
position: absolute;
top: 0%;
bottom: 0%;
margin: auto 0;
margin-left: -40px;
}
.carousel-nav-right{
height: 30px;
font-size: 30px;
position: absolute;
top: 0%;
bottom: 0%;
right: 0%;
margin: auto 0;
margin-right: -40px;
}
@media (max-width: 700px) {
.carousel-nav-left{
margin-left: -30px;
}
.carousel-nav-right{
margin-right: -30px;
}
.container { …
Run Code Online (Sandbox Code Playgroud)我最近一直在使用 Apple 的 Metal API 进行一些实验,现在我来到了主题问题 -如何在一个 Metal API 场景中使用不同的片段着色器?是否可以?
背景:整个几何基元由一个简单的顶点片段链渲染,其中颜色在内部定义/计算(假设我们有一个立方体,它的所有面都是用所描述的方法渲染的)。接下来,需要使用纹理额外渲染图元的一部分(仅向其中一个面添加一些图片)。
我们是否需要使用不同的片段着色器来实现这一点?我想可以在第一步使用一些默认纹理,这将提供一些解决方案。
你会推荐什么?
//============== 编辑部分更进一步==========//
正如 Warren 建议的那样,我尝试将MTLRenderPipelineState的两个不同对象与两对不同的渲染函数一起使用。使用以下代码我没有得到想要的结果。每个状态都按照单独完成时的预期进行渲染,但一起渲染只能得到第一个渲染的状态。
创作:
id <MTLFunction> fragmentProgram = [_defaultLibrary newFunctionWithName:@"color_fragment"];
// Load the vertex program into the library
id <MTLFunction> vertexProgram = [_defaultLibrary newFunctionWithName:@"lighting_vertex"];
// Create a vertex descriptor from the MTKMesh
MTLVertexDescriptor *vertexDescriptor = MTKMetalVertexDescriptorFromModelIO(_boxMesh.vertexDescriptor);
vertexDescriptor.layouts[0].stepRate = 1;
vertexDescriptor.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
// Create a reusable pipeline state
MTLRenderPipelineDescriptor *pipelineStateDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
pipelineStateDescriptor.label = @"MyPipeline"; …
Run Code Online (Sandbox Code Playgroud)